<commit_before>import math
from pyramid.httpexceptions import HTTPForbidden
from pyramid.view import view_config
from sqlalchemy import func

from ..models import Profile, Group, Qso, Mode, Band, Dxcc
from ..models.dbtools.datatypes import RcvdEnum, ModeEnum, ContinentEnum

from .api import json_api_config


@json_api_config(name='get_log')
def _get_log(dbsession, data):
    qsos = dbsession.query(Qso)
    count = dbsession.query(func.count(Qso.id))
    if 'call_filter' in data:
        qsos = qsos.filter(Qso.call.like(data['call_filter'] + '%'))
        count = count.filter(Qso.call.like(data['call_filter'] + '%'))
    if 'profile' in data:
        profile = data['profile']
        qsos = qsos.filter_by(profile=profile)
        count = count.filter_by(profile=profile)
    if 'group' in data:
        group = data['group']
        qsos = qsos.filter_by(group=group)
        count = count.filter_by(group=group)

    # if 'datetime_off_filter' in data:
    #    qsos = qsos.filter_by(call=data['call_filter'])

    if 'band_filter' in data:
        qsos = qsos.filter_by(band=data['band_filter'])
        count = count.filter_by(band=data['band_filter'])

    if 'mode_filter' in data:
        qsos = qsos.filter_by(mode=data['mode_filter'])
        count = count.filter_by(mode=data['mode_filter'])

    if 'dxcc_filter' in data:
        qsos = qsos.filter_by(dxcc=data['dxcc_filter'])
        count = count.filter_by(dxcc=data['dxcc_filter'])

    if 'cont_filter' in data:
        qsos = qsos.filter_by(cont=data['cont_filter'])
        count = count.filter_by(cont=data['cont_filter'])

    if 'ituz_filter' in data:
        qsos = qsos.filter_by(ituz=data['ituz_filter'])
        count = count.filter_by(ituz=data['ituz_filter'])

    if 'cqz_filter' in data:
        qsos = qsos.filter_by(cqz=data['cqz_filter'])
        count = count.filter_by(cqz=data['cqz_filter'])

    if 'sortby' in data:
        tmp = data['sortby']
        order_map = {
            'call': Qso.call,
            '-call': Qso.call.desc(),
            'datetime_on': Qso.datetime_off,
            '-datetime_on': Qso.datetime_off.desc(),
            'datetime_off': Qso.datetime_off,
            '-datetime_off': Qso.datetime_off.desc(),
            'band': Qso.band,
            '-band': Qso.band.desc(),
            'mode': Qso.mode,
            '-mode': Qso.mode.desc(),
            'dxcc': Qso.dxcc,
            '-dxcc': Qso.dxcc.desc(),<commit_msg>log date sort fix<commit_after>import math
from pyramid.httpexceptions import HTTPForbidden
from pyramid.view import view_config
from sqlalchemy import func

from ..models import Profile, Group, Qso, Mode, Band, Dxcc
from ..models.dbtools.datatypes import RcvdEnum, ModeEnum, ContinentEnum

from .api import json_api_config


@json_api_config(name='get_log')
def _get_log(dbsession, data):
    qsos = dbsession.query(Qso)
    count = dbsession.query(func.count(Qso.id))
    if 'call_filter' in data:
        qsos = qsos.filter(Qso.call.like(data['call_filter'] + '%'))
        count = count.filter(Qso.call.like(data['call_filter'] + '%'))
    if 'profile' in data:
        profile = data['profile']
        qsos = qsos.filter_by(profile=profile)
        count = count.filter_by(profile=profile)
    if 'group' in data:
        group = data['group']
        qsos = qsos.filter_by(group=group)
        count = count.filter_by(group=group)

    # if 'datetime_off_filter' in data:
    #    qsos = qsos.filter_by(call=data['call_filter'])

    if 'band_filter' in data:
        qsos = qsos.filter_by(band=data['band_filter'])
        count = count.filter_by(band=data['band_filter'])

    if 'mode_filter' in data:
        qsos = qsos.filter_by(mode=data['mode_filter'])
        count = count.filter_by(mode=data['mode_filter'])

    if 'dxcc_filter' in data:
        qsos = qsos.filter_by(dxcc=data['dxcc_filter'])
        count = count.filter_by(dxcc=data['dxcc_filter'])

    if 'cont_filter' in data:
        qsos = qsos.filter_by(cont=data['cont_filter'])
        count = count.filter_by(cont=data['cont_filter'])

    if 'ituz_filter' in data:
        qsos = qsos.filter_by(ituz=data['ituz_filter'])
        count = count.filter_by(ituz=data['ituz_filter'])

    if 'cqz_filter' in data:
        qsos = qsos.filter_by(cqz=data['cqz_filter'])
        count = count.filter_by(cqz=data['cqz_filter'])

    if 'sortby' in data:
        tmp = data['sortby']
        order_map = {
            'call': Qso.call,
            '-call': Qso.call.desc(),
            'datetime_on': Qso.datetime_on,
            '-datetime_on': Qso.datetime_on.desc(),
            'datetime_off': Qso.datetime_off,
            '-datetime_off': Qso.datetime_off.desc(),
            'band': Qso.band,
            '-band': Qso.band.desc(),
            'mode': Qso.mode,
            '-mode': Qso.mode.desc(),
            'dxcc': Qso.dxcc,
            '-dxcc': Qso.dxcc.desc(),
{'fraction_non_alphanumeric': 0.14157119476268412, 'fraction_numerical': 0.0, 'mean_word_length': 2.8315047021943576, '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': '1635339', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1701, 'n_words': 310}