def main(): client = db.get_client("localhost", 27017) db_conn = db.connect_to_db(client, "medium") collection = db.get_collection(db_conn, "userinfo") users = db.get(collection, {}) db.close(client) g = graph.create_graph(get_nodes(users), 200) graph_plt = graph.plot_graph( g, { "with_labels": False, "node_color": "blue", "width": 1.0, "node_width": 0.5 }) graph_plt.show() degree_histogram_plt = graph.plot_degree_distribution(g) degree_histogram_plt.show() betweenness_plt = graph.plot_betweenness(g) betweenness_plt.show() clustering_coefficient_plot = graph.plot_clustering_coefficient(g) clustering_coefficient_plot.show() print(graph.page_rank(g)) print(graph.average_clustering_coefficient(g))
def _parse_results(file): db = lib.db.db() db.params['dbname'] = 'databases/d2bfs.db' db.params['table'] = 'results' db.connect() lines = open(file, 'r').readlines() for line in lines: if '[ssh]' in line and 'host:' in line: line = line.split() host = line[2] user = line[4] passwd = line[6] db.select( 'SELECT * FROM ' + db.params['table'] + ' WHERE host=? AND user=? AND pass=?', ( host, user, passwd, )) if db.params['selects']: continue else: db.params['cursor'].execute( 'INSERT INTO ' + db.params['table'] + ' VALUES (NULL, ?, ?, ?)', ( host, user, passwd, )) db.params['connex'].commit() db.close()
def save(fit, suffix="tr"): bin = tuple(fit.cut["pt_ups"]) dbname = "chib3s" + ("_" + suffix if suffix else "") db = shelve.open('data/%s.db' % dbname) year = db.get(fit.year, {}) year[bin] = fit.model.params() db[fit.year] = year print db[fit.year] db.close() figname = fit.year + ("_" + suffix if suffix else "") canvas.SaveAs("figs/data/fits3s/f%s_%d_%s.pdf" % (figname, bin[0], str(bin[1])))
def store(self) -> None: """Stores/updates the answer in the sqlite database.""" con, c = db.connect() if not db.exists( 'SELECT * FROM answers WHERE id = ?', self.id, con=con): c.execute('INSERT INTO answers VALUES (?, ?, ?, ?, ?, ?, ?)', ( self.id, self.answer, self.likes, self.created, self.tell, self.user.id, self.parent_id, )) c.execute('UPDATE answers SET answer=?, likes=?, created=?, tell=?, user=? '+\ 'WHERE id = ?', (self.answer, self.likes, self.created, self.tell, self.user.id, self.id,)) db.close(con)
def store(self) -> None: """Stores/updates all the user's information in the sqlite db.""" con, c = db.connect() if not db.exists('SELECT * FROM users WHERE id = ?', self.id, con=con): c.execute( 'INSERT INTO users VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', ( self.avatar, self.followers, self.following, self.id, self.name, self.uname, self.about, self.likes, self.answers, self.tells, self.verified, )) c.execute('UPDATE users SET avatar=?, followers=?, following=?, name=?, uname=?, '+\ 'about=?, likes=?, answers=?, tells=?, verified=? WHERE id = ?', (self.avatar, self.followers, self.following, self.name, self.uname, self.about, self.likes, self.answers, self.tells, self.verified, self.id,)) db.close(con)
def test_close_set_connected(self): db = self.db() db.connect() db.close() self.assertFalse(db.connected())
def test_close(self): db = self.db() db.connect() conn = db._conn db.close() self.assertTrue(conn.close_kwargs is not None)
def teardown_request(exception): db = getattr(g, 'db', None) if db is not None: db.close()
def test_close_set_connected(self): db = self.db() db.connect() db.close() self.assertFalse(db.connected())
def test_close(self): db = self.db() db.connect() conn = db._conn db.close() self.assertTrue(conn.close_kwargs is not None)