1
|
|
|
"""Module that makes a pie chart."""
|
2
|
|
|
import logging
|
3
|
|
|
import plotly.graph_objects as go
|
4
|
|
|
|
5
|
|
|
log = logging.getLogger("MetaStalk")
|
6
|
|
|
|
7
|
|
|
|
8
|
|
|
def create_chart(table: list, pielabel: str) -> go.Figure():
|
9
|
|
|
"""create_chart
|
10
|
|
|
|
11
|
|
|
Creates the pie chart by frequency of items in a dictionary.
|
12
|
|
|
|
13
|
|
|
Arguments:
|
14
|
|
|
table {list} -- [description]
|
15
|
|
|
pielabel {str} -- The label of the pie chart.
|
16
|
|
|
|
17
|
|
|
Returns:
|
18
|
|
|
go.Figure -- A plotly PieChart
|
19
|
|
|
"""
|
20
|
|
|
freq = {}
|
21
|
|
|
for item in table:
|
22
|
|
|
if item in freq:
|
23
|
|
|
freq[item] += 1
|
24
|
|
|
else:
|
25
|
|
|
freq[item] = 1
|
26
|
|
|
|
27
|
|
|
(labels, values) = ([], [])
|
28
|
|
|
for key, value in freq.items():
|
29
|
|
|
if pielabel == "Camera focal":
|
30
|
|
|
labels.append("Length: {}".format(key))
|
31
|
|
|
else:
|
32
|
|
|
labels.append(key)
|
33
|
|
|
values.append(value)
|
34
|
|
|
|
35
|
|
|
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
|
36
|
|
|
fig.update_layout(title="{} Information".format(pielabel))
|
37
|
|
|
|
38
|
|
|
return fig
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
def PieChart(photos: list, pietype: str) -> go.Figure():
|
42
|
|
|
"""PieChart
|
43
|
|
|
|
44
|
|
|
Parses information and returns a pie chart
|
45
|
|
|
|
46
|
|
|
Arguments:
|
47
|
|
|
photos {list} -- A list of dictionaries with phot information.
|
48
|
|
|
pietype {str} -- The type of metadata for the pie chart
|
49
|
|
|
|
50
|
|
|
Returns:
|
51
|
|
|
go.Figure -- A plotly PieChart
|
52
|
|
|
"""
|
53
|
|
|
log.info("Staring %s Chart", pietype)
|
54
|
|
|
table = []
|
55
|
|
|
|
56
|
|
|
for each in photos:
|
57
|
|
|
try:
|
58
|
|
|
table.append(each[pietype])
|
59
|
|
|
except KeyError:
|
60
|
|
|
log.debug("%s has no %s data", each["item"], pietype)
|
61
|
|
|
|
62
|
|
|
return create_chart(table, pietype)
|
63
|
|
|
|