<commit_before># -*- coding: utf-8 -*-

import math
import logging
from datetime import datetime, timedelta
from tg import expose, validate, require, request, redirect, config
from tg.i18n import ugettext as _
from tg.decorators import override_template
from repoze.what.predicates import has_permission
from webob.exc import HTTPNotFound, HTTPForbidden, HTTPServerError
from sqlalchemy.sql.expression import desc, or_, and_, between
from sqlalchemy import func
from sprox.formbase import EditableForm
from sprox.widgets import PropertySingleSelectField
from skylines.lib.base import BaseController
from skylines import files
from skylines.model import DBSession, User, Club, Flight
from skylines.controllers.upload import UploadController
from skylines.lib.datatables import GetDatatableRecords
from skylines.lib.igc import read_igc_header
from skylines.lib.analysis import analyse_flight, flight_path
from skylinespolyencode import SkyLinesPolyEncoder

log = logging.getLogger(__name__)


class PilotSelectField(PropertySingleSelectField):
    def _my_update_params(self, d, nullable=False):
        users = DBSession.query(User) \
                .filter(User.club_id == request.identity['user'].club_id) \
                .order_by(User.display_name)
        options = [(None, 'None')] + \
                  [(user.user_id, user) for user in users]
        d['options'] = options
        return d


class SelectPilotForm(EditableForm):
    __model__ = Flight
    __hide_fields__ = ['id']
    __limit_fields__ = ['pilot', 'co_pilot']
    __base_widget_args__ = dict(action='select_pilot')
    pilot = PilotSelectField
    co_pilot = PilotSelectField

select_pilot_form = SelectPilotForm(DBSession)


class FlightController(BaseController):
    def __init__(self, flight):
        self.flight = flight

    def __get_flight_path(self, threshold = 0.001, max_points = 3000):
        fp = flight_path(self.flight, max_points)
        if len(fp) == 0:
            log.error('flight_path("' + self.flight.filename + '") returned with an empty list')
            raise HTTPServerError

        num_levels = 4
        zoom_factor = 4
        zoom_levels = [0]
        zoom_levels.extend([round(-math.log(32.0/45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels)])

        max_delta_time = max(4, (fp[-1][0] - fp[0][0]) / 500)

        encoder = SkyLinesPolyEncoder(num_levels=4, threshold=threshold, zoom_factor=4)

        fixes = map(lambda x: (x[2], x[1], (x[0]/max_delta_time*threshold)), fp)<commit_msg>flight: Fixed format<commit_after># -*- coding: utf-8 -*-

import math
import logging
from datetime import datetime, timedelta
from tg import expose, validate, require, request, redirect, config
from tg.i18n import ugettext as _
from tg.decorators import override_template
from repoze.what.predicates import has_permission
from webob.exc import HTTPNotFound, HTTPForbidden, HTTPServerError
from sqlalchemy.sql.expression import desc, or_, and_, between
from sqlalchemy import func
from sprox.formbase import EditableForm
from sprox.widgets import PropertySingleSelectField
from skylines.lib.base import BaseController
from skylines import files
from skylines.model import DBSession, User, Club, Flight
from skylines.controllers.upload import UploadController
from skylines.lib.datatables import GetDatatableRecords
from skylines.lib.igc import read_igc_header
from skylines.lib.analysis import analyse_flight, flight_path
from skylinespolyencode import SkyLinesPolyEncoder

log = logging.getLogger(__name__)


class PilotSelectField(PropertySingleSelectField):
    def _my_update_params(self, d, nullable=False):
        users = DBSession.query(User) \
                .filter(User.club_id == request.identity['user'].club_id) \
                .order_by(User.display_name)
        options = [(None, 'None')] + \
                  [(user.user_id, user) for user in users]
        d['options'] = options
        return d


class SelectPilotForm(EditableForm):
    __model__ = Flight
    __hide_fields__ = ['id']
    __limit_fields__ = ['pilot', 'co_pilot']
    __base_widget_args__ = dict(action='select_pilot')
    pilot = PilotSelectField
    co_pilot = PilotSelectField

select_pilot_form = SelectPilotForm(DBSession)


class FlightController(BaseController):
    def __init__(self, flight):
        self.flight = flight

    def __get_flight_path(self, threshold = 0.001, max_points = 3000):
        fp = flight_path(self.flight, max_points)
        if len(fp) == 0:
            log.error('flight_path("' + self.flight.filename + '") returned with an empty list')
            raise HTTPServerError

        num_levels = 4
        zoom_factor = 4
        zoom_levels = [0]
        zoom_levels.extend([round(-math.log(32.0 / 45.0 * (threshold * pow(zoom_factor, num_levels - i - 1)), 2)) for i in range(1, num_levels)])

        max_delta_time = max(4, (fp[-1][0] - fp[0][0]) / 500)

        encoder = SkyLinesPolyEncoder(num_levels=4, threshold=threshold, zoom_factor=4)

        fixes = map(lambda x: (x[2], x[1], (x[0] / max_delta_time * threshold)), fp)
{'fraction_non_alphanumeric': 0.09778561630413482, 'fraction_numerical': 0.01450127376053302, 'mean_word_length': 3.783505154639175, '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': '4099525', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1541, 'n_words': 404}