39 if (s ==
"t" || s ==
"T")
41 else if (s ==
"v" || s ==
"V")
49 Task(
const std::string& name,
const std::string& type, std::size_t ts_from, std::size_t ts_to,
VideoId video_ID,
76 SHLOG_I(
"Parsing tasks from '" << filepath <<
"'...");
78 auto ifs = std::ifstream(filepath, std::ios::in);
80 std::string msg{
"Error opening file: " + filepath };
82 throw std::runtime_error(msg);
89 std::size_t i_line = 0;
90 for (std::string line_text_buffer; std::getline(ifs, line_text_buffer); ++i_line) {
92 if (i_line == 0)
continue;
94 std::stringstream line_buffer_ss(line_text_buffer);
96 std::vector<std::string> tokens;
99 for (std::string token; std::getline(line_buffer_ss, token,
',');) {
100 tokens.push_back(token);
103 do_assert(tokens.size() == 7,
"Exactly 7 cols in the CSV.");
105 std::string& name = tokens[0];
106 std::string& type = tokens[1];
107 std::size_t ts_from = utils::str2<std::size_t>(tokens[2]);
108 std::size_t ts_to = utils::str2<std::size_t>(tokens[3]);
109 std::size_t video_ID = utils::str2<std::size_t>(tokens[4]);
110 std::size_t fr_from = utils::str2<std::size_t>(tokens[5]);
111 std::size_t fr_to = utils::str2<std::size_t>(tokens[6]);
113 _tasks.emplace_back(name, type, ts_from, ts_to, video_ID, fr_from, fr_to);
120 std::tuple<VideoId, FrameNum, FrameNum>
target(std::size_t ts) {
122 auto [ts_fr, ts_to] = t.timestamps();
123 if (ts_fr <= ts && ts <= ts_to) {
124 return std::tuple(t.video_ID(), t.frame_from(), t.frame_to());
128 std::string msg(
"No task found for timestamp '" + std::to_string(ts) +
"'!");
130 throw std::runtime_error(msg);
Definition: task-target-helper.h:34
Type type_to_enum(const std::string &s)
Definition: task-target-helper.h:38
FrameNum frame_from()
Definition: task-target-helper.h:61
FrameNum frame_to()
Definition: task-target-helper.h:63
std::pair< FrameNum, FrameNum > _frames_interval
Definition: task-target-helper.h:70
Type _type
Definition: task-target-helper.h:67
std::string _name
Definition: task-target-helper.h:66
VideoId video_ID()
Definition: task-target-helper.h:59
std::pair< std::size_t, std::size_t > timestamps()
Definition: task-target-helper.h:57
Task(const std::string &name, const std::string &type, std::size_t ts_from, std::size_t ts_to, VideoId video_ID, FrameNum fr_from, FrameNum fr_to)
Definition: task-target-helper.h:49
Type
Definition: task-target-helper.h:36
std::pair< std::size_t, std::size_t > _timestamps
Definition: task-target-helper.h:68
VideoId _video_ID
Definition: task-target-helper.h:69
Represents a real competition task and for the given timestamp responds with the target.
Definition: task-target-helper.h:32
std::vector< Task > _tasks
Definition: task-target-helper.h:134
TaskTargetHelper()=delete
TaskTargetHelper(const std::string &filepath)
Definition: task-target-helper.h:75
std::tuple< VideoId, FrameNum, FrameNum > target(std::size_t ts)
Definition: task-target-helper.h:120
Definition: common-types.h:33
unsigned VideoId
Definition: common-types.h:71
unsigned FrameNum
Definition: common-types.h:72
#define SHLOG_E(x)
Definition: static-logger.hpp:157
#define do_assert(assertion, msg)
Assert execuded at all times.
Definition: static-logger.hpp:210
#define SHLOG_I(x)
Definition: static-logger.hpp:172