Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the issues with columns in trajectory table. #71

Merged
merged 2 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pages/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
The workaround is to check if the input value is None.
"""
from dash import dcc, html, Input, Output, callback, register_page, dash_table

from datetime import date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am merging this for now, but we should revisit the time handling in general since datetime does not handle timezones very well. We should use arrow like the rest of the e-mission codebase, and also consider date formatting etc.

Can you please file a follow-up issue for this?

# Etc
import logging
import pandas as pd
Expand Down Expand Up @@ -38,9 +38,9 @@ def clean_location_data(df):
df['data.end_loc.coordinates'] = df['data.end_loc.coordinates'].apply(lambda x: f'({x[0]}, {x[1]})')
return df

def update_store_trajectories():
def update_store_trajectories(start_date_obj,end_date_obj):
global store_trajectories
df = query_trajectories()
df = query_trajectories(start_date_obj,end_date_obj)
records = df.to_dict("records")
store = {
"data": records,
Expand All @@ -57,8 +57,11 @@ def update_store_trajectories():
Input('store-trips', 'data'),
Input('store-demographics', 'data'),
Input('store-trajectories', 'data'),
Input('date-picker', 'start_date'),
Input('date-picker', 'end_date'),

)
def render_content(tab, store_uuids, store_trips, store_demographics, store_trajectories):
def render_content(tab, store_uuids, store_trips, store_demographics, store_trajectories, start_date, end_date):
data, columns, has_perm = None, [], False
if tab == 'tab-uuids-datatable':
data = store_uuids["data"]
Expand All @@ -79,11 +82,14 @@ def render_content(tab, store_uuids, store_trips, store_demographics, store_traj
elif tab == 'tab-trajectories-datatable':
# Currently store_trajectories data is loaded only when the respective tab is selected
#Here we query for trajectory data once "Trajectories" tab is selected
start_date_obj = date.fromisoformat(start_date) if start_date else None
end_date_obj = date.fromisoformat(end_date) if end_date else None
if store_trajectories == {}:
store_trajectories = update_store_trajectories()
store_trajectories = update_store_trajectories(start_date_obj,end_date_obj)
data = store_trajectories["data"]
columns = list(data[0].keys())
has_perm = perm_utils.has_permission('data_trajectories')
if data:
columns = list(data[0].keys())
has_perm = perm_utils.has_permission('data_trajectories')

df = pd.DataFrame(data)
if df.empty or not has_perm:
Expand Down
9 changes: 8 additions & 1 deletion utils/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,18 @@ def query_demographics():
return df


def query_trajectories():
def query_trajectories(start_date, end_date):
start_ts, end_ts = None, datetime.max.timestamp()
if start_date is not None:
start_ts = datetime.combine(start_date, datetime.min.time()).timestamp()

if end_date is not None:
end_ts = datetime.combine(end_date, datetime.max.time()).timestamp()
ts = esta.TimeSeries.get_aggregate_time_series()

entries = ts.find_entries(
key_list=["analysis/recreated_location"],
time_query=estt.TimeQuery("data.ts", start_ts, end_ts),
)
df = pd.json_normalize(list(entries))
if not df.empty:
Expand Down