import json


def get_subject_info(df_sub):
    """
    Args:
        df_sub (Pandas dataframe): Pandas dataframe containing
        earthquake-detective-subjects.csv file

    Returns (dictionary): Mapping of sub_id -> Time_Stamp Region_Code Station_Code Channel Label

    """
    subject_info = {}
    for index, row in df_sub.iterrows():
        sub_id = row['subject_id']
        meta = json.loads(row['metadata'])
        file_name = meta['!image_name'].split('_')
        '''
        file_name[0] = Region 
        file_name[1] = Station code 
        file_name[2] = location 
        file_name[3] = channel 
        file_name[4] = year 
        file_name[5] = month 
        file_name[6] = day 
        file_name[7] = hours 
        file_name[8] = minutes 
        file_name[9] = seconds 
        file_name[10] = timestamp offset 
        '''
        # If this is true then its a practice problem
        if '!Classification' in meta:
            subject_info[sub_id] = [meta['!image_name'][:-4], meta['!Classification']]
        # Ensure that the information is extracted only if the structure is correct
        elif len(file_name) >= 11:
            time_stamp = "-".join(file_name[4:7]) + ":".join(file_name[7:10]) + '.' + \
                         file_name[10][:3]

            subject_info[sub_id] = [time_stamp, file_name[0], file_name[1], file_name[3]]

    return subject_info