Fix statistics (once more)

This commit is contained in:
pietervdvn 2022-09-03 23:39:35 +02:00
parent 2a971cf253
commit ac3abb638c
4 changed files with 14 additions and 36 deletions

View file

@ -1,4 +1,4 @@
import {existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync} from "fs"; import {existsSync, mkdirSync, readdirSync, readFileSync, unlinkSync, writeFileSync} from "fs";
import ScriptUtils from "../../scripts/ScriptUtils"; import ScriptUtils from "../../scripts/ScriptUtils";
import {Utils} from "../../Utils"; import {Utils} from "../../Utils";
@ -36,9 +36,12 @@ class StatsDownloader {
} }
const features = [] const features = []
let monthIsFinished = true
const writtenFiles = []
for (let day = startDay; day <= 31; day++) { for (let day = startDay; day <= 31; day++) {
if (year === currentYear && month === currentMonth && day === today.getDate()) { if (year === currentYear && month === currentMonth && day === today.getDate()) {
monthIsFinished = false
break; break;
} }
{ {
@ -49,6 +52,7 @@ class StatsDownloader {
} }
} }
const path = `${this._targetDirectory}/stats.${year}-${month}-${(day < 10 ? "0" : "") + day}.day.json` const path = `${this._targetDirectory}/stats.${year}-${month}-${(day < 10 ? "0" : "") + day}.day.json`
writtenFiles.push(path)
if (existsSync(path)) { if (existsSync(path)) {
let features = JSON.parse(readFileSync(path, "UTF-8")) let features = JSON.parse(readFileSync(path, "UTF-8"))
features = features?.features ?? features features = features?.features ?? features
@ -69,7 +73,12 @@ class StatsDownloader {
features.push(...dayFeatures) features.push(...dayFeatures)
} }
writeFileSync(pathM, JSON.stringify({features})) if(monthIsFinished){
writeFileSync(pathM, JSON.stringify({features}))
for (const writtenFile of writtenFiles) {
unlinkSync(writtenFile)
}
}
} }
startDay = 1 startDay = 1
} }

View file

@ -1,32 +1 @@
[ ["file-overview.json","missing_editor.json","stats.2020-10.json","stats.2020-11.json","stats.2020-12.json","stats.2020-5.json","stats.2020-6.json","stats.2020-7.json","stats.2020-8.json","stats.2020-9.json","stats.2021-1.json","stats.2021-10.json","stats.2021-11.json","stats.2021-12.json","stats.2021-2.json","stats.2021-3.json","stats.2021-4.json","stats.2021-5.json","stats.2021-6.json","stats.2021-7.json","stats.2021-8.json","stats.2021-9.json","stats.2022-1.json","stats.2022-2.json","stats.2022-3.json","stats.2022-4.json","stats.2022-5.json","stats.2022-6.json","stats.2022-7.json","stats.2022-8.json","stats.2022-9-01.day.json","stats.2022-9-02.day.json"]
"file-overview.json",
"missing_editor.json",
"stats.2020-10.json",
"stats.2020-11.json",
"stats.2020-12.json",
"stats.2020-5.json",
"stats.2020-6.json",
"stats.2020-7.json",
"stats.2020-8.json",
"stats.2020-9.json",
"stats.2021-1.json",
"stats.2021-10.json",
"stats.2021-11.json",
"stats.2021-12.json",
"stats.2021-2.json",
"stats.2021-3.json",
"stats.2021-4.json",
"stats.2021-5.json",
"stats.2021-6.json",
"stats.2021-7.json",
"stats.2021-8.json",
"stats.2021-9.json",
"stats.2022-1.json",
"stats.2022-2.json",
"stats.2022-3.json",
"stats.2022-4.json",
"stats.2022-5.json",
"stats.2022-6.json",
"stats.2022-7.json",
"stats.2022-8.json"
]

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long