Passed
Push — master ( f4e57c...929827 )
by Cyb3r
01:59 queued 11s
created

MetaStalk.modules.DateTime.date_time()   B

Complexity

Conditions 5

Size

Total Lines 44
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 26
nop 1
dl 0
loc 44
ccs 18
cts 18
cp 1
crap 5
rs 8.7893
c 0
b 0
f 0
1
"""Makes a table that plots GPS timestamp or other timestamp metadata."""
2 1
import logging
3 1
import plotly.graph_objects as go
4
5 1
log = logging.getLogger("MetaStalk")
6
7
8 1
def date_time(photos: list) -> go.Figure():
9
    """date_time
10
11
    Makes a table with timestamp of photos.
12
    There are three name that DateTime data can be under `Creation date`,
13
    `Date-time original`, `Date-time digitized` and a column in made
14
    for each type.
15
16
    Arguments:
17
        photos {list} -- A list of dictionaries with phot information.
18
19
    Returns:
20
        go.Figure -- A plotly Table with the DateTime data.
21
    """
22 1
    log.info("Starting DateTime Charts")
23 1
    datetime, datetime_original, datetime_digitized = [], [], []
24 1
    types = [datetime, datetime_original, datetime_digitized]
25 1
    types_str = ["Creation date", "Date-time original", "Date-time digitized"]
26
27 1
    simple_photos = []
28 1
    for i, _ in enumerate(photos):
29 1
        simple_photos.append(photos[i]["item"])
30
31 1
    for each in photos:
32 1
        for i, _ in enumerate(types):
33 1
            try:
34 1
                types[i].append(each[types_str[i]])
35 1
                log.debug("%s has %s data", each["item"], types_str[i])
36 1
            except KeyError:
37 1
                log.info("%s has no %s data ", each["item"], types_str[i])
38
39 1
    fig = go.Figure(
40
        data=[go.Table(
41
            header=dict(values=[
42
                "Photo",
43
                "Creation Date",
44
                "Date Time Original",
45
                "Date Time Digitized"
46
            ]),
47
            cells=dict(values=[simple_photos, datetime, datetime_original,
48
                               datetime_digitized]))]
49
    )
50 1
    fig.update_layout(title="Timestamp Information", title_x=0.5)
51
    return fig
52