def update_players(server='na'):
    global tank_stat_url
    global max_account_num
    tank_stat_url = tank_stat_urls[server]
    max_account_num = max_account_map[server]
    conn, c = pg_connect()
    done = False
    start_points = {'na': [1000000000], 'eu': [500000000]}
    start_point = start_points[server]

    for _ in range(10):
        try:
            print("Starting player update")
            conn.commit()
            update_loop(c, conn, start_point)
            print("Finished player update")
            done = True
            break
        except:
            print(sys.exc_info(), 'Exception(sys)')

    conn.commit()
    conn.close()

    if done:
        return 1
    else:
        return 0
Esempio n. 2
0
def update_dpg(server='na'):
    global tank_stat_url
    tank_stat_url = tank_stat_urls[server]

    conn, c = pg_connect()

    print("Waking proxies up")
    update_loop(c, conn, wakeup=True)
    time.sleep(10)
    print("Second waking")
    update_loop(c, conn, wakeup=True)
    time.sleep(5)

    done = False

    for _ in range(10):
        try:
            print("Starting main update")
            conn.commit()
            update_loop(c, conn)
            print("Finished main update")
            done = True
            break
        except:
            print(sys.exc_info(), 'Exception(sys)')

    if done:
        done = False
        print("Processing fails")
        for _ in range(10):
            try:
                for _ in range(10):
                    conn.commit()
                    if update_loop(c, conn, proc_fails=True) == 1:
                        break
                done = True
                break
            except:
                print(sys.exc_info(), 'Exception(sys)')

    if done:
        c.execute('delete from dpg_done where account_id > 1')
    conn.commit()
    conn.close()

    if done:
        return 1
    else:
        return 0
Esempio n. 3
0
def update_players(server='na'):
    global tank_stat_url
    tank_stat_url = tank_stat_urls[server]

    conn, c = pg_connect()

    print("Waking proxies up")
    update_loop(c, conn, wakeup=True)
    time.sleep(10)
    print("Second waking")
    update_loop(c, conn, wakeup=True)
    time.sleep(5)

    done = False

    for _ in range(10):
        try:
            print("Starting player update")
            conn.commit()
            update_loop(c, conn)
            print("Finished player update")
            break
        except:
            print(sys.exc_info(), 'Exception(sys)')

    print("Processing player fails")
    for _ in range(10):
        try:
            for _ in range(20):
                conn.commit()
                if update_loop(c, conn, proc_fails=True) == 1:
                    break
            done = True
            break
        except:
            print(sys.exc_info(), 'Exception(sys)')

    conn.commit()
    conn.close()

    if done:
        return 1
    else:
        return 0
Esempio n. 4
0
def main():
    conn, c = pg_connect()

    start_time = timer()

    c.execute('drop table if exists top502')
    c.execute('''
    create table top502(account_id int, tank_id int, nickname text, tank_name text,
    battles int, dpg real, fpg real, wr real, rdpg real, rfpg real, rwr real, rb int,
    primary key(account_id, tank_id))''')
    conn.commit()
    c.execute('drop table if exists dpg')
    c.execute('''
    create table dpg as
      select * from dpg2
      where battles >= 100 or (select sum(s) from unnest(recent_battles) s) >= 35'''
              )
    conn.commit()

    c.execute('create index tid_dpg_idx on dpg(tank_id, dpg desc nulls last)')
    c.execute(
        'create index tid_rdpg_idx on dpg(tank_id, recent_dpg desc nulls last)'
    )
    c.execute(
        'create index tid_wr_idx on dpg(tank_id, (wins::real/battles::real) desc nulls last)'
    )
    c.execute(
        'create index tid_rwr_idx on dpg(tank_id, recent_wr desc nulls last)')
    conn.commit()

    c.execute('select tank_id, name from tanks where name is not null')
    tank_ids = c.fetchall()

    for tid, tname in tank_ids:
        c.execute(
            '''(select dpg.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg.account_id), %(n)s, dpg.battles, dpg,
           frags*1.0/dpg.battles, wins*100.0/dpg.battles, dpg.recent_dpg, dpg.recent_wr,
           (select sum(s) from unnest(recent_battles) s) as rb
           from dpg
           where tank_id=%(i)s and dpg.battles >= 150
           order by dpg desc nulls last
           limit 50)
           union
           (select dpg.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg.account_id), %(n)s, dpg.battles, dpg,
           frags*1.0/dpg.battles, wins*100.0/dpg.battles, dpg.recent_dpg, dpg.recent_wr,
           (select sum(s) from unnest(recent_battles) s) as rb
           from dpg
           where tank_id=%(i)s and dpg.battles >= 150
           order by (wins::double precision / battles::real) desc nulls last
           limit 50)
           union
           (select dpg.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg.account_id), %(n)s, dpg.battles, dpg,
           frags*1.0/dpg.battles, wins*100.0/dpg.battles, dpg.recent_dpg, dpg.recent_wr,
           (select sum(s) from unnest(recent_battles) s) as rb
           from dpg
           where tank_id=%(i)s and dpg.battles >= 100
           order by dpg desc nulls last
           limit 50)
           union
           (select dpg.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg.account_id), %(n)s, dpg.battles, dpg,
           frags*1.0/dpg.battles, wins*100.0/dpg.battles, dpg.recent_dpg, dpg.recent_wr,
           (select sum(s) from unnest(recent_battles) s) as rb
           from dpg
           where tank_id=%(i)s and dpg.battles >= 100
           order by (wins::double precision / battles::real) desc nulls last
           limit 50)
           union
           (select dpg.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg.account_id), %(n)s, dpg.battles, dpg,
           frags*1.0/dpg.battles, wins*100.0/dpg.battles, dpg.recent_dpg, dpg.recent_wr,
           (select sum(s) from unnest(recent_battles) s) as rb
           from dpg
           where tank_id=%(i)s and (select sum(s) from unnest(recent_battles) s) >= 35
           order by recent_dpg desc nulls last
           limit 50)
           union
           (select dpg.account_id, tank_id, (select nickname from players2 where players2.account_id = dpg.account_id), %(n)s, dpg.battles, dpg,
           frags*1.0/dpg.battles, wins*100.0/dpg.battles, dpg.recent_dpg, dpg.recent_wr,
           (select sum(s) from unnest(recent_battles) s) as rb
           from dpg
           where tank_id=%(i)s and (select sum(s) from unnest(recent_battles) s) >= 35
           order by recent_wr desc nulls last
           limit 50)
           ''', {
                'n': tname,
                'i': tid
            })
        res = c.fetchall()
        c.executemany(
            'insert into top502 values(%s,%s,%s,%s,%s,%s,%s,%s,%s,0,%s,%s)',
            res)
        conn.commit()
        print(tname)
    c.execute('drop table dpg')
    c.execute('delete from top50')
    c.execute('insert into top50 (select * from top502)')

    conn.commit()
    conn.close()
    print('Finished compute_tank_data()')
    print(timer() - start_time)
def main(server='na'):
    tank_stat_url = tank_stat_urls[server]

    conn, c = pg_connect()

    stat_url = tank_stat_url[0] + '?' + '&'.join(
        [k + '=' + deprecated_queries[k] for k in deprecated_queries])
    deprecated_result = json.loads(
        web.urlopen(stat_url).readall().decode('utf-8'))

    stat_url = tank_stat_url[1] + '?' + '&'.join(
        [k + '=' + queries[k] for k in queries])
    result = json.loads(web.urlopen(stat_url).readall().decode('utf-8'))

    tanks = []

    if result['status'] == 'error':
        print('Error: ', result)
    else:
        tank_data = result['data']

        for tank_id in tank_data:
            if not tank_data[tank_id]:
                continue
            result = [int(tank_id)]
            result.extend([tank_data[tank_id][k] for k in stat_fields])
            tanks.append(tuple(result))

        if deprecated_result['status'] == 'ok':
            deprecated_data = deprecated_result['data']
            for tank_id in deprecated_data:
                if tank_id in tank_data or not deprecated_data[tank_id]:
                    continue
                result = [int(tank_id)]
                result.extend([
                    deprecated_data[tank_id][k] for k in deprecated_stat_fields
                ])
                tanks.append(tuple(result))

        update_vals = ','.join(
            c.mogrify("(%s,%s,%s,%s,%s)", x).decode('utf-8') for x in tanks)
        update_str = [
            '''update tanks set name = c.name, nation = c.nation, type = c.type, tier = c.tier from (values'''
        ]
        update_str.append(update_vals)
        update_str.append(
            ''') as c(tank_id, name, nation, type, tier) where tanks.tank_id = c.tank_id'''
        )
        c.execute(' '.join(update_str))

        insert_str = [
            '''insert into tanks(tank_id, name, nation, type, tier) (select * from (values'''
        ]
        insert_str.append(update_vals)
        insert_str.append(
            ''') as c(tank_id, name, nation, type, tier) where not exists (select 1 from tanks where tanks.tank_id = c.tank_id ))'''
        )
        c.execute(' '.join(insert_str))
        conn.commit()

    conn.close()
Esempio n. 6
0
def main(server='na'):
    conn, c = pg_connect()

    c.execute('select distinct tank_id, tank_name from top50')
    valid_tanks = c.fetchall()

    query_strs = [
        ('''select nickname, battles, dpg, fpg, wr, case when rb > 0 then rdpg else null end, rb, rwr
            from top50
            where tank_id=%s and battles >= 150
            order by dpg desc nulls last
            limit 50;''', '150', 'DPG (150+ battles)'),
        ('''select nickname, battles, dpg, fpg, wr, case when rb > 0 then rdpg else null end, rb, rwr
            from top50
            where tank_id=%s and battles >= 100
            order by dpg desc nulls last
            limit 50;''', '100', 'DPG (100+ battles)'),
        ('''select nickname, battles, dpg, fpg, wr, rdpg, rb, rwr
            from top50
            where tank_id=%s and rb >= 35
            order by rdpg desc nulls last
            limit 50;''', 'recent', 'DPG (35+ recent battles)'),
        ('''select nickname, battles, dpg, fpg, wr, case when rb > 0 then rdpg else null end, rb, rwr
            from top50
            where tank_id=%s and battles >= 150
            order by wr desc nulls last
            limit 50;''', '150wr', 'W/R (150+ battles)'),
        ('''select nickname, battles, dpg, fpg, wr, case when rb > 0 then rdpg else null end, rb, rwr
            from top50
            where tank_id=%s and battles >= 100
            order by wr desc nulls last
            limit 50;''', '100wr', 'W/R (100+ battles)'),
        ('''select nickname, battles, dpg, fpg, wr, rdpg, rb, rwr
            from top50
            where tank_id=%s and rb >= 35
            order by rwr desc nulls last
            limit 50;''', 'recentwr', 'W/R (35+ recent battles)')
    ]

    for query_str, html_ext, stat_version in query_strs:
        for tank_id, tank_name in valid_tanks:
            c.execute(query_str, (tank_id, ))
            rows = c.fetchall()

            row_html = []

            for idx, row in enumerate(rows, 1):
                row_html.append('<tr>')
                row_html.append('<td>{}</td>'.format(idx))

                row_html.append(
                    '<td><a href="../../players/?player_name={}&v={}&server={}">{}</a></td>'
                    .format(row[0], html_ext, server, row[0]))

                row_html.append('<td>{}</td>'.format(row[1]))
                for i in range(2, 5):
                    row_html.append('<td>{0:.2f}</td>'.format(row[i]))
                if not row[5]:
                    row_html.append('<td>0</td>')
                    row_html.append('<td>0</td>')
                    row_html.append('<td>0</td>')
                else:
                    row_html.append('<td>{}</td>'.format(int(row[6])))
                    row_html.append('<td>{0:.2f}</td>'.format(row[5]))
                    row_html.append('<td>{0:.2f}</td>'.format(100.0 * row[7]))

                row_html.append('</tr>')

            with open(
                    'templates/{}/tanks/{}_{}.html'.format(
                        server, tank_id, html_ext), 'w') as f:
                page_str = ''.join(row_html)
                final_html = page_html.format(
                    **{
                        'tank_name': tank_name,
                        'rows': page_str,
                        'stat_version': stat_version
                    })
                final_html = final_html.encode(
                    'ascii', 'xmlcharrefreplace').decode('ascii')
                f.write(final_html)
                f.close()

    conn.close()