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

paulmthompson / WhiskerToolbox / 14342212362

08 Apr 2025 07:43PM UTC coverage: 12.935% (+0.008%) from 12.927%
14342212362

push

github

paulmthompson
clang tidy fixes in data manager files

0 of 153 new or added lines in 15 files covered. (0.0%)

45 existing lines in 8 files now uncovered.

208 of 1608 relevant lines covered (12.94%)

1.26 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>> data) {
×
NEW
14
    for (auto [key, value]: data) {
×
UNCOV
15
        _data[key].push_back(value);
×
16
    }
17
}
×
18

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

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

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

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

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

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

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

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

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

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

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

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

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

NEW
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
NEW
94
    if (_data.find(time) != _data.end()) {
×
UNCOV
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
NEW
102
bool is_number(std::string const & s) {
×
UNCOV
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(
×
108
        std::string const & filename,
109
        int const frame_column,
110
        int const x_column,
111
        int const y_column,
112
        char const column_delim) {
UNCOV
113
    std::string csv_line;
×
114

NEW
115
    auto line_output = std::map<int, Point2D<float>>{};
×
116

117
    std::fstream myfile;
×
NEW
118
    myfile.open(filename, std::fstream::in);
×
119

120
    std::string x_str;
×
121
    std::string y_str;
×
122
    std::string frame_str;
×
123
    std::string col_value;
×
124

NEW
125
    std::vector<std::pair<int, Point2D<float>>> csv_vector = {};
×
126

127
    while (getline(myfile, csv_line)) {
×
128

129
        std::stringstream ss(csv_line);
×
130

131
        int cols_read = 0;
×
NEW
132
        while (getline(ss, col_value, column_delim)) {
×
133
            if (cols_read == frame_column) {
×
134
                frame_str = col_value;
×
135
            } else if (cols_read == x_column) {
×
136
                x_str = col_value;
×
137
            } else if (cols_read == y_column) {
×
138
                y_str = col_value;
×
139
            }
140
            cols_read++;
×
141
        }
142

143
        if (is_number(frame_str)) {
×
144
            //line_output[std::stoi(frame_str)]=Point2D<float>{std::stof(x_str),std::stof(y_str)};
NEW
145
            csv_vector.emplace_back(std::make_pair(std::stoi(frame_str), Point2D<float>{std::stof(x_str), std::stof(y_str)}));
×
146
        }
147
    }
×
148
    std::cout.flush();
×
149

150
    std::cout << "Read " << csv_vector.size() << " lines from " << filename << std::endl;
×
151

152
    line_output.insert(csv_vector.begin(), csv_vector.end());
×
153

154
    return line_output;
×
155
}
×
156

NEW
157
std::map<std::string, std::map<int, Point2D<float>>> load_multiple_points_from_csv(std::string const & filename, int const frame_column) {
×
158
    std::fstream file;
×
159
    file.open(filename, std::fstream::in);
×
160

161
    std::string ln, ele;
×
162

NEW
163
    getline(file, ln);// skip the "scorer" row
×
164

NEW
165
    getline(file, ln);// bodyparts row
×
UNCOV
166
    std::vector<std::string> bodyparts;
×
167
    {
168
        std::stringstream ss(ln);
×
NEW
169
        while (getline(ss, ele, ',')) {
×
170
            bodyparts.push_back(ele);
×
171
        }
172
    }
×
173

NEW
174
    getline(file, ln);// coords row
×
175
    std::vector<std::string> dims;
×
176
    {
177
        std::stringstream ss(ln);
×
NEW
178
        while (getline(ss, ele, ',')) {
×
179
            dims.push_back(ele);
×
180
        }
181
    }
×
182

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

200
    return data;
×
201
}
×
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