Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.

Commit b5f22a9

Browse files
author
Francisco Marques
committed
Changed parameters and overall improvements
Also, started iterative merge (WIP)
1 parent 26c0b1c commit b5f22a9

File tree

2 files changed

+55
-35
lines changed

2 files changed

+55
-35
lines changed

statsTriggers.sql

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@ BEGIN
33
UPDATE client SET
44
nCon = (SELECT COUNT(*) FROM connection WHERE client = NEW.client),
55
totalTime = (SELECT SUM(duration) FROM connection WHERE client = NEW.client),
6-
maxTime = (SELECT MAX(duration) FROM connection WHERE client = NEW.client);
7-
END;
8-
9-
10-
CREATE TRIGGER user_stats AFTER UPDATE ON client WHEN NEW.user <> NULL
11-
BEGIN
12-
UPDATE user SET
13-
nCon = (SELECT SUM(nCon) FROM client WHERE user = NEW.user),
14-
totalTime = (SELECT SUM(duration) FROM client WHERE user = NEW.user),
15-
maxTime = (SELECT MAX(duration) FROM client WHERE user = NEW.user);
6+
maxTime = (SELECT MAX(duration) FROM connection WHERE client = NEW.client)
7+
WHERE id = NEW.client;
168
END;

ts3LogAnalyzer.py

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@
33
ts3LogAnalyzer.py
44
55
Usage:
6-
ts3LogAnalyzer.py <log>
7-
ts3LogAnalyzer.py <log> [-d <databse>] [--hide-ip] [--debug] [--output-logging]
6+
ts3LogAnalyzer.py <database> -a <path> [--stats] [--hide-ip] [--debug] [--output-logging]
7+
ts3LogAnalyzer.py <database> (--merge <c1> <c2> | --iterative-merge) [--debug] [--output-logging]
88
ts3LogAnalyzer.py -h | --help
99
ts3LogAnalyzer.py -v | --version
1010
1111
Options:
12-
-d --database <databse> Database to use or create (database.db used by default)
13-
--hide-ip Don't save ips
14-
--output-logging Output logging from THIS program to ts3LogAnalyzer.log
15-
--debug Output debug information
16-
-h --help Show this screen
17-
-v --version Show version
12+
-a --analyze <path> Log file or folder to analyze
13+
-s --stats Pre-populate statistic fields in client and user
14+
--hide-ip Don't save ips
15+
--iterative-merge Auto detect merging candidates and ask to merge them
16+
--output-logging Output logging from THIS program to ts3LogAnalyzer.log
17+
--debug Output debug information
18+
-h --help Show this screen
19+
-v --version Show version
1820
"""
1921

2022
__author__ = 'ToFran'
@@ -50,36 +52,50 @@ def main():
5052
handlers = [logging.FileHandler( "ts3LogAnalyzer.log", 'w', 'utf-8')] if arguments['--output-logging'] else None \
5153
)
5254

55+
database = arguments['<database>']
56+
logpath = arguments['--analyze']
5357
hideIp = arguments['--hide-ip']
54-
database = 'database.db'
55-
if arguments['--database']:
56-
database = arguments['--database']
58+
client_id_1 = arguments['<c1>']
59+
client_id_2 = arguments['<c2>']
5760

58-
#check if databse exits
61+
import time
62+
start_time = time.time()
63+
64+
#database
5965
exists = os.path.exists(database)
6066
db = sqlite3.connect(database)
6167
if not exists:
62-
setupDB()
68+
setupDB(arguments['--stats'])
6369
logging.info(database + ' created!')
64-
elif not arguments['--database']:
65-
logging.warning("-d not specified, using existing " + database)
6670

67-
#log files
68-
path = arguments['<log>']
71+
if logpath:
72+
analyze(logpath)
73+
elif client_id_1 and client_id_2:
74+
try:
75+
client_id_1 = int(client_id_1)
76+
client_id_2 = int(client_id_2)
77+
except Exception as e:
78+
logging.critical("Invalid merge input!")
79+
sys.exit()
80+
81+
mergeClients(client_id_1, client_id_2)
82+
83+
db.commit()
84+
db.close()
85+
print("--- %s seconds ---" % (time.time() - start_time))
86+
87+
def analyze(path):
6988
if os.path.isdir(path):
7089
logging.debug(path + " is a folder.")
71-
for f in glob.glob(arguments['<log>'] + '/*.log'):
90+
for f in glob.glob(path + '/*.log'):
7291
analyseFile(f)
7392
elif os.path.isfile(path):
7493
logging.debug(path + " is a file.")
7594
analyseFile(path)
7695
else:
77-
logging.critical(path + " does not exist! Terminating...")
96+
logging.critical(logpath + " does not exist! Terminating...")
7897
sys.exit()
7998

80-
db.commit()
81-
db.close()
82-
8399
def analyseFile(filepath):
84100
#check if logfile already analyzed
85101
savedLog = getLog(filepath)
@@ -224,7 +240,7 @@ def clientDisconnected(when, id, reason, logId, nickname = None):
224240
#################
225241
#DATABSE
226242

227-
def setupDB(statsTriggers = False):
243+
def setupDB(statsTriggers = True):
228244
with open("schema.sql", 'r') as f:
229245
schema = f.read()
230246
cur = db.cursor()
@@ -320,12 +336,24 @@ def mergeClients(client_id_1, client_id_2):
320336
return False
321337
elif(user1):
322338
setUser(client_id_2, user1)
323-
else:
339+
elif(user2):
324340
setUser(client_id_1, user2)
341+
else:
342+
#TODO
343+
logging.error("Not implemented!")
344+
return False
345+
logging.info("Client " + client_id_1 + " and " + client_id_2 + " merged.")
325346
return True
326347

327348
def iterativeMerge():
328-
349+
#Get nicknames used multiple times by multiple identeties
350+
timesUsed = 200
351+
c_nick = db.cursor()
352+
c_nick.execute("SELECT nickname from nickname GROUP BY nickname HAVING COUNT(client) >= 2 AND SUM(used) > ? ORDER BY SUM(used) DESC", [timesUsed])
353+
for nickname in c_nick:
354+
#c_cli = db.cursor()
355+
#c_nick.execute("SELECT client from nickname WHERE nickname = ", [timesUsed])
356+
print (nickname)
329357
return
330358

331359
# ----

0 commit comments

Comments
 (0)