# Path: filters.py
# def radian_to_degree(value):
#     return math.degrees(value)
# 
# def format_distance(distance, unit=True):
#     if distance > 1000:
#         return "%0.2f%s" % (distance / 1000.0, " km" if unit else "")
#     elif distance < 1000:
#         return "%0.3f%s" % (distance / 1000.0, " km" if unit else "")
# 
# def format_speed(speed, unit=True):
#     return "%0.1f%s" % (speed * 3.6, " km/h" if unit else "")
# 
# def format_altitude(altitude, unit=True):
#     return "%d%s" % (altitude, " m" if unit else "")
# 
# def format_temparature(temperature, unit=True):
#     return "%0.1f%s" % (temperature - 273.15, " °C" if unit else "")
# 
# def format_hr(hr, unit=True):
#     return "%d%s" % (hr * 60, " bpm" if unit else "")
# 
# def format_energyconsumption(energyconsumption, unit=True):
#     return "%0.1f%s" % (energyconsumption / 6.978 / 10.0, " kcal/min" if unit else "")
# 
# def format_date_time(time):
#     return time.strftime("%Y-%m-%d %H:%M:%S")
# 
# Path: model.py
# class Sample(db.Model):
#     __tablename__ = 'sample'
#     id = db.Column(db.Integer, name='id', primary_key=True)
# 
#     move_id = db.Column(db.Integer, db.ForeignKey(Move.id), name='move_id', nullable=False)
#     move = db.relationship(Move, backref=db.backref('samples', lazy='dynamic'))
# 
#     sample_type = db.Column(db.String, name='sample_type')
#     time = db.Column(db.Interval, name='time')
#     utc = db.Column(db.DateTime, name='utc')
# 
#     distance = db.Column(db.Float, name='distance')
#     speed = db.Column(db.Float, name='speed')
#     temperature = db.Column(db.Float, name='temperature')
# 
#     hr = db.Column(db.Float, name='hr')
#     energy_consumption = db.Column(db.Float, name='energy_consumption')
#     relative_performance_level = db.Column(db.Float, name='relative_performance_level')
# 
#     vertical_speed = db.Column(db.Float, name='vertical_speed')
#     sea_level_pressure = db.Column(db.Float, name='sea_level_pressure')
# 
#     gps_altitude = db.Column(db.Float, name='gps_altitude')
#     gps_heading = db.Column(db.Float, name='gps_heading')
#     gps_speed = db.Column(db.Float, name='gps_speed')
#     gps_hdop = db.Column(db.Float, name='gps_hdop')
# 
#     number_of_satellites = db.Column(db.Integer, name='number_of_satellites')
# 
#     latitude = db.Column(db.Float, name='latitude')
#     longitude = db.Column(db.Float, name='longitude')
# 
#     altitude = db.Column(db.Integer, name='altitude')
# 
#     ehpe = db.Column(db.Float, name='ehpe')  # Estimated Horizontal Position Error
# 
#     cadence = db.Column(db.Float, name='cadence')
# 
#     nav_type = db.Column(db.Integer, name='nav_type')
#     nav_valid = db.Column(db.String, name='nav_valid')
#     nav_type_explanation = db.Column(db.String, name='nav_type_explanation')
# 
#     events = db.Column(JsonEncodedDict(4096), name='events')
#     satellites = db.Column(JsonEncodedDict(4096), name='satellites')
#     apps_data = db.Column(JsonEncodedDict(4096), name='apps_data')


from functools import partial
from flask import flash
from filters import radian_to_degree, format_distance, format_speed, format_altitude, format_temparature, format_hr, \
    format_energyconsumption, format_date_time
from model import Sample

    if samples.count() == 0:
        flash("No samples found for CSV export", 'error')
        return None

    # Header
    header = ["Timestamp",
              "Duration",
              "Latitude [deg]",
              "Longitude [deg]",
              "Altitude [m]",

              "Distance [km]",
              "Speed [km/h]",
              "Temperature [°C]",
              "Heart rate [bpm]",
              "Energy consumption [kcal/min]",

              "HDOP",
              "Vertical speed [km/h]",
              "Number of satellites"
              ]
    rows = [";".join(header)]

    for sample in samples:
        row = []

        add_value(row, move.date_time + sample.time, formatter=format_date_time)
        add_value(row, sample.time)
        add_value(row, sample.latitude, formatter=radian_to_degree)

# Path: filters.py
# def radian_to_degree(value):
#     return math.degrees(value)
# 
# def format_distance(distance, unit=True):
#     if distance > 1000:
#         return "%0.2f%s" % (distance / 1000.0, " km" if unit else "")
#     elif distance < 1000:
#         return "%0.3f%s" % (distance / 1000.0, " km" if unit else "")
# 
# def format_speed(speed, unit=True):
#     return "%0.1f%s" % (speed * 3.6, " km/h" if unit else "")
# 
# def format_altitude(altitude, unit=True):
#     return "%d%s" % (altitude, " m" if unit else "")
# 
# def format_temparature(temperature, unit=True):
#     return "%0.1f%s" % (temperature - 273.15, " °C" if unit else "")
# 
# def format_hr(hr, unit=True):
#     return "%d%s" % (hr * 60, " bpm" if unit else "")
# 
# def format_energyconsumption(energyconsumption, unit=True):
#     return "%0.1f%s" % (energyconsumption / 6.978 / 10.0, " kcal/min" if unit else "")
# 
# def format_date_time(time):
#     return time.strftime("%Y-%m-%d %H:%M:%S")
# 
# Path: model.py
# class Sample(db.Model):
#     __tablename__ = 'sample'
#     id = db.Column(db.Integer, name='id', primary_key=True)
# 
#     move_id = db.Column(db.Integer, db.ForeignKey(Move.id), name='move_id', nullable=False)
#     move = db.relationship(Move, backref=db.backref('samples', lazy='dynamic'))
# 
#     sample_type = db.Column(db.String, name='sample_type')
#     time = db.Column(db.Interval, name='time')
#     utc = db.Column(db.DateTime, name='utc')
# 
#     distance = db.Column(db.Float, name='distance')
#     speed = db.Column(db.Float, name='speed')
#     temperature = db.Column(db.Float, name='temperature')
# 
#     hr = db.Column(db.Float, name='hr')
#     energy_consumption = db.Column(db.Float, name='energy_consumption')
#     relative_performance_level = db.Column(db.Float, name='relative_performance_level')
# 
#     vertical_speed = db.Column(db.Float, name='vertical_speed')
#     sea_level_pressure = db.Column(db.Float, name='sea_level_pressure')
# 
#     gps_altitude = db.Column(db.Float, name='gps_altitude')
#     gps_heading = db.Column(db.Float, name='gps_heading')
#     gps_speed = db.Column(db.Float, name='gps_speed')
#     gps_hdop = db.Column(db.Float, name='gps_hdop')
# 
#     number_of_satellites = db.Column(db.Integer, name='number_of_satellites')
# 
#     latitude = db.Column(db.Float, name='latitude')
#     longitude = db.Column(db.Float, name='longitude')
# 
#     altitude = db.Column(db.Integer, name='altitude')
# 
#     ehpe = db.Column(db.Float, name='ehpe')  # Estimated Horizontal Position Error
# 
#     cadence = db.Column(db.Float, name='cadence')
# 
#     nav_type = db.Column(db.Integer, name='nav_type')
#     nav_valid = db.Column(db.String, name='nav_valid')
#     nav_type_explanation = db.Column(db.String, name='nav_type_explanation')
# 
#     events = db.Column(JsonEncodedDict(4096), name='events')
#     satellites = db.Column(JsonEncodedDict(4096), name='satellites')
#     apps_data = db.Column(JsonEncodedDict(4096), name='apps_data')


# Path: csv_export.py
from functools import partial
from flask import flash
from filters import radian_to_degree, format_distance, format_speed, format_altitude, format_temparature, format_hr, \
    format_energyconsumption, format_date_time
from model import Sample


    if samples.count() == 0:
        flash("No samples found for CSV export", 'error')
        return None

    # Header
    header = ["Timestamp",
              "Duration",
              "Latitude [deg]",
              "Longitude [deg]",
              "Altitude [m]",

              "Distance [km]",
              "Speed [km/h]",
              "Temperature [°C]",
              "Heart rate [bpm]",
              "Energy consumption [kcal/min]",

              "HDOP",
              "Vertical speed [km/h]",
              "Number of satellites"
              ]
    rows = [";".join(header)]

    for sample in samples:
        row = []

        add_value(row, move.date_time + sample.time, formatter=format_date_time)
        add_value(row, sample.time)
        add_value(row, sample.latitude, formatter=radian_to_degree)

        add_value(row, sample.longitude, formatter=radian_to_degree)