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

paulmthompson / WhiskerToolbox / 17270491352

27 Aug 2025 02:57PM UTC coverage: 65.333%. Remained the same
17270491352

push

github

paulmthompson
Merge branch 'main' of https://github.com/paulmthompson/WhiskerToolbox

352 of 628 new or added lines in 92 files covered. (56.05%)

357 existing lines in 24 files now uncovered.

26429 of 40453 relevant lines covered (65.33%)

1119.34 hits per line

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

25.71
/src/DataManager/transforms/Masks/mask_area.cpp
1
#include "mask_area.hpp"
2

3
#include "AnalogTimeSeries/Analog_Time_Series.hpp"
4
#include "Masks/Mask_Data.hpp"
5
#include "TimeFrame/TimeFrame.hpp"
6

7
#include <iostream>
8
#include <map>
9

10
std::shared_ptr<AnalogTimeSeries> area(MaskData const * mask_data) {
8✔
11
    std::map<int, float> areas;
8✔
12

13
    for (auto const & mask_and_time: mask_data->getAllAsRange()) {
16✔
14
        float area = 0.0f;
8✔
15
        for (auto const & mask: mask_and_time.masks) {
28✔
16
            area += static_cast<float>(mask.size());
20✔
17
        }
18
        areas[static_cast<int>(mask_and_time.time.getValue())] = area;
8✔
19
    }
20

21
    return std::make_shared<AnalogTimeSeries>(areas);
16✔
22
}
8✔
23

24
///////////////////////////////////////////////////////////////////////////////
25

26
std::string MaskAreaOperation::getName() const {
×
27
    return "Calculate Area";
×
28
}
29

30
std::type_index MaskAreaOperation::getTargetInputTypeIndex() const {
×
31
    return typeid(std::shared_ptr<MaskData>);
×
32
}
33

34
std::unique_ptr<TransformParametersBase> MaskAreaOperation::getDefaultParameters() const {
×
35
    return std::make_unique<MaskAreaParameters>();
×
36
}
37

38
bool MaskAreaOperation::canApply(DataTypeVariant const & dataVariant) const {
×
39
    // 1. Check if the variant holds the correct alternative type (shared_ptr<MaskData>)
40
    if (!std::holds_alternative<std::shared_ptr<MaskData>>(dataVariant)) {
×
41
        return false;
×
42
    }
43

44
    // 2. Check if the shared_ptr it holds is actually non-null.
45
    //    Use get_if for safe access (returns nullptr if type is wrong, though step 1 checked)
46
    auto const * ptr_ptr = std::get_if<std::shared_ptr<MaskData>>(&dataVariant);
×
47

48
    // Return true only if get_if succeeded AND the contained shared_ptr is not null.
49
    return ptr_ptr && *ptr_ptr;
×
50
}
51

NEW
52
DataTypeVariant MaskAreaOperation::execute(DataTypeVariant const & dataVariant,
×
53
                                             TransformParametersBase const * transformParameters,
54
                                             ProgressCallback /*progressCallback*/) {
NEW
55
    return execute(dataVariant, transformParameters);
×
56
}
57

UNCOV
58
DataTypeVariant MaskAreaOperation::execute(DataTypeVariant const & dataVariant, TransformParametersBase const * transformParameters) {
×
59

60
    static_cast<void>(transformParameters);
61

62
    // 1. Safely get pointer to the shared_ptr<MaskData> if variant holds it.
UNCOV
63
    auto const * ptr_ptr = std::get_if<std::shared_ptr<MaskData>>(&dataVariant);
×
64

65
    // 2. Validate the pointer from get_if and the contained shared_ptr.
66
    //    This check ensures we have the right type and it's not a null shared_ptr.
67
    //    canApply should generally ensure this, but execute should be robust.
UNCOV
68
    if (!ptr_ptr || !(*ptr_ptr)) {
×
69
        // Logically this means canApply would be false. Return empty std::any for graceful failure.
UNCOV
70
        std::cerr << "MaskAreaOperation::execute called with incompatible variant type or null data." << std::endl;
×
UNCOV
71
        return {};// Return empty
×
72
    }
73

74
    // 3. Get the non-owning raw pointer to pass to the calculation function.
UNCOV
75
    MaskData const * mask_raw_ptr = (*ptr_ptr).get();
×
76

77
    // 4. Call the core calculation logic.
UNCOV
78
    std::shared_ptr<AnalogTimeSeries> result_ts = area(mask_raw_ptr);
×
79

80
    // 5. Handle potential failure from the calculation function.
81
    if (!result_ts) {
×
UNCOV
82
        std::cerr << "MaskAreaOperation::execute: 'calculate_mask_area' failed to produce a result." << std::endl;
×
UNCOV
83
        return {};// Return empty
×
84
    }
85

UNCOV
86
    std::cout << "MaskAreaOperation executed successfully using variant input." << std::endl;
×
87
    return result_ts;
×
88
}
×
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