Skip to content

Commit

Permalink
refactor(rabbit-filters): remove debug logging for clarity and mainta…
Browse files Browse the repository at this point in the history
…inability

This commit removes unnecessary console logging from the hasValidTrackingInPeriod and filterRabbitsForYearlyReport functions in the rabbit_filters module. The changes enhance code cleanliness and improve maintainability without altering the core functionality. These updates aim to streamline the codebase and improve performance by eliminating redundant debug statements.
  • Loading branch information
jhagberg committed Jan 1, 2025
1 parent a513dec commit b7f1853
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions frontend/src/utils/rabbit_filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const hasValidTrackingInPeriod = (
individual: Individual,
reportYear: number
): boolean => {
console.log(`Checking tracking for ${individual.number}:`);
// Remove duplicate tracking entries and sort
const uniqueTrackings = Array.from(
new Map(
Expand All @@ -69,18 +68,13 @@ export const hasValidTrackingInPeriod = (
(a: HerdTracking, b: HerdTracking) =>
new Date(b.date).getTime() - new Date(a.date).getTime()
);
console.log(
"Tracking dates:",
sortedTrackings.map((t) => t.date)
);

// Get the report year end date
const yearEnd = new Date(`${reportYear}-12-31T23:59:59`);
yearEnd.setHours(0, 0, 0, 0);

// If rabbit has a death note but no death date, consider it inactive
if (individual.death_note && !individual.death_date) {
console.log("Has death note but no death date - invalid");
return false;
}

Expand All @@ -89,7 +83,6 @@ export const hasValidTrackingInPeriod = (
const deathDate = new Date(individual.death_date);
deathDate.setHours(0, 0, 0, 0);
if (deathDate <= yearEnd) {
console.log("Died before year end - invalid");
return false;
}
}
Expand All @@ -101,7 +94,6 @@ export const hasValidTrackingInPeriod = (
return trackDate >= yearEnd;
});

console.log("Has valid tracking on/after year end:", hasValidTracking);
return hasValidTracking;
};

Expand Down Expand Up @@ -197,11 +189,8 @@ export function filterRabbitsForYearlyReport(
const yearEndDate = new Date(`${reportYear}-12-31`);

for (const individual of individuals) {
console.log(`\nChecking rabbit ${individual.number}:`);

// Skip rabbits without certificates
if (!individual.certificate && !individual.digital_certificate) {
console.log("No certificate - skipping");
continue;
}

Expand All @@ -210,13 +199,11 @@ export function filterRabbitsForYearlyReport(
? new Date(individual.death_date)
: null;
if (deathDate && deathDate <= yearEndDate) {
console.log("Died before year end - skipping");
continue;
}

// Skip rabbits with death note but no death date (considered dead)
if (individual.death_note && !individual.death_date) {
console.log("Has death note but no death date - skipping");
continue;
}

Expand All @@ -226,18 +213,14 @@ export function filterRabbitsForYearlyReport(
currentHerdId,
yearEndDate
);
console.log("Belongs to herd at year end:", belongsToHerd);
if (!belongsToHerd) {
console.log("Not in herd at year end - skipping");
continue;
}

// Skip rabbits born after the report year
if (individual.birth_date) {
const birthYear = new Date(individual.birth_date).getFullYear();
console.log("Birth year:", birthYear, "Report year:", reportYear);
if (birthYear > reportYear) {
console.log("Born after report year - skipping");
continue;
}
}
Expand All @@ -249,13 +232,10 @@ export function filterRabbitsForYearlyReport(
endDate,
reportYear
);
console.log("Has valid measurements:", hasValidMeasurements);

if (hasValidMeasurements) {
console.log("Adding to canSkip");
canSkip.push(individual);
} else {
console.log("Adding to needUpdate");
needUpdate.push(individual);
}
}
Expand Down

0 comments on commit b7f1853

Please sign in to comment.