forked from Minecraft/Stonks
Fix aggregates calculations
parent
959ac79fbd
commit
a86453f497
|
@ -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 (
|
||||||
|
SELECT Live."Type",
|
||||||
|
Live."Name",
|
||||||
|
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
|
LEFT JOIN AGGREGATESTATISTICS as Agg
|
||||||
ON Live."Type" = Agg."Type"
|
ON Live."Type" = Agg."Type"
|
||||||
WHERE array_contains(array['minecraft:mined'], Live."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 LiveMax."Type",
|
||||||
|
LiveMax."Name",
|
||||||
|
@Timestamp AS "Timestamp",
|
||||||
|
SUM(LiveMax."Value")
|
||||||
|
FROM (
|
||||||
SELECT Live."Type",
|
SELECT Live."Type",
|
||||||
Live."Name",
|
Live."Name",
|
||||||
@Timestamp AS "Timestamp",
|
MAX(Live."Value") AS "Value"
|
||||||
Sum(Live."Value")
|
|
||||||
FROM livestatistics as Live
|
FROM livestatistics as Live
|
||||||
LEFT JOIN AGGREGATESTATISTICS as Agg
|
|
||||||
ON Live."Type" = Agg."Type" AND Live."Name" = Agg."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")
|
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")
|
||||||
OR array_contains(array['minecraft:killed', 'minecraft:killed_by'], Live."Type")
|
OR array_contains(array['minecraft:killed', 'minecraft:killed_by'], Live."Type")
|
||||||
GROUP BY Live."Type", Live."Name"
|
GROUP BY Live."Type", Live."Name", Live."PlayerId"
|
||||||
HAVING sum(Live."Value") <> max(Agg."Value") OR max(Agg."Value") IS NULL;
|
) 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()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue