-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_stats.py
34 lines (25 loc) · 860 Bytes
/
game_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
from db.base import *
import os
os.system("clear")
session = sessionmaker()
# setup db in folder 'db' and file name of poll.sqlite
engine = create_engine(f"sqlite:///db/poll.sqlite")
session.configure(bind=engine)
# create all the tables
# delete db file to regenerate
Base.metadata.create_all(engine)
# Create db session
ses = session()
# Function to display poll answers and their percentages
def results(poll):
answers = poll.answers
total_responses = 0
for a in answers:
total_responses += a.response_count
print(f'Total Responses: {total_responses}')
print("[Answer: Count, Percentage]")
for a in answers:
share = round((a.response_count/total_responses) * 100, 2)
print(f'{a.answer_text}: {a.response_count}, {share}%')