-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (78 loc) · 3.59 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import multiprocessing
import os
import traceback
import cProfile
import pstats
import argparse
from datetime import datetime
from SingleFileParser import SingleFileParser
from src.utils import Logger
from src.utils.Logger import log
from src.utils.Configs import config
def run(filePath: str, fileVerdict: bool) -> None:
singleFileParser = SingleFileParser(filePath, fileVerdict)
singleFileParser.start()
def startProfiler(processArg):
filePath: str = processArg[0]
fileVerdict: bool = processArg[1]
configFile: str = processArg[2]
config.updateConfig(configFile)
Logger.setProcessName(filePath)
print(f"Starting - {filePath} | VERDICT - {fileVerdict}")
try:
with cProfile.Profile() as pr:
run(filePath= filePath, fileVerdict= fileVerdict)
stats = pstats.Stats(pr)
stats.sort_stats(pstats.SortKey.TIME)
stats.dump_stats(filename= f"./logs/{filePath}.prof")
except Exception:
log(traceback.format_exc())
print(traceback.format_exc())
else:
print(f"Completed - {filePath}")
def startMultiprocessing(processArgs: list):
with multiprocessing.Pool(processes=5) as pool:
pool.map(startProfiler, processArgs)
def main():
argParser = argparse.ArgumentParser(description="Parse CSGO Demo (.dem) files.")
argParser.add_argument("-v", "--verdict", type=int, help="Verdict for all players in the demo file/files. Either 1 (True), 0 (False), 2(Auto Assign)")
argParser.add_argument("-c", "--compile", action='store_true', help="compile all generate csv files into single csv file.")
argParser.add_argument("-cnf", "--config", type=str, help="Path to the config file.")
argParser.add_argument('--version', action='version', version='VERSION: 1.1', help='Show parser version')
args = argParser.parse_args()
Logger.setProcessName("DRIVER")
if args.config is None:
print("config file not provided...")
log("config file not provided...")
return
configFile: str = os.path.abspath(args.config)
verdict: bool | None = None
if args.verdict is not None:
# Verdict provided, check if verdict is illegal
assert int(args.verdict) in (0, 1, 2), "Unknown Verdict. Allowed values: Either 1 (True), 0 (False), 2(Auto Assign)"
if int(args.verdict) in (0, 1):
verdict = False if int(args.verdict) == 0 else True
processArgs = [[file, verdict, configFile] for file in os.listdir("./DemoFiles/Demos/") if file[-4:] == '.dem']
# Change labels automatically if required
if args.verdict is not None and int(args.verdict) == 2:
for i in range(len(processArgs)):
processArgs[i][1] = True if processArgs[i][0].startswith("auto") else False
startMultiprocessing(processArgs)
if args.compile:
from src.utils.csvConcat import concatenate_csv_files
print("Compiling CSV Files...")
log("Compiling CSV Files...")
# Get the current directory (should be 'GEPCS')
current_dir: str = os.getcwd()
# Construct the path to the './DemoFiles/csv' folder
demo_files_dir = os.path.join(current_dir, 'DemoFiles', 'csv')
log("Located CSV directory:", demo_files_dir)
output_file = f"output-{datetime.now().strftime('%H-%M-%S')}.csv"
concatenate_csv_files(demo_files_dir, output_file)
from src.utils.Logger import compileLogs
# addition of Driver process name
processList: list[str] = [processArg[0] for processArg in processArgs]
processList.append("DRIVER")
compileLogs(processList)
if __name__ == "__main__":
main()