Passed
Push — master ( 929827...929f74 )
by Cyb3r
02:12
created

MetaStalk.utils.parse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 89.47%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 34
ccs 17
cts 19
cp 0.8947
rs 10
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A _convert_to_degrees() 0 11 1
A gps_parse() 0 15 5
1
"""utils.parse
2
---
3
Parse needed to make exifread dictionaries easier"""
4
5
6 1
def gps_parse(tags: dict):
7
    """Returns GPS degrees"""
8 1
    latitude = tags["GPS GPSLatitude"]
9 1
    latitude_ref = tags["GPS GPSLatitudeRef"]
10 1
    longitude = tags["GPS GPSLongitude"]
11 1
    longitude_ref = tags["GPS GPSLongitudeRef"]
12 1
    if latitude:
13 1
        lat_value = _convert_to_degrees(latitude)
14 1
        if latitude_ref.values != 'N':
15
            lat_value = -lat_value
16 1
    if longitude:
17 1
        lon_value = _convert_to_degrees(longitude)
18 1
        if longitude_ref.values != 'E':
19
            lon_value = -lon_value
20 1
    return {'latitude': lat_value, 'longitude': lon_value}
2 ignored issues
show
introduced by
The variable lat_value does not seem to be defined in case latitude on line 12 is False. Are you sure this can never be the case?
Loading history...
introduced by
The variable lon_value does not seem to be defined in case longitude on line 16 is False. Are you sure this can never be the case?
Loading history...
21
22
23 1
def _convert_to_degrees(value) -> float:
24
    """
25
    Helper function to convert the GPS coordinates stored in the EXIF to degrees in float format
26
    :param value:
27
    :type value: exifread.utils.Ratio
28
    """
29 1
    d = float(value.values[0].num) / float(value.values[0].den)
30 1
    m = float(value.values[1].num) / float(value.values[1].den)
31 1
    s = float(value.values[2].num) / float(value.values[2].den)
32
33
    return d + (m / 60.0) + (s / 3600.0)
34