<commit_before>"""
Contains the functions and classes used to calculate and/or convert
values read from the sensors.
"""

import math
from .config import CALCULATE


TEMP_GROUND = 2
PRESS_GROUND = 100


def calculate_temp_NTC(raw_val):
    """
    Converts the raw value read from the NTC temperature sensor
    module into degrees celsius.
    """
    voltage = raw_val * 5 / 1023

    resistance = (5 * 10000 / voltage) - 10000

    temp = ((3.354016 * (10**-3)) + (2.569850 * (10**-4)) *
            math.log(resistance / 10000) + (2.62013 * (10**-12)) *
            (math.log(resistance / 10000))**2 + 6.38309 * (10**-15) *
            (math.log(resistance / 10000))**3)**-1 - 273.15

    return temp


def calculate_press(raw_val):
    """
    Converts the raw value read from the pressure sensor module
    into kilopascal.
    """
    return ((100 / 921) * raw_val) + 10


def calculate_height(air_press, ground_press, ground_temp):
    """
    Calculates the height based on the pressure, pressure at ground level,
    and temperature at ground level.
    """
    temp = ground_temp + 273.15  # Convert to kelvin

    a = CALCULATE["height"]["temperature_gradient"]
    R = CALCULATE["height"]["gas_constant"]
    grav = CALCULATE["height"]["gravitational_accelleration"]

    height = (temp / a) * ((air_press / ground_press)**(-((a * R) / grav)) - 1)

    return height


def calculate_acc_x(raw_val):
    """
    Converts the raw value read from the accelleration sensor module,
    taking calibration into consideration.
    """
    return 0.0072339 * raw_val + 0.45212


def calculate_acc_y(raw_val):
    """
    Converts the raw value read from the accelleration sensor module,
    taking calibration into consideration.<commit_msg>Calibrated for the new pressure module.<commit_after>"""
Contains the functions and classes used to calculate and/or convert
values read from the sensors.
"""

import math
from .config import CALCULATE


TEMP_GROUND = 2
PRESS_GROUND = 100


def calculate_temp_NTC(raw_val):
    """
    Converts the raw value read from the NTC temperature sensor
    module into degrees celsius.
    """
    voltage = raw_val * 5 / 1023

    resistance = (5 * 10000 / voltage) - 10000

    temp = ((3.354016 * (10**-3)) + (2.569850 * (10**-4)) *
            math.log(resistance / 10000) + (2.62013 * (10**-12)) *
            (math.log(resistance / 10000))**2 + 6.38309 * (10**-15) *
            (math.log(resistance / 10000))**3)**-1 - 273.15

    return temp


def calculate_press(raw_val):
    """
    Converts the raw value read from the pressure sensor module
    into kilopascal.
    """
    return raw_val / 10


def calculate_height(air_press, ground_press, ground_temp):
    """
    Calculates the height based on the pressure, pressure at ground level,
    and temperature at ground level.
    """
    temp = ground_temp + 273.15  # Convert to kelvin

    a = CALCULATE["height"]["temperature_gradient"]
    R = CALCULATE["height"]["gas_constant"]
    grav = CALCULATE["height"]["gravitational_accelleration"]

    height = (temp / a) * ((air_press / ground_press)**(-((a * R) / grav)) - 1)

    return height


def calculate_acc_x(raw_val):
    """
    Converts the raw value read from the accelleration sensor module,
    taking calibration into consideration.
    """
    return 0.0072339 * raw_val + 0.45212


def calculate_acc_y(raw_val):
    """
    Converts the raw value read from the accelleration sensor module,
    taking calibration into consideration.
{'fraction_non_alphanumeric': 0.11736150770988008, 'fraction_numerical': 0.06167904054825814, 'mean_word_length': 3.0218140068886337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2236018', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1073, 'n_words': 334}