Tribler - fixed a bug in StatusParser.
authorAdriana Draghici <adriana008@gmail.com>
Mon, 7 Dec 2009 21:23:30 +0000 (23:23 +0200)
committerAdriana Draghici <adriana008@gmail.com>
Mon, 7 Dec 2009 21:23:30 +0000 (23:23 +0200)
log-parser/tribler/StatusParser.py
log-parser/tribler/make_db [new file with mode: 0644]
log-parser/tribler/run_sample
log-parser/tribler/run_sample_verbose
tribler-mod/merge_status_msg.sh

index 6c592b4..f0b185a 100644 (file)
@@ -70,11 +70,26 @@ def tribler_canon_upload_size(non_canon_value):
     pass
 # 26.456787 -> 26 (seconds)
 def tribler_canon_eta(non_canon_value):
-    return int(float(non_canon_value))
+    if non_canon_value != 'None':
+        return int(float(non_canon_value))
+    return None
 
+""" Get date and timestamp and transform it into datetime format.
+    Format: dd-mm-yyyy hh:mm:ss
+"""
+def tribler_parse_timestamp(date, time):
+    
+    date_array = date.split("-");
+    time_array = time.split(":");
+    if len(date_array) != 3 or len(time_array) != 3:
+        return None
+    
+    timestamp = datetime.datetime(int(date_array[2]), int(date_array[1]), int(date_array[0]), #year, month, day
+                                    int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec
+    return timestamp
 #
 # sample tribler status line
-# 03 Nov 2009 12:18:55   aqua.mpeg DLSTATUS_DOWNLOADING 29.84% None up     0.00KB/s down  4414.39KB/s eta 12 peers 2
+# 03-Nov-2009 12:18:55   aqua.mpeg DLSTATUS_DOWNLOADING 29.84% None up     0.00KB/s down  4414.39KB/s eta 12 peers 2
 #
 def tribler_parse_status_line(line):
     num_peers = 0
@@ -90,50 +105,45 @@ def tribler_parse_status_line(line):
     
     if DEBUG == True:
         print "string_array is: ", string_array
-    if len(string_array) != 16:
+    if len(string_array) != 14:
         print "Error: Invalid line format!"
         return None
 
     # get timestamp and transform it in datetime format
-    time_array = string_array[3].split(":");
-    if len(time_array) != 3:
-        timestamp = None
-    else:
-        timestamp = datetime.datetime(int(string_array[2]), int(string_array[1]), int(string_array[0]), #year, month, day
-                                    int(time_array[0]), int(time_array[1]), int(time_array[2])) #hour, min, sec
+    timestamp= tribler_parse_timestamp(string_array[0], string_array[1])
     
-    filename = string_array[4]
+    filename = string_array[2]
     
-    i = 5 
+    i = 3 
     while i < len(string_array): #string_array:
         if string_array[i] == "peers":
             num_peers = tribler_canon_num_peers(string_array[i+1])
-            print "num_peers = %d" %(num_peers)
+            if DEBUG == True: print "num_peers = %d" %(num_peers)
             i = i + 2
             continue
         if string_array[i] == "down":
             download_speed = tribler_canon_download_speed(string_array[i+1])
-            print "download_speed = %d" %(download_speed)
+            if DEBUG == True: print "download_speed = %d" %(download_speed)
             i = i + 2
             continue
         if string_array[i] == "up":
             upload_speed = tribler_canon_upload_speed(string_array[i+1])
-            print "upload_speed= %d" %(upload_speed)
+            if DEBUG == True: print "upload_speed= %d" %(upload_speed)
             i = i + 2
             continue
         if string_array[i] == "DLSTATUS_DOWNLOADING" or string_array[i] == "DLSTATUS_SEEDING":
             download_size = tribler_canon_download_size(string_array[i+1], filename)
-            print "download_size = %d" %(download_size)
+            if DEBUG == True: print "download_size = %d" %(download_size)
             i = i + 2
             continue
         if string_array[i] == "eta":
             eta = tribler_canon_eta(string_array[i+1])
-            print "eta = %d" %(eta)
+            if DEBUG == True: print "eta = %s" %(eta)
             i = i + 2
             continue
         i = i + 1
-    
-    print "-----------------------------gata o linie----------------"
+    if DEBUG == True: 
+        print "-----------------------------gata o linie----------------"
     return (timestamp, num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta)
 
 def tribler_parse_status_file(dbw, client_session_id, filename):
@@ -155,7 +165,7 @@ def tribler_parse_status_file(dbw, client_session_id, filename):
             (time, num_peers, dht, download_speed, upload_speed, download_size, upload_size, eta_time) = tribler_parse_status_line(line)
 
             if DEBUG == True:
-                print "(%d, %s, %d, %d kb/s, %d kb/s, %d bytes, %d bytes)" % (num_peers, time, eta_time, download_speed, upload_speed, 
+                print "(%d, %s, %s, %d kb/s, %d kb/s, %d bytes, %d bytes)" % (num_peers, time, eta_time, download_speed, upload_speed, 
                                                                                 download_size, upload_size)
             dbw.add_status_message_datetime(client_session_id, time, num_peers, dht, download_speed, upload_speed, 
                                             download_size, upload_size, eta_time)
diff --git a/log-parser/tribler/make_db b/log-parser/tribler/make_db
new file mode 100644 (file)
index 0000000..9747724
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+DB_NAME=test.db
+
+# remove database in case it exists
+rm -f $DB_NAME
+
+# create database
+pushd . &> /dev/null
+cd ../../auto/db && ./db_init ../../log-parser/tribler/$DB_NAME
+popd &> /dev/null
+
+# fill database with test data
+PYTHONPATH=../../auto/db/ python ../../auto/db/DatabaseAccess.py $DB_NAME
+
index 32799ef..01e9840 100755 (executable)
@@ -1,18 +1,10 @@
 #!/bin/bash
 
-DB_NAME=test.db
+if test $# -lt 2
+       then
+               echo "Usage: $0 <log_filename> <db_name>"
+else
+       PYTHONPATH=PYTHONPATH:../../auto/db/ python StatusParser.py -i 1 -f $1 $2; 
+fi
 
-# remove database in case it exists
-rm -f $DB_NAME
-
-# create database
-pushd . &> /dev/null
-cd ../../auto/db && ./db_init ../../log-parser/tribler/$DB_NAME
-popd &> /dev/null
-
-# fill database with test data
-PYTHONPATH=../../auto/db/ python ../../auto/db/DatabaseAccess.py $DB_NAME
-
-# fill status information
-PYTHONPATH=../../auto/db/ python StatusParser.py -i 1 -f ../../log-samples/tribler/test2.txt $DB_NAME
 
index ce20741..199d120 100755 (executable)
@@ -1,9 +1,9 @@
 #!/bin/bash
 
-if test $# -lt 1
+if test $# -lt 2
        then
-               echo "Usage: $0 <log_filename>"
+               echo "Usage: $0 <log_filename> <db_name>"
 else
-       PYTHONPATH=PYTHONPATH:../../auto/db/ python LogParser.py -i 1 -f $1 ../../auto/db/p2p-next.db
+       PYTHONPATH=PYTHONPATH:../../auto/db/ python LogParser.py -i 1 -f $1 $2
 fi
 
index b01bb40..c126f9b 100755 (executable)
@@ -3,7 +3,7 @@
 
 if test $# -lt 2
        then
-                       echo "Usage: $0 <file1> <file2>"
+                       echo "Usage: $0 <file1> <file2> - Copies file1 into file2"
 else
        cat $1 >> $2
 fi