'item_id'] = df_times_in_impressions.index.astype(int)
        df_times_in_impressions = df_times_in_impressions.reindex(
            columns=['item_id', 'num_times_item_impressed'])
        df_times_in_impressions = df_times_in_impressions.sort_values(
            by=['item_id']).reset_index(drop=True)

        feature = pd.merge(clk_expanded,
                           df_times_in_impressions,
                           how='left',
                           on=['item_id']).fillna(0)
        feature.num_times_item_impressed = feature.num_times_item_impressed.astype(
            int)

        return feature[[
            'user_id', 'session_id', 'item_id', 'num_times_item_impressed'
        ]]


if __name__ == '__main__':
    import utils.menu as menu

    mode = menu.mode_selection()
    cluster = menu.cluster_selection()

    c = NumTimesItemImpressed(mode, cluster)

    print('Creating {} for {} {}'.format(c.name, c.mode, c.cluster))
    c.save_feature()

    print(c.read_feature())
                             actions_involving_impression_session_no_action))
                    count += 1
                return r

        train = data.train_df(mode=self.mode, cluster=self.cluster)
        test = data.test_df(mode=self.mode, cluster=self.cluster)
        df = pd.concat([train, test])
        df = df.drop(['timestamp', 'step', 'platform', 'city', 'device', 'current_filters', 'prices'], axis=1)
        s = df.groupby(
            ['user_id', 'session_id']).progress_apply(func)
        s = s.apply(pd.Series).reset_index().melt(id_vars=['user_id', 'session_id'], value_name='tuple').sort_values(
            by=['user_id', 'session_id']).dropna()
        s[['item_id', 'actions_involving_impression_session_clickout_item',
           'actions_involving_impression_session_interaction_item_deals',
           'actions_involving_impression_session_interaction_item_image',
           'actions_involving_impression_session_interaction_item_info',
           'actions_involving_impression_session_interaction_item_rating',
           'actions_involving_impression_session_search_for_item',
           'actions_involving_impression_session_no_action']] = pd.DataFrame(s['tuple'].tolist(), index=s.index)
        s = s.drop(['variable', 'tuple'], axis=1)
        s = s.reset_index(drop=True)
        return s


if __name__ == '__main__':
    from utils.menu import mode_selection, cluster_selection
    cluster = cluster_selection()
    mode = mode_selection()
    c = ActionsInvolvingImpressionSession(mode=mode, cluster=cluster)
    c.save_feature()
                                 cluster='no_cluster',
                                 dataset_name=flags_dict['dataset_name'],
                                 pred_name=name)
        model.name = f'tf_ranking_{name}'
        model.run()
        HERA.send_message('EXPORTED... mode:{}, name:{}'.format(
            flags_dict['mode'], name))


if __name__ == '__main__':
    global flags_dict
    flags_dict = {}

    # let the user insert the mode cluster and dataset name
    _MODE = menu.mode_selection()
    _CLUSTER = menu.cluster_selection()
    _DATASET_NAME = input('insert dataset name: \n')

    _BASE_PATH = f'dataset/preprocessed/tf_ranking/{_CLUSTER}/{_MODE}/{_DATASET_NAME}'
    _TRAIN_PATH = f'{_BASE_PATH}/train.hdf'
    _TEST_PATH = f'{_BASE_PATH}/test.hdf'
    _VALI_PATH = f'{_BASE_PATH}/vali.hdf'

    min_mrr = float(input('insert the min_MRR from which export the sub: \n'))

    # lets load the context features id
    context_features_id = list(
        np.load(f'{_BASE_PATH}/context_features_id.npy'))
    print(f'context features id are: {context_features_id}')
    flags_dict['context_features_id'] = context_features_id