2022-08-07 21:55:50 +02:00
|
|
|
import * as fs from "fs";
|
|
|
|
import type {Crossing} from "../interfaces";
|
|
|
|
|
2023-04-22 00:33:07 +02:00
|
|
|
export type Output = { "labels": string[], "values": number[] }
|
|
|
|
|
2022-08-07 21:55:50 +02:00
|
|
|
function runstats() {
|
2022-08-15 15:54:18 +02:00
|
|
|
const data: Crossing[] = JSON.parse(fs.readFileSync("../data/Wien.json", 'utf8'));
|
2022-08-07 21:55:50 +02:00
|
|
|
|
2022-12-11 20:47:19 +01:00
|
|
|
console.log("total", data.length)
|
2022-08-07 21:55:50 +02:00
|
|
|
|
2022-08-15 15:54:18 +02:00
|
|
|
const bezirke = data.map(c => c.bezirk!)
|
2022-08-07 21:55:50 +02:00
|
|
|
const counts: { [key: number]: number } = {};
|
|
|
|
|
|
|
|
for (const num of bezirke) {
|
|
|
|
counts[num] = counts[num] ? counts[num] + 1 : 1;
|
|
|
|
}
|
|
|
|
console.log(counts)
|
|
|
|
|
2023-04-22 00:33:07 +02:00
|
|
|
|
|
|
|
const files = ["Wien", "Burgenland", "Kärnten", "Niederösterreich", "Oberösterreich", "Salzburg", "Steiermark", "Tirol", "Vorarlberg"]
|
|
|
|
const dateCounts: { [key: string]: number } = {}
|
|
|
|
for (let year = 2019; year <= 2023; year++) {
|
|
|
|
for (let month = 1; month <= 12; month++) {
|
|
|
|
dateCounts[year + "-" + String(month).padStart(2, "0")] = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log(dateCounts)
|
2023-08-28 22:39:49 +02:00
|
|
|
let totalNumber = 0
|
2023-04-22 00:33:07 +02:00
|
|
|
files.forEach(f => {
|
|
|
|
const data: Crossing[] = JSON.parse(fs.readFileSync(`../data/${f}.json`, 'utf8'));
|
2023-08-28 22:39:49 +02:00
|
|
|
totalNumber += data.length
|
2023-04-22 00:33:07 +02:00
|
|
|
data.forEach(cr => {
|
|
|
|
const dates = cr.sources.filter(s => s.type != "proposal").map(s => s.date).sort()
|
|
|
|
const date = new Date(dates[0])
|
|
|
|
if (isNaN(date.getTime())) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
const dateStr = date.toISOString().slice(0, 7)
|
|
|
|
dateCounts[dateStr] = dateCounts[dateStr] ? dateCounts[dateStr] + 1 : 1;
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
2023-08-28 22:39:49 +02:00
|
|
|
console.log("total", totalNumber)
|
2023-04-22 00:33:07 +02:00
|
|
|
const dateCountList = []
|
|
|
|
for (let dateCountsKey in dateCounts) {
|
|
|
|
dateCountList.push({
|
|
|
|
key: dateCountsKey,
|
|
|
|
value: dateCounts[dateCountsKey]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
dateCountList.sort((a, b) => a.key.localeCompare(b.key))
|
|
|
|
const labels: string[] = []
|
|
|
|
const values: number[] = []
|
|
|
|
dateCountList.forEach(el => {
|
|
|
|
labels.push(el.key)
|
|
|
|
values.push(el.value)
|
|
|
|
})
|
|
|
|
console.log(labels)
|
|
|
|
console.log(values)
|
|
|
|
const output: Output = {labels, values}
|
|
|
|
fs.writeFileSync("../stats.json", JSON.stringify(output))
|
2022-08-07 21:55:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
runstats()
|