<commit_before>import datetime
import logging
from connexion import NoContent
from datetime import date

import api.models
from sqlalchemy import Date
from sqlalchemy import cast
from sqlalchemy import func

db_session = api.models.init_db()
from flask import request

def get_user(user_id):
    secret = request.headers.get('Authorization')
    user = db_session.query(api.models.User).filter(api.models.User.id == user_id). \
        filter(api.models.User.secret == secret).one_or_none()

    #get koin_count, mission_count_today and mission_count
    mission_count = db_session.query(api.models.Solution).filter(api.models.Solution.user_id == user_id).count()
    mission_count_today = db_session.query(api.models.Solution).filter(api.models.Solution.user_id == user_id). \
        filter(cast(api.models.Solution.create_date,Date) == date.today()).count()
    koin_count = db_session.query(func.sum(api.models.Solution.koin_count)).filter(api.models.Solution.user_id == user_id).scalar()

    print(user)
    if user:
        return user.dump(mission_count=mission_count, mission_count_today=mission_count_today, koin_count=koin_count)<commit_msg>count only valid missions in user stats<commit_after>import datetime
import logging
from connexion import NoContent
from datetime import date

import api.models
from sqlalchemy import Date
from sqlalchemy import cast
from sqlalchemy import func

db_session = api.models.init_db()
from flask import request

def get_user(user_id):
    secret = request.headers.get('Authorization')
    user = db_session.query(api.models.User).filter(api.models.User.id == user_id). \
        filter(api.models.User.secret == secret).one_or_none()

    #get koin_count, mission_count_today and mission_count
    mission_count = db_session.query(api.models.Solution).filter(api.models.Solution.user_id == user_id)\
        .filter(api.models.Solution.valid).count()
    mission_count_today = db_session.query(api.models.Solution).filter(api.models.Solution.user_id == user_id)\
        .filter(api.models.Solution.valid)\
        .filter(cast(api.models.Solution.create_date, Date) == date.today()).count()
    koin_count = db_session.query(func.sum(api.models.Solution.koin_count)).filter(api.models.Solution.user_id == user_id).scalar()

    print(user)
    if user:
        return user.dump(mission_count=mission_count, mission_count_today=mission_count_today, koin_count=koin_count)
{'fraction_non_alphanumeric': 0.11166253101736973, 'fraction_numerical': 0.0, 'mean_word_length': 4.857142857142857, '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': '2445066', 'n_tokens_mistral': 783, 'n_tokens_neox': 745, 'n_words': 136}