• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 15430655463

04 Jun 2025 12:26AM UTC coverage: 40.974% (+17.1%) from 23.832%
15430655463

push

github

paulmthompson
fix self copy with mask data

5 of 5 new or added lines in 2 files covered. (100.0%)

945 existing lines in 24 files now uncovered.

3003 of 7329 relevant lines covered (40.97%)

731.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.07
/src/WhiskerToolbox/DataManager/DigitalTimeSeries/Digital_Interval_Series.cpp
1
#include "Digital_Interval_Series.hpp"
2

3
#include <algorithm>
4
#include <utility>
5
#include <vector>
6

7
DigitalIntervalSeries::DigitalIntervalSeries(std::vector<Interval> digital_vector) {
3✔
8
    _data = std::move(digital_vector);
3✔
9
    _sortData();
3✔
10
}
3✔
11

12
void DigitalIntervalSeries::setData(std::vector<Interval> digital_vector) {
×
13
    _data = std::move(digital_vector);
×
14
    _sortData();
×
UNCOV
15
    notifyObservers();
×
16
}
×
17

18
void DigitalIntervalSeries::setData(std::vector<std::pair<float, float>> const & digital_vector) {
×
19
    std::vector<Interval> intervals;
×
20
    intervals.reserve(digital_vector.size());
×
UNCOV
21
    for (auto & interval: digital_vector) {
×
22
        intervals.emplace_back(Interval{static_cast<int64_t>(interval.first), static_cast<int64_t>(interval.second)});
×
23
    }
24
    setData(intervals);
×
25
}
×
26

27
std::vector<Interval> const & DigitalIntervalSeries::getDigitalIntervalSeries() const {
1✔
28
    return _data;
1✔
29
}
30

UNCOV
31
bool DigitalIntervalSeries::isEventAtTime(int const time) const {
×
32

UNCOV
33
    auto Contained = [time](auto const & event) {
×
UNCOV
34
        return is_contained(event, time);
×
35
    };
×
36

37
    if (std::ranges::any_of(_data, Contained)) return true;
×
38

39
    return false;
×
40
}
41

42
void DigitalIntervalSeries::addEvent(Interval new_interval) {
20✔
43
    _addEvent(new_interval);
20✔
44

45
    notifyObservers();
20✔
46
}
20✔
47

48
void DigitalIntervalSeries::_addEvent(Interval new_interval) {
20✔
49
    bool merged = false;
20✔
50

51
    for (auto it = _data.begin(); it != _data.end();) {
33✔
52
        if (is_overlapping(*it, new_interval) || is_contiguous(*it, new_interval)) {
13✔
53
            new_interval.start = std::min(new_interval.start, it->start);
1✔
54
            new_interval.end = std::max(new_interval.end, it->end);
1✔
55
            it = _data.erase(it);
1✔
56
            merged = true;
1✔
57
        } else if (is_contained(new_interval, *it)) {
12✔
UNCOV
58
            return;
×
59
        } else {
60
            ++it;
12✔
61
        }
62
    }
63

64
    _data.push_back(new_interval);
20✔
65

66
    _sortData();
20✔
67
}
68

UNCOV
69
void DigitalIntervalSeries::setEventAtTime(int time, bool const event) {
×
UNCOV
70
    _setEventAtTime(time, event);
×
UNCOV
71
    notifyObservers();
×
UNCOV
72
}
×
73

74
void DigitalIntervalSeries::_setEventAtTime(int time, bool const event) {
×
75
    if (!event) {
×
76
        _removeEventAtTime(time);
×
77
    } else {
78
        _addEvent(Interval{static_cast<int64_t>(time), static_cast<int64_t>(time)});
×
79
    }
80
}
×
81

82
void DigitalIntervalSeries::removeEventAtTime(int const time) {
×
UNCOV
83
    _removeEventAtTime(time);
×
84
    notifyObservers();
×
UNCOV
85
}
×
86

87
void DigitalIntervalSeries::_removeEventAtTime(int const time) {
×
88
    for (auto it = _data.begin(); it != _data.end(); ++it) {
×
89
        if (is_contained(*it, time)) {
×
UNCOV
90
            if (time == it->start && time == it->end) {
×
91
                _data.erase(it);
×
92
            } else if (time == it->start) {
×
93
                it->start = time + 1;
×
94
            } else if (time == it->end) {
×
95
                it->end = time - 1;
×
96
            } else {
97
                auto preceding_event = Interval{it->start, time - 1};
×
98
                auto following_event = Interval{time + 1, it->end};
×
99
                _data.erase(it);
×
UNCOV
100
                _data.push_back(preceding_event);
×
101
                _data.push_back(following_event);
×
102

103
                _sortData();
×
104
            }
105
            return;
×
106
        }
107
    }
108
}
109

110
void DigitalIntervalSeries::_sortData() {
23✔
111
    std::sort(_data.begin(), _data.end());
23✔
112
}
23✔
113

UNCOV
114
int find_closest_preceding_event(DigitalIntervalSeries * digital_series, int time) {
×
UNCOV
115
    auto const & events = digital_series->getDigitalIntervalSeries();
×
116

117
    // Check if sorted
118
    for (int i = 1; i < events.size(); ++i) {
×
119
        if (events[i].start < events[i - 1].start) {
×
UNCOV
120
            throw std::runtime_error("DigitalIntervalSeries is not sorted");
×
121
        }
122
    }
123
    int closest_index = -1;
×
124
    for (int i = 0; i < events.size(); ++i) {
×
UNCOV
125
        if (events[i].start <= time) {
×
UNCOV
126
            closest_index = i;
×
127
            if (time <= events[i].end) {
×
128
                return i;
×
129
            }
130
        } else {
131
            break;
×
132
        }
133
    }
UNCOV
134
    return closest_index;
×
135
}
136

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc