brynq-sdk-brynq 1.0.1__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of brynq-sdk-brynq might be problematic. Click here for more details.
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/PKG-INFO +1 -1
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk/brynq/brynq.py +38 -32
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/PKG-INFO +1 -1
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/setup.py +1 -1
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk/brynq/__init__.py +0 -0
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/SOURCES.txt +0 -0
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/not-zip-safe +0 -0
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/requires.txt +0 -0
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/top_level.txt +0 -0
- {brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/setup.cfg +0 -0
|
@@ -2,7 +2,7 @@ import os
|
|
|
2
2
|
import requests
|
|
3
3
|
import json
|
|
4
4
|
import pandas as pd
|
|
5
|
-
from typing import Union
|
|
5
|
+
from typing import Union, Literal
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class BrynQ:
|
|
@@ -26,55 +26,61 @@ class BrynQ:
|
|
|
26
26
|
'Domain': self.subdomain
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
def _get_mappings(self,
|
|
29
|
+
def _get_mappings(self, data_interface_id: int) -> dict:
|
|
30
30
|
"""
|
|
31
31
|
Get the mappings from the task in BrynQ
|
|
32
|
-
:param
|
|
32
|
+
:param data_interface_id: The id of the data_interface in BrynQ. this does not have to be the task id of the current task
|
|
33
33
|
:return: A dictionary with the following structure: {mapping_title: {tuple(input): output}}
|
|
34
34
|
"""
|
|
35
|
-
response = requests.get(url=f'{self.url}interfaces/{
|
|
36
|
-
|
|
35
|
+
response = requests.get(url=f'{self.url}interfaces/{data_interface_id}/data-mapping', headers=self._get_headers())
|
|
37
36
|
if response.status_code != 200:
|
|
38
37
|
raise ValueError(f'Error occurred while fetching mappings: {response.text}. Please always check if you have added BRYNQ_SUBDOMAIN to your .env file')
|
|
39
38
|
|
|
40
39
|
return response.json()
|
|
41
40
|
|
|
42
|
-
def get_mapping(self,
|
|
41
|
+
def get_mapping(self, data_interface_id: int, mapping: str, return_format: Literal['input_as_key', 'columns_names_as_keys', 'nested_input_output'] = 'input_as_key') -> dict:
|
|
43
42
|
"""
|
|
44
43
|
Get the mapping json from the mappings
|
|
45
|
-
:param
|
|
44
|
+
:param data_interface_id: The id of the task in BrynQ. this does not have to be the task id of the current task
|
|
46
45
|
:param mapping: The name of the mapping
|
|
47
|
-
:param
|
|
46
|
+
:param return_format: Determines how the mapping should be returned. Options are 'input_as_key' (Default, the input column is the key, the output columns are the values), 'columns_names_as_keys', 'nested_input_output'
|
|
48
47
|
:return: The json of the mapping
|
|
49
48
|
"""
|
|
50
49
|
# Find the mapping for the given sheet name
|
|
51
|
-
mappings = self._get_mappings(
|
|
50
|
+
mappings = self._get_mappings(data_interface_id=data_interface_id)
|
|
52
51
|
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
53
52
|
if not mapping_data:
|
|
54
53
|
raise ValueError(f"Mapping named '{mapping}' not found")
|
|
55
54
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
# If the user want to get the column names back as keys, transform the data accordingly and return
|
|
56
|
+
if return_format == 'columns_names_as_keys':
|
|
57
|
+
final_mapping = []
|
|
58
|
+
for row in mapping_data['values']:
|
|
59
|
+
combined_dict = {}
|
|
60
|
+
combined_dict.update(row['input'])
|
|
61
|
+
combined_dict.update(row['output'])
|
|
62
|
+
final_mapping.append(combined_dict)
|
|
63
|
+
elif return_format == 'nested_input_output':
|
|
64
|
+
final_mapping = mapping_data
|
|
65
|
+
else:
|
|
66
|
+
final_mapping = {}
|
|
67
|
+
for value in mapping_data['values']:
|
|
68
|
+
input_values = []
|
|
69
|
+
output_values = []
|
|
70
|
+
for _, val in value['input'].items():
|
|
71
|
+
input_values.append(val)
|
|
72
|
+
for _, val in value['output'].items():
|
|
73
|
+
output_values.append(val)
|
|
74
|
+
# Detect if there are multiple input or output columns and concatenate them
|
|
75
|
+
if len(value['input'].items()) > 1 or len(value['output'].items()) > 1:
|
|
76
|
+
concatenated_input = ','.join(input_values)
|
|
77
|
+
concatenated_output = ','.join(output_values)
|
|
78
|
+
final_mapping[concatenated_input] = concatenated_output
|
|
79
|
+
else: # Default to assuming there's only one key-value pair if not concatenating
|
|
80
|
+
final_mapping[input_values[0]] = output_values[0]
|
|
81
|
+
return final_mapping
|
|
82
|
+
|
|
83
|
+
def get_mapping_as_dataframe(self, data_interface_id: int, mapping: str, prefix: bool = False):
|
|
78
84
|
"""
|
|
79
85
|
Get the mapping dataframe from the mappings
|
|
80
86
|
:param mapping: The name of the mapping
|
|
@@ -82,7 +88,7 @@ class BrynQ:
|
|
|
82
88
|
:return: The dataframe of the mapping
|
|
83
89
|
"""
|
|
84
90
|
# Find the mapping for the given sheet name
|
|
85
|
-
mappings = self._get_mappings(
|
|
91
|
+
mappings = self._get_mappings(data_interface_id=data_interface_id)
|
|
86
92
|
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
87
93
|
if not mapping_data:
|
|
88
94
|
raise ValueError(f"Mapping named '{mapping}' not found")
|
|
File without changes
|
|
File without changes
|
{brynq_sdk_brynq-1.0.1 → brynq_sdk_brynq-1.1.0}/brynq_sdk_brynq.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|