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 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
44 from pathlib
import Path
46 from fiftyone_devicedetection.devicedetection_pipelinebuilder
import DeviceDetectionPipelineBuilder
47 from fiftyone_pipeline_core.logger
import Logger
48 from fiftyone_pipeline_core.basiclist_evidence_keyfilter
import BasicListEvidenceKeyFilter
49 from ..example_utils
import ExampleUtils
50 from fiftyone_devicedetection_shared.example_constants
import EVIDENCE_VALUES
51 from fiftyone_devicedetection_shared.example_constants
import LITE_DATAFILE_NAME
54 fgWhite =
"\u001b[37;1m" 55 colReset =
"\u001b[0m" 57 class MetaDataConsole():
58 def run(self, data_file, logger, output):
64 pipeline = DeviceDetectionPipelineBuilder(
65 data_file_path = data_file,
72 performance_profile =
"LowMemory",
75 usage_sharing =
False,
78 licence_keys =
"").add_logger(logger).build()
79 self.outputProperties(pipeline.get_element(
"device"), output)
80 self.outputEvidenceKeyDetails(pipeline.get_element(
"device"), output)
82 ExampleUtils.check_data_file(pipeline, logger)
85 def outputEvidenceKeyDetails(self, engine, output):
86 if (issubclass(type(engine.get_evidence_key_filter()), BasicListEvidenceKeyFilter)):
90 filter = engine.get_evidence_key_filter()
91 output(
"Accepted evidence keys:")
92 for key
in filter.list:
95 output(
"The evidence key filter has type " +
96 f
"{type(engine.get_evidence_key_filter())}. As this does not extend " +
97 "BasicListEvidenceKeyFilter, a list of accepted values cannot be " +
98 "displayed. As an alternative, you can pass evidence keys to " +
99 "filter.filter_evidence_key(string) to see if a particular key will be included " +
101 output(
"For example, header.user-agent is " +
102 (
"" if engine.get_evidence_key_filter().filter_evidence_key(
"header.user-agent")
else "not ") +
105 def outputProperties(self, engine, output):
106 for propertyName, property
in engine.get_properties().items():
110 output(f
"{bgRed}{fgWhite}Property - {propertyName}{colReset}" +
111 f
"[Category: {property['category']}] ({property['type']})")
122 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_DATAFILE_NAME)
125 logger = Logger(min_level=
"info")
127 if (data_file !=
None):
128 MetaDataConsole().run(data_file, logger,
print)
131 "Failed to find a device detection data file. Make sure the " +
132 "device-detection-data submodule has been updated by running " +
133 "`git submodule update --recursive`.")
135 if __name__ ==
"__main__":