blob: 5f5996215f576096edf20ac5eb7c02201ef46ab4 [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/local_aggregation_1_1/aggregation_procedures/at_least_once_aggregation_procedure.h"
#include "src/lib/statusor/status_macros.h"
#include "src/logger/encoder.h"
#include "src/pb/observation.pb.h"
namespace cobalt::local_aggregation {
AtLeastOnceAggregationProcedure::AtLeastOnceAggregationProcedure(const MetricDefinition &metric,
const ReportDefinition &report)
: AggregationProcedure(metric, report) {}
void AtLeastOnceAggregationProcedure::UpdateAggregateData(
const logger::EventRecord & /*event_record*/, AggregateData *aggregate_data,
EventCodeAggregate * /*aggregate*/) {
// TODO(fxbug.dev/53775): Handle the case where event_record is malformed.
aggregate_data->set_at_least_once(true);
}
std::string AtLeastOnceAggregationProcedure::DebugString() const { return "AT_LEAST_ONCE"; }
lib::statusor::StatusOr<std::unique_ptr<Observation>>
AtLeastOnceAggregationProcedure::GenerateSingleObservation(
const std::vector<EventCodeAggregate *> & /*aggregates*/,
const std::set<std::vector<uint32_t>> &event_vectors) {
std::vector<std::tuple<std::vector<uint32_t>, int64_t>> data;
data.reserve(event_vectors.size());
for (const auto &event_vector : event_vectors) {
data.emplace_back(std::make_tuple(event_vector, 1));
}
if (data.empty()) {
return {nullptr};
}
return logger::Encoder::EncodeIntegerObservation(data);
}
} // namespace cobalt::local_aggregation