\r\n

51Degrees Device Detection Python  4.3

Device Detection services for 51Degrees Pipeline

hash/match_metrics.py

This example shows how to access the 'match metrics' assocaited with a result from 51Degrees device detection. Match metrics are various properties that indicate the level of confidence that the supplied evidence corresponds to the result that has been returned.

1 # *********************************************************************
2 # This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 # Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4 # Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5 #
6 # This Original Work is licensed under the European Union Public Licence (EUPL)
7 # v.1.2 and is subject to its terms as set out below.
8 #
9 # If a copy of the EUPL was not distributed with this file, You can obtain
10 # one at https://opensource.org/licenses/EUPL-1.2.
11 #
12 # The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 # amended by the European Commission) shall be deemed incompatible for
14 # the purposes of the Work and the provisions of the compatibility
15 # clause in Article 5 of the EUPL shall not apply.
16 #
17 # If using the Work as, or as part of, a network application, by
18 # including the attribution notice(s) required under Article 5 of the EUPL
19 # in the end user terms of the application under an appropriate heading,
20 # such notice(s) shall fulfill the requirements of that article.
21 # ********************************************************************
22 
23 
28 
29 from fiftyone_devicedetection_onpremise.devicedetection_onpremise_pipelinebuilder import DeviceDetectionOnPremisePipelineBuilder
30 
31 # First create the device detection pipeline with the desired settings.
32 
33 data_file = "fiftyone_devicedetection_onpremise/device-detection-cxx/device-detection-data/51Degrees-LiteV4.1.hash"
34 
35 pipeline = DeviceDetectionOnPremisePipelineBuilder(
36  data_file_path = data_file,
37  licence_keys = "",
38  performance_profile = 'MaxPerformance',
39  auto_update=False).build()
40 
41 # Now we can take a User-Agent and run it through this pipeline
42 
43 # First we create a FlowData object from the pipeline
44 flowdata = pipeline.create_flowdata()
45 
46 # Then we add the User-Agent we are interested in as evidence
47 iphone_ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114"
48 
49 flowdata.evidence.add("header.user-agent", iphone_ua)
50 
51 # Now we process the FlowData using the engines in the Pipeline
52 
53 flowdata.process()
54 
55 # The device detection engine comes with additional metadata about each match
56 
57 if flowdata.device.deviceid.has_value():
58  print('Device ID: ' + str(flowdata.device.deviceID.value()))
59  print("""
60  Consists of four components separated by a hyphen symbol:
61  Hardware-Platform-Browser-IsCrawler where each Component
62  represents an ID of the corresponding Profile.""")
63 
64 if flowdata.device.useragents.has_value():
65  print('Matched useragents: ' + str(flowdata.device.useragents.value()))
66  print("The matched useragents")
67 
68 if flowdata.device.difference.has_value():
69  print('Difference: ' + str(flowdata.device.difference.value()))
70  print("""
71  Used when detection method is not Exact or None.
72  This is an integer value and the larger the value
73  the less confident the detector is in this result.""")
74 
75 if flowdata.device.method.has_value():
76  print('Method: ' + str(flowdata.device.method.value()))
77  print("""Provides information about the algorithm that was used to perform detection for a particular User-Agent.""")
78 
79 if flowdata.device.matchednodes.has_value():
80  print('Method: ' + str(flowdata.device.matchednodes.value()))
81  print("""
82  The number of hash nodes that have been matched before finding a result.""")