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