Fix aggregates calculations

main
Kevin Belisle 2021-09-02 00:25:24 -04:00
parent 959ac79fbd
commit a86453f497
1 changed files with 28 additions and 18 deletions

View File

@ -65,8 +65,6 @@ object StatisticsImporter {
} }
} }
transaction(database) { transaction(database) {
addLogger(StdOutSqlLogger)
statsFile?.stats?.forEach { type, stats -> statsFile?.stats?.forEach { type, stats ->
stats.forEach { name, value -> stats.forEach { name, value ->
if (playerStats.get(type)?.get(name) != value) { if (playerStats.get(type)?.get(name) != value) {
@ -134,29 +132,41 @@ object StatisticsImporter {
SET @Timestamp = CURRENT_TIMESTAMP; SET @Timestamp = CURRENT_TIMESTAMP;
INSERT INTO AGGREGATESTATISTICS ("Type", "Name", "Timestamp", "Value") INSERT INTO AGGREGATESTATISTICS ("Type", "Name", "Timestamp", "Value")
SELECT Live."Type", SELECT LiveMax."Type",
'', '',
@Timestamp AS "Timestamp", @Timestamp AS "Timestamp",
sum(Live."Value") SUM(LiveMax."Value")
FROM LIVESTATISTICS as Live FROM (
LEFT JOIN AGGREGATESTATISTICS as Agg SELECT Live."Type",
ON Live."Type" = Agg."Type" Live."Name",
WHERE array_contains(array['minecraft:mined'], Live."Type") MAX(Live."Value") AS "Value"
FROM livestatistics as Live
WHERE array_contains(array['minecraft:mined'], Live."Type")
GROUP BY Live."Type", Live."Name", Live."PlayerId"
) as LiveMax
LEFT JOIN AGGREGATESTATISTICS as Agg
ON Live."Type" = Agg."Type"
GROUP BY Live."Type" GROUP BY Live."Type"
HAVING sum(Live."Value") <> max(Agg."Value") OR max(Agg."Value") IS NULL; HAVING sum(Live."Value") <> max(Agg."Value") OR max(Agg."Value") IS NULL;
INSERT INTO AGGREGATESTATISTICS ("Type", "Name", "Timestamp", "Value") INSERT INTO AGGREGATESTATISTICS ("Type", "Name", "Timestamp", "Value")
SELECT Live."Type", SELECT LiveMax."Type",
Live."Name", LiveMax."Name",
@Timestamp AS "Timestamp", @Timestamp AS "Timestamp",
Sum(Live."Value") SUM(LiveMax."Value")
FROM livestatistics as Live FROM (
LEFT JOIN AGGREGATESTATISTICS as Agg SELECT Live."Type",
ON Live."Type" = Agg."Type" AND Live."Name" = Agg."Name" Live."Name",
WHERE array_contains(array['minecraft:animals_bred', 'minecraft:play_one_minute', 'minecraft:deaths', 'minecraft:player_kills', 'minecraft:aviate_one_cm', 'minecraft:boat_one_cm', 'minecraft:crouch_one_cm', 'minecraft:horse_one_cm', 'minecraft:minecart_one_cm', 'minecraft:sprint_one_cm', 'minecraft:strider_one_cm', 'minecraft:swim_one_cm', 'minecraft:walk_on_water_one_cm', 'minecraft:walk_one_cm', 'minecraft:walk_under_water_one_cm' ], Live."Name") MAX(Live."Value") AS "Value"
OR array_contains(array['minecraft:killed', 'minecraft:killed_by'], Live."Type") FROM livestatistics as Live
GROUP BY Live."Type", Live."Name" WHERE array_contains(array['minecraft:animals_bred', 'minecraft:play_one_minute', 'minecraft:deaths', 'minecraft:player_kills', 'minecraft:aviate_one_cm', 'minecraft:boat_one_cm', 'minecraft:crouch_one_cm', 'minecraft:horse_one_cm', 'minecraft:minecart_one_cm', 'minecraft:sprint_one_cm', 'minecraft:strider_one_cm', 'minecraft:swim_one_cm', 'minecraft:walk_on_water_one_cm', 'minecraft:walk_one_cm', 'minecraft:walk_under_water_one_cm' ], Live."Name")
HAVING sum(Live."Value") <> max(Agg."Value") OR max(Agg."Value") IS NULL; OR array_contains(array['minecraft:killed', 'minecraft:killed_by'], Live."Type")
GROUP BY Live."Type", Live."Name", Live."PlayerId"
) as LiveMax
LEFT JOIN AGGREGATESTATISTICS as Agg
ON LiveMax."Type" = Agg."Type" AND LiveMax."Name" = Agg."Name"
GROUP BY LiveMax."Type", LiveMax."Name"
HAVING SUM(LiveMax."Value") <> MAX(Agg."Value") OR MAX(Agg."Value") IS NULL;
""".trimIndent() """.trimIndent()
) )
} }