Skip to content
Permalink
Browse files

Get the metrics tests to pass with inferred data as well

- 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 fbb096e0a0dd3d682242cc313b17e64e31107c49
@@ -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
@@ -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

@@ -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
@@ -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,
@@ -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():
"""
@@ -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
@@ -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
@@ -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,

0 comments on commit fbb096e

Please sign in to comment.
You can’t perform that action at this time.