<commit_before>import uuid

import chryso.connection
import sqlalchemy

import vanth.platform.ofxsource
import vanth.tables


def _select():
    return sqlalchemy.select([
        vanth.tables.OFXAccount.c.account_id,
        vanth.tables.OFXAccount.c.name,
        vanth.tables.OFXAccount.c.password,
        vanth.tables.OFXAccount.c.source,
        vanth.tables.OFXAccount.c.type,
        vanth.tables.OFXAccount.c.user_id,
        vanth.tables.OFXAccount.c.uuid,
        vanth.tables.OFXSource.c.name.label('source.name'),
        vanth.tables.OFXSource.c.uuid.label('source.uuid'),
        vanth.tables.OFXUpdate.c.created,
    ]).where(
        vanth.tables.OFXAccount.c.source == vanth.tables.OFXSource.c.uuid
    ).where(
        vanth.tables.OFXAccount.c.uuid == vanth.tables.OFXUpdate.c.ofxaccount
    )

def _execute_and_convert(query):
    engine = chryso.connection.get()
    results = engine.execute(query)
    return [{
        'account_id'    : result[vanth.tables.OFXAccount.c.account_id],
        'name'          : result[vanth.tables.OFXAccount.c.name],
        'last_updated'  : result[vanth.tables.OFXUpdate.c.created],
        'password'      : result[vanth.tables.OFXAccount.c.password],
        'source'        : {
            'name'      : result[vanth.tables.OFXSource.c.name.label('source.name')],
            'uuid'      : result[vanth.tables.OFXSource.c.name.label('source.uuid')],
        },
        'type'          : result[vanth.tables.OFXAccount.c.type],
        'user_id'       : result[vanth.tables.OFXAccount.c.user_id],
        'uuid'          : result[vanth.tables.OFXAccount.c.uuid],
    } for result in results]<commit_msg>Properly get latest update for ofxaccount<commit_after>import logging
import uuid

import chryso.connection
import sqlalchemy
import sqlalchemy.sql.functions

import vanth.platform.ofxsource
import vanth.tables

LOGGER = logging.getLogger(__name__)

def _select():
    subselect = sqlalchemy.select([
        vanth.tables.OFXUpdate.c.ofxaccount,
        sqlalchemy.sql.functions.max(vanth.tables.OFXUpdate.c.created),
    ]).group_by(
        vanth.tables.OFXUpdate.c.ofxaccount
    ).alias('ofxupdates')
    return sqlalchemy.select([
        vanth.tables.OFXAccount.c.account_id,
        vanth.tables.OFXAccount.c.name,
        vanth.tables.OFXAccount.c.password,
        vanth.tables.OFXAccount.c.source,
        vanth.tables.OFXAccount.c.type,
        vanth.tables.OFXAccount.c.user_id,
        vanth.tables.OFXAccount.c.uuid,
        vanth.tables.OFXSource.c.name.label('source.name'),
        vanth.tables.OFXSource.c.uuid.label('source.uuid'),
        subselect,
    ]).select_from(
        subselect
    ).where(
        vanth.tables.OFXAccount.c.uuid == subselect.c.ofxaccount
    )

def _execute_and_convert(query):
    engine = chryso.connection.get()
    results = engine.execute(query)
    return [{
        'account_id'    : result[vanth.tables.OFXAccount.c.account_id],
        'name'          : result[vanth.tables.OFXAccount.c.name],
        'last_updated'  : result['max_1'],
        'password'      : result[vanth.tables.OFXAccount.c.password],
        'source'        : {
            'name'      : result[vanth.tables.OFXSource.c.name.label('source.name')],
            'uuid'      : result[vanth.tables.OFXSource.c.name.label('source.uuid')],
        },
        'type'          : result[vanth.tables.OFXAccount.c.type],
        'user_id'       : result[vanth.tables.OFXAccount.c.user_id],
        'uuid'          : result[vanth.tables.OFXAccount.c.uuid],
    } for result in results]
{'fraction_non_alphanumeric': 0.13316512475469583, 'fraction_numerical': 0.0002803476310625175, 'mean_word_length': 2.5326732673267327, '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': '2858542', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1213, 'n_words': 136}