why is it resetting call records?
This commit is contained in:
parent
a15e296918
commit
fb006a3c46
2
index.js
2
index.js
|
@ -91,9 +91,11 @@ function updateRecords(callStats, records) {
|
||||||
if (!records.callRecord) {
|
if (!records.callRecord) {
|
||||||
records.callRecord = { date: yesterdayDateString, count: callStats.totalCallsMade };
|
records.callRecord = { date: yesterdayDateString, count: callStats.totalCallsMade };
|
||||||
isNewRecord = true;
|
isNewRecord = true;
|
||||||
|
console.warn("No previous call record found, initializing new record.");
|
||||||
} else if (allTimeRecord.count < callStats.totalCallsThisMonth) {
|
} else if (allTimeRecord.count < callStats.totalCallsThisMonth) {
|
||||||
allTimeRecord.count = callStats.totalCallsThisMonth;
|
allTimeRecord.count = callStats.totalCallsThisMonth;
|
||||||
isNewRecord = true;
|
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}`;
|
callStats.allTimeRecord = `${allTimeRecord.count} calls on ${allTimeRecord.date}`;
|
||||||
|
|
||||||
|
|
23
records.js
23
records.js
|
@ -2,16 +2,19 @@ import fs from "fs";
|
||||||
|
|
||||||
export class Records {
|
export class Records {
|
||||||
constructor(records = {}) {
|
constructor(records = {}) {
|
||||||
if (typeof records.records === "object") for (const [ key, value ] of Object.entries(records.records)) {
|
if (typeof records.records === "object")
|
||||||
const oldTableMatches = key.match(/^monthly_total_(\d{4})-(\d{2})$/);
|
for (const [ key, value ] of Object.entries(records.records)) {
|
||||||
if (oldTableMatches) {
|
const oldTableMatches = key.match(/^monthly_total_(\d{4})-(\d{2})$/);
|
||||||
const year = oldTableMatches[1];
|
if (oldTableMatches) {
|
||||||
const month = oldTableMatches[2];
|
const year = oldTableMatches[1];
|
||||||
if (!this.monthlyTotals) this.monthlyTotals = {};
|
const month = oldTableMatches[2];
|
||||||
if (!this.monthlyTotals[year]) this.monthlyTotals[year] = {};
|
if (!this.monthlyTotals) this.monthlyTotals = {};
|
||||||
this.monthlyTotals[year][month] = value;
|
if (!this.monthlyTotals[year]) this.monthlyTotals[year] = {};
|
||||||
} 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}`);
|
this.monthlyTotals[year][month] = value;
|
||||||
} else for (const [ key, value ] of Object.entries(records)) this[key] = 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) {
|
static fromJSONFile(path) {
|
||||||
|
|
Loading…
Reference in a new issue