why is it resetting call records?

This commit is contained in:
Rory& 2025-09-20 22:02:57 +02:00
parent a15e296918
commit fb006a3c46
2 changed files with 15 additions and 10 deletions

View file

@ -91,9 +91,11 @@ function updateRecords(callStats, records) {
if (!records.callRecord) {
records.callRecord = { date: yesterdayDateString, count: callStats.totalCallsMade };
isNewRecord = true;
console.warn("No previous call record found, initializing new record.");
} else if (allTimeRecord.count < callStats.totalCallsThisMonth) {
allTimeRecord.count = callStats.totalCallsThisMonth;
isNewRecord = true;
console.log(`New all-time record: ${allTimeRecord.count} calls on ${yesterdayDateString}, previous record was ${records.callRecord.count} calls on ${records.callRecord.date}`);
}
callStats.allTimeRecord = `${allTimeRecord.count} calls on ${allTimeRecord.date}`;

View file

@ -2,16 +2,19 @@ import fs from "fs";
export class Records {
constructor(records = {}) {
if (typeof records.records === "object") for (const [ key, value ] of Object.entries(records.records)) {
const oldTableMatches = key.match(/^monthly_total_(\d{4})-(\d{2})$/);
if (oldTableMatches) {
const year = oldTableMatches[1];
const month = oldTableMatches[2];
if (!this.monthlyTotals) this.monthlyTotals = {};
if (!this.monthlyTotals[year]) this.monthlyTotals[year] = {};
this.monthlyTotals[year][month] = value;
} else if (key === "record_calls" && typeof value === "object" && value !== null) this.callRecord = new CallRecord(value.date, value.count); else if (key === "total_calls_ever_placed" && typeof value === "number") this.totalCallsEverPlaced = value; else throw new Error(`Unknown legacy record key: ${key}`);
} else for (const [ key, value ] of Object.entries(records)) this[key] = value;
if (typeof records.records === "object")
for (const [ key, value ] of Object.entries(records.records)) {
const oldTableMatches = key.match(/^monthly_total_(\d{4})-(\d{2})$/);
if (oldTableMatches) {
const year = oldTableMatches[1];
const month = oldTableMatches[2];
if (!this.monthlyTotals) this.monthlyTotals = {};
if (!this.monthlyTotals[year]) this.monthlyTotals[year] = {};
this.monthlyTotals[year][month] = value;
} else if (key === "record_calls" && typeof value === "object" && value !== null) this.callRecord = new CallRecord(value.date, value.count);
else if (key === "total_calls_ever_placed" && typeof value === "number") this.totalCallsEverPlaced = value;
else throw new Error(`Unknown legacy record key: ${key}`);
} else for (const [ key, value ] of Object.entries(records)) this[key] = value;
}
static fromJSONFile(path) {