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

Commit 84e7a70

Browse files
author
Francisco Marques
committed
Bugfixes and improvements
It is now ready for publishing
1 parent aac585e commit 84e7a70

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name = 'ts3LogAnalyzer',
13-
version = '2.0.1',
13+
version = '2.1',
1414
description = 'A cli utility for analyzing teamspeak 3 server logs.',
1515
ong_description = long_description,
1616
url = 'https://github.com/ToFran/TS3LogAnalyzer/',

ts3LogAnalyzer/schema.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,19 @@ CREATE TABLE IF NOT EXISTS log (
5151
size INTEGER NOT NULL DEFAULT 0
5252
);
5353

54-
CREATE TRIGGER TR_client_update_stats AFTER UPDATE ON client
54+
CREATE TRIGGER TR_client_update AFTER UPDATE ON client
5555
WHEN NEW.user_id <> NULL AND NEW.user_id <> OLD.user_id
5656
BEGIN
57+
--makes all brother clients point to the same father
58+
UPDATE client SET
59+
user_id = NEW.user_id
60+
WHERE user_id = OLD.user_id;
61+
62+
--delete lossen users
63+
DELETE FROM user
64+
WHERE user_id = OLD.user_id;
65+
66+
--update parent stats
5767
UPDATE user SET
5868
nCon = (SELECT SUM(nCon) FROM client WHERE user_id = NEW.user_id),
5969
totalTime = (SELECT SUM(totalTime) FROM client WHERE user_id = NEW.user_id),

ts3LogAnalyzer/ts3LogAnalyzer.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
__author__ = 'ToFran'
2626
__site__ = 'http://tofran.com/'
27-
__version__ = '2.0.1'
27+
__version__ = '2.1'
2828
__maintainer__ = 'ToFran'
2929
__email__ = 'me@tofran.com'
3030
__license__ = 'GNU GPLv3'
@@ -60,7 +60,6 @@ def main():
6060
logpath = arguments['--analyze']
6161
client_id_1 = arguments['<c1>']
6262
client_id_2 = arguments['<c2>']
63-
isMergeable = arguments['--mergeable'] or hasUsers()
6463

6564
import time
6665
start_time = time.time()
@@ -74,6 +73,8 @@ def main():
7473

7574
if logpath:
7675
analyze(logpath)
76+
77+
isMergeable = arguments['--mergeable'] or hasUsers()
7778
if isMergeable:
7879
mergeable()
7980
if client_id_1 and client_id_2:
@@ -340,8 +341,8 @@ def getCurTime():
340341
#User
341342
def hasUsers():
342343
cur = db.cursor()
343-
cur.execute("SELECT * FROM client TOP 1", [client_id])
344-
return cur.fetchone() is not none
344+
cur.execute("SELECT * FROM user LIMIT 1")
345+
return cur.fetchone() is not None
345346

346347
def getUser(client_id):
347348
cur = db.cursor()
@@ -384,8 +385,8 @@ def generateStats(users = False):
384385
cur.execute("SELECT user_id FROM user") #get all users
385386
for tup_id in cur: #set statistics for each user
386387
user_id = str(tup_id[0])
387-
cur = db.cursor()
388-
cur.execute(
388+
currUpdate = db.cursor()
389+
currUpdate.execute(
389390
"UPDATE user SET " + \
390391
"mainNickname = (SELECT nickname FROM nickname INNER JOIN client ON nickname.client_id = client.client_id WHERE client.user_id = :user_id ORDER BY used DESC LIMIT 1), " + \
391392
"nCon = (SELECT SUM(nCon) FROM client WHERE user_id = :user_id), " + \
@@ -396,18 +397,24 @@ def generateStats(users = False):
396397
)
397398
return
398399

399-
def removeIps():
400+
def removeIps(string = '0.0.0.0'):
401+
"""Replaces all ips with the parametized string
402+
"""
400403
cur = db.cursor()
401-
cur.execute("UPDATE connection SET ip = '0.0.0.0'")
404+
cur.execute("UPDATE connection SET ip = ?", string)
402405
return
403406

404407
def mergeable():
408+
"""Assign a new user for every client that doen't point to analyze
409+
This creates data duplication, but allows clients to be merged and shown properly
410+
"""
405411
cur = db.cursor()
406412
cur.execute("SELECT client_id FROM client WHERE user_id IS NULL") #get all crientid's that don't have user assigned
407413
for tup_id in cur: #set statistics for each crient
408414
client_id = str(tup_id[0])
409-
cur = db.cursor()
410-
cur.execute("UPDATE client SET user_id = ? WHERE client_id = ?", [insertUser(), client_id])
415+
newUser = insertUser()
416+
currUpdate = db.cursor()
417+
currUpdate.execute("UPDATE client SET user_id = ? WHERE client_id = ?", [newUser, client_id])
411418

412419

413420
def mergeClients(client_id_1, client_id_2):
@@ -418,7 +425,9 @@ def mergeClients(client_id_1, client_id_2):
418425
setUser(client_id_2, user1)
419426
elif(user2):
420427
setUser(client_id_1, user2)
421-
428+
else:
429+
logging.critical("Can merge useres, run mergeable before!")
430+
return False
422431

423432
logging.info("Client " + client_id_1 + " and " + client_id_2 + " merged.")
424433
return True

0 commit comments

Comments
 (0)