The example illustrates the various metrics that can be obtained about the device detection process, for example, the degree of certainty about the result. Running the example outputs those properties and values.
41 from itertools
import groupby
42 from pathlib
import Path
45 from fiftyone_pipeline_core.logger
import Logger
46 from fiftyone_pipeline_core.basiclist_evidence_keyfilter
import BasicListEvidenceKeyFilter
48 from ..example_utils
import ExampleUtils
52 class MatchMetricsConsole():
54 def run(self, data_file, show_descs, logger, output):
57 pipeline = DeviceDetectionPipelineBuilder(
58 data_file_path = data_file,
64 performance_profile =
"LowMemory",
68 usage_sharing =
False,
76 restricted_properties=[
"ismobile",
"hardwarename"],
87 use_predictive_graph =
True,
88 use_performance_graph =
False,
91 update_matched_useragent =
True).add_logger(logger).
build()
93 ExampleUtils.check_data_file(pipeline, logger)
95 data = pipeline.create_flowdata()
100 data.evidence.add_from_dict(self.Evidence)
105 output(
"--- Compare evidence with what was matched ---\n")
108 for entry
in sorted(self.Evidence.items(), key=
lambda item: len(item[1]), reverse=
True):
109 output(f
" {entry[0]}: {entry[1]}")
113 for entry
in sorted(device.useragents.value(), key=
lambda item: len(item)):
114 output(f
" Matched User-Agent: {entry}")
119 output(
"--- Listing all available properties, by component, by property name ---")
120 output(
"For a discussion of what the match properties mean, see: https://51degrees.com/documentation/_device_detection__hash.html#DeviceDetection_Hash_DataSetProduction_Performance\n")
125 hashEngineElementKey = pipeline.get_element(
"device").datakey
134 availableProperties = dict(pipeline.get_properties()[hashEngineElementKey])
138 def get_component(property):
139 return property[1][
"component"]
141 availableProperties = dict(sorted(availableProperties.items(),key=
lambda item: get_component(item)))
142 categoryMap = groupby(availableProperties.items(), get_component)
144 for component, properties
in categoryMap:
146 for propertyKey, property
in properties:
147 propertyName = property[
"name"]
148 propertyDescription = property[
"description"]
152 value = device[propertyKey]
156 if value.has_value()
and isinstance(value.value(), list):
157 output(f
" {propertyName}: {len(value.value())} Values")
158 for item
in value.value():
162 output(f
" {propertyName}: {value.value()}")
164 if (show_descs ==
True):
165 output(f
" {propertyDescription}")
168 logger.log(
"info",
"Finished Match Metrics Example")
172 Evidence = EVIDENCE_VALUES[2]
183 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_DATAFILE_NAME)
186 logger = Logger(min_level=
"info")
188 if (data_file !=
None):
189 MatchMetricsConsole().
run(data_file,
False, logger,
print)
192 "Failed to find a device detection data file. Make sure the " +
193 "device-detection-data submodule has been updated by running " +
194 "`git submodule update --recursive`.")
196 if __name__ ==
"__main__":