added file for generating table with 5 best times from each map
This commit is contained in:
parent
d1de5f6015
commit
d89ce6f0fd
55
RaceTimer/python3/generate_top_5_times_query.py
Normal file
55
RaceTimer/python3/generate_top_5_times_query.py
Normal file
@ -0,0 +1,55 @@
|
||||
from settings import get_connection_racetimer
|
||||
|
||||
def main():
|
||||
with get_connection_racetimer() as conn:
|
||||
with conn.cursor(buffered=True) as cur:
|
||||
sql_statement = """
|
||||
select column_name from information_schema.columns
|
||||
where table_schema = 'unloze_racetimer_css'
|
||||
and TABLE_NAME = 'zetimer_table_new'
|
||||
order by table_name,ordinal_position
|
||||
"""
|
||||
cur.execute(sql_statement)
|
||||
res = cur.fetchall()
|
||||
|
||||
#removing steamid and name
|
||||
res.pop(0)
|
||||
res.pop(0)
|
||||
sql_statement = "TRUNCATE TABLE unloze_racetimer_css.top5"
|
||||
cur.execute(sql_statement)
|
||||
for index, result in enumerate(res):
|
||||
result = result[0]
|
||||
sql_statement = f"""alter table unloze_racetimer_css.top5
|
||||
add column if not exists {result} DOUBLE """
|
||||
cur.execute(sql_statement)
|
||||
if index == 0:
|
||||
sql_statement = f"""
|
||||
insert into unloze_racetimer_css.top5 ({result})
|
||||
SELECT t2.{result}
|
||||
FROM unloze_racetimer_css.zetimer_table_new t2
|
||||
WHERE
|
||||
t2.{result} > 0
|
||||
ORDER BY t2.{result} ASC
|
||||
LIMIT 5
|
||||
"""
|
||||
else:
|
||||
sql_statement = f"""
|
||||
update unloze_racetimer_css.top5 t
|
||||
INNER JOIN (
|
||||
SELECT
|
||||
{result},
|
||||
ROW_NUMBER() OVER (ORDER BY {result} ASC) AS row_num
|
||||
FROM unloze_racetimer_css.zetimer_table_new
|
||||
WHERE {result} > 0
|
||||
limit 5
|
||||
) t2 ON t.id = t2.row_num
|
||||
set t.{result} = t2.{result}
|
||||
where t.id = t2.row_num
|
||||
"""
|
||||
cur.execute(sql_statement)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
Loading…
Reference in New Issue
Block a user