Skip to content

Commit

Permalink
removed unnecessary prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Arashhs committed Oct 21, 2023
1 parent 8643c29 commit ae64e5d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 40 deletions.
1 change: 1 addition & 0 deletions stream_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ def fetch_sensor_data():
data_loader = init_dataloader(inited=data_loader_inited,db_name=db_name)
data_loader_inited = True
df_dict = data_loader.get_next()
print(df_dict)
res = {}
for key, rows in df_dict.items():
rows_with_strftime = rows.copy()
Expand Down
Binary file modified user.db
Binary file not shown.
103 changes: 63 additions & 40 deletions viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ def get_data(session=None, real_time=False) -> pd.DataFrame:
df_coords = pd.DataFrame(data['coordinates'])
df_coords['value'] = df_coords['value'].apply(lambda x: wkb.loads(bytes.fromhex(x)))
df_coords = gpd.GeoDataFrame(df_coords, geometry='value')
print(df_coords)
# df_hrate['timestamp'] = pd.to_datetime(df_hrate['timestamp'])
# df_calories['timestamp'] = pd.to_datetime(df_calories['timestamp'])
# df_coords['timestamp'] = pd.to_datetime(df_coords['timestamp'])
Expand All @@ -128,7 +127,6 @@ def get_data(session=None, real_time=False) -> pd.DataFrame:
df_calories.sort_values(by=['timestamp'], inplace=True)
# query coordinates
df_coords = gpd.read_postgis(f"SELECT * FROM {DB_COORDINATES_TABLE} WHERE Date(timestamp) >= Date(%s) AND Date(timestamp) <= Date(%s)", db_conn, params=[start_date, end_date], geom_col='value')
print(df_coords)
df_coords.sort_values(by=['timestamp'], inplace=True)

df_hrate['timestamp'] = pd.to_datetime(df_hrate['timestamp'])
Expand Down Expand Up @@ -319,6 +317,7 @@ def input_page(garmin_df):
# preparing data
user_ids = garmin_df.subj_id.tolist()
rank_options = garmin_df['rank'].unique().tolist()
state_of_residence_options = garmin_df['state'].unique().tolist()
drop_type_options = garmin_df['drop_type'].unique().tolist()
weight_min, weight_max = int(garmin_df.weight.min()), int(garmin_df.weight.max())
height_min, height_max = int(garmin_df.height.min()), int(garmin_df.height.max())
Expand All @@ -341,22 +340,33 @@ def input_page(garmin_df):

selected_rank = []
selected_drop_type = []
selected_state_of_residence = []
selected_state_of_residence_control = []
selected_weight_range = []
selected_height_range = []
selected_age_range = []

if subject_selection_type == 'attribute':
st.subheader("Select Subject(s) Attributes")
col1, col2, col3, col4, col5 = st.columns(spec=[1, 3, 3, 3, 1], gap='large')
col1, col2, col3, col4 = st.columns(spec=[2, 3, 3, 3], gap='large')
# col1, col2, col3, col4, col5 = st.columns(spec=[1, 3, 3, 3, 1], gap='large')
# add radio selector for gender
selected_rank = col1.multiselect(
"Select military rank",
options=rank_options,
key='subject rank',
# index=session.get('selected_rank', 0)
default=session.get('selected_rank', [])
# selected_rank = col1.multiselect(
# "Select military rank",
# options=rank_options,
# key='subject rank',
# # index=session.get('selected_rank', 0)
# default=session.get('selected_rank', [])
# )
# selected_rank = selected_rank if selected_rank else rank_options

selected_state_of_residence = col1.multiselect(
"Select state of residence",
options=state_of_residence_options,
key='subject state of residence',
default=session.get('selected_state_of_residence', [])
)
selected_rank = selected_rank if selected_rank else rank_options
selected_state_of_residence = selected_state_of_residence if selected_state_of_residence else state_of_residence_options

# add sliders for weight, height, age
selected_age_range = col2.slider(
Expand Down Expand Up @@ -384,13 +394,13 @@ def input_page(garmin_df):
step=1,
key='subject height')

selected_drop_type = col5.multiselect(
"Select drop type",
options=drop_type_options,
key='drop type',
default=session.get('selected_drop_type', [])
)
selected_drop_type = selected_drop_type if selected_drop_type else drop_type_options
# selected_drop_type = col5.multiselect(
# "Select drop type",
# options=drop_type_options,
# key='drop type',
# default=session.get('selected_drop_type', [])
# )
# selected_drop_type = selected_drop_type if selected_drop_type else drop_type_options


# Selecting the control group
Expand All @@ -410,23 +420,32 @@ def input_page(garmin_df):
)

selected_rank_control = []
selected_state_of_residence_control = []
selected_drop_type_control = []
selected_weight_range_control = []
selected_height_range_control = []
selected_age_range_control = []

if control_selection_type == 'attribute':
st.subheader("Select Control Group Attributes")
col1, col2, col3, col4, col5 = st.columns(spec=[1, 3, 3, 3, 1], gap='large')
col1, col2, col3, col4 = st.columns(spec=[2, 3, 3, 3], gap='large')
# col1, col2, col3, col4, col5 = st.columns(spec=[1, 3, 3, 3, 1], gap='large')
# add radio selector for gender
selected_rank_control = col1.multiselect(
"Select military rank",
options=rank_options,
key='control military rank',
# index=session.get('selected_rank_control', 0)
default=session.get('selected_rank_control', [])
# selected_rank_control = col1.multiselect(
# "Select military rank",
# options=rank_options,
# key='control military rank',
# # index=session.get('selected_rank_control', 0)
# default=session.get('selected_rank_control', [])
# )
# selected_rank_control = selected_rank_control if selected_rank_control else rank_options
selected_state_of_residence_control = col1.multiselect(
"Select state of residence",
options=state_of_residence_options,
key='control state of residence',
default=session.get('selected_state_of_residence_control', [])
)
selected_rank_control = selected_rank_control if selected_rank_control else rank_options
selected_state_of_residence_control = selected_state_of_residence_control if selected_state_of_residence_control else state_of_residence_options

# add sliders for weight, height, age
selected_age_range_control = col2.slider(
Expand All @@ -453,14 +472,14 @@ def input_page(garmin_df):
step=1,
key='control height')

selected_drop_type_control = col5.multiselect(
"Select drop type",
options=drop_type_options,
key='control drop type',
# index=session.get('selected_rank_control', 0)
default=session.get('selected_drop_type_control', [])
)
selected_drop_type_control = selected_drop_type_control if selected_drop_type_control else drop_type_options
# selected_drop_type_control = col5.multiselect(
# "Select drop type",
# options=drop_type_options,
# key='control drop type',
# # index=session.get('selected_rank_control', 0)
# default=session.get('selected_drop_type_control', [])
# )
# selected_drop_type_control = selected_drop_type_control if selected_drop_type_control else drop_type_options


st.header("Visualization/Analysis Configuration")
Expand Down Expand Up @@ -522,7 +541,7 @@ def input_page(garmin_df):

if real_time_update:
window_size = st.number_input('Window Size (seconds)', value=session.get("window_size", DEFAULT_WINDOW_SIZE), step=15)
TIMEOUT = st.number_input('Fast Forward (Every 1 Minute Equals How Many Seconds?)', value=session.get('timeout', float(TIMEOUT)), step=float(1), format="%.1f", min_value=0.1, max_value=float(100))
TIMEOUT = st.number_input('Fast Forward (Every 1 Hour Equals How Many Seconds?)', value=session.get('timeout', float(TIMEOUT)), step=float(1), format="%.1f", min_value=0.1, max_value=float(100))



Expand All @@ -545,10 +564,12 @@ def input_page(garmin_df):
session["real_time_update"] = real_time_update
session['subject_selection_type'] = 0 if subject_selection_type == 'id' else 1
session['control_selection_type'] = 0 if control_selection_type == 'all' else 1 if control_selection_type == 'id' else 2
session['selected_rank'] = selected_rank
session['selected_rank_control'] = selected_rank_control
session['selected_drop_type'] = selected_drop_type
session['selected_drop_type_control'] = selected_drop_type_control
# session['selected_rank'] = selected_rank
# session['selected_rank_control'] = selected_rank_control
session['selected_state_of_residence'] = selected_state_of_residence
session['selected_state_of_residence_control'] = selected_state_of_residence_control
# session['selected_drop_type'] = selected_drop_type
# session['selected_drop_type_control'] = selected_drop_type_control
session['selected_age_range'] = selected_age_range
session['selected_age_range_control'] = selected_age_range_control
session['selected_weight_range'] = selected_weight_range
Expand All @@ -564,15 +585,17 @@ def input_page(garmin_df):
if subject_selection_type == 'id':
subjects_df = garmin_df.query('subj_id in @selected_users')
else:
subjects_df = garmin_df.query('rank == @selected_rank and drop_type == @selected_drop_type and weight >= @selected_weight_range[0] and weight <= @selected_weight_range[1] and height >= @selected_height_range[0] and height <= @selected_height_range[1] and age >= @selected_age_range[0] and age <= @selected_age_range[1]')
# subjects_df = garmin_df.query('rank == @selected_rank and drop_type == @selected_drop_type and weight >= @selected_weight_range[0] and weight <= @selected_weight_range[1] and height >= @selected_height_range[0] and height <= @selected_height_range[1] and age >= @selected_age_range[0] and age <= @selected_age_range[1]')
subjects_df = garmin_df.query('state in @selected_state_of_residence and weight >= @selected_weight_range[0] and weight <= @selected_weight_range[1] and height >= @selected_height_range[0] and height <= @selected_height_range[1] and age >= @selected_age_range[0] and age <= @selected_age_range[1]')

# Filter the dataframe based on the selected criteria for control group
if control_selection_type == 'all':
control_df = garmin_df
elif control_selection_type == 'id':
control_df = garmin_df.query('user_id in @selected_users_control')
else:
control_df = garmin_df.query('rank == @selected_rank_control and drop_type == @selected_drop_type_control and weight >= @selected_weight_range_control[0] and weight <= @selected_weight_range_control[1] and height >= @selected_height_range_control[0] and height <= @selected_height_range_control[1] and age >= @selected_age_range_control[0] and age <= @selected_age_range_control[1]')
# control_df = garmin_df.query('rank == @selected_rank_control and drop_type == @selected_drop_type_control and weight >= @selected_weight_range_control[0] and weight <= @selected_weight_range_control[1] and height >= @selected_height_range_control[0] and height <= @selected_height_range_control[1] and age >= @selected_age_range_control[0] and age <= @selected_age_range_control[1]')
control_df = garmin_df.query('state in @selected_state_of_residence_control and weight >= @selected_weight_range_control[0] and weight <= @selected_weight_range_control[1] and height >= @selected_height_range_control[0] and height <= @selected_height_range_control[1] and age >= @selected_age_range_control[0] and age <= @selected_age_range_control[1]')

# Store the filtered dataframe in session state
session['subjects_df'] = subjects_df
Expand Down

0 comments on commit ae64e5d

Please sign in to comment.