The device detection data file contains meta data that can provide additional information about the various records in the data model. This example shows how to access this data and display the values available.
A list of the properties will be displayed, along with some additional information about each property.
Finally, the evidence keys that are accepted by device detection are listed. These are the keys that, when added to the evidence collection in flow data, could have some impact on the result returned by device detection.
This example is available in full on GitHub.
This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
Required PyPi Dependencies:
44 from pathlib
import Path
47 from fiftyone_pipeline_core.logger
import Logger
48 from fiftyone_pipeline_core.basiclist_evidence_keyfilter
import BasicListEvidenceKeyFilter
50 from ..example_utils
import ExampleUtils
55 fgWhite =
"\u001b[37;1m" 56 colReset =
"\u001b[0m" 58 class MetaDataConsole():
59 def run(self, data_file, logger, output):
65 pipeline = DeviceDetectionPipelineBuilder(
66 data_file_path = data_file,
73 performance_profile =
"LowMemory",
76 usage_sharing =
False,
79 licence_keys =
"").add_logger(logger).
build()
80 self.outputProperties(pipeline.get_element(
"device"), output)
81 self.outputEvidenceKeyDetails(pipeline.get_element(
"device"), output)
83 ExampleUtils.check_data_file(pipeline, logger)
86 def outputEvidenceKeyDetails(self, engine, output):
87 if (issubclass(type(engine.get_evidence_key_filter()), BasicListEvidenceKeyFilter)):
91 filter = engine.get_evidence_key_filter()
92 output(
"Accepted evidence keys:")
93 for key
in filter.list:
96 output(
"The evidence key filter has type " +
97 f
"{type(engine.get_evidence_key_filter())}. As this does not extend " +
98 "BasicListEvidenceKeyFilter, a list of accepted values cannot be " +
99 "displayed. As an alternative, you can pass evidence keys to " +
100 "filter.filter_evidence_key(string) to see if a particular key will be included " +
102 output(
"For example, header.user-agent is " +
103 (
"" if engine.get_evidence_key_filter().filter_evidence_key(
"header.user-agent")
else "not ") +
106 def outputProperties(self, engine, output):
107 for propertyName, property
in engine.get_properties().items():
111 output(f
"{bgRed}{fgWhite}Property - {propertyName}{colReset}" +
112 f
"[Category: {property['category']}] ({property['type']})")
123 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_DATAFILE_NAME)
126 logger = Logger(min_level=
"info")
128 if (data_file !=
None):
129 MetaDataConsole().
run(data_file, logger,
print)
132 "Failed to find a device detection data file. Make sure the " +
133 "device-detection-data submodule has been updated by running " +
134 "`git submodule update --recursive`.")
136 if __name__ ==
"__main__":