Esempio n. 1
0
    def test_smooth_alternative_window_size(self):
        """Should smooth stream with given window size"""
        test_df = pd.DataFrame({"x": [1, 2, 3]})

        transform_result = streams.smooth(test_df, window_size=1)

        self.assertEqual(list(transform_result.x_smooth.values), [1, 2, 3])
Esempio n. 2
0
    def test_smooth_alternative_column_name(self):
        """Should smooth stream of given column name"""
        test_df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})

        transform_result = streams.smooth(test_df, smooth_colname="y")

        self.assertEqual(list(transform_result.columns.values), ["x", "y", "y_smooth"])
Esempio n. 3
0
    def test_smooth(self):
        """Should smooth stream using centered moving average, for default window size and column name"""
        test_df = pd.DataFrame({"x": [1, 2, 3, 4]})

        transform_result = streams.smooth(test_df)

        self.assertEqual(list(transform_result.columns.values), ["x", "x_smooth"])
        self.assertTrue(np.isnan(transform_result.x_smooth[0]))
        self.assertEqual(transform_result.x_smooth[1], 2.0)
        self.assertEqual(transform_result.x_smooth[2], 3.0)
        self.assertTrue(np.isnan(transform_result.x_smooth[3]))
Esempio n. 4
0
    def __total_deviation(self, activity_id):
        stream_df = load_stream(self.database_driver, activity_id, 'latlng')

        if stream_df is not None:
            stream_df = lat_long_to_x_y(stream_df)
            stream_df = smooth(stream_df, smooth_colname='x')
            stream_df = smooth(stream_df, smooth_colname='y')
            stream_df = derivative(stream_df, derivative_colname='x_smooth')
            stream_df = derivative(stream_df, derivative_colname='y_smooth')
            stream_df = rolling_similarity(stream_df, cosine_similarity, 'dx_smooth_dt', 'dy_smooth_dt')

            try:
                return np.nansum([cosine_to_deviation(cos)
                                  for cos in stream_df.cosine_similarity_dx_smooth_dt_dy_smooth_dt])
            except ValueError:
                logging.warning('Failed to compute route deviation for activity %d, returning NaN' % activity_id)
                return np.nan
        else:
            logging.warning('No gps stream available for activity %d, returning NaN' % activity_id)
            return np.nan