forked from LiteNet/freepbx-stats
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) {
|
||||
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}`;
|
||||
|
||||
|
|
23
records.js
23
records.js
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue