Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gradient improvements #28

Merged
merged 6 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"typeindex": "cpp",
"util": "cpp",
"export": "cpp",
"assert": "cpp"
"assert": "cpp",
"ranges": "cpp"
}
}
2 changes: 1 addition & 1 deletion src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void manager::run()

log.info("Telemetry processing time: {:.3f} s",
std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count()/1000.0);
log.info("Overlay pre-setup time: {:.3f} s",
log.info("Overlay setup time: {:.3f} s",
std::chrono::duration_cast<std::chrono::milliseconds>(t3 - t2).count()/1000.0);
log.info("Video generation time: {:.3f} s",
std::chrono::duration_cast<std::chrono::milliseconds>(t4 - t3).count()/1000.0);
Expand Down
2 changes: 0 additions & 2 deletions src/telemetry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ target_sources(vgraph_lib
PUBLIC
datapoint.h
field.h
value.h
parser.h
fit_parser.h
telemetry.h

)
4 changes: 2 additions & 2 deletions src/telemetry/datapoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define DATAPOINT_H

#include "field.h"
#include "value.h"

#include <map>
#include <vector>
Expand All @@ -17,7 +16,8 @@ struct datapoint {
std::map<EField, double> fields;
};

using datapoint_sequence = std::vector<std::shared_ptr<datapoint>>;
using datapoint_ptr = std::shared_ptr<datapoint>;
using datapoint_seq = std::vector<datapoint_ptr>;

} // namespace telemetry
} // namespace vgraph
Expand Down
1 change: 1 addition & 0 deletions src/telemetry/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace consts {
{"power", EField::Power},
{"power3s", EField::Power3s},
{"power10s", EField::Power10s},
{"power30s", EField::Power30s},
{"respiration_rate", EField::RespirationRate},
{"heart_rate", EField::HeartRate},
{"grit", EField::Grit},
Expand Down
1 change: 1 addition & 0 deletions src/telemetry/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum class EField
Power,
Power3s,
Power10s,
Power30s,
RespirationRate,
HeartRate,
Grit,
Expand Down
32 changes: 16 additions & 16 deletions src/telemetry/fit_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,37 @@ namespace consts {
const unsigned int garmin_epoch = 631065600; // seconds since 1970-01-01 00:00:00 to 1989-12-31 00:00:00
}

std::shared_ptr<datapoint_sequence> fit_parser::parse_impl(const std::filesystem::path& path)
datapoint_seq fit_parser::parse_impl(const std::filesystem::path& path)
{
log.info("Decoding FIT file {}", path.string());

if (!std::filesystem::exists(path)) {
log.error("File does not exist: {}", path.string());
return nullptr;
return {};
}

if (path.extension() != ".fit") {
log.error("File extension is not .fit: {}", path.string());
return nullptr;
return {};
}

std::fstream file;
file.open(path.c_str(), std::ios::in | std::ios::binary);

if (!file.is_open()) {
log.error("Error opening file {}", path.string());
return nullptr;
return {};
}

std::shared_ptr<datapoint_sequence> ptr = parse_filestream(file);
if (ptr) {
datapoint_seq seq(parse_filestream(file));
if (!seq.empty()) {
log.info("Decoded FIT file {}", path.string());
}

return ptr;
return std::move(seq);
}

std::shared_ptr<datapoint_sequence> fit_parser::parse_filestream(std::fstream& file)
datapoint_seq fit_parser::parse_filestream(std::fstream& file)
{
fit::Decode decode;
if (!decode.CheckIntegrity(file)) {
Expand All @@ -49,8 +49,8 @@ std::shared_ptr<datapoint_sequence> fit_parser::parse_filestream(std::fstream& f
using std::placeholders::_1;

fit::MesgBroadcaster msg_broadcaster;
std::shared_ptr<datapoint_sequence> seq = std::make_shared<datapoint_sequence>();
listener listen(std::bind(&fit_parser::handle_record, this, _1, seq));
datapoint_seq seq;
listener listen(std::bind(&fit_parser::handle_record, this, _1, std::ref(seq)));

msg_broadcaster.AddListener(listen);

Expand All @@ -61,20 +61,20 @@ std::shared_ptr<datapoint_sequence> fit_parser::parse_filestream(std::fstream& f
catch (const fit::RuntimeException& e)
{
log.error("Exception decoding file: {}", e.what());
return nullptr;
return {};
}
catch (...)
{
log.error("Exception decoding file");
return nullptr;
return {};
}

return seq;
return std::move(seq);
}

void fit_parser::handle_record(fit::RecordMesg& record, std::shared_ptr<datapoint_sequence> out_seq)
void fit_parser::handle_record(fit::RecordMesg& record, datapoint_seq& out_seq)
{
std::shared_ptr<vgraph::telemetry::datapoint> data = std::make_shared<vgraph::telemetry::datapoint>();
datapoint_ptr data = std::make_shared<datapoint>();

if (record.IsTimestampValid())
data->timestamp = parse_timestamp(record.GetTimestamp());
Expand Down Expand Up @@ -107,7 +107,7 @@ void fit_parser::handle_record(fit::RecordMesg& record, std::shared_ptr<datapoin
if (record.IsFlowValid())
data->fields[EField::Flow] = record.GetFlow();

out_seq->push_back(data);
out_seq.push_back(std::move(data));
}

// timestamp: seconds since UTC 00:00 Dec 31 1989
Expand Down
6 changes: 3 additions & 3 deletions src/telemetry/fit_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class fit_parser : public parser {
private:
utils::logging::logger log{"fit_parser"};

std::shared_ptr<datapoint_sequence> parse_impl(const std::filesystem::path& path) override;
std::shared_ptr<datapoint_sequence> parse_filestream(std::fstream& file);
void handle_record(fit::RecordMesg& record, std::shared_ptr<datapoint_sequence> out_seq);
datapoint_seq parse_impl(const std::filesystem::path& path) override;
datapoint_seq parse_filestream(std::fstream& file);
void handle_record(fit::RecordMesg& record, datapoint_seq& out_seq);
std::chrono::time_point<std::chrono::system_clock> parse_timestamp(FIT_UINT32 timestamp);

class listener : public fit::RecordMesgListener
Expand Down
Loading