-
Notifications
You must be signed in to change notification settings - Fork 1
/
entities_collect_script.py
executable file
·59 lines (52 loc) · 2.24 KB
/
entities_collect_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import csv
import sys
def get_last_player_id(csv_file):
if not os.path.exists(csv_file):
return 0 # Return 0 if file doesn't exist
else:
with open(csv_file, mode="r", newline="") as csvfile:
reader = csv.DictReader(csvfile)
last_player_id = 0
for row in reader:
last_player_id = int(row["Player_ID"])
return last_player_id
def count_player_logs(logs_folder):
count = 0
for filename in os.listdir(logs_folder):
if filename.startswith("player_log") and filename.endswith(".csv"):
count += 1
return count
def extract_player_logs(logs_folder, total_players, last_player_id):
player_logs = []
player_id = last_player_id + 1
for filename in os.listdir(logs_folder):
if filename.startswith("player_log") and filename.endswith(".csv"):
with open(os.path.join(logs_folder, filename), mode="r") as file:
reader = csv.DictReader(file, delimiter=";")
next(reader) # Skip header
for row in reader:
if int(row["Number of Players (Client)"]) >= total_players and int(row["Frame Number"]) > 1:
player_logs.append([player_id, total_players, row["NFE RTT"]])
player_id += 1
return player_logs
def save_results(player_logs):
file_exists = os.path.exists("/var/scratch/esu530/entities_results.csv")
with open("/var/scratch/esu530/entities_results.csv", mode="a", newline="") as file:
writer = csv.writer(file)
if not file_exists: # Write header only if file is empty
writer.writerow(["Player_ID", "Total_Players", "RoundTripDelay_ms"])
for log in player_logs:
writer.writerow(log)
def main(logs_folder):
total_players = count_player_logs(logs_folder)
last_player_id = get_last_player_id("/var/scratch/esu530/entities_results.csv")
player_logs = extract_player_logs(logs_folder, total_players, last_player_id)
save_results(player_logs)
print("Script execution completed.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script_name.py <logs_folder>")
sys.exit(1)
logs_folder = sys.argv[1]
main(logs_folder)