def _build_malt_row_dict(app_row, domain_name, user, monthspan, run_date): app_data = _get_malt_app_data(domain_name, app_row.app_id) return { 'month': monthspan.startdate, 'user_id': user._id, 'username': user.username, 'email': user.email, 'user_type': user.doc_type, 'domain_name': domain_name, 'num_of_forms': app_row.doc_count, 'app_id': app_row.app_id or MISSING_APP_ID, 'device_id': app_row.device_id, 'wam': AMPLIFY_COUCH_TO_SQL_MAP.get(app_data.wam, NOT_SET), 'pam': AMPLIFY_COUCH_TO_SQL_MAP.get(app_data.pam, NOT_SET), 'use_threshold': app_data.use_threshold, 'experienced_threshold': app_data.experienced_threshold, 'is_app_deleted': app_data.is_app_deleted, 'last_run_date': run_date, }
def get_gir_dict_for_domain_and_monthspan(domain, monthspan): user_tuple = GIRTableGenerator.classify_users(domain, monthspan) max_device = GIRTableGenerator.get_max_device(domain, monthspan) possible_experience = get_possibly_experienced(domain, monthspan) recently_active = GIRTableGenerator.get_active_recent(domain, monthspan) gir_dict = { 'month': monthspan.startdate, 'domain_name': domain.name, 'country': ', '.join([unicode(COUNTRIES.get(abbr, abbr)) for abbr in domain.deployment.countries]), 'sector': domain.internal.area, 'subsector': domain.internal.sub_area, 'bu': GIRTableGenerator.get_bu(domain), 'self_service': domain.internal.self_started, 'test_domain': TEST_COUCH_TO_SQL_MAP.get(domain.is_test, NOT_SET), 'start_date': domain.date_created, 'device_id': max_device, 'wam': AMPLIFY_COUCH_TO_SQL_MAP.get(domain.internal.amplifies_workers, NOT_SET), 'pam': AMPLIFY_COUCH_TO_SQL_MAP.get(domain.internal.amplifies_project, NOT_SET), 'wams_current': len(user_tuple.performing & user_tuple.experienced), 'active_users': len(user_tuple.active | user_tuple.sms), 'using_and_performing': len(user_tuple.performing), 'not_performing': len(user_tuple.active - user_tuple.performing), 'inactive_experienced': len((user_tuple.total - user_tuple.active) & user_tuple.experienced), 'inactive_not_experienced': len((user_tuple.total - user_tuple.active) - user_tuple.experienced), 'not_experienced': len(user_tuple.performing - user_tuple.experienced), 'not_performing_not_experienced': len(user_tuple.active - user_tuple.performing - user_tuple.experienced), 'active_ever': len(possible_experience | recently_active), 'possibly_exp': len(possible_experience), 'ever_exp': len(user_tuple.experienced), 'exp_and_active_ever': len(user_tuple.active & user_tuple.experienced), 'active_in_span': len(recently_active), 'eligible_forms': user_tuple.eligible, 'experienced_threshold': domain.internal.experienced_threshold or DEFAULT_EXPERIENCED_THRESHOLD, 'performance_threshold': domain.internal.performance_threshold or DEFAULT_PERFORMANCE_THRESHOLD, } return gir_dict
def _get_malt_row_dicts(self, domain_name, monthspan, users_by_id): malt_row_dicts = [] for users in chunked(list(users_by_id), 1000): apps_submitted_for = get_app_submission_breakdown_es(domain_name, monthspan, users) for app_row in apps_submitted_for: app_id = app_row.app_id num_of_forms = app_row.doc_count try: app_data = self._app_data(domain_name, app_id) user_id, username, user_type, email = self._user_data( app_row.user_id, app_row.username, users_by_id ) except Exception as ex: logger.error("Failed to get rows for user {id}, app {app_id}. Exception is {ex}".format (id=user_id, app_id=app_id, ex=str(ex)), exc_info=True) continue malt_dict = { 'month': monthspan.startdate, 'user_id': user_id, 'username': username, 'email': email, 'user_type': user_type, 'domain_name': domain_name, 'num_of_forms': num_of_forms, 'app_id': app_id or MISSING_APP_ID, 'device_id': app_row.device_id, 'wam': AMPLIFY_COUCH_TO_SQL_MAP.get(app_data.wam, NOT_SET), 'pam': AMPLIFY_COUCH_TO_SQL_MAP.get(app_data.pam, NOT_SET), 'use_threshold': app_data.use_threshold, 'experienced_threshold': app_data.experienced_threshold, 'is_app_deleted': app_data.is_app_deleted, } malt_row_dicts.append(malt_dict) return malt_row_dicts