1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-12-12 11:38:06 +00:00

feat(sensor_data): added get_average_f32() utility method

This commit is contained in:
Victor Castillo
2025-08-03 00:06:30 +02:00
committed by Carles Fernandez
parent d86e813a57
commit e22564f75e
2 changed files with 30 additions and 0 deletions

View File

@@ -110,6 +110,35 @@ SensorDataSample<float> SensorDataAggregator::get_last_f32(SensorIdentifier::val
return samples.back();
}
SensorDataSample<float> SensorDataAggregator::get_average_f32(SensorIdentifier::value_type sensor_id) const
{
// The map is populated on construction with empty vectors for each provided sensor.
// If a required sensor is not provided, the error is handled on construction.
const std::vector<SensorDataSample<float>> samples = f32_data_.at(sensor_id);
if (samples.empty())
{
return {0, 0};
}
float acc = 0.0;
float count = 0;
bool first = true;
for (const auto& sample : samples)
{
if (first)
{
first = false;
continue;
}
acc += sample.value;
++count;
}
if (count == 0)
{
return {samples.back().timestamp, 0};
}
return {samples.back().timestamp, acc / count};
}
void SensorDataAggregator::append_data(const pmt::pmt_t& data_dict)
{

View File

@@ -53,6 +53,7 @@ public:
const std::vector<SensorDataSample<float>>& get_f32(SensorIdentifier::value_type sensor_id) const;
SensorDataSample<float> get_last_f32(SensorIdentifier::value_type sensor_id) const;
SensorDataSample<float> get_average_f32(SensorIdentifier::value_type sensor_id) const;
// More getters to be added in the future for different types
// For now, all supported sensors are represented as f32