Skip to content

Commit eadbd06

Browse files
committed
refactor score_team to team_score
add event from back in service for launch log_analyser
1 parent e454b84 commit eadbd06

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

src/log_analyser/log_analyser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
class LogAnalyser:
77

8-
def __init__(self, path_csv, name) -> None:
8+
def __init__(self, path, name, team_id) -> None:
99

10-
self.path_csv = path_csv
10+
self.path_csv = "{}/{}".format(path, name)
1111
self.name = name
12+
self.team_id = team_id
1213

1314
self.date = self.name2datetime()
1415

@@ -48,8 +49,9 @@ def process_map_start(self, data):
4849
"map_type": data[4],
4950
"team1_name": data[5],
5051
"team2_name": data[6],
51-
"score_team1": 0,
52-
"score_team2": 0,
52+
"team1_score": 0,
53+
"team2_score": 0,
54+
"team_id": self.team_id
5355
})
5456

5557
self.actions = {"match_start": self.process_map_start,

src/log_analyser/objects/map.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ def __init__(self, **kwargs):
1414
"map_type": str,
1515
"team1_name": str,
1616
"team2_name": str,
17-
"score_team1": int,
18-
"score_team2": int,
17+
"team1_score": int,
18+
"team2_score": int,
19+
"team_id": str
1920
}
2021

2122
super().__init__(data_schema, **kwargs)
@@ -139,7 +140,7 @@ def add_objective_progress(self, data):
139140

140141
def end_round(self, data):
141142

142-
end_round_data = {"time": data[2], "score_team1": data[5], "score_team2": data[6]}
143+
end_round_data = {"time": data[2], "team1_score": data[5], "team2_score": data[6]}
143144

144145
for team in self.rounds[self.actual_round].teams:
145146
for player in self.rounds[self.actual_round].teams[team].players:
@@ -148,13 +149,13 @@ def end_round(self, data):
148149
self.rounds[self.actual_round].teams[team].players[player].characters[character].played_time[-1]["end"] = end_round_data["time"]
149150

150151

151-
self.score_team1 = end_round_data["score_team1"]
152-
self.score_team2 = end_round_data["score_team2"]
152+
self.score_team1 = end_round_data["team1_score"]
153+
self.score_team2 = end_round_data["team2_score"]
153154
print("###### END ROUND {} #######\n".format(self.actual_round))
154155

155156
def end_map(self, data):
156157

157-
end_map_data = {"time": data[2], "score_team1": data[4], "score_team2": data[5]}
158+
end_map_data = {"time": data[2], "team1_score": data[4], "team2_score": data[5]}
158159

159-
self.score_team1 = end_map_data["score_team1"]
160-
self.score_team2 = end_map_data["score_team2"]
160+
self.score_team1 = end_map_data["team1_score"]
161+
self.score_team2 = end_map_data["team2_score"]

src/log_analyser/objects/object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def export_json(self):
5656
else:
5757
dict_class_final[key] = self.export_json_recursive(value)
5858
# return json.dumps(dict_class_final, indent=4, sort_keys=True, default=str)
59-
return json.dumps(dict_class_final, skipkeys=False, ensure_ascii=True, check_circular=True)
59+
return dict_class_final
6060
def convert_timefile_to_datetime(self, time_string):
6161

6262

src/main.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,24 @@ def __init__(self):
2222
def on_callback_test(self, topic, data):
2323
print("message receive : ", topic, data)
2424

25-
la = LogAnalyser('logs/Log-2023-12-22-21-12-32.txt', "Log-2023-12-22-21-12-32.txt")
26-
la.run()
27-
self.producer_thread.send("analyse.report", la.map.export_json())
25+
filePath = data["filePath"]
26+
fileName = data["fileName"]
27+
teamId = data["teamId"]
2828

29+
if self.check_txt_extension(fileName):
30+
31+
la = LogAnalyser(filePath, fileName, teamId)
32+
la.run()
33+
if la.map != None:
34+
self.producer_thread.send("analyse.report", la.map.export_json())
35+
else:
36+
self.producer_thread.send("analyse.report", {"error": "File txt not correct"})
37+
38+
else:
39+
self.producer_thread.send("analyse.report", {"error": "File extension not correct"})
40+
41+
def check_txt_extension(self, filename):
42+
return filename.lower().endswith('.txt')
2943
def run(self):
3044

3145
while self.running:

0 commit comments

Comments
 (0)