From 0759abccfdd0359e69b4a74a0c0a67a79ad7ddbe Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 17:32:53 +0100 Subject: [PATCH 1/7] Add counter metric for finished quests --- minecraft_exporter.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index fc3af1a..b2ec8cb 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -14,7 +14,11 @@ class MinecraftCollector(object): self.statsdirectory = "/world/stats" self.playerdirectory = "/world/playerdata" self.advancementsdirectory = "/world/advancements" + self.betterquesting = "/world/betterquesting" self.map = dict() + self.questsEnabled = False + if os.path.isdir(self.betterquesting): + self.questsEnabled = True def get_players(self): return [f[:-5] for f in listdir(self.statsdirectory) if isfile(join(self.statsdirectory, f))] @@ -27,6 +31,7 @@ class MinecraftCollector(object): result = requests.get('https://api.mojang.com/user/profiles/'+uuid+'/names') self.map[uuid] = result.json()[0]['name'] return(result.json()[0]['name']) + def get_server_stats(self): if not all(x in os.environ for x in ['RCON_HOST','RCON_PASSWORD']): return [] @@ -65,6 +70,16 @@ class MinecraftCollector(object): return[dim_tps,dim_ticktime,overall_tps,overall_ticktime,player_online,entities] + def get_player_quests_finished(self,uuid): + with open(self.betterquesting+"/QuestProgress.json") as json_file: + data = json.load(json_file) + json_file.close() + counter = 0 + for key, value in data['questProgress:9'].items(): + for _, uuid in value['tasks:9']['0:10']['completeUsers:9'].items(): + if uuid == player['uuid']: + counter++ + return counter def get_player_stats(self,uuid): with open(self.statsdirectory+"/"+uuid+".json") as json_file: @@ -83,6 +98,8 @@ class MinecraftCollector(object): if value["done"] == True: count += 1 data["stat.advancements"] = count + if self.questsEnabled: + data["quests_finished"] = get_player_quests_finished(uuid) return data def update_metrics_for_player(self,uuid): @@ -105,6 +122,7 @@ class MinecraftCollector(object): player_playtime = Metric('player_playtime',"Time in Minutes a Player was online","counter") player_advancements = Metric('player_advancements', "Number of completed advances of a player","counter") player_slept = Metric('player_slept',"Times a Player slept in a bed","counter") + player_quests_finished = Metric('player_quests_finished', 'Number of quests a Player has finished', 'counter') player_used_crafting_table = Metric('player_used_crafting_table',"Times a Player used a Crafting Table","counter") for key, value in data.items(): stat = key.split(".")[1] # entityKilledBy @@ -163,6 +181,8 @@ class MinecraftCollector(object): player_slept.add_sample('player_slept',value=value,labels={'player':name}) elif stat == "craftingTableInteraction": player_used_crafting_table.add_sample('player_used_crafting_table',value=value,labels={'player':name}) + elif stat == "questsFinished": + player_quests_finished.add_sample('player_quests_finished',value=value,labels={'player':name}) return [blocks_mined,blocks_picked_up,player_deaths,player_jumps,cm_traveled,player_xp_total,player_current_level,player_food_level,player_health,player_score,entities_killed,damage_taken,damage_dealt,blocks_crafted,player_playtime,player_advancements,player_slept,player_used_crafting_table] def collect(self): From 596dced55e7933f4b322e0e5173c06b49346e0a3 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 17:41:22 +0100 Subject: [PATCH 2/7] Remove unused var --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index b2ec8cb..29d502c 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -75,7 +75,7 @@ class MinecraftCollector(object): data = json.load(json_file) json_file.close() counter = 0 - for key, value in data['questProgress:9'].items(): + for _, value in data['questProgress:9'].items(): for _, uuid in value['tasks:9']['0:10']['completeUsers:9'].items(): if uuid == player['uuid']: counter++ From 63c45107d4bc8ed3d9d6d5beb1a7a9b07c390a37 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 17:47:00 +0100 Subject: [PATCH 3/7] Return updated metric --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 29d502c..cba4564 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -183,7 +183,7 @@ class MinecraftCollector(object): player_used_crafting_table.add_sample('player_used_crafting_table',value=value,labels={'player':name}) elif stat == "questsFinished": player_quests_finished.add_sample('player_quests_finished',value=value,labels={'player':name}) - return [blocks_mined,blocks_picked_up,player_deaths,player_jumps,cm_traveled,player_xp_total,player_current_level,player_food_level,player_health,player_score,entities_killed,damage_taken,damage_dealt,blocks_crafted,player_playtime,player_advancements,player_slept,player_used_crafting_table] + return [blocks_mined,blocks_picked_up,player_deaths,player_jumps,cm_traveled,player_xp_total,player_current_level,player_food_level,player_health,player_score,entities_killed,damage_taken,damage_dealt,blocks_crafted,player_playtime,player_advancements,player_slept,player_used_crafting_table,player_quests_finished] def collect(self): for player in self.get_players(): From a13c342920e904a0ced6726aae4f14dc43a41cee Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 17:57:04 +0100 Subject: [PATCH 4/7] Fix minor bugs --- minecraft_exporter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index cba4564..6f5e2bc 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -76,9 +76,9 @@ class MinecraftCollector(object): json_file.close() counter = 0 for _, value in data['questProgress:9'].items(): - for _, uuid in value['tasks:9']['0:10']['completeUsers:9'].items(): - if uuid == player['uuid']: - counter++ + for _, u in value['tasks:9']['0:10']['completeUsers:9'].items(): + if u == uuid: + counter +=1 return counter def get_player_stats(self,uuid): @@ -99,7 +99,7 @@ class MinecraftCollector(object): count += 1 data["stat.advancements"] = count if self.questsEnabled: - data["quests_finished"] = get_player_quests_finished(uuid) + data["quests_finished"] = get_player_quests_finished(self,uuid) return data def update_metrics_for_player(self,uuid): From ddb69f18444f044f2ca6bf5418e5d5e7d4cc7b52 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 18:02:38 +0100 Subject: [PATCH 5/7] Fix own stupidity --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 6f5e2bc..383dac6 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -99,7 +99,7 @@ class MinecraftCollector(object): count += 1 data["stat.advancements"] = count if self.questsEnabled: - data["quests_finished"] = get_player_quests_finished(self,uuid) + data["quests_finished"] = self.get_player_quests_finished(uuid) return data def update_metrics_for_player(self,uuid): From d572829703a1a3336580287d7e092f50bfbd8e07 Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 18:04:28 +0100 Subject: [PATCH 6/7] Add stat key prefix --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index 383dac6..dde7cce 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -99,7 +99,7 @@ class MinecraftCollector(object): count += 1 data["stat.advancements"] = count if self.questsEnabled: - data["quests_finished"] = self.get_player_quests_finished(uuid) + data["stat.quests_finished"] = self.get_player_quests_finished(uuid) return data def update_metrics_for_player(self,uuid): From f046ecb2354b0fe2410b6942c500f575998f2d8d Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Sat, 11 Jan 2020 18:09:14 +0100 Subject: [PATCH 7/7] Fix stat string --- minecraft_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minecraft_exporter.py b/minecraft_exporter.py index dde7cce..11df32a 100644 --- a/minecraft_exporter.py +++ b/minecraft_exporter.py @@ -99,7 +99,7 @@ class MinecraftCollector(object): count += 1 data["stat.advancements"] = count if self.questsEnabled: - data["stat.quests_finished"] = self.get_player_quests_finished(uuid) + data["stat.questsFinished"] = self.get_player_quests_finished(uuid) return data def update_metrics_for_player(self,uuid):