From: Razvan Deaconescu Date: Sat, 21 Nov 2009 19:08:22 +0000 (+0200) Subject: updated table verbose_messages to use direction field; updated database handling... X-Git-Tag: getopt_long~244 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=de408985abc4fd6a646caa9b549d4c8f02a8dab5;p=cs-p2p-next.git updated table verbose_messages to use direction field; updated database handling scripts accordingly --- diff --git a/auto/db/DatabaseAccess.py b/auto/db/DatabaseAccess.py index 31e925d..116eb30 100644 --- a/auto/db/DatabaseAccess.py +++ b/auto/db/DatabaseAccess.py @@ -248,13 +248,13 @@ class DatabaseAccess: if DEBUG == True: print "[verbose_messages] insert row", row try: - self.cursor.execute("insert into verbose_messages values (?,?,?,?,?,?,?,?,?)", row) + self.cursor.execute("insert into verbose_messages values (?,?,?,?,?,?,?,?,?,?)", row) self.conn.commit() except sqlite3.Error, e: print ("[verbose_messages]An error ocurred: ", e.args[0]) - def insert_verbose_messages(self, cs_id, timestamp, peer_ip, peer_port, message_type, _index, begin, length, listen_port): - self.insert_verbose_messages_row([cs_id, timestamp, peer_ip, peer_port, message_type, _index, begin, length, listen_port]) + def insert_verbose_messages(self, cs_id, timestamp, direction, peer_ip, peer_port, message_type, _index, begin, length, listen_port): + self.insert_verbose_messages_row([cs_id, timestamp, direction, peer_ip, peer_port, message_type, _index, begin, length, listen_port]) def select_verbose_messages(self, show = True, cs_id = -1, restrictArray=None): try: @@ -297,7 +297,11 @@ def main(): Test case """ - dba = DatabaseAccess("p2p-next.db") + if len(sys.argv) != 2: + print "Usage: python DatabaseAccess dbfile" + sys.exit(2) + + dba = DatabaseAccess(sys.argv[1]) dba.connect() @@ -325,8 +329,8 @@ def main(): ]: dba.insert_status_messages_row(t) - for t in [('1', '2455128.121295811', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), - ('4', '2455128.121295811', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), + for t in [('1', '2455128.121295811', '0', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), + ('4', '2455128.121295811', '1', '127.0.0.1', '1345', '0', '3', '4', '13', '777'), ]: dba.insert_verbose_messages_row(t) diff --git a/auto/db/DatabaseWriter.py b/auto/db/DatabaseWriter.py index 7694e65..8d6a272 100644 --- a/auto/db/DatabaseWriter.py +++ b/auto/db/DatabaseWriter.py @@ -13,27 +13,22 @@ class DatabaseWriter: self.dba = DatabaseAccess(dbname) self.dba.connect() - def add_status_message(self, cs_id, date, time, peer_num, dht, download_speed, upload_speed, download_size, upload_size, eta_time): + def add_status_message(self, cs_id, date, time, peer_num, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds): timestamp = float(julian.stringToJulian(date, time)); - eta = datetime.timedelta(eta_time[0], eta_time[3], 0, 0, eta_time[2], eta_time[1], 0) - eta_seconds = eta.days * 24 * 3600 + eta.seconds self.dba.insert_status_messages(cs_id, timestamp, peer_num, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds) - def add_status_message_datetime(self, cs_id, dt, peer_num, dht, download_speed, upload_speed, download_size, upload_size, eta_time): + def add_status_message_datetime(self, cs_id, dt, peer_num, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds): timestamp = float(julian.datetimeToJulian(dt)); - # adriana >:) - #eta = datetime.timedelta(eta_time[0], eta_time[3], 0, 0, eta_time[2], eta_time[1], 0) - #eta_seconds = eta.days * 24 * 3600 + eta.seconds - eta_seconds = eta_time #!!! already in seconds (tribler's fault) !!!! self.dba.insert_status_messages(cs_id, timestamp, peer_num, dht, download_speed, upload_speed, download_size, upload_size, eta_seconds) - def add_verbose_message(self, cs_id, date, time, peer_ip, peer_port, message_type, index, begin, length, listen_port): + def add_verbose_message(self, cs_id, date, time, direction, peer_ip, peer_port, message_type, index, begin, length, listen_port): timestamp = float(julian.stringToJulian(date, time)); - self.dba.insert_verbose_messages(cs_id, timestamp, peer_ip, peer_port, message_type, index, begin, length, listen_port) + self.dba.insert_verbose_messages(cs_id, timestamp, direction, peer_ip, peer_port, message_type, index, begin, length, listen_port) - def add_verbose_message(self, cs_id, dt, peer_ip, peer_port, message_type, index, begin, length, listen_port): + def add_verbose_message_datetime(self, cs_id, dt, direction, peer_ip, peer_port, message_type, index, begin, length, listen_port): timestamp = float(julian.datetimeToJulian(dt)); - self.dba.insert_verbose_messages(cs_id, timestamp, peer_ip, peer_port, message_type, index, begin, length, listen_port) + + self.dba.insert_verbose_messages(cs_id, timestamp, direction, peer_ip, peer_port, message_type, index, begin, length, listen_port) def show_status_messages(self, cs_id = -1): self.dba.select_status_messages(True, cs_id) diff --git a/auto/sql/p2p-log-sqlite.sql b/auto/sql/p2p-log-sqlite.sql index 6f3762b..b4616fd 100644 --- a/auto/sql/p2p-log-sqlite.sql +++ b/auto/sql/p2p-log-sqlite.sql @@ -43,9 +43,15 @@ create table status_messages ( upload_size integer check(upload_size between 0 and 100000000000), eta integer); +--- +--- direction = 0 -> receive (from peer) +--- direction = 1 -> send (to peer) +--- + create table verbose_messages ( cs_id integer references client_sessions(id) on delete cascade on update cascade, timestamp date, + direction integer check(direction between 0 and 1), peer_ip text, peer_port integer check(peer_port between 1 and 65535), message_type integer check (message_type between 0 and 100),