| // 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/logger/encoder.h" |
| #include "src/pb/observation.pb.h" |
| |
| namespace cobalt::local_aggregation { |
| |
| void CountAggregationProcedure::UpdateAggregateData(const logger::EventRecord &event_record, |
| AggregateData *aggregate_data, |
| EventCodeAggregate * /*aggregate*/) { |
| uint64_t occurrence_count = event_record.event()->occurrence_event().count(); |
| aggregate_data->set_count(aggregate_data->count() + occurrence_count); |
| } |
| |
| lib::statusor::StatusOr<std::unique_ptr<Observation>> |
| CountAggregationProcedure::GenerateHourlyObservation(EventCodeAggregate *aggregate) { |
| std::vector<std::tuple<std::vector<uint32_t>, int64_t>> data; |
| data.reserve(aggregate->by_event_code_size()); |
| |
| for (const EventCodesAggregateData &aggregate_data : aggregate->by_event_code()) { |
| std::vector<uint32_t> event_codes(aggregate_data.event_codes().begin(), |
| aggregate_data.event_codes().end()); |
| data.emplace_back(std::make_tuple(event_codes, aggregate_data.data().count())); |
| } |
| |
| if (data.empty()) { |
| return {nullptr}; |
| } |
| |
| return logger::Encoder::EncodeIntegerObservation(data); |
| } |
| |
| std::string CountAggregationProcedure::DebugString() const { return "COUNT"; } |
| |
| } // namespace cobalt::local_aggregation |