Skip to content

Commit

Permalink
fixed boundary condition in trim #203
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Aug 26, 2019
1 parent 6bc2d2e commit 99b49d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion jams/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ def trim(self, start_time, end_time, strict=False):
obs_start = obs.time
obs_end = obs_start + obs.duration

if obs_start < trim_end and obs_end > trim_start:
if obs_start < trim_end and obs_end >= trim_start:

new_start = max(obs_start, trim_start)
new_end = min(obs_end, trim_end)
Expand Down
24 changes: 12 additions & 12 deletions tests/test_jams.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,10 +801,10 @@ def test_annotation_trim_partial_overlap_beginning():
# range: at the beginning
# strict=False
namespace = 'tag_open'
data = dict(time=[5.0, 5.0, 10.0],
duration=[2.0, 4.0, 4.0],
value=['one', 'two', 'three'],
confidence=[0.9, 0.9, 0.9])
data = dict(time=[5.0, 5.0, 5.0, 10.0],
duration=[0.0, 2.0, 4.0, 4.0],
value=['zero', 'one', 'two', 'three'],
confidence=[0.1, 0.9, 0.9, 0.9])
ann = jams.Annotation(namespace, data=data, time=5.0, duration=10.0)

ann_trim = ann.trim(0, 8, strict=False)
Expand All @@ -816,10 +816,10 @@ def test_annotation_trim_partial_overlap_beginning():
assert ann_trim.namespace == ann.namespace
assert ann_trim.annotation_metadata == ann.annotation_metadata

expected_data = dict(time=[5.0, 5.0],
duration=[2.0, 3.0],
value=['one', 'two'],
confidence=[0.9, 0.9])
expected_data = dict(time=[5.0, 5.0, 5.0],
duration=[0.0, 2.0, 3.0],
value=['zero', 'one', 'two'],
confidence=[0.1, 0.9, 0.9])
expected_ann = jams.Annotation(namespace, data=expected_data, time=5.0,
duration=3.0)

Expand All @@ -835,10 +835,10 @@ def test_annotation_trim_partial_overlap_beginning():
assert ann_trim.namespace == ann.namespace
assert ann_trim.annotation_metadata == ann.annotation_metadata

expected_data = dict(time=[5.0],
duration=[2.0],
value=['one'],
confidence=[0.9])
expected_data = dict(time=[5.0, 5.0],
duration=[0.0, 2.0],
value=['zero', 'one'],
confidence=[0.1, 0.9])
expected_ann = jams.Annotation(namespace, data=expected_data, time=5.0,
duration=3.0)

Expand Down

0 comments on commit 99b49d3

Please sign in to comment.