Skip to content

Commit 869edb5

Browse files
authored
Merge pull request #4 from DataStrike/CSV-files-#1
Csv files #1
2 parents cd03be6 + c0f42fb commit 869edb5

21 files changed

+2680
-5
lines changed

deploy/docker-compose.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ services:
66
ZOOKEEPER_CLIENT_PORT: 2181
77
ZOOKEEPER_TICK_TIME: 2000
88
ports:
9-
- 22181:2181
9+
- 22182:2181
1010

1111
kafka:
1212
image: confluentinc/cp-kafka:latest
1313
depends_on:
1414
- zookeeper
1515
ports:
16-
- 29092:29092
16+
- 29093:29092
1717
environment:
1818
KAFKA_BROKER_ID: 1
1919
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181

deploy/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
kafka-python==2.0.2
1+
kafka-python==2.0.2
2+
pandas==2.1.4
3.6 KB
Binary file not shown.

src/log_analyser/log_analyser.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import os
2+
from datetime import datetime, timedelta
3+
from objects.match import Match
4+
5+
6+
class LogAnalyser:
7+
8+
def __init__(self, path_csv, name) -> None:
9+
10+
self.path_csv = path_csv
11+
self.name = name
12+
13+
self.date = self.name2datetime()
14+
15+
self.match = None
16+
17+
self.actions = {"match_start": self.process_match_start}
18+
19+
def run(self):
20+
21+
with open(self.path_csv, encoding='utf-8') as my_file:
22+
file = my_file.read()
23+
lines = file.split("\n")
24+
for line in lines:
25+
line_split = line.split(",")
26+
27+
if len(line_split) > 1:
28+
type = line_split[1]
29+
if type in self.actions:
30+
self.actions[type](line_split)
31+
32+
with open("../logs_process/{}.json".format(self.name.split(".")[0]), "w") as file:
33+
file.write(self.match.export_json())
34+
35+
36+
def name2datetime(self):
37+
38+
date_string = self.name.split(".")[0].split("Log-")[1]
39+
date_object = datetime.strptime(date_string, '%Y-%m-%d-%H-%M-%S')
40+
41+
return date_object
42+
43+
def process_match_start(self, data):
44+
45+
self.match = Match.from_json({"rounds": [],
46+
"date": self.date,
47+
"map_name": data[3],
48+
"map_type": data[4],
49+
"team1_name": data[5],
50+
"team2_name": data[6],
51+
"score_team1": 0,
52+
"score_team2": 0,
53+
})
54+
55+
self.actions = {"match_start": self.process_match_start,
56+
"round_start": self.match.add_round,
57+
"round_end": self.match.end_round,
58+
"hero_spawn": self.process_hero_spawn,
59+
"hero_swap": self.process_hero_swap,
60+
"kill": self.match.add_kill,
61+
"ultimate_charged": self.match.add_ultimate_charged,
62+
"ultimate_start": self.match.add_ultimate_start,
63+
"ultimate_end": self.match.add_ultimate_end,
64+
"objective_captured": self.match.add_objective_captured,
65+
"player_stat": self.match.add_player_stat,
66+
"point_progress": self.match.add_objective_progress,
67+
"payload_progress": self.match.add_objective_progress,
68+
}
69+
70+
def process_hero_spawn(self, data):
71+
72+
player_data = {"time": data[2], "team_name": data[3], "player_name": data[4], "character_name": data[5]}
73+
self.match.add_player(player_data)
74+
75+
def process_hero_swap(self, data):
76+
77+
hero_data = {"time": data[2], "team_name": data[3], "player_name": data[4], "character_name": data[5], "character_swap": data[6]}
78+
self.match.add_hero_swap(hero_data)
79+
80+
def convert_timefile_to_datetime(self, time_string):
81+
82+
# Utilisation de strptime pour convertir la chaîne en datetime
83+
time_delta = datetime.strptime(time_string, "[%H:%M:%S]")
84+
85+
# Conversion en timedelta (représentation de la durée)
86+
duration = timedelta(hours=time_delta.hour, minutes=time_delta.minute, seconds=time_delta.second)
87+
return duration
88+
89+
90+
for file in os.listdir("../logs"):
91+
if file.endswith(".txt"):
92+
print(file)
93+
la = LogAnalyser('../logs/{}'.format(file), file)
94+
la.run()
95+
96+
# la = LogAnalyser('../logs/Log-2023-12-22-21-12-32.txt', "Log-2023-12-22-21-12-32.txt")
97+
# la.run()
2.39 KB
Binary file not shown.
1.87 KB
Binary file not shown.
1.07 KB
Binary file not shown.
912 Bytes
Binary file not shown.
1.21 KB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from objects.object import Object
2+
3+
4+
class Character(Object):
5+
def __init__(self, **kwargs):
6+
7+
data_schema = {"name": str,
8+
"stats": dict,
9+
"played_time": list,
10+
"kills": list,
11+
"deads": list,
12+
"offensive_assists": list,
13+
"defensive_assists": list,
14+
"ultimate_charged": list,
15+
"ultimate_use": list}
16+
17+
super().__init__(data_schema, **kwargs)
18+
19+
20+
def add_played_time(self, data):
21+
self.played_time.append(data)
22+
23+
def add_kill(self, data):
24+
self.kills.append(data)
25+
26+
def add_death(self, data):
27+
self.deads.append(data)
28+
29+
def add_offensive_assist(self, data):
30+
self.offensive_assists.append(data)
31+
32+
def add_defensive_assist(self, data):
33+
self.defensive_assists.append(data)
34+
35+
def add_ultimate_charged(self, data):
36+
self.ultimate_charged.append(data)
37+
38+
def add_ultimate_start(self, data):
39+
self.ultimate_use.append(data)
40+
41+
def add_ultimate_end(self, data):
42+
43+
if len(self.ultimate_use) == 0:
44+
return -1
45+
self.ultimate_use[-1]["end"] = data["end"]
46+
47+
def add_character_stats(self, data):
48+
self.stats = data

0 commit comments

Comments
 (0)