# Path: cogspaces/datasets/derivative.py
# def get_study_info():
#     input_data, targets = load_reduced_loadings(data_dir=get_data_dir())
#     targets = pd.concat(targets.values(), axis=0)
#     targets['#subjects'] = targets.groupby(by=['study', 'task', 'contrast'])['subject'].transform('nunique')
#     targets['#contrasts_per_task'] = targets.groupby(by=['study', 'task'])['contrast'].transform('nunique')
#     targets['#contrasts_per_study'] = targets.groupby(by='study')['contrast'].transform('nunique')
#     targets['chance_study'] = 1 / targets['#contrasts_per_study']
#     targets['chance_task'] = 1 / targets['#contrasts_per_task']
#     citations = _get_citations()
#     targets = pd.merge(targets, citations, on='study', how='left')
#     targets = targets.groupby(by=['study', 'task', 'contrast']).first().sort_index().drop(columns='index').reset_index()
# 
#     targets['study__task'] = targets.apply(lambda x: f'{x["study"]}__{x["task"]}', axis='columns')
#     targets['name_task'] = targets.apply(lambda x: f'[{x["bibkey"]}] {x["task"]}', axis='columns')
# 
#     def apply(x):
#         comment = x['comment'].iloc[0]
#         if comment != '':
#             tasks = comment
#             tasks_lim = comment
#         else:
#             tasks_list = x['task'].unique()
#             tasks = ' & '.join(tasks_list)
#             if len(tasks) > 50:
#                 tasks_lim = tasks_list[0] + ' & ...'
#             else:
#                 tasks_lim = tasks
#         name = f'[{x["bibkey"].iloc[0]}] {tasks_lim}'
#         latex_name = f'\cite{{{x["citekey"].iloc[0]}}} {tasks}'.replace('&', '\&')
#         name = pd.DataFrame(data={'name': name,
#                                   'latex_name':latex_name}, index=x.index)
#         return name
#     name = targets.groupby(by='study').apply(apply)
#     targets = pd.concat([targets, name], axis=1)
#     return targets


import pandas as pd
from cogspaces.datasets.derivative import get_study_info


info = get_study_info().groupby(by='study').first()

info = info[['latex_name', '#contrasts_per_study', '#subjects']].reset_index(drop=True)
total = info.sum(axis=0)
total['latex_name'] = 'Total'
total = total.to_frame().T
info = pd.concat([info, total], axis=0)

# Path: cogspaces/datasets/derivative.py
# def get_study_info():
#     input_data, targets = load_reduced_loadings(data_dir=get_data_dir())
#     targets = pd.concat(targets.values(), axis=0)
#     targets['#subjects'] = targets.groupby(by=['study', 'task', 'contrast'])['subject'].transform('nunique')
#     targets['#contrasts_per_task'] = targets.groupby(by=['study', 'task'])['contrast'].transform('nunique')
#     targets['#contrasts_per_study'] = targets.groupby(by='study')['contrast'].transform('nunique')
#     targets['chance_study'] = 1 / targets['#contrasts_per_study']
#     targets['chance_task'] = 1 / targets['#contrasts_per_task']
#     citations = _get_citations()
#     targets = pd.merge(targets, citations, on='study', how='left')
#     targets = targets.groupby(by=['study', 'task', 'contrast']).first().sort_index().drop(columns='index').reset_index()
# 
#     targets['study__task'] = targets.apply(lambda x: f'{x["study"]}__{x["task"]}', axis='columns')
#     targets['name_task'] = targets.apply(lambda x: f'[{x["bibkey"]}] {x["task"]}', axis='columns')
# 
#     def apply(x):
#         comment = x['comment'].iloc[0]
#         if comment != '':
#             tasks = comment
#             tasks_lim = comment
#         else:
#             tasks_list = x['task'].unique()
#             tasks = ' & '.join(tasks_list)
#             if len(tasks) > 50:
#                 tasks_lim = tasks_list[0] + ' & ...'
#             else:
#                 tasks_lim = tasks
#         name = f'[{x["bibkey"].iloc[0]}] {tasks_lim}'
#         latex_name = f'\cite{{{x["citekey"].iloc[0]}}} {tasks}'.replace('&', '\&')
#         name = pd.DataFrame(data={'name': name,
#                                   'latex_name':latex_name}, index=x.index)
#         return name
#     name = targets.groupby(by='study').apply(apply)
#     targets = pd.concat([targets, name], axis=1)
#     return targets


# Path: exps/count.py
import pandas as pd
from cogspaces.datasets.derivative import get_study_info



info = get_study_info().groupby(by='study').first()

info = info[['latex_name', '#contrasts_per_study', '#subjects']].reset_index(drop=True)
total = info.sum(axis=0)
total['latex_name'] = 'Total'
total = total.to_frame().T
info = pd.concat([info, total], axis=0)

info.columns = pd.Index(['Study and task description', '\# contrasts', '\# subjects'])