def stat_js(rpath): import re con = db.get_con(SyncDB.CONNECTION_ID, db=SyncDB.DATABASE) #get last update date; dt = db.from_sql( con, "Select * FROM {0}.statistics order by history desc".format( SyncDB.DATABASE)) dt['history'] = dt['history'].apply(str) latest_build_date = max(dt['history']) #Tracer()() dt = dt.query("history=='" + latest_build_date + "'") jquery_str = "window.descriptionStatistics ={'latest_build':'" + latest_build_date + "','ds_counts':{\n" totals = [] for table in [['i_ann_', 'annotation'], ['i_gene_', 'gid2terms'], ['i_term_', 'term2gids'], ['i_interaction_', 'interaction']]: dt_type = dt.query("table_name=='" + table[1] + "'") for k, g in dt_type.groupby(by=['type_id']): total_in_one_type = g['total'].sum() totals.append("'" + table[0] + str(k) + "':" + str(total_in_one_type)) jquery_str += ',\n'.join(totals) + "}}" with open(rpath + "gp_description_stats.js", "w") as report_file: report_file.write(jquery_str) files = util.unix('cp ' + rpath + 'gp_description_stats.js ' + rpath + 'gp_description_stats_' + latest_build_date + '.js')
def get_indexes_names(): result = [] query = 'SELECT TermTypeId, TermTypeName FROM termtype WHERE TermTypeID > 0 and isUsed = 1 ORDER BY Rank' con, cur = get_con() cur.execute(query) order = 0 for row in cur.fetchall(): result.append({'sort': order, 'type': row[0], 'label': row[1], 'hits': '0'}) order += 1 con.close() return json.dumps(result, ensure_ascii=False)
def browse_tree_by_serial(serial): # get topic id con, cur = get_con() # query = 'select TopicID from Topics where SerialPageID = %s' query = 'SELECT TopicID FROM Topics_Data WHERE SerialPageID = %s' cur.execute(query, (serial, )) row = cur.fetchone() if row is not None: topicID = row[0] con.close() return browse_tree(topicID) else: return "Not Found"
def get_serial(topicID): pageSerial = 1 query = 'SELECT SerialPageID FROM TopicsData WHERE TopicID = %s ORDER BY SerialPageID LIMIT 1' con, cur = get_con() cur.execute(query, (topicID,)) result = cur.fetchone() if result is not None: pageSerial = result[0] con.close() return json.dumps({'serial': pageSerial}, ensure_ascii=False)
def get_root_elements(): con, cur = get_con() query = 'select TopicID, TopicName, IsLeaf, SerialPageID from Topics where parentID is NULL ' \ 'or ParentID = 0 order by SortID' cur.execute(query) result = cur.fetchall() root = [] if result is not None: for row in result: short_title = shorten(row[1], 15) root.append({'TopicID': row[0], 'TopicName': short_title, 'IsLeaf': row[2], 'SerialPageID': row[3]}) con.close() return root
def get_tree_head(topicID): con, cur = get_con() query = 'select TopicID, TopicName, Path, IsLeaf from Topics where TopicID = %s' cur.execute(query, (topicID,)) row = cur.fetchone() head = [] if row is not None: path = row[2] # print 'path is ', path for tid in path.split('/'): cur.execute(query, (tid,)) row = cur.fetchone() if row is not None: head.append({'TopicID': row[0], 'TopicName': shorten(row[1], 25), 'IsLeaf': row[3]}) return head
def get_tree_kids(topicID): con, cur = get_con() from search import shorten query = 'select TopicID, TopicName, IsLeaf, SerialPageID from Topics where parentID = %s order by SortID' cur.execute(query, (topicID, )) result = cur.fetchall() body = [] body_count = 0 if result is not None: for row in result: body_count += 1 short_title = shorten(row[1], 15) body.append({'TopicID': row[0], 'TopicName': short_title, 'IsLeaf': row[2], 'SerialPageID': row[3]}) con.close() return body
def history(): con = db.get_con(SyncDB.CONNECTION_ID, db=SyncDB.DATABASE) query = "DELETE FROM {0}.statistics where history = CURDATE()" query = query.format(SyncDB.DATABASE) db.from_sql(con, query) query = """ INSERT INTO {0}.statistics SELECT a.*, CURDATE() AS history FROM( SELECT 'gid2source_id' AS table_name, it.display_name AS type_name, it.id_type_id as type_id, it.ds_name as ds, gs.tax_id, COUNT(*) AS total FROM {0}.gid2source_id gs , {0}.id_type it WHERE gs.id_type_id = it.id_type_id GROUP BY gs.id_type_id, gs.tax_id UNION ALL SELECT 'annotation' AS table_name, a_t.display_name AS type_name, a_t.annotation_type_id as type_id, a_t.ds_name as ds, a.tax_id, COUNT(*) AS total FROM {0}.annotation a, {0}.annotation_type a_t WHERE a.annotation_type_id = a_t.annotation_type_id GROUP BY a.annotation_type_id, a.tax_id UNION ALL SELECT 'gid2terms' AS table_name, tc.category_name AS type_name, tc.term_category_id as type_id, tc.ds_name as ds, gt.tax_id , COUNT(*) FROM {0}.gid2terms gt, {0}.term_category tc where tc.term_category_id = gt.term_category_id GROUP BY tc.term_category_id, gt.tax_id UNION ALL SELECT 'homologene' AS table_name, 'Homologene' AS type_name, 1 as type_id, 'NCBI' as ds, hg.tax_id, COUNT(*) AS total FROM {0}.homologene hg group by hg.tax_id UNION ALL SELECT 'term' AS table_name, tc.category_name AS type_name, tc.term_category_id as type_id, tc.ds_name as ds, NULL as tax_id, COUNT(*) AS total FROM {0}.term t, {0}.term_category tc WHERE t.term_category_id = tc.term_category_id GROUP BY t.term_category_id UNION ALL SELECT 'term2gids' AS table_name, tc.category_name AS type_name, tc.term_category_id as type_id, tc.ds_name as ds, gt.tax_id, COUNT(*) as total FROM {0}.term2gids gt, {0}.term_category tc where tc.term_category_id = gt.term_category_id GROUP BY tc.term_category_id, gt.tax_id UNION ALL SELECT 'term2term' AS table_name, 'Term relations' AS type_name, tc.term_category_id as type_id, tc.ds_name as ds, NULL as tax_id, COUNT(*) AS total FROM {0}.term2term tt, {0}.term_category tc WHERE tt.term_category_id = tc.term_category_id GROUP BY tt.term_category_id UNION ALL SELECT 'interaction' AS table_name, i_t.interaction_type_name AS type_name, i_t.interaction_type_id as type_id, i_t.ds_name as ds, i.tax_id_A as tax_id, COUNT(*) AS total FROM {0}.interaction i, {0}.interaction_type i_t WHERE i.interaction_type_id = i_t.interaction_type_id GROUP BY i.interaction_type_id, i.tax_id_A )a order by a.table_name, a.ds, a.type_name, a.tax_id """ query = query.format(SyncDB.DATABASE) db.from_sql(con, query)
def report_js(rpath): import re con = db.get_con(SyncDB.CONNECTION_ID, db=SyncDB.DATABASE) #get last update date; dt = db.from_sql( con, "Select * FROM {0}.statistics order by history desc".format( SyncDB.DATABASE)) dt['history'] = dt['history'].apply(str) cur_date = max(dt['history']) json_arr = [] for c in dt.columns: json_arr.append('"' + c + '":' + dt[c].to_json(orient='values')) with open(rpath + "gp_stats.js", "w") as report_file: report_file.write("window.buildLogStatistics=") report_file.write(dt.to_json(orient='records')) files = util.unix('cp ' + rpath + 'gp_stats.js ' + rpath + 'gp_stats_' + cur_date + '.js')
def get_index_item_hits(index_type, item_id): result = [] # url query parameters passed from python are strings index_type = int(index_type) query = "" con, cur = db.get_con() if index_type == 1: # Ayat # query = 'SELECT DISTINCT Terms_Ayat.SerialPageID, Topics.TopicName FROM Terms_Ayat INNER JOIN Topics ON Topics.TopicID = Terms_Ayat.TopicID WHERE ID = %s ORDER BY Terms_Ayat.SerialPageID' query = 'SELECT DISTINCT Terms_Ayat.SerialPageID, Topics.TopicName FROM Terms_Ayat INNER JOIN Topics ON Topics.TopicID = Terms_Ayat.TopicID WHERE AyaID = %s ORDER BY Terms_Ayat.SerialPageID' elif index_type == 2: # ahadeth_qawlia query = 'SELECT DISTINCT Terms_Hadeth.SerialPageID, Topics.TopicName FROM Terms_Hadeth INNER JOIN Topics ON Topics.TopicID = Terms_Hadeth.TopicID WHERE JoinType = 1 AND JoinID = %s ORDER BY Terms_Hadeth.SerialPageID' elif index_type == 3: # ahadeth-fe3lia query = 'SELECT DISTINCT Terms_Hadeth.SerialPageID, Topics.TopicName FROM Terms_Hadeth INNER JOIN Topics ON Topics.TopicID = Terms_Hadeth.TopicID WHERE JoinType = 2 AND JoinID = %s ORDER BY Terms_Hadeth.SerialPageID' elif index_type == 5: # kotob query = 'SELECT DISTINCT Terms_Topics.SerialPageID, Topics.TopicName FROM Terms_Topics INNER JOIN Topics ON Topics.TopicID = Terms_Topics.TopicID WHERE JoinType = 5 AND JoinedTopicID = %s ORDER BY Terms_Topics.SerialPageID' elif index_type == 7: # aalam query = 'SELECT DISTINCT Terms_Topics.SerialPageID, Topics.TopicName FROM Terms_Topics INNER JOIN Topics ON Topics.TopicID = Terms_Topics.TopicID WHERE JoinType = 7 AND JoinedTopicID = %s ORDER BY Terms_Topics.SerialPageID' elif index_type == 8: # ma3lama query = 'SELECT DISTINCT Terms_Topics.SerialPageID, Topics.TopicName FROM Terms_Topics INNER JOIN Topics ON Topics.TopicID = Terms_Topics.TopicID WHERE JoinType = 3 AND JoinedTopicID = %s ORDER BY Terms_Topics.SerialPageID' elif index_type == 9: # mostala7at query = 'SELECT DISTINCT Terms_Topics.SerialPageID, Topics.TopicName FROM Terms_Topics INNER JOIN Topics ON Topics.TopicID = Terms_Topics.TopicID WHERE JoinType = 9 AND JoinedTopicID = %s ORDER BY Terms_Topics.SerialPageID' else: # More than 9 # query = "SELECT SerialPageID, Name FROM Terms_Topics WHERE JoinType=%s AND JoinedTopicID=%s order by Name_Sort" query = '''SELECT DISTINCT Terms_Topics.SerialPageID, Topics.TopicName FROM Terms_Topics INNER JOIN Topics ON Topics.TopicID = Terms_Topics.TopicID WHERE JoinType = %s AND JoinedTopicID = %s ORDER BY Terms_Topics.SerialPageID''' if index_type >= 1 and index_type <= 9: cur.execute(query, (item_id,)) else: cur.execute(query, (index_type, item_id)) for row in cur.fetchall(): serial = row[0] text = row[1] title = db.shorten_text(row[1], 7) highlight_code = create_highlight_code(index_type, item_id) result.append({'text': text, 'serial': int(serial), 'title': title, 'highlight': highlight_code}) con.close() return json.dumps(result, ensure_ascii=False)
def browse_tree(topic_id): con, cur = get_con() topic_id = int(topic_id) if topic_id == 1: # special ID means that is root tree view root = get_root_elements() if len(root) == 1: # one head element head = root body = get_tree_kids(head[0]['TopicID']) else: # multi head elements head = [] body = root else: # Just legal and valid ID got from database body = get_tree_kids(topic_id) head = get_tree_head(topic_id) return json.dumps({'head': head, 'body': body}, ensure_ascii=False)
def get_definition(definition_type, definition_ids_str): # definition_title = 'invalid ID' # definition_text = 'invalid ID' if definition_type == 'TermALAM': query = 'SELECT TermName, TermDefinitions FROM Terms WHERE TermTypeID = 7 AND TermID = %s' elif definition_type == 'TermMost': query = 'SELECT TermName, TermDefinitions FROM Terms WHERE TermTypeID = 9 AND TermID = %s' elif definition_type == 'BR': query = 'SELECT Name, Notes FROM Books_References WHERE ID = %s' #Added By Abdeldayem elif definition_type == 'JudSys': query = 'SELECT TopicName AS Name, TopicText AS Notes FROM TopicsJudicialSystems WHERE TopicID = %s' elif definition_type == 'Bodies_Inst': query = 'SELECT Name, Notes FROM Bodies_Institutions WHERE ID = %s' elif definition_type == 'JudPrinc': query = 'SELECT Name, Notes FROM JudicialPrinciples WHERE ID = %s' elif definition_type == 'ContractTerms': query = 'SELECT Name, Notes FROM ContractualTerms WHERE ID = %s' elif definition_type == 'Place': query = 'SELECT Name, Notes FROM Places WHERE ID = %s' else: query = None # It is a set of IDs definition_ids = str(definition_ids_str).split(",") final_result = [] if query is None: return json.dumps(final_result, ensure_ascii=False) con, cur = get_con() for def_id in definition_ids: cur.execute(query, (def_id,)) result = cur.fetchone() if result is not None: definition_title = result[0] definition_text = page.cleanup_text(result[1]) final_result.append({'title': definition_title, 'text': definition_text}) con.close() return json.dumps(final_result, ensure_ascii=False)
def get_page(page_serial, index_highlight_code): page_serial = str(page_serial) # convert to ensure data type page = 'invalid ID' con, cur = get_con() query = 'SELECT PageText, SerialPageID, PageID, TopicID, Path FROM Topics_Data WHERE SerialPageID = %s' cur.execute(query, (page_serial,)) path = '' result = cur.fetchone() if result is not None: # arabicStyle = 'text-align: justify;font-size:15pt; font-family: Traditional Arabic; padding-left: 15px;' arabicStyle = '' # page = '<div dir=rtl id="page_div_%s" style="%s">%s</div>' % (page_serial, arabicStyle, result[0]) page = '<div id="page_div_%s">%s</div>' % (page_serial, result[0]) page_serial = result[1] number = result[2] topic_id = result[3] # path = result[4] query = 'SELECT FootNoteID, FootNoteText FROM TopicsFootNotes WHERE TopicID = %s AND PageID = %s ORDER BY FootNoteID' cur.execute(query, (topic_id, number)) result = cur.fetchall() # footnoteStyle = 'text-align: justify;font-size:11pt; font-family: Traditional Arabic; padding-left: 15px;' # footnoteStyle = '' if result is not None: page += '<br><hr>' for row in result: # page += '<spin id="hamesh_%d_%d" dir=rtl style="%s">(%d) %s</spin><br>' % ( page += '<spin class="footnote-text" id="hamesh_%d_%d">(%d) %s</spin><br>' % ( page_serial, row[0], row[0], row[1]) con.close() page = cleanup_text(page) if len(index_highlight_code) > 0: # if index item exist that needs highlighting # By adding class= at the start, you ensure you do not replace unwanted text page = page.replace("class=\"" + index_highlight_code, "class=\"" + "highlight") # print ">>> Page is changed, ", index_highlight_code return page.encode("UTF-8")
def run(self): con = db.get_con() trans = con.transaction() while 1: Base.vlock.acquire() self.chunks = Base.chunks Base.chunks = [] Base.vlock.release() print "Hanlding harvested data(%d)" % len(self.chunks) for chunk in self.chunks: try: handler.handle(chunk, trans) except Exception: print "ERROR IN %s" % chunk if self.chunks: trans.commit() print "COMMITED (%d)" % len(self.chunks) else: print "NOTHING" self.chunks = [] time.sleep(HANDLER_DELAY)
def run(self): con = db.get_con() trans = con.transaction() while 1: Base.vlock.acquire() self.chunks = Base.chunks Base.chunks = [] Base.vlock.release() print "Hanlding harvested data(%d)" % len(self.chunks) for chunk in self.chunks: try: handler.handle(chunk,trans) except Exception: print "ERROR IN %s" % chunk if self.chunks: trans.commit() print "COMMITED (%d)" % len(self.chunks) else: print "NOTHING" self.chunks=[] time.sleep(HANDLER_DELAY)
def get_index(index_type): result = [] # url query parameters passed from python are strings index_type = str(index_type) querySource = { #'1': 'SELECT Name, ID FROM Terms_Ayat ORDER BY SoraNO, AyaNO', # ayat '1': 'SELECT DISTINCT Name_Shamla AS Name, AyaID AS ID FROM Terms_Ayat ORDER BY AyaID', # ayat '2': 'SELECT Name, ID FROM Terms_Hadeth WHERE JoinType = 1 and ID=JoinID ORDER BY Name_Sort', # ahadeth_qawlia '3': 'SELECT Name, ID FROM Terms_Hadeth WHERE JoinType = 2 and ID=JoinID ORDER BY Name_Sort', # ahadeth-fe3lia '5': 'SELECT Name, ID FROM Books_References ORDER BY Name_Sort', # kotob '7': 'SELECT TermName, TermID FROM Terms WHERE TermTypeID = 7 ORDER BY Name_Sort', # aalam '8': 'SELECT BookName, BookID FROM Books ORDER BY Name_Sort', # ma3lama '9': 'SELECT TermName, TermID FROM Terms WHERE TermTypeID = 9 ORDER BY Name_Sort', # mostala7at # New indexes '10': 'SELECT Name, ID FROM Places ORDER BY Name_Sort', '16': 'SELECT TopicName, TopicID FROM TopicsFeqh ORDER BY SortID', '17': 'SELECT Name, ID FROM Ejma3at ORDER BY Name_Sort', '18': 'SELECT Name, ID FROM JudicialPrinciples ORDER BY Name_Sort', '19': 'SELECT Name, ID FROM ContractualTerms ORDER BY Name_Sort', '21': 'SELECT Name, ID FROM Bodies_Institutions ORDER BY Name_Sort', '22': 'SELECT TopicName, TopicID FROM topicsjudicialsystems ORDER BY SortID', '24': 'SELECT Name, ID FROM Judge ORDER BY Name_Sort', '25': 'SELECT Name, ID FROM Claimant ORDER BY Name_Sort', '26': 'SELECT Name, ID FROM Respondent ORDER BY Name_Sort', '27': 'SELECT Name, ID FROM Witnesses ORDER BY Name_Sort', '28': 'SELECT Name, ID FROM Experts ORDER BY Name_Sort', } con, cur = db.get_con() cur.execute(querySource[index_type]) for row in cur.fetchall(): text = row[0] ID = row[1] result.append({'text': text, 'id': ID, 'type': index_type}) con.close() return json.dumps(result, ensure_ascii=False)
def __init__(self, taxidList): self.con = db.get_con('GENEGO') self.taxidList = taxidList
def report_html(rpath): import re con = db.get_con(SyncDB.CONNECTION_ID, db=SyncDB.DATABASE) #get last update date; dt = db.from_sql( con, "Select distinct history FROM {0}.statistics order by history desc" .format(SyncDB.DATABASE)) if (len(dt['history']) < 2): print "No previous build statistics found." return cur_date = str(dt['history'][0]) last_date = str(dt['history'][1]) query = """ select t.* from ( SELECT new.ds as data_source, new.table_name, new.type_name, new.total as size, (new.total - old.total) as growth, (new.total - old.total)/old.total *100 AS delta, 0 as new_missing FROM {2}.statistics old, {2}.statistics new WHERE old.history = '{0}' AND new.history = '{1}' AND old.table_name = new.table_name AND old.type_name = new.type_name UNION SELECT new.ds as data_source, new.table_name, new.type_name, new.total as size, new.total as growth, 101 AS delta, 1 as new_missing FROM {2}.statistics new left Join (select * from {2}.statistics where history = '{0}') old on old.table_name = new.table_name and old.type_name = new.type_name WHERE new.history = '{1}' AND old.table_name is NULL UNION SELECT old.ds as data_source, old.table_name, old.type_name, old.total as size, -old.total as growth, -101 AS delta, -1 as new_missing FROM {2}.statistics old left Join (select * from {2}.statistics where history = '{1}') new on old.table_name = new.table_name and old.type_name = new.type_name WHERE old.history = '{0}' AND old.table_name is NULL ) t ORDER BY data_source, table_name, delta DESC; """ query = query.format(last_date, cur_date, SyncDB.DATABASE) dt = db.from_sql(con, query) #Tracer()() missing_data = dt.query('new_missing < 0') new_data = dt.query('new_missing > 0') expanded_data = dt.query('growth > 0') reduced_data = dt.query('growth < 0') unchanged_data = dt.query('growth == 0 and new_missing==0') reports = [ r for r in sorted(os.listdir(rpath)) if "Report_" in r and r != "Report_" + cur_date + ".html" ] last_report = reports[len(reports) - 1] if len(reports) > 0 else None #import datetime #time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') html = '<!DOCTYPE html><html><head><title> GP Build Report ' + cur_date + '</title></head><body><h1> GP Build Report ' + cur_date + '</h1>' if last_report: html += '<span id="lastreportlink"><a href="' + last_report + '"><<</a></span>\n' html += '<span id="nextreportlink"></span>\n' html += '<div>' if (len(missing_data) > 0): html += '<h4> Missing Data: </h4><table><tr><th>Data Source</th><th>Table Name</th><th>Type Name</th><th>Size</th></tr>' for i in range(len(missing_data)): html += '<tr><td>' + missing_data.irow( i)['data_source'] + '</td><td>' + missing_data.irow( i)['table_name'] + '</td><td>' + missing_data.irow( i)['type_name'] + '</td><td>' + str( missing_data.irow(i)['growth']) + '</td></tr>' if (len(missing_data) > 0): html += '</table>' html += '</div><div>' if (len(new_data) > 0): html += '<h4> New Data: </h4><table><tr><th>Data Source</th><th>Table Name</th><th>Type Name</th><th>Size</th></tr>' for i in range(len(new_data)): html += '<tr><td>' + new_data.irow( i)['data_source'] + '</td><td>' + new_data.irow( i)['table_name'] + '</td><td>' + new_data.irow( i)['type_name'] + '</td><td>' + str( new_data.irow(i)['growth']) + '</td></tr>' if (len(new_data) > 0): html += '</table>' html += '</div><div>' if (len(expanded_data) > 0): html += '<h4> Expanded Data: </h4><table><tr><th>Data Source</th><th>Table Name</th><th>Type Name</th><th>Size Diff</th> <th>Ratio</th></tr>' for i in range(len(expanded_data)): html += '<tr><td>' + expanded_data.irow( i)['data_source'] + '</td><td>' + expanded_data.irow( i)['table_name'] + '</td><td>' + expanded_data.irow( i)['type_name'] + '</td><td>' + str( expanded_data.irow(i) ['growth']) + '</td><td>' + str( expanded_data.irow(i)['delta']) + '</td></tr>' if (len(expanded_data) > 0): html += '</table>' html += '</div><div>' if (len(reduced_data) > 0): html += '<h4> Reduced Data: </h4><table><tr><th>Data Source</th><th>Table Name</th><th>Type Name</th><th>Size Diff</th> <th>Ratio</th></tr>' for i in range(len(reduced_data)): html += '<tr><td>' + reduced_data.irow( i)['data_source'] + '</td><td>' + reduced_data.irow( i)['table_name'] + '</td><td>' + reduced_data.irow( i)['type_name'] + '</td><td>' + str( reduced_data.irow(i) ['growth']) + '</td><td>' + str( reduced_data.irow(i)['delta']) + '</td></tr>' if (len(reduced_data) > 0): html += '</table>' html += '</div><div>' if (len(unchanged_data) > 0): html += '<h4> Unchanged Data: </h4><table><tr><th>Data Source</th><th>Table Name</th><th>Type Name</th><th>Size</th> </tr>' for i in range(len(unchanged_data)): html += '<tr><td>' + unchanged_data.irow( i)['data_source'] + '</td><td>' + unchanged_data.irow( i)['table_name'] + '</td><td>' + unchanged_data.irow( i)['type_name'] + '</td><td>' + str( unchanged_data.irow(i)['size']) + '</td></tr>' if (len(unchanged_data) > 0): html += '</table>' html += '</div>' html += '</body></html>' with open(rpath + "Report.html", "w") as report_file: report_file.write(html) files = util.unix('cp ' + rpath + 'Report.html ' + rpath + 'Report_' + cur_date + '.html') if last_report: with open(rpath + last_report, "r") as last_report_file: last_html = last_report_file.read() last_html = re.sub( r"<span id=\"nextreportlink\">.*</span>", '<span id="nextreportlink"><a href="' + 'Report_' + cur_date + '.html">>></a></span>', last_html) with open(rpath + last_report, "w") as last_report_file: last_report_file.write(last_html)
def get_connection_controller(): return get_con()
def get_connection(self): if self.con is None: self.con = db.get_con(SyncDB.CONNECTION_ID, db=SyncDB.DATABASE) return self.con
# <title>Topology of testnetwork(s):</title> # <META HTTP-EQUIV="REFRESH" CONTENT="180;URL=http://sleon.dyndns.org/~sleon/functions.py/gentopology"> # </head> # <body> # <img alt="topologymap" src=/~sleon/output.png> # </body> # </html> # """ oldnstate={} if len(sys.argv) > 1: delay=int(sys.argv[1]) else: delay=60 print "delay is %d" % delay for i in range(10): con = db.get_con() trans = con.transaction() generator = Generator(oldnstate) #STARING TRANS generator.gentopology(trans) histogram.gen(trans) ciclegraph.gen(trans) #COMMITING TRANS trans.commit() oldnstate = generator.oldnstate trans.close() db.close_con(con) print "sleeping for %d seconds" % delay sleep(delay)
def inert(self): con, cur = get_con() cur.execute( "insert into(id,username,password,ip) values(1,'%s','%s','%s')" % (self.user, self.password, self.ip))
#!/usr/bin/env python from os import sys, path p1 = path.join(path.dirname(path.abspath(__file__)), '../mylib') print p1 sys.path.insert(0, p1) import pandas as pd import util import db import urllib con = db.get_con('GENEGO') t = db.from_sql('select 1 from dual') print t
# <title>Topology of testnetwork(s):</title> # <META HTTP-EQUIV="REFRESH" CONTENT="180;URL=http://sleon.dyndns.org/~sleon/functions.py/gentopology"> # </head> # <body> # <img alt="topologymap" src=/~sleon/output.png> # </body> # </html> # """ oldnstate = {} if len(sys.argv) > 1: delay = int(sys.argv[1]) else: delay = 60 print "delay is %d" % delay for i in range(10): con = db.get_con() trans = con.transaction() generator = Generator(oldnstate) #STARING TRANS generator.gentopology(trans) histogram.gen(trans) ciclegraph.gen(trans) #COMMITING TRANS trans.commit() oldnstate = generator.oldnstate trans.close() db.close_con(con) print "sleeping for %d seconds" % delay sleep(delay)