make_dataset_count.py 4.89 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python
import config as cfg
from tools import file_reader, file_writer
from tools import preprocessor
from utility import embedder
import pandas as pd
import numpy as np

USE_CAT_NAMES = True

def main():
    make_complete_count()
    make_compliance_count()
    make_fall_short_count()
    make_fall_long_count()
    
def make_complete_count():
    case = 'Complete'
    ats = {str(i)+'Ats':str for i in range(1, cfg.ATS_RESOLUTION+1)}
    df = file_reader.read_csv(cfg.PROCESSED_DATA_DIR,
                              f'complete.csv',
                              converters=ats)
    
    cols_ats = [str(i)+'Ats' for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = [df[f'{i}Ats'].unique() for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = list(set(np.concatenate(unique_ats)))
    df_ats = preprocessor.extract_cat_count(df, unique_ats, cols_ats, '')
    
    if USE_CAT_NAMES:
        df = df.drop(cols_ats, axis=1)
        df = pd.concat([df.drop(case, axis=1), df_ats, df[[case]]], axis=1)
        df = df.drop('0', axis=1)
    else:
        num_cols = embedder.get_numerical_cols(df, case)
        df = pd.concat([df, df_ats], axis=1)
        ats_columns = ['Ats_' + ats for ats in unique_ats]
        df = df[num_cols + ats_columns + df[[case]]]
        df = df.drop(['Ats_0'], axis=1)

    file_writer.write_csv(df, cfg.PROCESSED_DATA_DIR, 'complete_count.csv')
    
def make_compliance_count():
    case = 'Compliance'
    ats = {str(i)+'Ats':str for i in range(1, cfg.ATS_RESOLUTION+1)}
    df = file_reader.read_csv(cfg.PROCESSED_DATA_DIR,
                              f'compliance.csv',
                              converters=ats)
    
    cols_ats = [str(i)+'Ats' for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = [df[f'{i}Ats'].unique() for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = list(set(np.concatenate(unique_ats)))
    df_ats = preprocessor.extract_cat_count(df, unique_ats, cols_ats, '')
    
    if USE_CAT_NAMES:
        df = df.drop(cols_ats, axis=1)
        df = pd.concat([df.drop(case, axis=1), df_ats, df[[case]]], axis=1)
        df = df.drop('0', axis=1)
    else:
        num_cols = embedder.get_numerical_cols(df, case)
        df = pd.concat([df, df_ats], axis=1)
        ats_columns = ['Ats_' + ats for ats in unique_ats]
        df = df[num_cols + ats_columns + df[[case]]]
        df = df.drop(['Ats_0'], axis=1)
        
    file_writer.write_csv(df, cfg.PROCESSED_DATA_DIR, 'compliance_count.csv')

def make_fall_short_count():
    case = 'FallShort'
    ats = {str(i)+'Ats':str for i in range(1, cfg.ATS_RESOLUTION+1)}
    df = file_reader.read_csv(cfg.PROCESSED_DATA_DIR,
                              f'fall_short.csv',
                              converters=ats)
    
    cols_ats = [str(i)+'Ats' for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = [df[f'{i}Ats'].unique() for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = list(set(np.concatenate(unique_ats)))
    df_ats = preprocessor.extract_cat_count(df, unique_ats, cols_ats, '')
    
    if USE_CAT_NAMES:
        df = df.drop(cols_ats, axis=1)
        df = pd.concat([df.drop(case, axis=1), df_ats, df[[case]]], axis=1)
        df = df.drop('0', axis=1)
    else:
        num_cols = embedder.get_numerical_cols(df, case)
        df = pd.concat([df, df_ats], axis=1)
        ats_columns = ['Ats_' + ats for ats in unique_ats]
        df = df[num_cols + ats_columns + df[[case]]]
        df = df.drop(['Ats_0'], axis=1)
        
    file_writer.write_csv(df, cfg.PROCESSED_DATA_DIR, 'fall_short_count.csv')

def make_fall_long_count():
    case = 'FallLong'
    ex = {str(i)+'Ex':str for i in range(1, cfg.EX_RESOLUTION+1)}
    ats = {str(i)+'Ats':str for i in range(1, cfg.ATS_RESOLUTION+1)}
    converters = {**ex, **ats}
    df = file_reader.read_csv(cfg.PROCESSED_DATA_DIR,
                              f'fall_long.csv',
                              converters=converters)
    
    num_cols = embedder.get_numerical_cols(df, case)
    
    # Extract exercises
    cols_ex = [str(i)+'Ex' for i in range(1, cfg.EX_RESOLUTION+1)]
    unique_ex = [df[f'{i}Ex'].unique() for i in range(1, cfg.EX_RESOLUTION+1)]
    unique_ex = list(set(np.concatenate(unique_ex)))
    df_ex = preprocessor.extract_cat_count(df, unique_ex, cols_ex, 'Ex_')
    
    # Extract ats
    cols_ats = [str(i)+'Ats' for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = [df[f'{i}Ats'].unique() for i in range(1, cfg.ATS_RESOLUTION+1)]
    unique_ats = list(set(np.concatenate(unique_ats)))
    df_ats = preprocessor.extract_cat_count(df, unique_ats, cols_ats, 'Ats_')

    # Merge dataframes
    df = pd.concat([df, df_ex, df_ats], axis=1)
    ex_columns = ['Ex_' + ex for ex in unique_ex]
    ats_columns = ['Ats_' + ats for ats in unique_ats]
    df = df[num_cols + ex_columns + ats_columns + [case]]
    df = df.drop(['Ex_0', 'Ats_0'], axis=1)
    file_writer.write_csv(df, cfg.PROCESSED_DATA_DIR, 'fall_long_count.csv')

if __name__ == "__main__":
    main()