-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyzer.py
128 lines (88 loc) · 4.01 KB
/
analyzer.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
from scipy.interpolate import CubicSpline
from enums import GraphType
import matplotlib.pyplot as plt
from matplotlib.axes import Axes
import pandas as pd
import numpy as np
class Analyzer():
def __init__(self, sample_data, graph_type: GraphType):
self.x = None
self.y = None
self.points: list[tuple[float,float]] = []
self.stats: dict = {}
self.original_x = sample_data['phi']
self.original_y = sample_data['cum.wht%']
match graph_type:
case GraphType.CUM:
x, y = self.original_x, self.original_y
self.interp = CubicSpline(x, y)
self.x = np.linspace(x.min(), x.max(), 500)
self.y = self.interp(self.x)
case GraphType.HIST:
self.x = sample_data['phi']
self.y = sample_data['wht%']
self.calculate_stats()
def calculate_stats(self):
x, y = self.original_x, self.original_y
self.phi_perc: list[int] = [5, 16, 25, 50, 75, 84, 95]
self.points = [
(round(np.interp(phi,y,x), 2), phi) for phi in self.phi_perc
]
self.phi_quant: dict[str, float] = {f"{k}": v for v, k in self.points}
self.mean: float = (self.phi_quant['16']+self.phi_quant['50']+self.phi_quant['84'])/3
self.std: float = (
((self.phi_quant['84']-self.phi_quant['16'])/4)+
((self.phi_quant['95']-self.phi_quant['5'])/6.6)
)
self.skewness: float = (
((self.phi_quant['16']+self.phi_quant['84']-(2*self.phi_quant['50']))/
(2*(self.phi_quant['84'])-self.phi_quant['16']))+
(self.phi_quant['5']+self.phi_quant['95']-(2*self.phi_quant['50']))/
(2*(self.phi_quant['95'])-self.phi_quant['5'])
)
self.kurtosis: float = (
(self.phi_quant['95']-self.phi_quant['5'])/
2.44*(self.phi_quant['75']/self.phi_quant['25'])
)
self.stats = {'mean': self.mean, 'std': self.std,
'skewness': self.skewness, 'kurtosis': self.kurtosis}
def get_stats(self) -> dict[str, int]:
self.stats = {k: round(v,2) for k, v in self.stats.items()}
return self.stats
def get_plot_data(self) -> list:
return[self.x, self.y, self.points]
class Plotter():
'''
The class handeling the plotting of the data booth in terms of going and showing!
'''
def __init__(self, x: pd.Series, y: pd.Series,
points: list[tuple[float,float]],
ax: Axes, _type: GraphType):
self.x = x
self.y = y
self.points = points
self.ax = ax
self.type = _type
match self.type:
case GraphType.CUM:
self.ax.set_xlim(-3, 5)
self.ax.set_ylim(0, 100)
self.plot_cum()
case GraphType.HIST:
self.plot_histo()
def plot_cum(self):
for point in self.points:
self.x_cord, self.y_cord = point
self.x_cords: list = [self.ax.get_xlim()[0], self.x_cord, self.x_cord]
self.y_cords: list = [self.y_cord, self.y_cord, self.ax.get_ylim()[0]]
self.ax.plot(self.x, self.y)
self.ax.plot(self.x_cords, self.y_cords, '--k')
self.ax.plot(self.x_cord, self.y_cord, '--.k')
self.ax.annotate(f"x={round(self.x_cord,2)}, y={self.y_cord}%",
xy=(self.x_cord+.2, self.y_cord))
self.ax.set_xlabel("phi (\u00D8)")
self.ax.set_ylabel("cumulative weight %")
def plot_histo(self):
self.ax.bar(self.x, self.y)
self.ax.set_xlabel("phi (\u00D8)")
self.ax.set_ylabel("weight %")