"""
This script holds dictionaries of all the potential features that can be extracted
Each feature in turn contains a dictionary of its salient features:
feature_id:
    name: descriptive name of feature,
    filename: filename containing feature scripts without extension,
    extension: either .sql or .py,
    default: default value of feature,
    dependencies: later features that depend on this extraction being run first,
    desc: description of what this feature is looking at
"""


USER_FEATURE_CATALOG = {
    # Dropouts
    1: {'name': "dropout",
        'filename': '1_dropout',
        'extension': '.sql',
        'table': 'user_long_feature',
        'default': 0,
        'dependencies': [],
        'desc': "Whether or not the student has not dropped out by this week (this is the label used in prediction)"},
    2: {'name': "sum_observed_events_duration",
        'filename': '2_sum_observed_events_duration',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [10],
        'desc': "Total time spent on each resource during the week. "},
    3: {'name': "number_of_forum_posts",
        'filename': '3_number_of_forum_posts',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [103],
        'desc': "Number of forum posts during the week"},
    4: {'name': "number_of_wiki_edits",
        'filename': '4_number_of_wiki_edits',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [104],
        'desc': "Number of wiki edits during the week. "},
    5: {'name': "average_length_of_forum_posts",
        'filename': '5_average_length_of_forum_posts',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [105],
        'desc': "Average length of forum posts during the week"},
    6: {'name': "distinct_attempts",
        'filename': '6_distinct_attempts',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [11, 111],
        'desc': "Number of distinct problems attempted during the week. "},
    7: {'name': "number_of_attempts",
        'filename': '7_number_of_attempts',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [209],
        'desc': "Number of potentially non-distinct problem attempts during the week"},
    8: {'name': "distinct_problems_correct",
        'filename': '8_distinct_problems_correct',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [10, 11, 110, 111],
        'desc': "Number of distinct problems correct during the week. "},
    9: {'name': "average_number_of_attempts",
        'filename': '9_average_number_of_attempts',
        'extension': '.sql',
          'table': 'user_long_feature',
        'default': 0,
        'dependencies': [109, 202, 203],
        'desc': "Average number of problem attempts during the week. "},
    10: {'name': "sum_observed_events_duration_per_correct_problem",
         'filename': '10_sum_observed_events_duration_per_correct_problem',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': -1,
         'dependencies': [110],
         'desc': "Total time spent on all resources during the week (feat. 2) divided by number of correct problems (feat. 8)"},
    11: {'name': "number_problem_attempted_per_correct_problem",
         'filename': '11_number_problem_attempted_per_correct_problem',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': -1,
         'dependencies': [111],
         'desc': "Number of problems attempted (feat. 6) divided by number of correct problems (feat. 8)"},
    12: {'name': "average_time_to_solve_problem",
         'filename': '12_average_time_to_solve_problem',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': -1,
         'dependencies': [112],
         'desc': "Average of (max(attempt.timestamp) - min(attempt.timestamp)) for each problem during the week"},
    13: {'name': "observed_event_timestamp_variance",
         'filename': '13_observed_event_timestamp_variance',
         'extension': '.py',
         'table': 'user_long_feature',
         'default': 0,
         'dependencies': [],
         'desc': "Variance of a students observed event timestamps in one week. "},
    14: {'name': "number_of_collaborations",
         'filename': '14_number_of_collaborations',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': 0,
         'dependencies': [],
         'desc': "Number of collaborations during the week"},
    15: {'name': "max_duration_resources",
         'filename': '15_max_duration_resources',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': 0,
         'dependencies': [],
         'desc': "Duration of longest observed event"},
    16: {'name': "sum_observed_events_lecture",
         'filename': '16_sum_observed_events_lecture',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': 0,
         'dependencies': [],
         'desc': "Total time spent on all lecture-related resources during the week"},
    17: {'name': "sum_observed_events_book",
         'filename': '17_sum_observed_events_book',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': 0,
         'dependencies': [],
         'desc': "Total time spent on all book-related resources during the week"},
    18: {'name': "sum_observed_events_wiki",
         'filename': '18_sum_observed_events_wiki',
         'extension': '.sql',
          'table': 'user_long_feature',
         'default': 0,
         'dependencies': [],
         'desc': "Total time spent on all wiki-related resources during the week"},
    103: {'name': "difference_feature_3",
          'filename': '103_difference_feature_3',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Number of forum posts in current week divided by number of forum posts in previous week (difference of feature 3)"},
    104: {'name': "difference_feature_4",
          'filename': '104_difference_feature_4',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Number of wiki edits in current week divided by number of wiki edits in previous week (difference of feature 4)"},
    105: {'name': "difference_feature_5",
          'filename': '105_difference_feature_5',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Average length of forum posts in current week divided by average length of forum posts in previous week, where number of forum posts in previous week is > 5 (difference of feature 5)"},
    109: {'name': "difference_feature_9",
          'filename': '109_difference_feature_9',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Average number of attempts in current week divided by average number of attempts in previous week (difference of feature 9)"},
    110: {'name': "difference_feature_10",
          'filename': '110_difference_feature_10',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "(Total time spent on all resources during current week (feat. 2) divided by number of correct problems during current week (feat. 8)) divided by same thing from previous week (difference of feature 10)"},
    111: {'name': "difference_feature_11",
          'filename': '111_difference_feature_11',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "(Number of problems attempted (feat. 6) divided by number of correct problems (feat. 8)) divided by same thing from previous week (difference of feature 11)"},
    112: {'name': "difference_feature_12",
          'filename': '112_difference_feature_12',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "(Average of (max(attempt.timestamp) - min(attempt.timestamp)) for each problem during current week) divided by same thing from previous week (difference of feature 12)"},
    201: {'name': "number_of_forum_responses",
          'filename': '201_number_of_forum_responses',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Number of forum responses per week (also known as CF1)"},
    202: {'name': "percentile_of_average_number_of_attempts",
          'filename': '202_percentile_of_average_number_of_attempts',
          'extension': '.py',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Each students average number of attempts during the week (feat. 9) compared with other students as a percentile"},
    203: {'name': "percent_of_average_number_of_attempts",
          'filename': '203_percent_of_average_number_of_attempts',
          'extension': '.py',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Each students average number of attempts during the week (feat. 9) compared with other students as a percent of max"},
    204: {'name': "pset_grade",
          'filename': '204_pset_grade',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [205],
          'desc': "Number of homework problems correct in a week divided by number of homework problems in the week"},
    205: {'name': "pset_grade_over_time",
          'filename': '205_pset_grade_over_time',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': -1,
          'dependencies': [],
          'desc': "Pset grade from current week (feature 204) - avg(pset grade from previous week)"},
    206: {'name': "lab_grade",
          'filename': '206_lab_grade',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [207],
          'desc': "Number of lab problems correct in a week divided by number of lab problems in the week"},
    207: {'name': "lab_grade_over_time",
          'filename': '207_lab_grade_over_time',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Lab grade from current week (feature 206) - avg(lab grade from previous week)"},
    208: {'name': "attempts_correct",
          'filename': '208_attempts_correct',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': -1,
          'dependencies': [209],
          'desc': "Number of attempts (any type) that were correct during the week"},
    209: {'name': "percent_correct_submissions",
          'filename': '209_percent_correct_submissions',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Percentage of total submissions that were correct (feature 208 / feature 7)"},
    210: {'name': "average_predeadline_submission_time",
          'filename': '210_average_predeadline_submission_time',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': -1,
          'dependencies': [],
          'desc': "Average time between problem submissions and problem due date (in seconds)"},
    301: {'name': "std_hours_working",
          'filename': '301_std_hours_working',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Standard deviation of the hours the user produces events and collaborations. Tries to capture how regular a student is with her schedule while doing a MOOC"},
    302: {'name': "time_to_react",
          'filename': '302_time_to_react',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Average time in days a student takes to react when a new resource in posted. Tried to capteloure how fast a student is reacting to new content"},
    # Following are all features for John Ding's Video-Watching behavior paper
    # Dropouts for visualization
    701: {'name': "user_dropout_week",
          'filename': '701_user_dropout_week',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [1],
          'desc': "The dropout week of a user"},
    # Following are 10 classes of video watching features
    711: {'name': "number_of_videos_per_user_per_week",
          'filename': '711_number_of_videos_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "The number of distinct videos that a user has watched in a week"},
    712: {'name': "number_of_users_per_video",
          'filename': '712_number_of_users_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "The number of distinct users that watch a specific video"},
    713: {'name': "number_of_videos_per_user",
          'filename': '713_number_of_videos_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [711],
          'desc': "The number of distinct videos that a user has watched"},
    714: {'name': "number_of_videos_per_week",
          'filename': '714_number_of_videos_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [711],
          'desc': "The number of videos that has been watched by users in a week"},
    721: {'name': "total_engagement_time_per_user_per_week",
          'filename': '721_total_engagement_time_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Total engagement time of a user in a week"},
    722: {'name': "total_engagement_time_per_video",
          'filename': '722_total_engagement_time_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Total engagement time on a video"},
    723: {'name': "total_engagement_time_per_user",
          'filename': '723_total_engagement_time_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [721],
          'desc': "Total engagement time of a user"},
    724: {'name': "total_engagement_time_per_week",
          'filename': '724_total_engagement_time_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [721],
          'desc': "Total engagement time in a week"},
    731: {'name': "session_engagement_time_per_user_per_week",
          'filename': '731_session_engagement_time_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [721],
          'desc': "Average engagement time of a watching session of a user in a week"},
    732: {'name': "session_engagement_time_per_video",
          'filename': '732_session_engagement_time_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [722],
          'desc': "Average engagement time of a watching session of a video"},
    733: {'name': "session_engagement_time_per_user",
          'filename': '733_session_engagement_time_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [731],
          'desc': "Average engagement time of a watching session of a user"},
    734: {'name': "session_engagement_time_per_week",
          'filename': '734_session_engagement_time_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [731],
          'desc': "Average engagement time of a watching session in a week"},
    741: {'name': "completion_rate_casual_per_user_per_week",
          'filename': '741_completion_rate_casual_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Percentage of videos that are completed over a certain threshold of a user in a week"},
    742: {'name': "completion_rate_casual_per_video",
          'filename': '742_completion_rate_casual_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Percentage of users that completed the video over a certain threshold of a video"},
    743: {'name': "completion_rate_casual_per_user",
          'filename': '743_completion_rate_casual_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [741],
          'desc': "Percentage of videos that are completed over a certain threshold of a user"},
    744: {'name': "completion_rate_per_week",
          'filename': '744_completion_rate_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [741],
          'desc': "Percentage of videos that are completed over a certain threshold in a week"},

    # Following features are user longitudinal features for dropout prediction
    751: {'name': "watching_frequency_casual_per_user_per_week",
          'filename': '751_watching_frequency_casual_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "The watching frequency counted by casual method of a user in a week"},
    752: {'name': "watching_frequency_casual_per_video",
          'filename': '752_watching_frequency_casual_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "The watching frequency counted by casual method of a week"},
    753: {'name': "watching_frequency_casual_per_user",
          'filename': '753_watching_frequency_casual_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [751],
          'desc': "The watching frequency counted by casual method of a user"},
    754: {'name': "watching_frequency_casual_per_week",
          'filename': '754_watching_frequency_casual_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [751],
          'desc': "The watching frequency counted by casual method in a week"},
    755: {'name': "watching_frequency_strict_per_user_per_week",
          'filename': '755_watching_frequency_strict_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "The watching frequency counted by strict method of a user in a week"},
    756: {'name': "watching_frequency_strict_per_video",
          'filename': '756_watching_frequency_strict_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "The watching frequency counted by strict method of a week"},
    757: {'name': "watching_frequency_strict_per_user",
          'filename': '757_watching_frequency_strict_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [755],
          'desc': "The watching frequency counted by strict method of a user"},
    758: {'name': "watching_frequency_strict_per_week",
          'filename': '758_watching_frequency_strict_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [755],
          'desc': "The watching frequency counted by strict method in a week"},
    761: {'name': "seeking_forward_frequency_per_user_per_week",
          'filename': '761_seeking_forward_frequency_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Seeking forward frequency of a user in a week"},
    762: {'name': "seeking_forward_frequency_per_video",
          'filename': '762_seeking_forward_frequency_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Seeking forward frequency of a video"},
    763: {'name': "seeking_forward_frequency_per_user",
          'filename': '763_seeking_forward_frequency_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [761],
          'desc': "Seeking forward frequency of a user"},
    764: {'name': "seeking_forward_frequency_per_week",
          'filename': '764_seeking_forward_frequency_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [761],
          'desc': "Seeking forward frequency in a week"},
    765: {'name': "seeking_back_frequency_per_user_per_week",
          'filename': '765_seeking_back_frequency_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Seeking back frequency of a user in a week"},
    766: {'name': "seeking_back_frequency_per_video",
          'filename': '766_seeking_back_frequency_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Seeking back frequency of a video"},
    767: {'name': "seeking_back_frequency_per_user",
          'filename': '767_seeking_back_frequency_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [765],
          'desc': "Seeking back frequency of a user"},
    768: {'name': "seeking_back_frequency_per_week",
          'filename': '768_seeking_back_frequency_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [765],
          'desc': "Seeking back frequency in a week"},
    771: {'name': "pausing_frequency_per_user_per_video",
          'filename': '771_pausing_frequency_per_user_per_video',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Pausing frequency of a user in a week"},
    772: {'name': "pausing_frequency_per_video",
          'filename': '772_pausing_frequency_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Pausing frequency of a video"},
    773: {'name': "pausing_frequency_per_user",
          'filename': '773_pausing_frequency_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [771],
          'desc': "Pausing frequency of a user"},
    774: {'name': "pausing_frequency_per_week",
          'filename': '774_pausing_frequency_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [771],
          'desc': "Pausing frequency in a week"},
    781: {'name': "total_pausing_time_per_user_per_week",
          'filename': '781_total_pausing_time_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Total pausing time of a user in a week"},
    782: {'name': "total_pausing_time_per_video",
          'filename': '782_total_pausing_time_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Total pausing time of a video"},
    783: {'name': "total_pausing_time_per_user",
          'filename': '783_total_pausing_time_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [781],
          'desc': "Total pausing time of a user"},
    784: {'name': "total_pausing_time_per_week",
          'filename': '784_total_pausing_time_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [781],
          'desc': "Total pausing time in a week"},
    791: {'name': "average_watching_speed_per_user_per_week",
          'filename': '791_average_watching_speed_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Average watching speed of a user in a week"},
    792: {'name': "average_watching_speed_per_video",
          'filename': '792_average_watching_speed_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Average watching speed of a video"},
    793: {'name': "average_watching_speed_per_user",
          'filename': '793_average_watching_speed_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [791],
          'desc': "Average watching speed of a user"},
    794: {'name': "average_watching_speed_per_week.sql",
          'filename': '794_average_watching_speed_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [791],
          'desc': "Average watching speed in a week"},
    801: {'name': "real_watching_time_per_user_per_week",
          'filename': '801_real_watching_time_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Real watching time of a user in a week"},
    802: {'name': "real_watching_time_per_video",
          'filename': '802_real_watching_time_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Real watching time of a video"},
    803: {'name': "real_watching_time_per_user",
          'filename': '803_real_watching_time_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [801],
          'desc': "Real watching time of a user"},
    804: {'name': "real_watching_time_per_week",
          'filename': '804_real_watching_time_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [801],
          'desc': "Real watching time in a week"},
    
    # Following are features for verification
    911: {'name': "video_length_per_video",
          'filename': '911_video_length_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Length of a video"},
    921: {'name': "watched_frequency_per_video",
          'filename': '921_watched_frequency_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Watching frequency of a video (for verification)"},
    922: {'name': "viewed_frequency_per_video",
          'filename': '922_viewed_frequency_per_video',
          'extension': '.sql',
          'table': 'video_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Viewing frequency of a video (for verification)"},
    931: {'name': "number_of_video_per_user_per_week",
          'filename': '931_number_of_video_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Number of distinct videos watched by a user in a week (for verification)"},
    932: {'name': "number_of_video_per_user",
          'filename': '932_number_of_video_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [931],
          'desc': "Number of distinct videos watched by a user (for verification)"},
    933: {'name': "number_of_video_per_week",
          'filename': '933_number_of_video_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [931],
          'desc': "Number of distinct videos watched in a week (for verification)"},
    934: {'name': "seeking_frequency_per_user_per_week",
          'filename': '934_seeking_frequency_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Seeking frequency of a user in a week (for verification)"},
    935: {'name': "seeking_frequency_per_user",
          'filename': '935_seeking_frequency_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [934],
          'desc': "Seeking frequency of a user (for verification)"},
    936: {'name': "seeking_frequency_per_week",
          'filename': '936_seeking_frequency_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [934],
          'desc': "Seeking frequency in a week (for verification)"},
    937: {'name': "viewed_frequency_per_user_per_week",
          'filename': '937_viewed_frequency_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Viewing frequency of a user in a week (for verification)"},
    938: {'name': "viewed_frequency_per_user",
          'filename': '938_viewed_frequency_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [937],
          'desc': "Viewing frequency of a user (for verification)"},
    939: {'name': "viewed_frequency_per_week",
          'filename': '939_viewed_frequency_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [937],
          'desc': "Viewing frequency in a week (for verification)"},
    940: {'name': "watched_time_per_user_per_week",
          'filename': '940_watched_time_per_user_per_week',
          'extension': '.sql',
          'table': 'user_long_feature',
          'default': 0,
          'dependencies': [],
          'desc': "Watching time of a user in a week (for verification)"},
    941: {'name': "watched_time_per_user",
          'filename': '941_watched_time_per_user',
          'extension': '.sql',
          'table': 'user_feature',
          'default': 0,
          'dependencies': [940],
          'desc': "Watching time of a user (for verification)"},
    942: {'name': "watched_time_per_week",
          'filename': '942_watched_time_per_week',
          'extension': '.sql',
          'table': 'long_feature',
          'default': 0,
          'dependencies': [940],
          'desc': "Watching time in a week (for verification)"},
}


def get_feature_ids():
    return list(USER_FEATURE_CATALOG.keys())


def get_feature_dict(feature_id):
    return USER_FEATURE_CATALOG[feature_id] if feature_id in USER_FEATURE_CATALOG else None


def process_exec(exec_list):
    exec_list = [fid for fid in exec_list if fid in USER_FEATURE_CATALOG.keys()]
    if not exec_list:
        return []
    return sorted(exec_list)


def process_skip(skip_list):
    exec_list = skip2exec(skip_list)
    return process_exec(exec_list)


def get_dependencies(feature_list):
    dependencies = []
    for fid in feature_list:
        dependencies += USER_FEATURE_CATALOG[fid]['dependencies']
    return list(set(dependencies))


def skip2exec(skip_list):
    dependencies = get_dependencies([fid for fid in USER_FEATURE_CATALOG.keys() if fid not in skip_list])
    missed_dependencies = [fid for fid in dependencies if fid in skip_list]
    if missed_dependencies:
        print("Warning: the following dependencies of queued features are skipped:\n")
        print("%s\n", str([USER_FEATURE_CATALOG[fid]['name'] for fid in missed_dependencies]))
    return [fid for fid in USER_FEATURE_CATALOG.keys() if fid not in skip_list]
