<commit_before>import logging
from modularodm import Q

from scripts.analytics.base import SnapshotAnalytics

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


class AddonSnapshot(SnapshotAnalytics):

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

    def get_events(self, date=None):
        super(AddonSnapshot, self).get_events(date)

        from website.settings import ADDONS_AVAILABLE
        counts = []
        addons_available = {k: v for k, v in [(addon.short_name, addon) for addon in ADDONS_AVAILABLE]}

        for short_name, addon in addons_available.iteritems():
            user_count = addon.settings_models['user'].find().count() if addon.settings_models.get('user') else 0
            connected_count = addon.settings_models['node'].find().count() if addon.settings_models.get('node') else 0
            deleted_count = addon.settings_models['node'].find(Q('deleted', 'eq', True)).count() if addon.settings_models.get('node') else 0
            disconnected_count = addon.settings_models['node'].find(Q('external_account', 'eq', None) & Q('deleted', 'ne', True)).count() if addon.settings_models.get('node') else 0
            total = connected_count + deleted_count + disconnected_count
            counts.append({
                'provider': {
                    'name': short_name
                },
                'users': {
                    'total': user_count
                },
                'nodes': {
                    'total': total,
                    'connected': connected_count,
                    'deleted': deleted_count,
                    'disconnected': disconnected_count
                }
            })

            logger.info('{} counted. Users: {}, Total Nodes: {}'.format(addon.short_name, user_count, total))

        return counts


if __name__ == '__main__':
    addon_snapshot = AddonSnapshot()
    events = addon_snapshot.get_events()
    addon_snapshot.send_events(events)<commit_msg>Add init app to addon snapshot as well<commit_after>import logging
from modularodm import Q

from website.app import init_app
from scripts.analytics.base import SnapshotAnalytics

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


class AddonSnapshot(SnapshotAnalytics):

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

    def get_events(self, date=None):
        super(AddonSnapshot, self).get_events(date)

        from website.settings import ADDONS_AVAILABLE
        counts = []
        addons_available = {k: v for k, v in [(addon.short_name, addon) for addon in ADDONS_AVAILABLE]}

        for short_name, addon in addons_available.iteritems():
            user_count = addon.settings_models['user'].find().count() if addon.settings_models.get('user') else 0
            connected_count = addon.settings_models['node'].find().count() if addon.settings_models.get('node') else 0
            deleted_count = addon.settings_models['node'].find(Q('deleted', 'eq', True)).count() if addon.settings_models.get('node') else 0
            disconnected_count = addon.settings_models['node'].find(Q('external_account', 'eq', None) & Q('deleted', 'ne', True)).count() if addon.settings_models.get('node') else 0
            total = connected_count + deleted_count + disconnected_count
            counts.append({
                'provider': {
                    'name': short_name
                },
                'users': {
                    'total': user_count
                },
                'nodes': {
                    'total': total,
                    'connected': connected_count,
                    'deleted': deleted_count,
                    'disconnected': disconnected_count
                }
            })

            logger.info('{} counted. Users: {}, Total Nodes: {}'.format(addon.short_name, user_count, total))

        return counts


if __name__ == '__main__':
    init_app()
    addon_snapshot = AddonSnapshot()
    events = addon_snapshot.get_events()
    addon_snapshot.send_events(events)
{'fraction_non_alphanumeric': 0.11464189684673674, 'fraction_numerical': 0.001955512099731117, 'mean_word_length': 2.479591836734694, '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': '4134078', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1122, 'n_words': 245}