-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotline.py
105 lines (87 loc) · 3.07 KB
/
hotline.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
#!/usr/bin/env python3
#coding: utf-8
############################################
# MATHEMATICS #
############################################
# #
# MONFA-MATAS Patricica & ROZET Corentin #
# #
# Project : 202unsold_2019 #
# #
############################################
from time import time
from sys import argv
from compute import Math
from math import *
class Hotline():
"""
Main class that allows computation and output printing.
"""
def __init__(self):
self._n = False
self._k = False
self._d = False
def computeBinomial(self):
"""
Run computations and process output printing for the first case.
"""
math = Math()
result = math.binomialCoef(self._n, self._k)
print("%d-combinations of a set of size %d:\n%d" %(self._k, self._n, result))
def computeDistributions(self):
"""
Run computations and process output printing for the second case.
"""
maths = Math()
def computeOverload(l:list) -> float:
res = 0
for i in range(26):
res += l[i]
return 1 - res
def binomialDistributions():
init = time()
p = self._d / (3600 * 8)
bi = []
for i in range (0, 51):
bi.append(maths.binomial(3500, i, p))
print("{:d} -> {:.3f}".format(i, bi[-1]), end='')
if (i+1) % 5 == 0:
print()
elif i != 50:
print("\t", end='')
if self._d > 320:
print("\nOverload: 100%")
else:
print("\nOverload: {:.1f}%".format(computeOverload(bi) * 100))
print("Computation time: {:.2f}ms".format(((time()-init) * 100)))
def poissonDistributions():
init = time()
people = 3500 * (self._d / (3600 * 8))
bi = []
for i in range (0, 51):
bi.append(exp(-people) * pow(people, i) / factorial(i))
print("{:d} -> {:0.3f}".format(i, bi[-1]), end='')
if (i+1) % 5 == 0:
print()
elif i != 50:
print("\t", end='')
if self._d > 320:
print("\nOverload: 100%")
else:
print("\nOverload: {:.1f}%".format(computeOverload(bi) * 100))
print("Computation time: {:.2f}ms".format((time() - init) * 100))
print("Binomial distribution:")
binomialDistributions()
print("\nPoisson distribution:")
poissonDistributions()
def run(self):
"""
Redirect to the right function.
"""
if len(argv) == 2:
self._d = int(argv[1])
self.computeDistributions()
elif len(argv) == 3:
self._n = int(argv[1])
self._k = int(argv[2])
self.computeBinomial()