<commit_before>import datetime
import exifread
import logging
import xmltodict as x2d

from opensfm.sensors import sensor_data
from opensfm import types


logger = logging.getLogger(__name__)


def eval_frac(value):
    try:
        return float(value.num) / float(value.den)
    except ZeroDivisionError:
        return None


def gps_to_decimal(values, reference):
    sign = 1 if reference in 'NE' else -1
    degrees = eval_frac(values[0])
    minutes = eval_frac(values[1])
    seconds = eval_frac(values[2])
    return sign * (degrees + minutes / 60 + seconds / 3600)


def get_float_tag(tags, key):
    if key in tags:
        return float(tags[key].values[0])
    else:
        return None


def get_frac_tag(tags, key):
    if key in tags:
        try:
            return eval_frac(tags[key].values[0])
        except ZeroDivisionError:
            return None
    else:
        return None


def compute_focal(focal_35, focal, sensor_width, sensor_string):
    if focal_35 > 0:
        focal_ratio = focal_35 / 36.0  # 35mm film produces 36x24mm pictures.
    else:
        if not sensor_width:
            sensor_width = sensor_data.get(sensor_string, None)<commit_msg>fix(exif): Check the instance when getting exif tag as float<commit_after>import datetime
import exifread
import logging
import xmltodict as x2d

from opensfm.sensors import sensor_data
from opensfm import types


logger = logging.getLogger(__name__)


def eval_frac(value):
    try:
        return float(value.num) / float(value.den)
    except ZeroDivisionError:
        return None


def gps_to_decimal(values, reference):
    sign = 1 if reference in 'NE' else -1
    degrees = eval_frac(values[0])
    minutes = eval_frac(values[1])
    seconds = eval_frac(values[2])
    return sign * (degrees + minutes / 60 + seconds / 3600)


def get_float_tag(tags, key):
    if key in tags:
        if isinstance(tags[key].values[0], exifread.utils.Ratio):
            return float(tags[key].values[0].num) / tags[key].values[0].den
        else:
            return float(tags[key].values[0])
    else:
        return None


def get_frac_tag(tags, key):
    if key in tags:
        try:
            return eval_frac(tags[key].values[0])
        except ZeroDivisionError:
            return None
    else:
        return None


def compute_focal(focal_35, focal, sensor_width, sensor_string):
    if focal_35 > 0:
        focal_ratio = focal_35 / 36.0  # 35mm film produces 36x24mm pictures.
    else:
        if not sensor_width:
            sensor_width = sensor_data.get(sensor_string, None)
{'fraction_non_alphanumeric': 0.08804051421893261, 'fraction_numerical': 0.024542267238021036, 'mean_word_length': 2.798816568047337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7508631', 'n_tokens_mistral': 855, 'n_tokens_neox': 801, 'n_words': 227}