-
Notifications
You must be signed in to change notification settings - Fork 4
/
schoonmaaktijden.py
641 lines (510 loc) · 25.3 KB
/
schoonmaaktijden.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
#import scipy.stats as ss
import matplotlib.pyplot as plt
import numpy as np
import math
from scipy import stats
#from scipy.stats import weibull_min
import pandas as pd
from statistics import mean
# from matplotlib.backends.backend_agg import RendererAgg
# _lock = RendererAgg.lock
import streamlit as st
import random
from itertools import cycle
#from streamlit import caching
import time
# partly derived from https://stackoverflow.com/a/37036082/4173718
def cleaning_weibull():
# fitting cleaning times to weibull and give info
# https://chatgpt.com/c/5f499843-4325-4b54-95cb-ebd61f1b6ffd
# Sample data: cleaning times in minutes
data = [56, 18, 15, 30, 34, 30, 7, 15, 44, 23, 50, 20, 50, 18, 19, 32, 40, 36, 26, 30, 8, 15, 19, 23, 30, 74, 25, 34, 28, 61, 22, 13, 14, 70, 38, 31, 29, 31, 42, 62, 7, 40, 56, 28, 35, 12, 13, 13, 7, 30, 23, 42, 36, 38, 30, 25, 13, 55, 40, 40, 10, 10, 16, 27, 17, 15, 43, 27, 30, 22, 10, 27, 48, 30, 53, 24, 58, 11, 17, 26, 13, 86, 26, 40, 25, 13, 17, 47, 51, 41, 9, 13, 29, 5, 22, 15, 20, 75, 54, 40, 11, 34, 35, 37, 36, 39, 41, 40, 33, 28, 57, 45, 16, 12, 33, 27, 14, 26, 16, 18, 19, 70, 15, 11, 46, 35, 20, 22, 60, 7, 67, 28, 14, 15, 49, 20, 20, 40, 26, 20, 19, 26, 83, 22, 32, 29, 20, 14, 15, 38]
n_acco = 10
p_low, p_high = 0.025, 0.975
# Fit Weibull distribution to data
k, loc, lambda_ = weibull_min.fit(data, floc=0)
print(f"Shape parameter (k): {k}")
print(f"Scale parameter (λ): {lambda_}")
# Calculate the fitted values using the Weibull distribution
fitted_values = weibull_min.pdf(data, k, loc, lambda_)
# Calculate the actual values (normalized histogram counts)
num_bins = round(math.sqrt(len(data)))
hist, bin_edges = np.histogram(data, bins=num_bins, density=True)
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2
# Calculate the SSE
sse = np.sum((hist - weibull_min.pdf(bin_centers, k, loc, lambda_))**2)
print(f"SSE: {sse}")
# 95th percentile calculation for one accommodation
# Specifically, the scale parameter is the value below which 63.2% of the distribution's data points fall, representing the 63.2nd percentile.
p_ = [p_low, p_high, 0.632]
for p in p_:
t_95_one = lambda_ * (-np.log(1 - p))**(1/k)
print(f"{p*100}th percentile for one accommodation: {t_95_one:.2f} minutes")
# Mean and standard deviation for one Weibull distribution
mean_time = lambda_ * gamma(1 + 1/k)
std_time = np.sqrt(lambda_**2 * (gamma(1 + 2/k) - (gamma(1 + 1/k))**2))
print(f"Mean time: {mean_time:.2f} minutes")
print(f"Standard deviation: {std_time:.2f} minutes")
print(f"CI: {mean_time-(1.96*std_time)} - {mean_time+(1.96*std_time)}")
# Prepare data for the DataFrame
results = {
'n_acco': [],
'5th_percentile': [],
'95th_percentile': [],
'5th_percentile_avg': [],
'95th_percentile_avg': []
}
# Parameters for the sum of n_acco independent Weibull distributions
for n_acco in range(1, 100001, 1000):
mean_sum = n_acco * mean_time
std_sum = np.sqrt(n_acco) * std_time
p_5 = stats.norm.ppf(p_low, loc=mean_sum, scale=std_sum)
p_95 = stats.norm.ppf(p_high, loc=mean_sum, scale=std_sum)
results['n_acco'].append(n_acco)
results['5th_percentile'].append(p_5)
results['95th_percentile'].append(p_95)
results['5th_percentile_avg'].append(p_5/n_acco)
results['95th_percentile_avg'].append(p_95/n_acco)
# print(f"5th percentile total cleaning time for {n_acco} accommodations: {p_5:.1f} minutes ({p_5/n_acco:.1f} per acco)")
# print(f"95th percentile total cleaning time for {n_acco} accommodations: {p_95:.1f} minutes ({p_95/n_acco:.1f} per acco)")
# Create DataFrame
df = pd.DataFrame(results)
st.write(df)
# https://chatgpt.com/c/de742f40-3c1d-41c2-9287-76539aa6cdcf
def calculate_weibull_pdf(x, scale, shape):
return (shape/scale) * ((x/scale)**(shape - 1)) * np.exp(-1*((x/scale)**shape))
def calculate_weibull_pdf_wrong(x, scale, shape):
# almost same as PDF, but not the good one I think
return (((shape / scale) * ((x)/scale))**(shape-1)) * (np.exp(-1* ((x)/scale)**shape))
def calculate_weibull_cdf(x, scale, shape):
return 1 - (np.exp(- (x/scale)**shape))
def calculate_weibull_cumm_hazard(x, scale, shape):
return (x/scale)**shape
def calculate_weibul_ppf (p, scale, shape):
""" Percentual point function
Args:
p ([type]): percentage
scale ([type]): [description]
shape ([type]): [description]
Returns:
[type]: onder de aantal minuten
"""
#https://www.itl.nist.gov/div898/handbook/eda/section3/eda362.htm#PPF
q = 1-p
return scale * (-1 * np.log(q))**(1/shape)
def calculate_weibull_pmf_step(x, scale, shape, step):
"""Probability mass function
Discrete scale, with steps
Args:
x ([type]): [description]
scale ([type]): [description]
shape ([type]): [description]
"""
a = np.exp(-1*(x/scale)**shape)
b =np.exp(-1*((x+step)/scale)**shape)
return a-b
def calculate_weibull_cdf_discr(x, scale, shape):
"""Cumulative distribution function
Discrete scale
Args:
x ([type]): [description]
scale ([type]): [description]
shape ([type]): [description]
"""
b =np.exp(-1*((x+1)/scale)**shape)
return (1-b)
def calculate_mean(scale,shape):
n = (1+ (1/shape))
gamma = math.gamma(n)
# for t in range (1_000_000):
# gamma += t**(n-1)* np.exp(-t)
return scale*gamma
def calculate_weibull_pdf_not_used(x, scale, shape):
#if x == 0: return 0
x_min_1 = 1-np.exp(-1*((x-1/scale)**shape))
xx = 1-np.exp(-1*((x/scale)**shape))
return (x_min_1 - xx)
@st.cache_data(ttl=60 * 60 * 24)
def read():
sheet_id = "1Lqddg3Rsq0jhFgL5U-HwvDdo0473QBZtjbAp9ol8kcg"
sheet_name = "gegevens"
url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
#url = "C:\\Users\\rcxsm\\Documents\\pyhton_scripts\\in\\schoonmaaktijden.csv",
df = pd.read_csv(url, delimiter=',')
#df = df[:-1] #remove last row which appears to be a Nan
df["Datum"] = pd.to_datetime(df["Datum"], format="%d-%m-%Y")
return df
def lineplot(data, acco_name):
"""Maak een plot Schoonmaaktijden door de tijd heen
Args:
data ([type]): [description]
acco_name ([type]): [description]
"""
data_serie = pd.Series(data)
sma = data_serie.rolling(window=5, center=False).mean()
if 1==1:
# with _lock:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(data, linestyle="dotted")
ax.plot(sma)
title = (f"Cleaning times through the time - {acco_name} ")
plt.xlabel("Number of cleans")
plt.title(title)
st.pyplot(fig)
fig = plt.close()
def extra_plots(what, acco_name, data, bins_formula, bins, shape, scale):
#with st.expander(f"Extra plots {what}" , expanded = False):
if 1==1:
# with _lock:
fig_extra_plot = plt.figure()
ax = fig_extra_plot.add_subplot(1, 1, 1)
if what =="PDF":
ax.plot (bins_formula, calculate_weibull_pdf(bins_formula, scale, shape))
elif what =="CDF":
ax.plot (bins_formula, calculate_weibull_cdf(bins_formula, scale, shape))
elif what =="CHZ":
ax.plot (bins_formula, calculate_weibull_cumm_hazard(bins_formula, scale, shape))
elif what =="CDF_disc":
y = [calculate_weibull_cdf_discr(x, scale, shape) for x in list(bins_formula)]
ax.bar (bins_formula, y)
# ax.hist(y, bins = bins , density=False, alpha=0.5)
elif what =="PMF":
y = [calculate_weibull_pmf_step(x, scale, shape,1) for x in list(bins_formula)]
#ax.plot (bins_formula, calculate_weibull_pmf(bins_formula, scale, shape))
ax.bar (bins_formula, y)
title = (f"{what} - {acco_name}\n\nShape: {round(shape,2)} - Scale: {round(scale,2)}")
plt.grid()
plt.title(title)
st.pyplot(fig_extra_plot)
fig_extra_plot = plt.close()
def extra_plot_pmf(df, acco_name, data, bins_formula, bins, shape, scale, binwidth):
"""Calculate a plot with the real data compared with the data following the formula with given shape and scale
Args:
what ([type]): [description]
acco_name ([type]): [description]
data ([type]): [description]
bins_formula ([type]): [description]
bins ([type]): [description]
shape ([type]): [description]
scale ([type]): [description]
"""
totaal_aantal = len(df)
px = [0.10, 0.25,0.5,0.632,0.75,0.9, 0.95,0.99]
reeks = df["tijd in minuten"].tolist()
reeks.sort()
lengte_reeks = len(reeks)
#reeks_test = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23]
#len_reeks_test = len(reeks_test)
for p in px:
y = round(calculate_weibul_ppf (p, scale, shape))
df_temp = df[df["tijd in minuten"] < y ]
temp_aantal = len(df_temp)
st.write (f"{round(p*100)} % of the cleans are done in less than {y} minutes. (Reality {reeks[round(p * lengte_reeks)-1]} minutes)")
# uitgegaan vd berekende minuten -> (realiteit {round(temp_aantal/totaal_aantal*100,1)} % )
#st.write (f"TEST Realiteit onder de {reeks_test[round(p * len_reeks_test)-1]} minuten")
xx = [10,15,30,45,60]
for x in xx:
df_temp = df[df["tijd in minuten"] <= x ]
temp_aantal = len(df_temp)
st.write (f"{round( 100 * (calculate_weibull_cdf (x, scale, shape)),1)} % of the cleans are done in less than {x} minutes. (reality: {round(temp_aantal/totaal_aantal*100,1)} % = {temp_aantal} acco's) ")
st.write (f"{round (100 - ( 100 * (calculate_weibull_cdf (x, scale, shape))),1)} % of the cleans need more than {x} minutes. (reality: {round (100 - (temp_aantal/totaal_aantal*100),1)} % = {totaal_aantal - temp_aantal} acco's) ")
if 1==1:
# with _lock:
bins_new = []
y_new, y_reality = [],[]
j = 0
fig_extra_plot = plt.figure()
if binwidth == None:
step = round(max(data) / 10)
else:
step = binwidth
for i in range(((reeks[-1])+1+step)):
if i % step == 0 or i== (reeks[-1]+step+1):
y_ = len(data) * calculate_weibull_pmf_step(i, scale, shape, step)
bins_new.append (i)
y_new.append(y_)
lengte_selectie = find_ge(reeks, j,i)
cumm_y =+ lengte_selectie / lengte_reeks
y_reality.append(cumm_y * lengte_reeks )
j = i+1
plt.bar(bins_new, y_new, align="center", width=step,alpha=0.5, label = "PMF_formula", color = "red")
#plt.hist(data, bins = bins , density=False, alpha=0.5, label = "PMF_reality", color = "yellow")
plt.bar(bins_new, y_reality, align="center", width=step, alpha=0.5, label = "PMF_reality", color = "yellow")
title = (f"Reality vs. PMF - {acco_name} (n={len(data)})\n\nShape: {round(shape,2)} - Scale: {round(scale,2)}")
# secax = ax.secondary_xaxis('top', functions=(deg2rad, rad2deg))
# secax.set_xlabel('angle [rad]')
plt.show()
plt.grid()
plt.legend()
plt.title(title)
st.pyplot(fig_extra_plot)
fig_extra_plot = plt.close()
# correlation, p_value = stats.pearsonr(data, y_new) #first I have te rework the data in frequencies
import bisect
def find_ge(a, low, high):
i = bisect.bisect_left(a, low)
g = bisect.bisect_right(a, high)
if i != len(a) and g != len(a):
# return a[i:g]
#st.write (f"{low} {high} {i} {g} {a[i:g]}")
return len(a[i:g])
else:
#st.write (f"{low} {high} {i} {g} {a[i:g]} {len(a)} {len(a[i:g])}")
return len(a[i:g])
def extra_plot_cdf(df, acco_name, data, bins_formula, bins, shape, scale, binwidth):
"""Calculate a plot with the real data compared with the data following the formula with given shape and scale
Args:
what ([type]): [description]
acco_name ([type]): [description]
data ([type]): [description]
bins_formula ([type]): [description]
bins ([type]): [description]
shape ([type]): [description]
scale ([type]): [description]
"""
totaal_aantal = len(df)
reeks = df["tijd in minuten"].tolist()
reeks.sort()
lengte_reeks = len(reeks)
#reeks_test = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,23]
#len_reeks_test = len(reeks_test)
if 1==1:
# with _lock:
bins_new = []
y_new, y_reality = [],[]
fig_extra_plot = plt.figure()
cumm_y = 0
j=0
if binwidth == None:
step = round(max(data) / 10)
else:
step = binwidth
for i in range((max(data)+1+binwidth)):
temp = 0
if i % step == 0:
y_ = calculate_weibull_cdf_discr(i, scale, shape)
bins_new.append (i)
y_new.append(y_)
temp = 0
lengte_selectie = find_ge(reeks, j,i)
cumm_y =+ lengte_selectie / lengte_reeks
y_reality.append(cumm_y)
plt.bar(bins_new, y_new, align="center", width=step,alpha=0.5, label = "CDF_formula", color = "red")
plt.bar(bins_new, y_reality, align="center", width=step, alpha=0.5, label = "CDF_reality", color = "yellow")
#plt.hist(data, bins = bins , density=False, alpha=0.5, label = "reality", color = "yellow")
title = (f"Reality vs. CDF - {acco_name} (n={len(data)})\n\nShape: {round(shape,2)} - Scale: {round(scale,2)}")
plt.grid()
plt.legend()
plt.title(title)
st.pyplot(fig_extra_plot)
fig_extra_plot = plt.close()
# correlation, p_value = stats.pearsonr(data, y_new) #first I have te rework the data in frequencies
def calculate_and_plot(df_selection, data, acco_name, modus, animation, binwidth):
"""[summary]
Args:
data (list): [description]
acco_name (string): [description]
modus (string): exponweib or weib_min
animation (boolean): make animation?
binwidth :
Returns:
samenvatting: list with the calculated [acco_name, len(data), shape, scale , mediaan, mean_data, mean_calc]
"""
if modus == "exponweib":
a_in = 1 # α = 1 gives the Weibull distribution;
loc_in = 0
a_out, Kappa_out, loc_out, Lambda_out = stats.exponweib.fit(data, f0=a_in,floc=loc_in)
else:
shape, loc, scale = stats.weibull_min.fit(data, floc=0)
Kappa_out = shape
Lambda_out = scale
#Plot
bins_formula = range( int(max(data))+1)
#binwidth = max(data)/10
bins = np.arange(min(data), max(data) + binwidth, binwidth)
if 1==1:
# with _lock:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax3 = ax.twinx()
if modus == "exponweib":
ax3.plot(bins_formula, stats.exponweib.pdf(bins_formula, a=a_out,c=Kappa_out,loc=loc_out,scale = Lambda_out))
else:
# JUST TO TEST IF THE FORMULA IS GOOD ax3.plot(bins_formula, stats.weibull_min(shape, loc, scale).pdf(bins_formula), color = "yellow", label = "scipi", alpha = 0.5 )
# WRONG ax3.plot (bins_formula, calculate_weibull_pdf_wrong(bins_formula, scale, shape), color = "red", label = "old/pdf_wrong", alpha = 0.5)
ax3.plot (bins_formula, calculate_weibull_pdf(bins_formula, scale, shape), color = "blue", label = "pdf", alpha = 0.5)
pass
ax.hist(data, bins = bins , density=False, alpha=0.5, label = "reality")
mediaan =Lambda_out *(np.log(2) **(1/Kappa_out))
mean_data = mean(data)
mean_calc =calculate_mean (scale, shape)
title = (f"{acco_name} (n={len(data)})\n\nShape: {round(Kappa_out,2)} - Scale: {round(Lambda_out,2)}\nMediaan : {round(mediaan,2)} - mean data : {round(mean_data,2)} - - mean calc : {round(mean_calc,2)}")
samenvatting = [acco_name, len(data), round(Kappa_out,2), round(Lambda_out,2), round(mediaan,2), round(mean_data,2), round(mean_calc,2)]
plt.title(title)
plt.grid()
plt.legend()
if animation ==True:
placeholder.pyplot(fig)
fig = plt.close()
else:
st.pyplot(fig)
fig = plt.close()
with st.expander(f"Extra plots {acco_name}" , expanded = False):
extra_plot_pmf(df_selection, acco_name, data, bins_formula, bins, shape, scale, binwidth)
extra_plot_cdf(df_selection, acco_name, data, bins_formula, bins, shape, scale, binwidth)
# what_list = ["PDF", "CDF", "CHZ"] PDF and CHZ doesnt have an added value for now
what_list = ["PDF", "CDF","PMF", "CDF_disc", "CHZ",]
for what in what_list:
extra_plots(what, acco_name, data, bins_formula, bins, shape, scale)
st.write(df_selection)
return samenvatting
def show_animation(df, acco_codes, acco_names, distribution_to_use,binwidth ):
code_ = st.selectbox("Which accotype to show", acco_names, index=0)
code = acco_codes[acco_names.index(code_)]
df_selection, data_selection = select_data(df, code)
global placeholder
animations = {"None": None, "Slow": 0.4, "Medium": 0.2, "Fast": 0.05}
animate = st.sidebar.radio("", options=list(animations.keys()), index=2)
animation_speed = animations[animate]
slider_placeholder = st.empty()
placeholder = st.empty()
if animation_speed:
c = range(1,len(data_selection)+1)
for i in cycle(c):
time.sleep(animation_speed)
#TO FIX: stap 1 wordt overgeslagen.
j = slider_placeholder.slider("Aantal cleans", min_value=1, max_value=len(data_selection), value=i, key = str(random.random()))
# df_to_show = df_selection.iloc[:j+1]
# data_selection = df_to_show["tijd in minuten"].tolist()
data_selection_ = data_selection[:j+1]
calculate_and_plot(df_selection, data_selection_, code_, distribution_to_use, True, binwidth)
else:
i = slider_placeholder.slider("Number of cleans to show", min_value=1, max_value=len(data_selection), value=len(data_selection))
# df_to_show = df_selection.iloc[:i]
# data_selection = df_to_show["tijd in minuten"].tolist()
data_selection_ = data_selection[:i]
samenvatting_ = calculate_and_plot(df_selection, data_selection_,code_, distribution_to_use, True, binwidth)
# st.subheader("brondata")
# st.write(df_to_show.iloc[:, : 7])
def select_data(df, code):
"""Select the rows with the right accotype
Args:
df (df): df
code (str): the acco type to select
Returns:
list: list with the cleaning times for the given acco type
"""
if code == "all":
df_selection = df.copy(deep=False)
else:
df_selection = df[df["Type acco"] == code].copy(deep=False)
return df_selection, df_selection["tijd in minuten"].tolist()
def show_various_plots(df, acco_codes, acco_names, distribution_to_use, binwidth):
samenvatting =[]
for code, name in zip (acco_codes, acco_names):
#print (acco_name[acco_code.index(code)])
df_selection, data = select_data(df, code)
samenvatting_ = calculate_and_plot(df_selection, data, name, distribution_to_use, False, binwidth)
samenvatting.append(samenvatting_)
df_samenvatting = pd.DataFrame(samenvatting, columns = ['Name', 'number', 'Shape', 'scale', 'mediaan', 'mean data', 'mean calc'])
st.subheader("Samenvatting")
try:
st.write(df_samenvatting.style.format("{:.2}"))
except:
st.write(df_samenvatting)
for code, name in zip (acco_codes, acco_names):
df_selection, data = select_data(df, code)
lineplot(data, name)
st.subheader("brondata")
st.write(df.iloc[:, : 7])
def edit_sheet():
html = '<iframe src="https://docs.google.com/spreadsheets/d/e/2PACX-1vQDON7pstUaT3Ftghe6jpDmYQv8iurBHKZbhKE_EYERxIy27KnIPr4zMRmd0FmWThuFanx8HJmr9fr6/pubhtml?widget=true&headers=false"></iframe>'
html = '<iframe src="https://docs.google.com/spreadsheets/d/1Lqddg3Rsq0jhFgL5U-HwvDdo0473QBZtjbAp9ol8kcg/edit#gid=0" width"100%" height="100%"></iframe>'
st.markdown(html, unsafe_allow_html=True)
def make_list_accos():
"""Return the acco numbers as list
Returns:
list: List with acco numbers
"""
list_saharas= list(range(1,23))
list_kalaharis =list(range (637,656))
list_balis = list(range (621,627))
list_waikikis = list(range(627,637))
list_serengeti = list(range(659,668))
return list_saharas + list_kalaharis+list_balis+list_waikikis+list_serengeti
def check_accos_never_cleaned(df):
"""Which acco's did Rene clean and which one didnt he clean at all?
Args:
df (df): the dataframe
"""
gecleande_accos = df["acco nr"].tolist()
list_accos = make_list_accos()
never_cleaned = ""
for i in list_accos:
if i not in gecleande_accos:
never_cleaned = never_cleaned + str(i) + " - "
st.write (f"{never_cleaned} is nooit door Rene (geregistreerd) schoongemaakt")
st.subheader("Wat heeft hij wel gedaan dan?")
for i in list_accos:
if i in gecleande_accos:
aantal_keer = gecleande_accos.count(i)
st.write (f"{i} is {aantal_keer} keer door Rene schoongemaakt")
st.write(df)
def main():
df = read()
acco_codes = ["all","w", "sa", "se", "k", "b"]
acco_names = ["All","Waikiki", "Sahara", "Serengeti", "Kalahari", "Bali"]
# distributions = ["weibull_min", "exponweib"]
# distribution_to_use = st.sidebar.selectbox(
# "Which distribution to use",
# distributions,
# index=0)
# exponweib doesnt work properly
distribution_to_use = "weibull_min"
# distribution_to_use = "exponweib"
st.title(f"Schoonmaaktijden gefit aan Weibull verdeling")
menu_choice = st.sidebar.radio("",["ALL", "animated", "never cleaned", "edit sheet","simple", "show formulas"], index=0)
binwidth = st.sidebar.slider("Binwidth", 1, 20, 6)
st.sidebar.write("Attention: Guests are supposed to leave the accomodation clean behind as they found it. These cleaning times are in fact 'make perfect'-times !")
st.sidebar.write("Google sheet : https://docs.google.com/spreadsheets/d/1Lqddg3Rsq0jhFgL5U-HwvDdo0473QBZtjbAp9ol8kcg/edit#gid=0")
st.sidebar.write("Broncode : https://github.com/rcsmit/streamlit_scripts/schoonmaaktijden.py")
if menu_choice == "ALL":
show_various_plots(df, acco_codes, acco_names, distribution_to_use, binwidth)
elif menu_choice == "edit sheet":
edit_sheet()
elif menu_choice == "never cleaned":
check_accos_never_cleaned(df)
elif menu_choice == "animated":
show_animation(df, acco_codes, acco_names, distribution_to_use, binwidth)
elif menu_choice == "show formulas":
st.header("Formulas")
#st.write ("distribution: y = (shape/scale) * ((x/scale)**(shape - 1)) * np.exp(-1*((x/scale)**shape)) ")
st.write ("PDF - probability density function : y = (shape/scale) * ((x/scale)**(shape - 1)) * np.exp(-1*((x/scale)**shape))")
st.write ("CDF - cummulative distribution function: y = 1 - (np.exp(- (x/scale)**shape))")
st.subheader("From percentage to time (x % of the cleans is under y minutes)")
st.write ("PPF - Percentual point function: q = 1-p | y = scale * (-1 * np.log(q))**(1/shape)")
st.subheader("Discrete / steps")
st.write ("PMF - probability mass function : a = np.exp(-1*(x/scale)**shape) | b =np.exp(-1*((x+step)/scale)**shape) | y = a-b")
st.write ("CDF - Cummulative distribution function : b =np.exp(-1*((x+1)/scale)**shape) | y = (1-b)")
st.subheader("Various")
st.write ("cumm_hazard : y = (x/scale)**shape")
st.write ("mean : n = (1+ (1/shape)) | gamma = math.gamma(n) | y = scale*gamma")
st.write ("pdf_not_used : x_min_1 = 1-np.exp(-1*((x-1/scale)**shape)) | xx = 1-np.exp(-1*((x/scale)**shape))| y = (x_min_1 - xx)")
st.subheader("Extra info")
st.write(" the shape parameter describes the shape of your data’s distribution. Statisticians also refer to it as the Weibull slope because its value equals the slope of the line on a probability plot. Shape value of 2 equals a Rayleigh distribution, which is equivalent to a Chi-square distribution with two degrees of freedom. Shape value near of 3 approximates the normal distribution")
st.write ("The scale parameter represents the variability present in the distribution. The value of the scale parameter equals the 63.2 percentile in the distribution. 63.2% of the values in the distribution are less than the scale value.")
st.write("https://statisticsbyjim.com/probability/weibull-distribution/")
st.subheader("Links")
st.write("https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.weibull_min.html")
st.write("https://stat.ethz.ch/R-manual/R-devel/library/stats/html/Weibull.html")
st.write("https://www.sciencedirect.com/topics/computer-science/weibull-distribution")
st.write("https://www.itl.nist.gov/div898/handbook/eda/section3/eda3668.htm")
elif menu_choice == "simple":
cleaning_weibull()
else:
st.write("ËRROR")
st.stop()
if __name__ == "__main__":
#caching.clear_cache()
main()