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

paulmthompson / WhiskerToolbox / 17920603410

22 Sep 2025 03:39PM UTC coverage: 71.97% (-0.05%) from 72.02%
17920603410

push

github

paulmthompson
all tests pass

277 of 288 new or added lines in 8 files covered. (96.18%)

520 existing lines in 35 files now uncovered.

40275 of 55961 relevant lines covered (71.97%)

1225.8 hits per line

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

94.29
/src/DataManager/utils/TableView/computers/IntervalPropertyComputer.h
1
#ifndef INTERVAL_PROPERTY_COMPUTER_H
2
#define INTERVAL_PROPERTY_COMPUTER_H
3

4
#include "utils/TableView/interfaces/IColumnComputer.h"
5
#include "utils/TableView/interfaces/IIntervalSource.h"
6
#include "utils/TableView/core/ExecutionPlan.h"
7
#include "utils/TableView/columns/IColumn.h"
8
#include "Entity/EntityTypes.hpp"
9

10
#include <cstdint>
11
#include <memory>
12
#include <string>
13
#include <vector>
14

15
/**
16
 * @brief Enumeration of operations that can be performed on interval properties.
17
 */
18
enum class IntervalProperty : std::uint8_t {
19
    Start,     ///< Returns the start time/index of the interval
20
    End,       ///< Returns the end time/index of the interval
21
    Duration   ///< Returns the duration (end - start) of the interval
22
};
23

24
/**
25
 * @brief Templated computer for extracting properties from time intervals.
26
 * 
27
 * Source type: IIntervalSource
28
 * Selector type: Interval
29
 * Output type: T
30
 * 
31
 * This computer works with IIntervalSource data and can extract different properties
32
 * from intervals that are used as row selectors. The template parameter T
33
 * determines the return type based on the property being extracted:
34
 * - IntervalProperty::Start requires T = int64_t or float
35
 * - IntervalProperty::End requires T = int64_t or float
36
 * - IntervalProperty::Duration requires T = int64_t or float
37
 */
38
template<typename T>
39
class IntervalPropertyComputer : public IColumnComputer<T> {
40
public:
41
    /**
42
     * @brief Constructor for IntervalPropertyComputer.
43
     * @param source Shared pointer to the interval source.
44
     * @param property The property to extract from intervals.
45
     * @param sourceName The name of the data source (for dependency tracking).
46
     */
47
    IntervalPropertyComputer(std::shared_ptr<IIntervalSource> source, 
37✔
48
                            IntervalProperty property,
49
                            std::string sourceName)
50
        : m_source(std::move(source)), m_property(property), m_sourceName(std::move(sourceName)) {}
37✔
51

52
    /**
53
     * @brief Computes the result for all intervals in the execution plan.
54
     * @param plan The execution plan containing interval boundaries.
55
     * @return Vector of computed results for each interval.
56
     */
57
    [[nodiscard]] std::pair<std::vector<T>, ColumnEntityIds> compute(const ExecutionPlan& plan) const override {
36✔
58
        if (!plan.hasIntervals()) {
36✔
59
            throw std::runtime_error("IntervalPropertyComputer requires an ExecutionPlan with intervals");
1✔
60
        }
61
        
62
        auto intervals = plan.getIntervals();
35✔
63
        auto destinationTimeFrame = plan.getTimeFrame();
35✔
64
        
65
        // Validate that row intervals are a subset of source intervals
66
        _validateRowIntervalsAreSubset(intervals, destinationTimeFrame.get());
35✔
67
        
68
        std::vector<T> results;
34✔
69
        results.reserve(intervals.size());
34✔
70
        std::vector<EntityId> entity_ids;
34✔
71
        entity_ids.reserve(intervals.size());
34✔
72
        
73
        for (const auto& interval : intervals) {
236✔
74

75
            auto intervals_with_ids = m_source->getIntervalsWithIdsInRange(interval.start, 
202✔
76
                interval.end, destinationTimeFrame.get());
101✔
77

78
            auto this_interval = intervals_with_ids.back();
101✔
79
            entity_ids.push_back(this_interval.entity_id);
101✔
80

81
            switch (m_property) {
101✔
82
                case IntervalProperty::Start:
37✔
83
                    results.push_back(static_cast<T>(this_interval.interval.start));
37✔
84
                    break;
37✔
85
                case IntervalProperty::End:
22✔
86
                    results.push_back(static_cast<T>(this_interval.interval.end));
22✔
87
                    break;
22✔
88
                case IntervalProperty::Duration:
42✔
89
                    results.push_back(static_cast<T>(this_interval.interval.end - this_interval.interval.start));
42✔
90
                    break;
42✔
UNCOV
91
                default:
×
UNCOV
92
                    throw std::runtime_error("Unknown IntervalProperty");
×
93
            }
94
        }
95
        
96
        return {results, entity_ids};
68✔
97
    }
36✔
98

99
    [[nodiscard]] auto getSourceDependency() const -> std::string override {
64✔
100
        return m_sourceName;
64✔
101
    }
102

103
    /**
104
     * @brief Gets the EntityID structure type for this computer.
105
     * @return EntityIdStructure::Simple since each interval maps to one value.
106
     */
107
    [[nodiscard]] EntityIdStructure getEntityIdStructure() const override {
22✔
108
        return EntityIdStructure::Simple;
22✔
109
    }
110

111
private:
112
    std::shared_ptr<IIntervalSource> m_source;
113
    IntervalProperty m_property;
114
    std::string m_sourceName;
115

116
    /**
117
     * @brief Validates that row intervals are a subset of source intervals.
118
     * @param rowIntervals The intervals from the row selector.
119
     * @param destinationTimeFrame The destination timeframe for comparison.
120
     * @throws std::runtime_error if row intervals are not a subset of source intervals.
121
     */
122
    void _validateRowIntervalsAreSubset(const std::vector<TimeFrameInterval>& rowIntervals, 
123
                                       const TimeFrame* destinationTimeFrame) const;
124
};
125

126

127

128
#endif // INTERVAL_PROPERTY_COMPUTER_H
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