def find_threshold(): with gc.get_conn() as conn: gnuids = conn.execute('select posmatchid from posmatchids') gnuids = (row[0] for row in gnuids) m = [(gnuid, gg.position_id_to_max_pips(gnuid.split(':')[0])) for gnuid in gnuids] m.sort(key=lambda o: o[1]) total_records = len(m) print m[int(total_records * .95)]
def f_(self, *args, **kwargs): t0 = time.time() with gc.get_conn() as conn: logger.info('Time taken for connecting to db: %.3f', time.time() - t0) cp.thread_data.conn = conn try: return f(self, *args, **kwargs) except cp.HTTPRedirect as r: conn.commit() raise
def main(): with gc.get_conn() as conn: it = conn.execute('select posmatchid, decisiontype from posmatchids') for row in it: gnuid = row[0] decision_type = row[1] if gc.should_gnuid_be_filtered(gnuid, decision_type): print 'Deleting gnuid:', gnuid conn.execute('delete from posmatchids where posmatchid = %s', [gnuid]) conn.commit()
def main(): with gc.get_conn() as conn: conn.execute( ''' update stats set numofpositions = ( select count(*) from posmatchids p1 where p1.version >= %s ) ,numofsubmissionslast24h = ( select count(*) from usersposmatchids where submittedat > adddate(utc_timestamp(), -1) ) ''', [gc.get_config().POSITIONS_VERSION_TO_USE])
def test_registration_matching_passwords(self): username = '******' password = '******' out = requests.post(SERVER_URL + '/register', data = { 'username' : username, 'password' : password, 'password_again' : password, }) self.assertEqual(out.status_code, 200) with gc.get_conn() as conn: users_found = conn.execute(''' select count(*) from users where username = %s ''', [username]).fetchone()[0] self.assertEqual(users_found, 1)
def export(): with gc.get_conn() as conn: rs = conn.execute(''' select pm.posmatchid, pm.decisiontype, an.move, an.equity, pm.version, an.ply from posmatchids pm join analyses an on pm.posmatchid = an.posmatchid where coalesce(pm.exported, 0) = 0 order by pm.posmatchid, an.equity desc ''') for suffint in itertools.count(1): path = os.path.join( ROOT_DIR, 'dump', str(suffint) + '.csv', ) if not os.path.exists(path): break exported = [] with open(path, 'wb') as outf: for row in rs: posmatchid, decisiontype, move, equity, version, ply = row outf.write(';'.join(str(c) for c in row)) outf.write('\n') exported.append(posmatchid) for posmatchid in exported: conn.execute( ''' update posmatchids set exported = 1 where posmatchid = %s ''', [posmatchid])
import logging, os, glob import gnubg.common as gc logger = logging.getLogger(__name__) ROOT_DIR = os.path.dirname(__file__) with gc.get_conn() as conn: for path in glob.glob(os.path.join(ROOT_DIR, 'dump', '*.csv')): print 'Processing', path, '...' with open(path, 'rb') as inf: for line in inf: posmatchid, decisiontype, move, equity, version, ply = line.split( ';') sql = ''' insert ignore into posmatchids (posmatchid, decisiontype, version, createddate) values (%s, %s, %s, current_timestamp) ''' conn.execute(sql, [posmatchid, decisiontype, version]) sql = ''' replace into analyses (posmatchid, move, equity, ply) values (%s, %s, %s, %s) ''' conn.execute(
def test_db_access(self): gc.get_conn()