<commit_before>#!/usr/bin/env python
# encoding: utf-8

import tabulate
from modularodm import Q

from website.app import init_app
from website.models import User


LOG_THRESHOLD = 11


def get_active_users(extra=None):
    query = (
        Q('is_registered', 'eq', True) &
        Q('password', 'ne', None) &
        Q('merged_by', 'eq', None) &
        Q('date_confirmed', 'ne', None) &
        Q('date_disabled', ' eq', None)
    )
    query = query & extra if extra else query
    return User.find(query)


def count_user_logs(user, query=None):
    if query:
        return len(user.nodelog__created.find(query))
    return len(user.nodelog__created)


def get_depth_users(users):
    rows = [
        (user.fullname, user.username, count_user_logs(user))
        for user in users
    ]
    return [
        row
        for row in rows
        if row[2] >= LOG_THRESHOLD
    ]

<commit_msg>optimized iteration on users<commit_after>#!/usr/bin/env python
# encoding: utf-8

import tabulate
from modularodm import Q

from website.app import init_app
from website.models import User


LOG_THRESHOLD = 11


def get_active_users(extra=None):
    query = (
        Q('is_registered', 'eq', True) &
        Q('password', 'ne', None) &
        Q('merged_by', 'eq', None) &
        Q('date_confirmed', 'ne', None) &
        Q('date_disabled', ' eq', None)
    )
    query = query & extra if extra else query
    return User.find(query)


def count_user_logs(user, query=None):
    if query:
        return len(user.nodelog__created.find(query))
    return len(user.nodelog__created)


def get_depth_users(users):
    rows = []
    for user in users:
        log_count = count_user_logs(user)
        if log_count >= LOG_THRESHOLD:
            rows.append((user.fullname, user.username, log_count))
    return rows


{'fraction_non_alphanumeric': 0.11693325979040264, 'fraction_numerical': 0.003861003861003861, 'mean_word_length': 2.8350951374207187, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7298372', 'n_tokens_mistral': 620, 'n_tokens_neox': 596, 'n_words': 151}