Skip to content

Commit

Permalink
Get the metrics tests to pass with inferred data as well
Browse files Browse the repository at this point in the history
- First, add the inference to the intake pipeline in the tests common file
- Next, copy testing tests on cleaned data to a separate test file
- Finally, create a new test for metrics on inferred modes and update the
  expected values for the inferred modes by looking at the current results
  • Loading branch information
shankari committed Feb 24, 2018
1 parent 2666a68 commit fbb096e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
6 changes: 5 additions & 1 deletion emission/analysis/result/metrics/time_grouping.py
Expand Up @@ -20,6 +20,7 @@
import emission.storage.timeseries.aggregate_timeseries as estag
import emission.core.wrapper.motionactivity as ecwm
import emission.core.wrapper.modestattimesummary as ecwms
import emission.core.wrapper.modeprediction as ecwmp
import emission.core.wrapper.localdate as ecwl

import emission.analysis.config as eac
Expand Down Expand Up @@ -117,7 +118,10 @@ def grouped_to_summary(time_grouped_df, key_to_fill_fn, summary_fn):
mode_grouped_df = section_group_df.groupby('sensed_mode')
mode_results = summary_fn(mode_grouped_df)
for mode, result in mode_results.items():
curr_msts[ecwm.MotionTypes(mode).name] = result
if eac.get_section_key_for_analysis_results() == "analysis/inferred_section":
curr_msts[ecwmp.PredictedModeTypes(mode).name] = result
else:
curr_msts[ecwm.MotionTypes(mode).name] = result
ret_list.append(curr_msts)
return ret_list

Expand Down
4 changes: 4 additions & 0 deletions emission/core/wrapper/modestattimesummary.py
Expand Up @@ -8,6 +8,7 @@
import logging
import emission.core.wrapper.wrapperbase as ecwb
import emission.core.wrapper.motionactivity as ecwm
import emission.core.wrapper.modeprediction as ecwmp

# Used for various metrics such as count, distance, mean speed calorie consumption,
# median speed calorie consumption
Expand All @@ -22,7 +23,10 @@ class ModeStatTimeSummary(ecwb.WrapperBase):
# Each distance will have
#
#
# Make this only predicted mode, or remove completely depending on what we
# do for mode stuff
props = dict([(t.name, ecwb.WrapperBase.Access.WORM) for t in ecwm.MotionTypes])
props.update(dict([(t.name, ecwb.WrapperBase.Access.WORM) for t in ecwmp.PredictedModeTypes]))
props.update(
{'ts': ecwb.WrapperBase.Access.WORM, # YYYY-MM-DD
'local_dt': ecwb.WrapperBase.Access.WORM,
Expand Down
2 changes: 2 additions & 0 deletions emission/tests/common.py
Expand Up @@ -128,12 +128,14 @@ def runIntakePipeline(uuid):
import emission.analysis.intake.segmentation.section_segmentation as eaiss
import emission.analysis.intake.cleaning.location_smoothing as eaicl
import emission.analysis.intake.cleaning.clean_and_resample as eaicr
import emission.analysis.classification.inference.mode.pipeline as eacimp

eaicf.filter_accuracy(uuid)
eaist.segment_current_trips(uuid)
eaiss.segment_current_sections(uuid)
eaicl.filter_current_sections(uuid)
eaicr.clean_and_resample(uuid)
eacimp.predict_mode(uuid)

def configLogging():
"""
Expand Down
Expand Up @@ -8,6 +8,7 @@
import unittest
import logging
import arrow
import os

import emission.core.get_database as edb
import emission.core.wrapper.localdate as ecwl
Expand All @@ -23,6 +24,8 @@

class TestMetrics(unittest.TestCase):
def setUp(self):
self.analysis_conf_path = \
etc.set_analysis_config("analysis.result.section.key", "analysis/cleaned_section")
etc.setupRealExample(self,
"emission/tests/data/real_examples/shankari_2015-aug-21")
self.testUUID1 = self.testUUID
Expand All @@ -39,14 +42,15 @@ def setUp(self):

def tearDown(self):
self.clearRelatedDb()
os.remove(self.analysis_conf_path)

def clearRelatedDb(self):
edb.get_timeseries_db().remove({"user_id": self.testUUID})
edb.get_analysis_timeseries_db().remove({"user_id": self.testUUID})
edb.get_pipeline_state_db().remove({"user_id": self.testUUID})
edb.get_timeseries_db().remove({"user_id": self.testUUID1})
edb.get_analysis_timeseries_db().remove({"user_id": self.testUUID1})
edb.get_pipeline_state_db().remove({"user_id": self.testUUID1})
edb.get_timeseries_db().delete_many({"user_id": self.testUUID})
edb.get_analysis_timeseries_db().delete_many({"user_id": self.testUUID})
edb.get_pipeline_state_db().delete_many({"user_id": self.testUUID})
edb.get_timeseries_db().delete_many({"user_id": self.testUUID1})
edb.get_analysis_timeseries_db().delete_many({"user_id": self.testUUID1})
edb.get_pipeline_state_db().delete_many({"user_id": self.testUUID1})

def testCountTimestampMetrics(self):
met_result = metrics.summarize_by_timestamp(self.testUUID,
Expand Down

0 comments on commit fbb096e

Please sign in to comment.