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

paulmthompson / WhiskerToolbox / 14367106902

09 Apr 2025 09:13PM UTC coverage: 13.06%. Remained the same
14367106902

push

github

paulmthompson
clang tidy fixes

0 of 14 new or added lines in 2 files covered. (0.0%)

1 existing line in 1 file now uncovered.

210 of 1608 relevant lines covered (13.06%)

1.25 hits per line

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

0.0
/src/WhiskerToolbox/DataManager/Points/Point_Data.cpp
1

2
#include "Point_Data.hpp"
3
#include "utils/container.hpp"
4
#include "utils/string_manip.hpp"
5

6
#include <algorithm>
7
#include <fstream>
8
#include <iomanip>
9
#include <iostream>
10
#include <sstream>
11

12

NEW
13
PointData::PointData(std::map<int, Point2D<float>> const & data) {
×
14
    for (auto [key, value]: data) {
×
15
        _data[key].push_back(value);
×
16
    }
17
}
×
18

19
PointData::PointData(std::map<int, std::vector<Point2D<float>>> data) {
×
NEW
20
    _data = std::move(data);
×
21
}
×
22

23
void PointData::clearPointsAtTime(int const time) {
×
24
    _clearPointsAtTime(time);
×
25
    notifyObservers();
×
26
}
×
27

28
void PointData::_clearPointsAtTime(int const time) {
×
29
    if (_data.find(time) == _data.end()) {
×
30
        return;
×
31
    }
32

33
    _data[time].clear();
×
34
}
35

36
void PointData::overwritePointAtTime(int const time, float const x, float const y) {
×
37
    _overwritePointAtTime(time, x, y);
×
38
    notifyObservers();
×
39
}
×
40

41
void PointData::_overwritePointAtTime(int const time, float const x, float const y) {
×
42
    _clearPointsAtTime(time);
×
43
    _addPointAtTime(time, x, y);
×
44
    notifyObservers();
×
45
}
×
46

47
void PointData::overwritePointsAtTime(int const time, std::vector<Point2D<float>> const & points) {
×
48
    _overwritePointsAtTime(time, points);
×
49
    notifyObservers();
×
50
}
×
51

52
void PointData::_overwritePointsAtTime(int const time, std::vector<Point2D<float>> const & points) {
×
53
    _clearPointsAtTime(time);
×
54
    _addPointsAtTime(time, points);
×
55
    notifyObservers();
×
56
}
×
57

58
void PointData::addPointAtTime(int const time, float const x, float const y) {
×
59
    _addPointAtTime(time, x, y);
×
60
    notifyObservers();
×
61
}
×
62

63
void PointData::_addPointAtTime(int const time, float const x, float const y) {
×
64
    if (_data.find(time) == _data.end()) {
×
65
        _data[time] = std::vector<Point2D<float>>{Point2D<float>{x, y}};
×
66
    }
67
    _data[time].push_back(Point2D<float>{x, y});
×
68
}
×
69

70
void PointData::addPointsAtTime(int const time, std::vector<Point2D<float>> const & points) {
×
71
    _addPointsAtTime(time, points);
×
72
    notifyObservers();
×
73
}
×
74

75
void PointData::_addPointsAtTime(int const time, std::vector<Point2D<float>> const & points) {
×
76
    if (_data.find(time) == _data.end()) {
×
77
        _data[time] = points;
×
78
    } else {
79
        _data[time].insert(_data[time].end(), points.begin(), points.end());
×
80
    }
81
}
×
82

83
std::vector<int> PointData::getTimesWithPoints() const {
×
84
    std::vector<int> keys;
×
85
    keys.reserve(_data.size());
×
NEW
86
    for (auto const & kv: _data) {
×
87
        keys.push_back(kv.first);
×
88
    }
89
    return keys;
×
90
}
×
91

92
std::vector<Point2D<float>> const & PointData::getPointsAtTime(int const time) const {
×
93
    // [] operator is not const because it inserts if mask is not present
94
    if (_data.find(time) != _data.end()) {
×
95
        return _data.at(time);
×
96
    } else {
97
        return _empty;
×
98
    }
99
}
100

101
//https://stackoverflow.com/questions/4654636/how-to-determine-if-a-string-is-a-number-with-c
102
bool is_number(std::string const & s) {
×
103
    return !s.empty() && std::find_if(s.begin(),
×
104
                                      s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
×
105
}
106

NEW
107
std::map<int, Point2D<float>> load_points_from_csv(CSVPointLoaderOptions const & opts) {
×
UNCOV
108
    std::string csv_line;
×
109

110
    auto line_output = std::map<int, Point2D<float>>{};
×
111

112
    std::fstream myfile;
×
NEW
113
    myfile.open(opts.filename, std::fstream::in);
×
114

115
    std::string x_str;
×
116
    std::string y_str;
×
117
    std::string frame_str;
×
118
    std::string col_value;
×
119

120
    std::vector<std::pair<int, Point2D<float>>> csv_vector = {};
×
121

122
    while (getline(myfile, csv_line)) {
×
123

124
        std::stringstream ss(csv_line);
×
125

126
        int cols_read = 0;
×
NEW
127
        while (getline(ss, col_value, opts.column_delim)) {
×
NEW
128
            if (cols_read == opts.frame_column) {
×
129
                frame_str = col_value;
×
NEW
130
            } else if (cols_read == opts.x_column) {
×
131
                x_str = col_value;
×
NEW
132
            } else if (cols_read == opts.y_column) {
×
133
                y_str = col_value;
×
134
            }
135
            cols_read++;
×
136
        }
137

138
        if (is_number(frame_str)) {
×
139
            //line_output[std::stoi(frame_str)]=Point2D<float>{std::stof(x_str),std::stof(y_str)};
NEW
140
            csv_vector.emplace_back(std::stoi(frame_str), Point2D<float>{std::stof(x_str), std::stof(y_str)});
×
141
        }
142
    }
×
143
    std::cout.flush();
×
144

NEW
145
    std::cout << "Read " << csv_vector.size() << " lines from " << opts.filename << std::endl;
×
146

147
    line_output.insert(csv_vector.begin(), csv_vector.end());
×
148

149
    return line_output;
×
150
}
×
151

152
std::map<std::string, std::map<int, Point2D<float>>> load_multiple_points_from_csv(std::string const & filename, int const frame_column) {
×
153
    std::fstream file;
×
154
    file.open(filename, std::fstream::in);
×
155

156
    std::string ln, ele;
×
157

158
    getline(file, ln);// skip the "scorer" row
×
159

160
    getline(file, ln);// bodyparts row
×
161
    std::vector<std::string> bodyparts;
×
162
    {
163
        std::stringstream ss(ln);
×
164
        while (getline(ss, ele, ',')) {
×
165
            bodyparts.push_back(ele);
×
166
        }
167
    }
×
168

169
    getline(file, ln);// coords row
×
170
    std::vector<std::string> dims;
×
171
    {
172
        std::stringstream ss(ln);
×
173
        while (getline(ss, ele, ',')) {
×
174
            dims.push_back(ele);
×
175
        }
176
    }
×
177

178
    std::map<std::string, std::map<int, Point2D<float>>> data;
×
179
    while (getline(file, ln)) {
×
180
        std::stringstream ss(ln);
×
181
        int col_no = 0;
×
182
        int frame_no = -1;
×
183
        while (getline(ss, ele, ',')) {
×
184
            if (col_no == frame_column) {
×
185
                frame_no = std::stoi(extract_numbers_from_string(ele));
×
186
            } else if (dims[col_no] == "x") {
×
187
                data[bodyparts[col_no]][frame_no].x = std::stof(ele);
×
188
            } else if (dims[col_no] == "y") {
×
189
                data[bodyparts[col_no]][frame_no].y = std::stof(ele);
×
190
            }
191
            ++col_no;
×
192
        }
193
    }
×
194

195
    return data;
×
196
}
×
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