-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcharts.py
More file actions
58 lines (49 loc) · 1.33 KB
/
charts.py
File metadata and controls
58 lines (49 loc) · 1.33 KB
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
"""
Chart or graph specific numeric mod
-----------------------------------
| Copyright 2022 by Joel C. Alcarez |
| [[email protected]] |
|-----------------------------------|
| We make absolutely no warranty |
| of any kind, expressed or implied |
|-----------------------------------|
| Contact primary author |
| if you plan to use this |
| in a commercial product at |
-----------------------------------
"""
from numbers import Number
def getdatalisttotal(dlist: list[Number]
) -> Number:
"""Returns the total of a
list of ints or floats
Args:
dlist: list of ints or floats
Returns:
float or int
"""
return sum(d[0] for d in dlist)
def genpiechartdata(dlist: list):
"""Preprocess data to make
it suitable for a pie chart
Args:
dlist: [[20, c['red']],
[30, c['brightyellow']],
...]
Returns:
list and large value (if any)
"""
sa = 0
tot = getdatalisttotal(dlist)
alist = []
big = -1
for d in dlist:
p = d[0] / tot
ea = sa + p * 360
p *= 100
alist.append([sa, ea, d[1], d[0], p])
if p >= 50:
big = dlist.index(d)
sa = ea
return alist, big