#include "components/segmentation_platform/internal/metadata/metadata_utils.h"
#include <inttypes.h>
#include "base/metrics/metrics_hashes.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "components/segmentation_platform/internal/database/signal_key.h"
#include "components/segmentation_platform/internal/proto/model_prediction.pb.h"
#include "components/segmentation_platform/public/proto/aggregation.pb.h"
#include "components/segmentation_platform/public/proto/model_metadata.pb.h"
#include "components/segmentation_platform/public/proto/output_config.pb.h"
#include "components/segmentation_platform/public/proto/segmentation_platform.pb.h"
#include "components/segmentation_platform/public/proto/types.pb.h"
namespace segmentation_platform::metadata_utils {
namespace {
uint64_t GetExpectedTensorLength(const proto::UMAFeature& feature) { … }
std::string FeatureToString(const proto::UMAFeature& feature) { … }
ValidationResult ValidateBinaryClassifier(
const proto::Predictor::BinaryClassifier& classifier) { … }
ValidationResult ValidateBinnedClassifier(
const proto::Predictor::BinnedClassifier& classifier) { … }
}
ValidationResult ValidateSegmentInfo(const proto::SegmentInfo& segment_info) { … }
ValidationResult ValidateMetadata(
const proto::SegmentationModelMetadata& model_metadata) { … }
ValidationResult ValidateMetadataUmaFeature(const proto::UMAFeature& feature) { … }
ValidationResult ValidateMetadataSqlFeature(const proto::SqlFeature& feature) { … }
ValidationResult ValidateMetadataCustomInput(
const proto::CustomInput& custom_input) { … }
ValidationResult ValidateMetadataAndFeatures(
const proto::SegmentationModelMetadata& model_metadata) { … }
ValidationResult ValidateIndexedTensors(
const processing::IndexedTensors& tensor,
size_t expected_size) { … }
ValidationResult ValidateSegmentInfoMetadataAndFeatures(
const proto::SegmentInfo& segment_info) { … }
ValidationResult ValidateOutputConfig(
const proto::OutputConfig& output_config) { … }
ValidationResult ValidateMultiClassClassifier(
const proto::Predictor_MultiClassClassifier& multi_class_classifier) { … }
void SetFeatureNameHashesFromName(
proto::SegmentationModelMetadata* model_metadata) { … }
bool HasExpiredOrUnavailableResult(const proto::SegmentInfo& segment_info,
const base::Time& now) { … }
bool HasFreshResults(const proto::SegmentInfo& segment_info,
const base::Time& now) { … }
base::TimeDelta GetTimeUnit(
const proto::SegmentationModelMetadata& model_metadata) { … }
base::TimeDelta ConvertToTimeDelta(proto::TimeUnit time_unit) { … }
SignalKey::Kind SignalTypeToSignalKind(proto::SignalType signal_type) { … }
proto::SignalType SignalKindToSignalType(SignalKey::Kind kind) { … }
float ConvertToDiscreteScore(const std::string& mapping_key,
float input_score,
const proto::SegmentationModelMetadata& metadata) { … }
std::string SegmetationModelMetadataToString(
const proto::SegmentationModelMetadata& model_metadata) { … }
std::vector<proto::UMAFeature> GetAllUmaFeatures(
const proto::SegmentationModelMetadata& model_metadata,
bool include_outputs) { … }
VisitUmaFeature;
void VisitAllUmaFeatures(const proto::SegmentationModelMetadata& model_metadata,
bool include_outputs,
VisitUmaFeature visit) { … }
proto::PredictionResult CreatePredictionResult(
const std::vector<float>& model_scores,
const proto::OutputConfig& output_config,
base::Time timestamp,
int64_t model_version) { … }
proto::ClientResult CreateClientResultFromPredResult(
proto::PredictionResult pred_result,
base::Time timestamp) { … }
bool ConfigUsesLegacyOutput(const Config* config) { … }
bool SegmentUsesLegacyOutput(proto::SegmentId segment_id) { … }
}