-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIvrigste klatrer.py
80 lines (67 loc) · 1.97 KB
/
Ivrigste klatrer.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 17 10:38:27 2020
@author: tho2303
"""
import requests
import numpy as np
import pandas as pd
import dataframe_image as dfi #lager tabell direkte fra en pd.dataframe
#%% henter csv-fil fra BK-app
body = {
'email':'',
'password':''
}
response = requests.post('https://app.buldrekontoret.com/api/login', json=body)
requestCookies = {'connect.sid': response.cookies['connect.sid']}
data = requests.get('https://app.buldrekontoret.com/api/admin/reservations.csv', cookies=requestCookies)
#%% ordner opp i datastrengen og samler den i array M
string=data.text.replace('\r\n',',')
list= string.split(",")
M=np.zeros(int((len(list)/3)),dtype=object)
for i in range(0,len(M)):
M[i]=list[i*3]+list[i*3+1]+list[i*3+2]
#M Inneholder like mange elementer som i csv-fil
#%% Deler opp sortert liste i ny array T
T=[None]*(len(M))
for i in range (0,len(T)):
tekst=M[i]
T[i]=tekst[48:48+20]
T.sort()
uni=np.unique(T)
T=T+['tom']
#%%
K=[None]*int(len(uni)) #Oppretter tom liste
for i in range(0,len(K)):
it=0
test=True
while test:
if T[it]==T[it+1]:
it+=1
else:
test=False
K[i]=str("%02d" % (it+1))+';'+T[0]
for i in range(0,it+1):
T.pop(0)
K.sort(reverse=True)
#%% Finner ut hvor mange i k som har mindre enn halvparten av maksøkt.
maks=int(K[0][0:2])
grense=int(np.floor(maks/3))
antall=0
for i in range (0,len(K)):
if int(K[i][0:2])>=grense:
antall+=1
print(antall)
#%%
arr=np.zeros([antall,2],dtype=object)
for i in range (0,antall):
tekst=K[i]
arr[i,0]=tekst[0:2]
arr[i,1]=tekst[3:20]
#%% Oppretter panda dataframe fra T
data = pd.DataFrame(arr)
data.rename(columns={0: 'Antall økter', 1: 'Navn'}, inplace=True)
print(data)
#%% eksport til png-tabell
df_styled = data.style.background_gradient()
dfi.export(df_styled,"Ivrigste klatrer.png")