The device detection data file contains meta data that can provide additional information about the various records in the data model.
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 downloaded with the
scripts in the data GitHub repository, which
this repository includes at cxx/data. Fetch the submodules by running
git submodule update --init --recursive, then run
sh cxx/data/get-data-files.sh 51Degrees-LiteV4.1.hash from the repository root,
which saves the file as cxx/data/device-detection/51Degrees-LiteV4.1.hash.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
The Enterprise data file has every property.
Contact us about a copy.
from pathlib import Path
import sys
CONTACT_US = "/contact-us?utm_source=code&utm_medium=example&utm_campaign=51degrees-python&utm_content=fiftyone_devicedetection_examples-src-fiftyone_devicedetection_examples-onpremise-metadata_console.py&utm_term=enterprise-data-file"
bgRed = "\u001b[41m"
fgWhite = "\u001b[37;1m"
colReset = "\u001b[0m"
class MetaDataConsole():
def run(self, data_file, logger, output):
pipeline = DeviceDetectionPipelineBuilder(
data_file_path = data_file,
performance_profile = "LowMemory",
usage_sharing = False,
auto_update = False,
licence_keys =
"").add_logger(logger).
build()
with pipeline:
self.outputProperties(pipeline.get_element("device"), output)
self.outputEvidenceKeyDetails(pipeline.get_element("device"), output)
ExampleUtils.check_data_file(pipeline, logger)
if ExampleUtils.is_lite_data_file(pipeline.get_element("device")):
output("")
output(ExampleUtils.get_enterprise_offer(CONTACT_US))
def outputEvidenceKeyDetails(self, engine, output):
if (issubclass(type(engine.get_evidence_key_filter()), BasicListEvidenceKeyFilter)):
filter = engine.get_evidence_key_filter()
output("Accepted evidence keys:")
for key in filter.list:
output(f"\t{key}")
else:
output("The evidence key filter has type " +
f"{type(engine.get_evidence_key_filter())}. As this does not extend " +
"BasicListEvidenceKeyFilter, a list of accepted values cannot be " +
"displayed. As an alternative, you can pass evidence keys to " +
"filter.filter_evidence_key(string) to see if a particular key will be included " +
"or not.")
output("For example, header.user-agent is " +
("" if engine.get_evidence_key_filter().filter_evidence_key("header.user-agent") else "not ") +
"accepted.")
def outputProperties(self, engine, output):
for propertyName, property in engine.get_properties().items():
output(f"{bgRed}{fgWhite}Property - {propertyName}{colReset}" +
f"[Category: {property['category']}] ({property['type']})")
def main(argv):
data_file = argv[0] if len(argv) > 0 else ExampleUtils.find_file(LITE_DATAFILE_NAME)
logger = Logger(min_level="info")
if (data_file != None):
MetaDataConsole().run(data_file, logger, print)
else:
logger.log("error",
"Failed to find a device detection data file. Make sure the " +
"data submodule is there, by running " +
"`git submodule update --init --recursive`, and run this " +
"example again to download the file.")
if __name__ == "__main__":
main(sys.argv[1:])
Definition onpremise/build/__init__.py:1
Definition devicedetection_pipelinebuilder.py:1
Definition example_utils.py:1
Definition example_constants.py:1