Skip to content

Commit

Permalink
Merge pull request #966 from jiji14/survey-dashboard
Browse files Browse the repository at this point in the history
Dashboard Survey Metrics
  • Loading branch information
shankari authored May 29, 2024
2 parents 3150c99 + 5c20021 commit e7d028a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
10 changes: 7 additions & 3 deletions emission/net/api/cfc_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,18 @@ def summarize_metrics(time_type):
else:
old_style = True
is_return_aggregate = True

app_config = request.json['app_config'] if 'app_config' in request.json else None

time_type_map = {
'timestamp': metrics.summarize_by_timestamp,
'local_date': metrics.summarize_by_local_date
'timestamp': metrics.summarize_by_timestamp, # used by old UI
'local_date': metrics.summarize_by_local_date,
'yyyy_mm_dd': metrics.summarize_by_yyyy_mm_dd # used by new UI
}
metric_fn = time_type_map[time_type]
ret_val = metric_fn(user_uuid,
start_time, end_time,
freq_name, metric_list, is_return_aggregate)
freq_name, metric_list, is_return_aggregate, app_config)
if old_style:
logging.debug("old_style metrics found, returning array of entries instead of array of arrays")
assert(len(metric_list) == 1)
Expand Down
19 changes: 17 additions & 2 deletions emission/net/api/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,31 @@

import emission.analysis.result.metrics.time_grouping as earmt
import emission.analysis.result.metrics.simple_metrics as earms
import emission.storage.decorations.analysis_timeseries_queries as esda
import emission.storage.decorations.local_date_queries as esdl
import emission.storage.timeseries.tcquery as esttc

def summarize_by_timestamp(user_id, start_ts, end_ts, freq, metric_list, include_aggregate):
import emcommon.metrics.metrics_summaries as emcms

def summarize_by_timestamp(user_id, start_ts, end_ts, freq, metric_list, include_aggregate, app_config=None):
return _call_group_fn(earmt.group_by_timestamp, user_id, start_ts, end_ts,
freq, metric_list, include_aggregate)

def summarize_by_local_date(user_id, start_ld, end_ld, freq_name, metric_list, include_aggregate):
def summarize_by_local_date(user_id, start_ld, end_ld, freq_name, metric_list, include_aggregate, app_config=None):
local_freq = earmt.LocalFreq[freq_name]
return _call_group_fn(earmt.group_by_local_date, user_id, start_ld, end_ld,
local_freq, metric_list, include_aggregate)

def summarize_by_yyyy_mm_dd(user_id, start_ymd, end_ymd, freq, metric_list, include_agg, app_config):
time_query = esttc.TimeComponentQuery(
"data.start_local_dt",
esdl.yyyy_mm_dd_to_local_date(start_ymd),
esdl.yyyy_mm_dd_to_local_date(end_ymd)
)
trips = esda.get_entries(esda.COMPOSITE_TRIP_KEY, None, time_query)
print('found ' + str([e for e in trips]))
return emcms.generate_summaries(metric_list, trips, app_config)

def _call_group_fn(group_fn, user_id, start_time, end_time, freq, metric_list, include_aggregate):
summary_fn_list = [earms.get_summary_fn(metric_name)
for metric_name in metric_list]
Expand Down
12 changes: 12 additions & 0 deletions emission/storage/decorations/local_date_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ def get_comparison_query(field_prefix, base_ld, limit_ld, units, gt_or_lt):
return { "$or": or_conditions }
else:
return {}

def yyyy_mm_dd_to_local_date(ymd: str) -> ecwl.LocalDate:
return ecwl.LocalDate({
'year': int(ymd[0:4]),
'month': int(ymd[5:7]),
'day': int(ymd[8:10])
})

def get_yyyy_mm_dd_range_query(field_name, start_ymd: str, end_ymd: str) -> dict:
start_local_date = yyyy_mm_dd_to_local_date(start_ymd)
end_local_date = yyyy_mm_dd_to_local_date(end_ymd)
return get_range_query(field_name, start_local_date, end_local_date)
2 changes: 1 addition & 1 deletion setup/environment36.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies:
- scipy=1.10.0
- utm=0.7.0
- pip:
- git+https://github.com/JGreenlee/e-mission-common@0.4.3
- git+https://github.com/JGreenlee/e-mission-common@0.5.1
- pyfcm==1.5.4
- pygeocoder==1.2.5
- pymongo==4.3.3
Expand Down

0 comments on commit e7d028a

Please sign in to comment.