#include "chrome/renderer/companion/visual_query/visual_query_eligibility.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "components/optimization_guide/proto/hints.pb.h"
namespace companion::visual_query {
namespace {
constexpr char kNormalizedPrefix[] = …;
constexpr char kNormalizeByPrefix[] = …;
constexpr int kMaxNumStored = …;
bool SortDesc(const std::pair<std::string, double>& p1,
const std::pair<std::string, double>& p2) { … }
bool SortAsc(const std::pair<std::string, double>& p1,
const std::pair<std::string, double>& p2) { … }
bool SortDescImages(const std::pair<int, int>& p1,
const std::pair<int, int>& p2) { … }
double ComputeDistanceToViewPortCenter(const Rect& onpage_image_rect,
float viewport_width,
float viewport_height) { … }
double ComputeFractionCover(const Rect& image1_onpage_rect,
const Rect& image2_onpage_rect) { … }
}
EligibilityModule::EligibilityModule(const EligibilitySpec& spec)
: … { … }
EligibilityModule::~EligibilityModule() = default;
std::vector<std::string>
EligibilityModule::RunFirstPassEligibilityAndCacheFeatureValues(
const SizeF& viewport_image_size,
const std::vector<SingleImageGeometryFeatures>& images) { … }
std::vector<std::string>
EligibilityModule::RunSecondPassPostClassificationEligibility(
const base::flat_map<std::string, double>& shopping_classifier_scores,
const base::flat_map<std::string, double>& sensitivity_classifier_scores) { … }
base::flat_map<std::string, double>
EligibilityModule::GetDebugFeatureValuesForImage(const std::string& image_id) { … }
void EligibilityModule::Clear() { … }
void EligibilityModule::ComputeNormalizingFeatures(
const std::vector<SingleImageGeometryFeatures>& images) { … }
bool EligibilityModule::IsEligible(
const google::protobuf::RepeatedPtrField<OrOfThresholdingRules>& rules,
const std::string& image_id) { … }
bool EligibilityModule::EvaluateEligibilityRule(
const OrOfThresholdingRules& eligibility_rule,
const std::string& image_id) { … }
bool EligibilityModule::IsImageShoppyForMetrics(const std::string& image_id) { … }
bool EligibilityModule::IsImageSensitiveForMetrics(
const std::string& image_id) { … }
bool EligibilityModule::EvaluateThresholdingRule(
const ThresholdingRule& thresholding_rule,
const std::string& image_id) { … }
void EligibilityModule::ComputeFeaturesForOrOfThresholdingRules(
const google::protobuf::RepeatedPtrField<OrOfThresholdingRules>& rules,
const SingleImageGeometryFeatures& image) { … }
void EligibilityModule::ComputeFeaturesForSortingClauses(
const SingleImageGeometryFeatures& image) { … }
double EligibilityModule::GetMaxFeatureValue(
FeatureLibrary::ImageLevelFeatureName feature_name,
const std::vector<SingleImageGeometryFeatures>& images) { … }
double EligibilityModule::MaxFeatureValueAfterSecondPass(
FeatureLibrary::ImageLevelFeatureName image_feature_name) { … }
double EligibilityModule::GetImageFeatureValue(
FeatureLibrary::ImageLevelFeatureName feature_name,
const SingleImageGeometryFeatures& image) { … }
std::optional<double> EligibilityModule::RetrieveImageFeatureIfPresent(
FeatureLibrary::ImageLevelFeatureName feature_name,
const std::string& image_id) { … }
double EligibilityModule::RetrieveImageFeatureOrDie(
FeatureLibrary::ImageLevelFeatureName feature_name,
const std::string& image_id) { … }
double EligibilityModule::RetrieveNormalizingFeatureOrDie(
FeatureLibrary::ImageLevelFeatureName feature_name,
FeatureLibrary::NormalizingOp normalizing_op) { … }
double EligibilityModule::ComputeAndGetNormalizingFeatureValue(
FeatureLibrary::ImageLevelFeatureName feature_name,
FeatureLibrary::NormalizingOp normalizing_op,
const std::vector<SingleImageGeometryFeatures>& images,
bool limit_to_second_pass_eligible) { … }
void EligibilityModule::GetDebugFeatureValuesForRules(
const std::string& image_id,
const google::protobuf::RepeatedPtrField<OrOfThresholdingRules>& rules,
base::flat_map<std::string, double>& output_map) { … }
void EligibilityModule::RenormalizeForThirdPass() { … }
void EligibilityModule::SortImages(
std::vector<std::pair<std::string, double>>* images_with_feature_values) { … }
void EligibilityModule::RunAdditionalCheapPruning(
const std::vector<SingleImageGeometryFeatures>& images) { … }
}