Skip to content

Commit

Permalink
Update stats.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mickahell committed Oct 23, 2021
1 parent 277f4c3 commit 0dd3a35
Showing 1 changed file with 26 additions and 59 deletions.
85 changes: 26 additions & 59 deletions quantronauts/stats.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,29 @@
from os import path
import pandas as pd
import datetime
import os
import requests


def stats(winner):
file_csv = 'stats/qnim_results.csv'
date_x = datetime.datetime.now()
date_day = str(date_x.month) + '-' + str(date_x.year)

robot_csv = []
human_csv = []
date_csv = []

##################################################################################
# CSV exist
if path.exists(file_csv):

csv_file = pd.read_csv(file_csv, header=None)

for i in range(len(csv_file[0])):
robot_csv.append(csv_file[0][i])
human_csv.append(csv_file[1][i])
date_csv.append(csv_file[2][i])

test = 0
for i in range(len(date_csv)):
if date_day == date_csv[i]:
if winner == "robot":
robot_csv[i] += 1
else:
human_csv[i] += 1
test = 1

if test == 0:
if winner == "robot":
robot_csv.append(1)
human_csv.append(0)
else:
robot_csv.append(0)
human_csv.append(1)
date_csv.append(date_day)

csv_file = {'robot': robot_csv, 'human': human_csv, 'date': date_csv}
df = pd.DataFrame(csv_file)
df.to_csv(file_csv, index=False, header=None)

##################################################################################
# CSV doesn't exist
if not path.exists(file_csv):

if winner == "robot":
robot_csv.append(1)
human_csv.append(0)
else:
robot_csv.append(0)
human_csv.append(1)
date_csv.append(date_day)

csv_file = {'robot': robot_csv, 'human': human_csv, 'date': date_csv}
df = pd.DataFrame(csv_file)
df.to_csv(file_csv, index=False, header=None)
TOKEN = os.environ.get("GITHUB_TOKEN")

if TOKEN is not None:
headers = {
"Accept": "application/vnd.github.v3+json",
"Authorization": f"token {TOKEN}",
}

data = {
"event_type": "games-stats",
"client_payload": {
"game": "qpokemon",
"winner": f"{winner}"
}
}

r = requests.post(
url="https://api.github.com/repos/mickahell/robots-data/dispatches",
headers=headers,
json=data
)

else:
print("Your token is empty ! The stats aren't updated.")

0 comments on commit 0dd3a35

Please sign in to comment.