-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
131 lines (111 loc) · 5.46 KB
/
app.py
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
125
126
127
128
129
130
131
"""
This module implements the high level logic for data pre-processing and data visualizations.
Warnings
--------
Before running any of the code, copy the data set folder named
"OU-InertGaitAction_wStepAnnotation" into the project directory (app.py).
Then set FIX = True.
After the first run, set Fix = False.
INFO: This module can also be used for testing the entire code. Import as: >>> from app import *
"""
from threading import Thread
from visualization.data_plot import data_plot as dp
from visualization.feature_plot import feature_plot as fp
from data_generator.features import feature_extractor
from visualization.age_distribution import gen_age_histogram
from dataset_operations import data_structs as ds, dataset_manipulator as dm
from config import USED_CLASS_LABEL
# Configuration variables
# True if the Data set needs to be fixed, otherwise False
FIX = True
DATA_PLOT = False
DEVELOPER_MODE = True
DATA_VISUALIZATION = True
TEST_SUBJECT_ID = 1
if __name__ == '__main__':
# Fixing the entire Data set
if FIX:
# Renaming the data set files to fix the naming scheme
dm.dataset_rename()
# Verifying that every subject has a data set in each sub-directory (Center, Right, Left)
dm.dataset_analysis()
# Demonstrating the use of the Subject class and data_plot function
# Generating the subject list and subject data from the data set
subs_list, subs_data = dm.generate_subjects_data(gen_csv=False)
# Choosing a subject to get features and visualizations for
sub = ds.Subject(subs_list[TEST_SUBJECT_ID])
# Generating & Printing the features
print(f'Generating features for file - {sub.subject_id}\n')
features_list, features, step_positions_actual, step_positions_updated, step_positions_updated_bool = \
feature_extractor(sub, "right")
# from data_generator.features import print_features
# print_features(features)
# import pandas as pd
# with pd.option_context('display.max_rows', None, 'display.max_columns', None):
# print(features)
# Plotting the subject data
if DATA_VISUALIZATION:
t1 = Thread(target=dp, args=(sub, step_positions_actual), kwargs={'sensor_axis': "all"})
t1.start()
# Plotting the feature data
t2 = Thread(target=fp, args=(sub, features_list, features,
step_positions_updated, step_positions_updated_bool,))
t2.start()
if DATA_PLOT:
gen_age_histogram(open_plot=True)
else:
print(f"\nModule imported : {__name__}\n")
import pandas as pd
from config import WINDOW_SIZE, WINDOW_TYPE
res = str(input(f"Would you like to FIX the data set? (y/n)")).lower()
if res == 'y':
if DEVELOPER_MODE:
res = str(input(f"Would you like to proceed with prompts enabled? (y/n)")).lower()
if res == 'n':
dm.FORCE = True
elif res == 'y':
dm.FORCE = False
else:
print("Invalid input! Please run the program again.")
if dm.FORCE:
res = 'y'
else:
res = str(input(f"Would you like to Fix the data set in folder '{dm.ORIGINAL_DATASET}'?")).lower()
if res == 'n':
print("Program terminated by the user...")
elif res == 'y':
# Renaming the data set files to fix the naming scheme
dm.dataset_rename()
# Verifying that every subject has a data set in each sub-directory (Center, Right, Left)
dm.dataset_analysis()
# Generating the subject list (Global variable) for the data set
subs_list, subs_data = dm.generate_subjects_data()
# Generating a sample 'Subject' class object
sub = ds.Subject(subs_list[TEST_SUBJECT_ID])
else:
print("Invalid input! Please run the program again.")
elif res == 'n':
# Generating the subject list (Global variable) for the data set
subs_list, subs_data = dm.generate_subjects_data(gen_csv=False)
# Generating a sample 'Subject' class object
sub = ds.Subject(subs_list[TEST_SUBJECT_ID])
print(f'\nThe "Subject" class object "sub" has been created for testing.\n')
sensor_pos = 'right'
data = sub.sensor_pos[sensor_pos].label[USED_CLASS_LABEL]
res = str(input(f"Which output type for feature_extractor()? (df/dict)")).lower()
if res == 'df':
col_names, df, step_positions_actual, step_positions_updated, step_positions_updated_bool \
= feature_extractor(sub, sensor_pos, output_type='df')
print(f'\n"col_names", "df", "step_positions_actual", "step_positions_updated" and '
f'"step_positions_updated_bool" have been returned after a call to feature_extractor()\n')
print(f'\nRatio of no_step(0)/step(1) for subject - {sub.subject_id[:-4]} = '
f'{len(df[df["StepLabel"]==0]) / len(df[df["StepLabel"]==1])}\n')
elif res == 'dict':
features_list, features, step_positions_actual, step_positions_updated, step_positions_updated_bool = \
feature_extractor(sub, "right")
print(f'\n"features_list", "features", "step_positions_actual", "step_positions_updated" and '
f'"step_positions_updated_bool" have been returned after a call to feature_extractor()\n')
else:
print("Invalid input! Please run the program again.")
else:
print("Invalid input! Please run the program again.")