Skip to content

Commit 3a6b0a7

Browse files
committed
associate main service and log analyser (launch analysis with kafka)
1 parent 92d3805 commit 3a6b0a7

File tree

9 files changed

+27
-24
lines changed

9 files changed

+27
-24
lines changed

src/kafka_lib.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ def __init__(self, url, date=None, nb_try_connection=10):
1818
self.date = date
1919
self.nb_try_connection = nb_try_connection
2020

21-
22-
2321
self.init_producer_ok, self.producer = self.init_producer(url)
2422
self.queue_sender = queue.Queue(2)
2523

src/log_analyser/log_analyser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
from datetime import datetime, timedelta
3-
from objects.match import Match
3+
from log_analyser.objects.match import Match
44

55

66
class LogAnalyser:
@@ -29,8 +29,8 @@ def run(self):
2929
if type in self.actions:
3030
self.actions[type](line_split)
3131

32-
with open("../logs_process/{}.json".format(self.name.split(".")[0]), "w") as file:
33-
file.write(self.match.export_json())
32+
# with open("../logs_process/{}.json".format(self.name.split(".")[0]), "w") as file:
33+
# file.write(self.match.export_json())
3434

3535

3636
def name2datetime(self):
@@ -87,11 +87,11 @@ def convert_timefile_to_datetime(self, time_string):
8787
return duration
8888

8989

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()
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()
9595

9696
# la = LogAnalyser('../logs/Log-2023-12-22-21-12-32.txt', "Log-2023-12-22-21-12-32.txt")
9797
# la.run()

src/log_analyser/objects/character.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from objects.object import Object
1+
from log_analyser.objects.object import Object
22

33

44
class Character(Object):
@@ -22,7 +22,7 @@ def add_kill(self, data):
2222
self.kills.append(data)
2323

2424
def add_death(self, data):
25-
self.deads.append(data)
25+
self.deaths.append(data)
2626

2727
def add_offensive_assist(self, data):
2828
self.offensive_assists.append(data)

src/log_analyser/objects/match.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from objects.object import Object
2-
from objects.round import Round
3-
from objects.team import Team
1+
from log_analyser.objects.object import Object
2+
from log_analyser.objects.round import Round
3+
from log_analyser.objects.team import Team
44
from datetime import datetime
55

66

src/log_analyser/objects/object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def export_json(self):
5555
dict_class_final.pop(key)
5656
else:
5757
dict_class_final[key] = self.export_json_recursive(value)
58-
return json.dumps(dict_class_final, indent=4, sort_keys=True, default=str)
59-
58+
# 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)
6060
def convert_timefile_to_datetime(self, time_string):
6161

6262

src/log_analyser/objects/player.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# from src.log_analyser.character import Character
2-
from objects.object import Object
3-
from objects.character import Character
2+
from log_analyser.objects.object import Object
3+
from log_analyser.objects.character import Character
44

55

66
class Player(Object):

src/log_analyser/objects/round.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from objects.object import Object
2-
from objects.team import Team
1+
from log_analyser.objects.object import Object
2+
from log_analyser.objects.team import Team
33

44

55
class Round(Object):

src/log_analyser/objects/team.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from objects.object import Object
2-
from objects.player import Player
1+
from log_analyser.objects.object import Object
2+
from log_analyser.objects.player import Player
3+
34

45
class Team(Object):
56

src/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import sys
44
from kafka_lib import ProducerThread, ConsumerThread
5+
from log_analyser.log_analyser import LogAnalyser
56

67

78
class DatastrikePythonProcessing:
@@ -21,7 +22,10 @@ def __init__(self):
2122
def on_callback_test(self, topic, data):
2223
print("message receive : ", topic, data)
2324

24-
self.producer_thread.send("analyse_report", "test")
25+
la = LogAnalyser('logs/Log-2023-12-22-21-12-32.txt', "Log-2023-12-22-21-12-32.txt")
26+
la.run()
27+
a = la.match.export_json()
28+
self.producer_thread.send("analyse.report", la.match.export_json())
2529

2630
def run(self):
2731

0 commit comments

Comments
 (0)