<commit_before>import logging
from dateutil.parser import parse
from datetime import datetime, timedelta

from modularodm import Q

from website.app import init_app
from website.models import User
from scripts.analytics.base import SummaryAnalytics

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


class UserSummary(SummaryAnalytics):

    @property
    def collection_name(self):
        return 'user_summary'

    def get_events(self, date):
        super(UserSummary, self).get_events(date)

        # Convert to a datetime at midnight for queries and the timestamp
        timestamp_datetime = datetime(date.year, date.month, date.day)
        query_datetime = timestamp_datetime + timedelta(1)

        counts = {
            'keen': {
                'timestamp': timestamp_datetime.isoformat()
            },
            'active_users': User.find(
                Q('is_registered', 'eq', True) &
                Q('password', 'ne', None) &
                Q('merged_by', 'eq', None) &
                Q('date_disabled', 'eq', None) &
                Q('date_confirmed', 'ne', None) &
                Q('date_confirmed', 'lt', query_datetime)
            ).count(),
            'unconfirmed_users': User.find(
                Q('date_registered', 'lt', query_datetime) &
                Q('date_confirmed', 'eq', None)
            ).count(),
            'deactivated_users': User.find(
                Q('date_disabled', 'ne', None) &
                Q('date_disabled', 'lt', query_datetime)
            ).count()
        }
        logger.info(
            'Users counted. Active: {}, Unconfirmed: {}, Deactivated: {}'.format(
                counts['active_users'],
                counts['unconfirmed_users'],
                counts['deactivated_users']
            )
        )
        return [counts]


if __name__ == '__main__':
    init_app()
    user_summary = UserSummary()
    args = user_summary.parse_args()
    date = parse(args.date).date() if args.date else None
    events = user_summary.get_events(date)
    user_summary.send_events(events)<commit_msg>Adjust output of user summary counts<commit_after>import logging
from dateutil.parser import parse
from datetime import datetime, timedelta

from modularodm import Q

from website.app import init_app
from website.models import User
from scripts.analytics.base import SummaryAnalytics

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)


class UserSummary(SummaryAnalytics):

    @property
    def collection_name(self):
        return 'user_summary'

    def get_events(self, date):
        super(UserSummary, self).get_events(date)

        # Convert to a datetime at midnight for queries and the timestamp
        timestamp_datetime = datetime(date.year, date.month, date.day)
        query_datetime = timestamp_datetime + timedelta(1)

        counts = {
            'keen': {
                'timestamp': timestamp_datetime.isoformat()
            },
            'status': {
                'active': User.find(
                    Q('is_registered', 'eq', True) &
                    Q('password', 'ne', None) &
                    Q('merged_by', 'eq', None) &
                    Q('date_disabled', 'eq', None) &
                    Q('date_confirmed', 'ne', None) &
                    Q('date_confirmed', 'lt', query_datetime)
                ).count(),
                'unconfirmed': User.find(
                    Q('date_registered', 'lt', query_datetime) &
                    Q('date_confirmed', 'eq', None)
                ).count(),
                'deactivated': User.find(
                    Q('date_disabled', 'ne', None) &
                    Q('date_disabled', 'lt', query_datetime)
                ).count()
            }
        }
        logger.info(
            'Users counted. Active: {}, Unconfirmed: {}, Deactivated: {}'.format(
                counts['status']['active'],
                counts['status']['unconfirmed'],
                counts['status']['deactivated']
            )
        )
        return [counts]


if __name__ == '__main__':
    init_app()
    user_summary = UserSummary()
    args = user_summary.parse_args()
    date = parse(args.date).date() if args.date else None
    events = user_summary.get_events(date)
    user_summary.send_events(events)
{'fraction_non_alphanumeric': 0.11757911757911758, 'fraction_numerical': 0.000462000462000462, 'mean_word_length': 2.0731014904187366, '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': '3083518', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1140, 'n_words': 269}