<commit_before>#!/usr/bin/env python2.7

import db, datetime, queue

def update(conn, active_contracts, update_time):
    q0to24 = q24to48 = q48to72 = ip0to24 = ip24to48 = ip48to72 = 0
    for contract in active_contracts:
        if contract.created_min is None: continue
        age = (update_time - contract.created_min).total_seconds() / 3600.0
        if contract.accepted is not None and update_time > contract.accepted:
            if age < 24.0: ip0to24 += 1
            elif age < 48.0: ip24to48 += 1
            elif age < 72.0: ip48to72 += 1
        else:
            if age < 24.0: q0to24 += 1
            elif age < 48.0: q24to48 += 1
            elif age < 72.0: q48to72 += 1
            
    db.add_queue_history(conn, update_time, q0to24, q24to48, q48to72, ip0to24, ip24to48, ip48to72)

def regenerate(conn):
    # load server update history
    update_times = []
    c = conn.cursor()
    c.execute("SELECT update_time FROM serverupdates")
    for row in c:
        update_times.append(row['update_time'])
    update_times.sort()

    # load contract history
    all_contracts = db.Contract.load_where(conn = conn, clause = 'created_min IS NOT NULL')
    contracts_by_creation_time = list(all_contracts)
    contracts_by_creation_time.sort(lambda x,y: cmp(x.created_min,y.created_min))
    contracts_by_completion_time = [x for x in all_contracts if (x.state in (db.Contract.DONE,db.Contract.GONE))]<commit_msg>Fix a silly loop that's better as a list comprehension.<commit_after>#!/usr/bin/env python2.7

import db, datetime, queue

def update(conn, active_contracts, update_time):
    q0to24 = q24to48 = q48to72 = ip0to24 = ip24to48 = ip48to72 = 0
    for contract in active_contracts:
        if contract.created_min is None: continue
        age = (update_time - contract.created_min).total_seconds() / 3600.0
        if contract.accepted is not None and update_time > contract.accepted:
            if age < 24.0: ip0to24 += 1
            elif age < 48.0: ip24to48 += 1
            elif age < 72.0: ip48to72 += 1
        else:
            if age < 24.0: q0to24 += 1
            elif age < 48.0: q24to48 += 1
            elif age < 72.0: q48to72 += 1
            
    db.add_queue_history(conn, update_time, q0to24, q24to48, q48to72, ip0to24, ip24to48, ip48to72)

def regenerate(conn):
    # load server update history
    c = conn.cursor()
    c.execute("SELECT update_time FROM serverupdates")
    update_times = [row['update_time'] for row in c]
    update_times.sort()

    # load contract history
    all_contracts = db.Contract.load_where(conn = conn, clause = 'created_min IS NOT NULL')
    contracts_by_creation_time = list(all_contracts)
    contracts_by_creation_time.sort(lambda x,y: cmp(x.created_min,y.created_min))
    contracts_by_completion_time = [x for x in all_contracts if (x.state in (db.Contract.DONE,db.Contract.GONE))]
{'fraction_non_alphanumeric': 0.09989521480964024, 'fraction_numerical': 0.06845965770171149, 'mean_word_length': 2.8755074424898512, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, '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': '3648963', 'n_tokens_mistral': 1082, 'n_tokens_neox': 971, 'n_words': 252}