MetaStalk.modules.DateTime.date_time()   B
last analyzed

Complexity

Conditions 5

Size

Total Lines 61
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 37
nop 1
dl 0
loc 61
ccs 19
cts 19
cp 1
crap 5
rs 8.5253
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 = [
26
        "Image DateTime",
27
        "EXIF DateTimeOriginal",
28
        "EXIF DateTimeDigitized",
29
        "GPS GPSDate",
30
    ]
31
32 1
    simple_photos = []
33 1
    for i, _ in enumerate(photos):
34 1
        simple_photos.append(photos[i]["item"])
35
36 1
    for each in photos:
37 1
        for i, _ in enumerate(types):
38 1
            try:
39 1
                date_type = str(each[types_str[i]]).replace(":", "/", 2)
40 1
                types[i].append(date_type)
41 1
                log.debug("%s has %s data", each["item"], types_str[i])
42 1
            except KeyError:
43 1
                log.info("%s has no %s data ", each["item"], types_str[i])
44
45 1
    fig = go.Figure(
46
        data=[
47
            go.Table(
48
                header=dict(
49
                    values=[
50
                        "Photo",
51
                        "Image DateTime",
52
                        "Date Time Original",
53
                        "Date Time Digitized",
54
                    ]
55
                ),
56
                cells=dict(
57
                    values=[
58
                        simple_photos,
59
                        datetime,
60
                        datetime_original,
61
                        datetime_digitized,
62
                    ]
63
                ),
64
            )
65
        ]
66
    )
67 1
    fig.update_layout(title="Timestamp Information", title_x=0.5)
68
    return fig
69