def test_split_into_intervals_starts_new_interval_if_time_decreases(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 160000000, 6.05, 9.72, -1.95), (1, 'Jogging', 10, 4.48, 14.18, -2.11), (1, 'Jogging', 51000000, 3.95, 12.26, -2.68), (1, 'Jogging', 110000000, 6.05, 9.72, -1.95), (1, 'Jogging', 161000000, 6.05, 9.72, -1.95), (1, 'Jogging', 199000000, 5.24, 7.21, -5.56), ) expected = ( ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 160000000, 6.05, 9.72, -1.95), ), ( (1, 'Jogging', 10, 4.48, 14.18, -2.11), (1, 'Jogging', 51000000, 3.95, 12.26, -2.68), (1, 'Jogging', 110000000, 6.05, 9.72, -1.95), (1, 'Jogging', 161000000, 6.05, 9.72, -1.95), (1, 'Jogging', 199000000, 5.24, 7.21, -5.56), ), ) # Interval length of 0.2 seconds or 200,000,000 nanoseconds result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected
def test_split_into_intervals_returns_two_expected_intervals_ignoring_trailing_data(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), (1, 'Jogging', 250000000, 7.27, 5.79, -6.51), (1, 'Jogging', 310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 399000000, 7.06, 11.35, 0.89), (1, 'Jogging', 1050000000, 6.66, 10.0, 11.73), (1, 'Jogging', 1100000000, 1.76, 9.85, 1.99) ) expected = ( ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), ), ( (1, 'Jogging', 250000000, 7.27, 5.79, -6.51), (1, 'Jogging', 310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 399000000, 7.06, 11.35, 0.89), ) ) # Interval length of 0.2 seconds or 200,000,000 nanoseconds result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected
def test_split_into_intervals_drops_interval_if_gap_too_great_due_to_all_zero_rows(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 140000000, 5.24, 7.21, -5.56), (1, 'Jogging', 200000000, 7.27, 5.79, -6.51), (1, 'Jogging', 1310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 0, 0, 0, 0.0), (1, 'Jogging', 0, 0, 0, 0.0), (1, 'Jogging', 0, 0, 0, 0.0), (1, 'Jogging', 1500000000, 1.76, 9.85, 1.99), (1, 'Jogging', 1549000000, -0.0, -3.214402, 1.334794), (1, 'Jogging', 1599999999, -2.7513103, 9.615966, 12.4489975), ) expected = ( ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 140000000, 5.24, 7.21, -5.56), (1, 'Jogging', 200000000, 7.27, 5.79, -6.51), ), ) # Interval length of 0.2 seconds or 200,000,000 nanoseconds result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected
def test_split_into_intervals_drops_last_interval_because_gap_to_end_is_too_large(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), (1, 'Jogging', 250000000, 7.27, 5.79, -6.51), (1, 'Jogging', 260000000, 1.61, 12.07, -2.18), (1, 'Jogging', 270000000, 1.5, 17.69, -3.6), (1, 'Jogging', 299000000, 7.06, 11.35, 0.89), ) expected = ( ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), ), ) # Interval length of 0.2 seconds or 200,000,000 nanoseconds result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected
def test_split_into_intervals_does_not_produce_an_interval_of_length_one_in_this_case(): given = ( (11, 'Walking', 2097702312000, 12.45, 7.86, -6.510526), (11, 'Walking', 2097752299000, 6.44, 10.76, 1.6889231), (11, 'Walking', 2097802287000, 7.67, 11.18, -1.607201), (11, 'Walking', 2097852336000, 3.53, 9.34, -0.46309182), (11, 'Walking', 2097912242000, 4.02, 9.23, -0.7627395), (11, 'Walking', 2181765514000, -5.67, 2.68, -1.0351465), (11, 'Walking', 2181824443000, -4.79, 4.25, 0.313268), (11, 'Walking', 2181882335000, -5.52, 6.44, -0.14982383), (11, 'Walking', 2181932323000, -8.27, 6.63, -0.7218784), ) expected = ( ( (11, 'Walking', 2097702312000, 12.45, 7.86, -6.510526), (11, 'Walking', 2097752299000, 6.44, 10.76, 1.6889231), (11, 'Walking', 2097802287000, 7.67, 11.18, -1.607201), (11, 'Walking', 2097852336000, 3.53, 9.34, -0.46309182), ), ( (11, 'Walking', 2181765514000, -5.67, 2.68, -1.0351465), (11, 'Walking', 2181824443000, -4.79, 4.25, 0.313268), (11, 'Walking', 2181882335000, -5.52, 6.44, -0.14982383), (11, 'Walking', 2181932323000, -8.27, 6.63, -0.7218784), ), ) result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=180000000, maximum_gap_in_nanoseconds=60000000 ) assert result == expected
def test_split_into_intervals_handles_this_pathological_case_in_the_data(): given = ( (15, "Jogging", 728142284000, 13.14, -10.34, -2.9147544), (15, "Jogging", 728192638000, 12.11, -7.93, 3.5276701), (15, "Jogging", 728192638000, 12.11, -7.93, 3.5276701), (15, "Jogging", 728192638000, 12.11, -7.93, 3.5276701), (15, "Jogging", 0, 0, 0, 0.0), (15, "Jogging", 0, 0, 0, 0.14982383), (15, "Jogging", 728362224000, -0.11, 14.02, 0.14982383), (15, "Jogging", 728362224000, -0.11, 14.02, 0.14982383), (15, "Jogging", 728362224000, -0.11, 14.02, 0.14982383), (15, "Jogging", 728582835000, 0.11, 6.59, -3.9499009), (15, "Jogging", 728582835000, 0.11, 6.59, -3.9499009), (15, "Jogging", 728632548000, 4.4, 17.08, 5.134871), (15, "Jogging", 728682262000, 19.57, 19.57, -8.19945), ) expected = ( ( (15, "Jogging", 728142284000, 13.14, -10.34, -2.9147544), (15, "Jogging", 728192638000, 12.11, -7.93, 3.5276701), (15, "Jogging", 728362224000, -0.11, 14.02, 0.14982383), (15, "Jogging", 728582835000, 0.11, 6.59, -3.9499009), (15, "Jogging", 728632548000, 4.4, 17.08, 5.134871), (15, "Jogging", 728682262000, 19.57, 19.57, -8.19945), ), ) result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=(6 * 10 ** 8), # 0.6 seconds maximum_gap_in_nanoseconds=300000000, # 0.3 seconds ) assert result == expected
def test_split_into_intervals_returns_empty_tuple_given_empty_tuple(): given = () expected = () result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected
def test_split_into_intervals_raises_if_activity_changes(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), (1, 'Jogging', 250000000, 7.27, 5.79, -6.51), (1, 'Jogging', 310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 400000000, 7.06, 11.35, 0.89), (1, 'Jogging', 4500000000, 6.66, 10.0, 11.73), (1, 'Jogging', 5000000000, 1.76, 9.85, 1.99), (1, 'Jogging', 5490000000, -0.0, -3.214402, 1.334794), (1, 'Walking', 5999999999, -2.7513103, 9.615966, 12.4489975), ) with pytest.raises(ValueError): parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 )
def test_split_into_intervals_handles_repeated_time_at_start_of_series(): given = ( (7, 'Downstairs', 208772451722000, 5.94, 7.16, -0.99), (7, 'Downstairs', 208772451722000, 5.94, 7.16, -0.99), (7, 'Downstairs', 208772561708000, 2.41, 2.15, -3.06), (7, 'Downstairs', 208772601625000, 1.08, 5.67, -1.23), (7, 'Downstairs', 208772641633000, 3.95, 18.31, 0.91), ) expected = ( ( (7, 'Downstairs', 208772451722000, 5.94, 7.16, -0.99), (7, 'Downstairs', 208772561708000, 2.41, 2.15, -3.06), (7, 'Downstairs', 208772601625000, 1.08, 5.67, -1.23), (7, 'Downstairs', 208772641633000, 3.95, 18.31, 0.91), ), ) result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=190000000 ) assert result == expected
def test_split_into_intervals_works_for_intervals_of_lengths_5(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 140000000, 5.24, 7.21, -5.56), (1, 'Jogging', 200000000, 7.27, 5.79, -6.51), (1, 'Jogging', 1310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 1351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 1399000000, 7.06, 11.35, 0.89), (1, 'Jogging', 1450000000, 6.66, 10.0, 11.73), (1, 'Jogging', 1500000000, 1.76, 9.85, 1.99), (1, 'Jogging', 1549000000, -0.0, -3.214402, 1.334794), (1, 'Jogging', 1599999999, -2.7513103, 9.615966, 12.4489975), ) expected = ( ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 140000000, 5.24, 7.21, -5.56), (1, 'Jogging', 200000000, 7.27, 5.79, -6.51), ), ( (1, 'Jogging', 1310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 1351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 1399000000, 7.06, 11.35, 0.89), (1, 'Jogging', 1450000000, 6.66, 10.0, 11.73), (1, 'Jogging', 1500000000, 1.76, 9.85, 1.99), ), ) # Interval length of 0.2 seconds or 200,000,000 nanoseconds result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected
def test_split_into_intervals_returns_two_expected_intervals_ignoring_repeating_timepoints(): given = ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), (1, 'Jogging', 250000000, 7.27, 5.79, -6.51), (1, 'Jogging', 310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), # Identical repeating rows in data at time 728192638000 (1, 'Jogging', 351000000, 1.5, 0, 0), # Non-identical repeating rows found in data at time 8948102277000. (1, 'Jogging', 399000000, 7.06, 11.35, 0.89), (1, 'Jogging', 399000000, 7.06, 11.35, 0.89), ) expected = ( ( (1, 'Jogging', 0, 4.48, 14.18, -2.11), (1, 'Jogging', 50000000, 3.95, 12.26, -2.68), (1, 'Jogging', 100000000, 6.05, 9.72, -1.95), (1, 'Jogging', 200000000, 5.24, 7.21, -5.56), ), ( (1, 'Jogging', 250000000, 7.27, 5.79, -6.51), (1, 'Jogging', 310000000, 1.61, 12.07, -2.18), (1, 'Jogging', 351000000, 1.5, 17.69, -3.6), (1, 'Jogging', 399000000, 7.06, 11.35, 0.89), ) ) # Interval length of 0.2 seconds or 200,000,000 nanoseconds result = parse.split_into_intervals( data=given, interval_duration_in_nanoseconds=200000000, maximum_gap_in_nanoseconds=100000000 ) assert result == expected