|
2 | 2 | Tools for interacting with the Vuforia Cloud Recognition Web APIs. |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import datetime |
5 | 6 | import io |
6 | | -from typing import Any, Dict, List |
| 7 | +from typing import List, Optional |
7 | 8 | from urllib.parse import urljoin |
8 | 9 |
|
9 | 10 | import requests |
10 | 11 | from urllib3.filepost import encode_multipart_formdata |
11 | 12 | from vws_auth_tools import authorization_header, rfc_1123_date |
12 | 13 |
|
13 | | -from ._result_codes import raise_for_result_code |
14 | | -from .exceptions import ( |
| 14 | +from vws._result_codes import raise_for_result_code |
| 15 | +from vws.exceptions import ( |
15 | 16 | ConnectionErrorPossiblyImageTooLarge, |
16 | 17 | MatchProcessing, |
17 | 18 | MaxNumResultsOutOfRange, |
18 | 19 | ) |
19 | | -from .include_target_data import CloudRecoIncludeTargetData |
| 20 | +from vws.include_target_data import CloudRecoIncludeTargetData |
| 21 | +from vws.reports import QueryResult, TargetData |
20 | 22 |
|
21 | 23 |
|
22 | 24 | class CloudRecoService: |
@@ -46,7 +48,7 @@ def query( |
46 | 48 | max_num_results: int = 1, |
47 | 49 | include_target_data: |
48 | 50 | CloudRecoIncludeTargetData = CloudRecoIncludeTargetData.TOP, |
49 | | - ) -> List[Dict[str, Any]]: |
| 51 | + ) -> List[QueryResult]: |
50 | 52 | """ |
51 | 53 | Use the Vuforia Web Query API to make an Image Recognition Query. |
52 | 54 |
|
@@ -132,4 +134,28 @@ def query( |
132 | 134 | response=response, |
133 | 135 | expected_result_code='Success', |
134 | 136 | ) |
135 | | - return list(response.json()['results']) |
| 137 | + |
| 138 | + result = [] |
| 139 | + result_list = list(response.json()['results']) |
| 140 | + for item in result_list: |
| 141 | + target_data: Optional[TargetData] = None |
| 142 | + if 'target_data' in item: |
| 143 | + target_data_dict = item['target_data'] |
| 144 | + metadata = target_data_dict['application_metadata'] |
| 145 | + timestamp_string = target_data_dict['target_timestamp'] |
| 146 | + target_timestamp = datetime.datetime.utcfromtimestamp( |
| 147 | + timestamp_string, |
| 148 | + ) |
| 149 | + target_data = TargetData( |
| 150 | + name=target_data_dict['name'], |
| 151 | + application_metadata=metadata, |
| 152 | + target_timestamp=target_timestamp, |
| 153 | + ) |
| 154 | + |
| 155 | + query_result = QueryResult( |
| 156 | + target_id=item['target_id'], |
| 157 | + target_data=target_data, |
| 158 | + ) |
| 159 | + |
| 160 | + result.append(query_result) |
| 161 | + return result |
0 commit comments