mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-12-13 12:08:05 +00:00
feat(sensor_data): added get_average_f32() utility method
This commit is contained in:
committed by
Carles Fernandez
parent
d86e813a57
commit
e22564f75e
@@ -110,6 +110,35 @@ SensorDataSample<float> SensorDataAggregator::get_last_f32(SensorIdentifier::val
|
|||||||
return samples.back();
|
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)
|
void SensorDataAggregator::append_data(const pmt::pmt_t& data_dict)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
|
|
||||||
const std::vector<SensorDataSample<float>>& get_f32(SensorIdentifier::value_type sensor_id) const;
|
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_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
|
// More getters to be added in the future for different types
|
||||||
// For now, all supported sensors are represented as f32
|
// For now, all supported sensors are represented as f32
|
||||||
|
|||||||
Reference in New Issue
Block a user