| // 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/count_aggregation_procedure.h" |
| |
| #include <tuple> |
| |
| #include "src/lib/statusor/status_macros.h" |
| #include "src/lib/util/datetime_util.h" |
| #include "src/local_aggregation_1.1/aggregation_procedures/aggregation_procedure.h" |
| #include "src/pb/observation.pb.h" |
| #include "src/registry/packed_event_codes.h" |
| |
| namespace cobalt::local_aggregation { |
| |
| void CountAggregationProcedure::UpdateAggregateData(const logger::EventRecord & /*event_record*/, |
| AggregateData *aggregate_data, |
| EventCodeAggregate * /*aggregate*/) { |
| aggregate_data->set_count(aggregate_data->count() + 1); |
| } |
| |
| lib::statusor::StatusOr<std::unique_ptr<Observation>> |
| CountAggregationProcedure::GenerateHourlyObservation(const logger::Encoder *encoder, |
| EventCodeAggregate *aggregate) { |
| std::vector<std::tuple<std::vector<uint32_t>, int64_t>> data; |
| data.reserve(aggregate->by_event_code_size()); |
| |
| for (const auto &event_code : aggregate->by_event_code()) { |
| data.emplace_back( |
| std::make_tuple(config::UnpackEventCodes(event_code.first), event_code.second.count())); |
| } |
| |
| if (data.empty()) { |
| return {nullptr}; |
| } |
| |
| return encoder->EncodeIntegerObservation(data); |
| } |
| |
| std::string CountAggregationProcedure::DebugString() const { return "COUNT"; } |
| |
| } // namespace cobalt::local_aggregation |