Add counter metric for finished quests
This commit is contained in:
parent
d460cae665
commit
0759abccfd
1 changed files with 20 additions and 0 deletions
|
@ -14,7 +14,11 @@ class MinecraftCollector(object):
|
||||||
self.statsdirectory = "/world/stats"
|
self.statsdirectory = "/world/stats"
|
||||||
self.playerdirectory = "/world/playerdata"
|
self.playerdirectory = "/world/playerdata"
|
||||||
self.advancementsdirectory = "/world/advancements"
|
self.advancementsdirectory = "/world/advancements"
|
||||||
|
self.betterquesting = "/world/betterquesting"
|
||||||
self.map = dict()
|
self.map = dict()
|
||||||
|
self.questsEnabled = False
|
||||||
|
if os.path.isdir(self.betterquesting):
|
||||||
|
self.questsEnabled = True
|
||||||
|
|
||||||
def get_players(self):
|
def get_players(self):
|
||||||
return [f[:-5] for f in listdir(self.statsdirectory) if isfile(join(self.statsdirectory, f))]
|
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')
|
result = requests.get('https://api.mojang.com/user/profiles/'+uuid+'/names')
|
||||||
self.map[uuid] = result.json()[0]['name']
|
self.map[uuid] = result.json()[0]['name']
|
||||||
return(result.json()[0]['name'])
|
return(result.json()[0]['name'])
|
||||||
|
|
||||||
def get_server_stats(self):
|
def get_server_stats(self):
|
||||||
if not all(x in os.environ for x in ['RCON_HOST','RCON_PASSWORD']):
|
if not all(x in os.environ for x in ['RCON_HOST','RCON_PASSWORD']):
|
||||||
return []
|
return []
|
||||||
|
@ -65,6 +70,16 @@ class MinecraftCollector(object):
|
||||||
|
|
||||||
return[dim_tps,dim_ticktime,overall_tps,overall_ticktime,player_online,entities]
|
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):
|
def get_player_stats(self,uuid):
|
||||||
with open(self.statsdirectory+"/"+uuid+".json") as json_file:
|
with open(self.statsdirectory+"/"+uuid+".json") as json_file:
|
||||||
|
@ -83,6 +98,8 @@ class MinecraftCollector(object):
|
||||||
if value["done"] == True:
|
if value["done"] == True:
|
||||||
count += 1
|
count += 1
|
||||||
data["stat.advancements"] = count
|
data["stat.advancements"] = count
|
||||||
|
if self.questsEnabled:
|
||||||
|
data["quests_finished"] = get_player_quests_finished(uuid)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def update_metrics_for_player(self,uuid):
|
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_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_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_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")
|
player_used_crafting_table = Metric('player_used_crafting_table',"Times a Player used a Crafting Table","counter")
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
stat = key.split(".")[1] # entityKilledBy
|
stat = key.split(".")[1] # entityKilledBy
|
||||||
|
@ -163,6 +181,8 @@ class MinecraftCollector(object):
|
||||||
player_slept.add_sample('player_slept',value=value,labels={'player':name})
|
player_slept.add_sample('player_slept',value=value,labels={'player':name})
|
||||||
elif stat == "craftingTableInteraction":
|
elif stat == "craftingTableInteraction":
|
||||||
player_used_crafting_table.add_sample('player_used_crafting_table',value=value,labels={'player':name})
|
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]
|
||||||
|
|
||||||
def collect(self):
|
def collect(self):
|
||||||
|
|
Loading…
Reference in a new issue