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

paulmthompson / WhiskerToolbox / 15430655463

04 Jun 2025 12:26AM UTC coverage: 40.974% (+17.1%) from 23.832%
15430655463

push

github

paulmthompson
fix self copy with mask data

5 of 5 new or added lines in 2 files covered. (100.0%)

945 existing lines in 24 files now uncovered.

3003 of 7329 relevant lines covered (40.97%)

731.35 hits per line

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

0.0
/src/WhiskerToolbox/DataManager/Points/IO/CSV/Point_Data_CSV.cpp
1

2
#include "Point_Data_CSV.hpp"
3

4
#include "Points/Point_Data.hpp"
5
#include "transforms/data_transforms.hpp"
6
#include "utils/string_manip.hpp"
7

8
#include <filesystem>
9
#include <fstream>
10
#include <iomanip>
11
#include <iostream>
12
#include <sstream>
13

14
//https://stackoverflow.com/questions/4654636/how-to-determine-if-a-string-is-a-number-with-c
UNCOV
15
bool is_number(std::string const & s) {
×
16
    return !s.empty() && std::find_if(s.begin(),
×
17
                                      s.end(), [](unsigned char c) { return !std::isdigit(c); }) == s.end();
×
18
}
19

20
std::map<int, Point2D<float>> load(CSVPointLoaderOptions const & opts) {
×
UNCOV
21
    std::string csv_line;
×
22

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

25
    std::fstream myfile;
×
26
    myfile.open(opts.filename, std::fstream::in);
×
27

28
    std::string x_str;
×
UNCOV
29
    std::string y_str;
×
UNCOV
30
    std::string frame_str;
×
UNCOV
31
    std::string col_value;
×
32

UNCOV
33
    std::vector<std::pair<int, Point2D<float>>> csv_vector = {};
×
34

UNCOV
35
    while (getline(myfile, csv_line)) {
×
36

UNCOV
37
        std::stringstream ss(csv_line);
×
38

39
        int cols_read = 0;
×
UNCOV
40
        while (getline(ss, col_value, opts.column_delim)) {
×
41
            if (cols_read == opts.frame_column) {
×
42
                frame_str = col_value;
×
UNCOV
43
            } else if (cols_read == opts.x_column) {
×
UNCOV
44
                x_str = col_value;
×
45
            } else if (cols_read == opts.y_column) {
×
46
                y_str = col_value;
×
47
            }
UNCOV
48
            cols_read++;
×
49
        }
50

51
        if (is_number(frame_str)) {
×
52
            //line_output[std::stoi(frame_str)]=Point2D<float>{std::stof(x_str),std::stof(y_str)};
UNCOV
53
            csv_vector.emplace_back(std::stoi(frame_str), Point2D<float>{std::stof(x_str), std::stof(y_str)});
×
54
        }
55
    }
×
UNCOV
56
    std::cout.flush();
×
57

UNCOV
58
    std::cout << "Read " << csv_vector.size() << " lines from " << opts.filename << std::endl;
×
59

60
    line_output.insert(csv_vector.begin(), csv_vector.end());
×
61

62
    return line_output;
×
63
}
×
64

65
std::map<std::string, std::map<int, Point2D<float>>> load_multiple_points_from_csv(std::string const & filename, int const frame_column) {
×
UNCOV
66
    std::fstream file;
×
67
    file.open(filename, std::fstream::in);
×
68

69
    std::string ln, ele;
×
70

71
    getline(file, ln);// skip the "scorer" row
×
72

73
    getline(file, ln);// bodyparts row
×
74
    std::vector<std::string> bodyparts;
×
75
    {
76
        std::stringstream ss(ln);
×
77
        while (getline(ss, ele, ',')) {
×
78
            bodyparts.push_back(ele);
×
79
        }
80
    }
×
81

82
    getline(file, ln);// coords row
×
UNCOV
83
    std::vector<std::string> dims;
×
84
    {
85
        std::stringstream ss(ln);
×
UNCOV
86
        while (getline(ss, ele, ',')) {
×
87
            dims.push_back(ele);
×
88
        }
89
    }
×
90

UNCOV
91
    std::map<std::string, std::map<int, Point2D<float>>> data;
×
92
    while (getline(file, ln)) {
×
UNCOV
93
        std::stringstream ss(ln);
×
94
        int col_no = 0;
×
UNCOV
95
        int frame_no = -1;
×
96
        while (getline(ss, ele, ',')) {
×
97
            if (col_no == frame_column) {
×
UNCOV
98
                frame_no = std::stoi(extract_numbers_from_string(ele));
×
99
            } else if (dims[col_no] == "x") {
×
100
                data[bodyparts[col_no]][frame_no].x = std::stof(ele);
×
101
            } else if (dims[col_no] == "y") {
×
UNCOV
102
                data[bodyparts[col_no]][frame_no].y = std::stof(ele);
×
103
            }
UNCOV
104
            ++col_no;
×
105
        }
UNCOV
106
    }
×
107

108
    return data;
×
UNCOV
109
}
×
110

111
void save(PointData const * point_data, CSVPointSaverOptions const & opts)
×
112
{
113
    //Check if directory exists
114
    if (!std::filesystem::exists(opts.parent_dir)) {
×
UNCOV
115
        std::filesystem::create_directories(opts.parent_dir);
×
116
        std::cout << "Created directory: " << opts.parent_dir << std::endl;
×
117
    }
118

119
    std::string const filename = opts.parent_dir + "/" + opts.filename;
×
120
    std::fstream fout;
×
121

UNCOV
122
    fout.open(filename, std::fstream::out);
×
123
    if (!fout.is_open()) {
×
UNCOV
124
        std::cerr << "Failed to open file for saving: " << filename << std::endl;
×
125
        return;
×
126
    }
127

128
    if (opts.save_header) {
×
129
        fout << opts.header << opts.line_delim;
×
130
    }
131

132
    for (auto const& timePointsPair : point_data->GetAllPointsAsRange()) {
×
133
        fout << timePointsPair.time;
×
134
        for (size_t i = 0; i < timePointsPair.points.size(); ++i) {
×
135
            fout << opts.delimiter << timePointsPair.points[i].x << opts.delimiter << timePointsPair.points[i].y;
×
136
        }
UNCOV
137
        fout << opts.line_delim;
×
138
    }
UNCOV
139
    fout.close();
×
140
    std::cout << "Successfully saved points to " << filename << std::endl;
×
UNCOV
141
}
×
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