def get_table_weight(table_id: int, session=None) -> int: """Calculate the weight of table. Used for ranking in auto completion and sidebar table search. Arguments: table_id {int} -- Id of DataTable Keyword Arguments: session -- Sqlalchemy DB session (default: {None}) Returns: int -- The integer weight """ num_samples = get_table_query_samples_count(table_id, session=session) num_impressions = get_viewers_count_by_item_after_date( ImpressionItemType.DATA_TABLE, table_id, get_last_impressions_date(), session=session, ) boost_score = get_table_by_id(table_id, session=session).boost_score # Samples worth 10x as much as impression # Log the score to flatten the score distrution (since its power law distribution) return int( math.log2(((num_impressions + num_samples * 10) + 1) * boost_score))
def get_impression_item_impression_count(item_type, item_id): return logic.get_viewers_count_by_item_after_date( item_type, item_id, logic.get_last_impressions_date())
def get_impression_item_impression_timeseries(item_type, item_id): return logic.get_item_timeseries_after_date( item_type, item_id, logic.get_last_impressions_date())