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

paulmthompson / WhiskerToolbox / 17846711083

19 Sep 2025 02:28AM UTC coverage: 72.02% (+0.08%) from 71.942%
17846711083

push

github

paulmthompson
event in interval computer works with entity ids

259 of 280 new or added lines in 6 files covered. (92.5%)

268 existing lines in 17 files now uncovered.

40247 of 55883 relevant lines covered (72.02%)

1227.29 hits per line

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

92.68
/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, 
35✔
48
                            IntervalProperty property,
49
                            std::string sourceName)
50
        : m_source(std::move(source)), m_property(property), m_sourceName(std::move(sourceName)) {}
35✔
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]] auto compute(const ExecutionPlan& plan) const -> std::vector<T> override {
34✔
58
        if (!plan.hasIntervals()) {
34✔
59
            throw std::runtime_error("IntervalPropertyComputer requires an ExecutionPlan with intervals");
1✔
60
        }
61
        
62
        auto intervals = plan.getIntervals();
33✔
63
        auto destinationTimeFrame = plan.getTimeFrame();
33✔
64
        
65
        std::vector<T> results;
33✔
66
        results.reserve(intervals.size());
33✔
67
        
68
        for (const auto& interval : intervals) {
132✔
69
            switch (m_property) {
99✔
70
                case IntervalProperty::Start:
35✔
71
                    results.push_back(static_cast<T>(interval.start.getValue()));
35✔
72
                    break;
35✔
73
                case IntervalProperty::End:
22✔
74
                    results.push_back(static_cast<T>(interval.end.getValue()));
22✔
75
                    break;
22✔
76
                case IntervalProperty::Duration:
42✔
77
                    results.push_back(static_cast<T>(interval.end.getValue() - interval.start.getValue()));
42✔
78
                    break;
42✔
UNCOV
79
                default:
×
UNCOV
80
                    throw std::runtime_error("Unknown IntervalProperty");
×
81
            }
82
        }
83
        
84
        return results;
33✔
85
    }
33✔
86

87
    [[nodiscard]] auto getSourceDependency() const -> std::string override {
76✔
88
        return m_sourceName;
76✔
89
    }
90

91
    /**
92
     * @brief Gets the EntityID structure type for this computer.
93
     * @return EntityIdStructure::Simple since each interval maps to one value.
94
     */
95
    [[nodiscard]] EntityIdStructure getEntityIdStructure() const override {
10✔
96
        return EntityIdStructure::Simple;
10✔
97
    }
98

99
    /**
100
     * @brief Checks if this computer can provide EntityID information.
101
     * @return True since intervals have EntityIDs.
102
     */
103
    [[nodiscard]] bool hasEntityIds() const override {
4✔
104
        return true;
4✔
105
    }
106

107
    /**
108
     * @brief Computes all EntityIDs for the column using Simple structure.
109
     * @param plan The execution plan containing interval boundaries.
110
     * @return ColumnEntityIds variant containing std::vector<EntityId>.
111
     */
112
    [[nodiscard]] ColumnEntityIds computeColumnEntityIds(ExecutionPlan const & plan) const override {
12✔
113
        if (!plan.hasIntervals()) {
12✔
UNCOV
114
            return std::monostate{};
×
115
        }
116
        
117
        auto intervals = plan.getIntervals();
12✔
118
        std::vector<EntityId> entity_ids;
12✔
119
        entity_ids.reserve(intervals.size());
12✔
120
        
121
        // Extract EntityIDs from the interval source
122
        // The intervals in the ExecutionPlan correspond to the source intervals by index
123
        for (size_t i = 0; i < intervals.size(); ++i) {
72✔
124
            EntityId entity_id = m_source->getEntityIdAt(i);
60✔
125
            entity_ids.push_back(entity_id);
60✔
126
        }
127
        
128
        return entity_ids;
12✔
129
    }
12✔
130

131
private:
132
    std::shared_ptr<IIntervalSource> m_source;
133
    IntervalProperty m_property;
134
    std::string m_sourceName;
135
};
136

137

138

139
#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