def remote_server_post_analytics( request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], realm_counts: List[Dict[str, Any]] = REQ(json_validator=check_list( check_dict_only([ ("property", check_string), ("realm", check_int), ("id", check_int), ("end_time", check_float), ("subgroup", check_none_or(check_string)), ("value", check_int), ]))), installation_counts: List[Dict[str, Any]] = REQ(json_validator=check_list( check_dict_only([ ("property", check_string), ("id", check_int), ("end_time", check_float), ("subgroup", check_none_or(check_string)), ("value", check_int), ]))), realmauditlog_rows: Optional[List[Dict[str, Any]]] = REQ( json_validator=check_list( check_dict_only([ ("id", check_int), ("realm", check_int), ("event_time", check_float), ("backfilled", check_bool), ("extra_data", check_none_or(check_string)), ("event_type", check_int), ])), default=None, ), ) -> HttpResponse: server = validate_entity(entity) validate_incoming_table_data(server, RemoteRealmCount, realm_counts, True) validate_incoming_table_data(server, RemoteInstallationCount, installation_counts, True) if realmauditlog_rows is not None: validate_incoming_table_data(server, RemoteRealmAuditLog, realmauditlog_rows) row_objects = [ RemoteRealmCount( property=row["property"], realm_id=row["realm"], remote_id=row["id"], server=server, end_time=datetime.datetime.fromtimestamp(row["end_time"], tz=datetime.timezone.utc), subgroup=row["subgroup"], value=row["value"], ) for row in realm_counts ] batch_create_table_data(server, RemoteRealmCount, row_objects) row_objects = [ RemoteInstallationCount( property=row["property"], remote_id=row["id"], server=server, end_time=datetime.datetime.fromtimestamp(row["end_time"], tz=datetime.timezone.utc), subgroup=row["subgroup"], value=row["value"], ) for row in installation_counts ] batch_create_table_data(server, RemoteInstallationCount, row_objects) if realmauditlog_rows is not None: row_objects = [ RemoteRealmAuditLog( realm_id=row["realm"], remote_id=row["id"], server=server, event_time=datetime.datetime.fromtimestamp( row["event_time"], tz=datetime.timezone.utc), backfilled=row["backfilled"], extra_data=row["extra_data"], event_type=row["event_type"], ) for row in realmauditlog_rows ] batch_create_table_data(server, RemoteRealmAuditLog, row_objects) return json_success()
def remote_server_post_analytics( request: HttpRequest, entity: Union[UserProfile, RemoteZulipServer], realm_counts: List[Dict[str, Any]] = REQ(validator=check_list( check_dict_only([ ('property', check_string), ('realm', check_int), ('id', check_int), ('end_time', check_float), ('subgroup', check_none_or(check_string)), ('value', check_int), ]))), installation_counts: List[Dict[str, Any]] = REQ(validator=check_list( check_dict_only([ ('property', check_string), ('id', check_int), ('end_time', check_float), ('subgroup', check_none_or(check_string)), ('value', check_int), ]))), realmauditlog_rows: Optional[List[Dict[str, Any]]] = REQ( validator=check_list( check_dict_only([ ('id', check_int), ('realm', check_int), ('event_time', check_float), ('backfilled', check_bool), ('extra_data', check_none_or(check_string)), ('event_type', check_int), ])), default=None) ) -> HttpResponse: server = validate_entity(entity) validate_incoming_table_data(server, RemoteRealmCount, realm_counts, True) validate_incoming_table_data(server, RemoteInstallationCount, installation_counts, True) if realmauditlog_rows is not None: validate_incoming_table_data(server, RemoteRealmAuditLog, realmauditlog_rows) row_objects = [ RemoteRealmCount(property=row['property'], realm_id=row['realm'], remote_id=row['id'], server=server, end_time=datetime.datetime.fromtimestamp( row['end_time'], tz=timezone_utc), subgroup=row['subgroup'], value=row['value']) for row in realm_counts ] batch_create_table_data(server, RemoteRealmCount, row_objects) row_objects = [ RemoteInstallationCount( property=row['property'], remote_id=row['id'], server=server, end_time=datetime.datetime.fromtimestamp(row['end_time'], tz=timezone_utc), subgroup=row['subgroup'], value=row['value']) for row in installation_counts ] batch_create_table_data(server, RemoteInstallationCount, row_objects) if realmauditlog_rows is not None: row_objects = [ RemoteRealmAuditLog( realm_id=row['realm'], remote_id=row['id'], server=server, event_time=datetime.datetime.fromtimestamp(row['event_time'], tz=timezone_utc), backfilled=row['backfilled'], extra_data=row['extra_data'], event_type=row['event_type']) for row in realmauditlog_rows ] batch_create_table_data(server, RemoteRealmAuditLog, row_objects) return json_success()