Skip to content

Commit

Permalink
latest stable chat-message-processor.
Browse files Browse the repository at this point in the history
  • Loading branch information
BoQsc committed Aug 18, 2024
1 parent 9dde121 commit d36d559
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
19 changes: 16 additions & 3 deletions webserver/Webserver-testing/Webserver/chat-message-processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ def datetime_to_string(obj):
return obj.strftime('%Y-%m-%dT%H:%M:%S')
raise TypeError(f"Object of type {obj.__class__.__name__} is not JSON serializable")

def process_log_file(file_path, data):
def load_player_status():
with open('Webserver_player_status.json', 'r') as f:
return json.load(f)

def get_player_name(pltfm_id, player_status):
for player_name, player_info in player_status['players'].items():
if player_info['pltfm_id'] == pltfm_id:
return player_name
return pltfm_id # Return pltfm_id if no matching player name is found

def process_log_file(file_path, data, player_status):
chat_messages = data.get('chat_messages', [])
last_processed_position = data.get('last_processed_position', 0)
last_processed_file = data.get('last_processed_file', '')
Expand All @@ -31,9 +41,11 @@ def process_log_file(file_path, data):
match = re.search(chat_pattern, line)
if match:
timestamp, pltfm_id, entity_id, chat_type, message = match.groups()
player_name = get_player_name(pltfm_id, player_status)
chat_messages.append({
'timestamp': datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S'),
'pltfm_id': pltfm_id,
'player_name': player_name,
'entity_id': entity_id,
'chat_type': chat_type,
'message': message
Expand Down Expand Up @@ -71,7 +83,7 @@ def analyze_chat(chat_messages):
word_frequency = {}

for message in chat_messages:
player = message['pltfm_id']
player = message['player_name']
player_message_counts[player] = player_message_counts.get(player, 0) + 1
chat_types.add(message['chat_type'])

Expand All @@ -96,8 +108,9 @@ def main():
while True:
latest_log_file = get_path_latest_game_server_log_file.get_path_latest_game_server_log_file()
data = load_data(data_file)
player_status = load_player_status()

result = process_log_file(latest_log_file, data)
result = process_log_file(latest_log_file, data, player_status)

if result['new_lines_processed'] > 0:
print(f"Processed {result['new_lines_processed']} new lines.")
Expand Down
7 changes: 6 additions & 1 deletion webserver/Webserver-testing/Webserver/chat_analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,39 @@
{
"timestamp": "2024-08-17T15:04:26",
"pltfm_id": "Steam_76561198072601792",
"player_name": "boqsc",
"entity_id": "171",
"chat_type": "Global",
"message": "gewwta"
},
{
"timestamp": "2024-08-17T15:10:01",
"pltfm_id": "Steam_76561198072601792",
"player_name": "boqsc",
"entity_id": "171",
"chat_type": "Global",
"message": "aa"
},
{
"timestamp": "2024-08-17T15:10:26",
"pltfm_id": "Steam_76561198072601792",
"player_name": "boqsc",
"entity_id": "171",
"chat_type": "Global",
"message": "dsf"
},
{
"timestamp": "2024-08-17T15:11:26",
"pltfm_id": "Steam_76561198072601792",
"player_name": "boqsc",
"entity_id": "171",
"chat_type": "Global",
"message": "test"
},
{
"timestamp": "2024-08-17T15:14:26",
"pltfm_id": "Steam_76561198072601792",
"player_name": "boqsc",
"entity_id": "171",
"chat_type": "Global",
"message": "zzz"
Expand All @@ -42,7 +47,7 @@
"analysis": {
"total_messages": 5,
"unique_players": 1,
"most_active_player": "Steam_76561198072601792",
"most_active_player": "boqsc",
"chat_types": [
"Global"
],
Expand Down

0 comments on commit d36d559

Please sign in to comment.