diff --git a/src/client/classes/Statistics.ts b/src/client/classes/Statistics.ts index 438e5c0..78ea997 100644 --- a/src/client/classes/Statistics.ts +++ b/src/client/classes/Statistics.ts @@ -25,36 +25,31 @@ export default class Statistics { radio.datastore = client.datastore?.getEntry(guild.id); - //@ts-ignore + if(radio.datastore === undefined) return; + if(!radio.datastore.statistics[radio.station.name]){ - //@ts-ignore radio.datastore.statistics[radio.station.name] = { time: 0, used: 0 }; - //@ts-ignore client.datastore?.updateEntry(guild, radio.datastore); } let date = new Date(); radio.currentTime = date.getTime(); radio.playTime = radio.currentTime - radio.startTime; - //@ts-ignore - radio.datastore.statistics[radio.station.name].time = parseInt(radio.datastore.statistics[radio.station.name].time) + radio.playTime; - - //@ts-ignore - radio.datastore.statistics[radio.station.name].used = parseInt(radio.datastore.statistics[radio.station.name].used)+1; - //@ts-ignore + radio.datastore.statistics[radio.station.name] = { + time: radio.datastore.statistics[radio.station.name].time + radio.playTime, + used: radio.datastore.statistics[radio.station.name].used + 1 + } client.datastore?.updateEntry(guild, radio.datastore); this.calculateGlobal(client); } calculateGlobal(client: RadioClient){ - if(!client.stations) return; if(!client.datastore?.map) return; let guilds = client.datastore.map.keys(); - let stations = client.stations; let statistics : statistics = {}; if(!client.stations) return; @@ -64,10 +59,10 @@ export default class Statistics { while (!calculation.done) { let currentGuild = client.datastore.getEntry(calculation.value); if(calculation.value != 'global'){ - if(stations){ - for(const station of stations) { - //@ts-ignore - if(currentGuild.statistics[station.name] && currentGuild.statistics[station.name]?.time && parseInt(currentGuild.statistics[station.name].time) != 0 && currentGuild.statistics[station.name].used && parseInt(currentGuild.statistics[station.name].used) != 0){ + if(client.stations){ + for(const station of client.stations) { + if(!currentGuild) return; + if(currentGuild.statistics[station.name] && currentGuild.statistics[station.name]?.time && currentGuild.statistics[station.name].time != 0 && currentGuild.statistics[station.name].used && currentGuild.statistics[station.name].used != 0){ if(!statistics[station.name]){ statistics[station.name] = { time: 0, @@ -75,10 +70,10 @@ export default class Statistics { }; } - //@ts-ignore - statistics[station.name].time = parseInt(statistics[station.name].time)+parseInt(currentGuild.statistics[station.name].time); - //@ts-ignore - statistics[station.name].used = parseInt(statistics[station.name].used)+parseInt(currentGuild.statistics[station.name].used); + statistics[station.name] = { + time: statistics[station.name].time + currentGuild.statistics[station.name].time, + used: statistics[station.name].used + currentGuild.statistics[station.name].used + } } } } @@ -91,7 +86,8 @@ export default class Statistics { id: "global", name: "global" }, - statistics: statistics + statistics: statistics, + state: null }; client.datastore.updateEntry(newData.guild, newData); }