sarapy 2.2.0__py3-none-any.whl → 2.3.0__py3-none-any.whl

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.
@@ -1,125 +0,0 @@
1
- from dateutil import parser
2
-
3
-
4
- """
5
- En 'estructura_datos' se registra cuantos bits se ocupan para cada dato.
6
- Por ejemplo, los primeros 6 bits para anio, los siguientes 4 para mes y asi.
7
- """
8
-
9
- estructura_datos = {
10
- "anio": 6,
11
- "mes": 4,
12
- "dia": 5,
13
- "hora": 5,
14
- "minutos": 6,
15
- "segundos": 6,
16
- "operacion": 16,
17
- "PT": 2,
18
- "FR": 2,
19
- "OR": 2,
20
- "MO": 2,
21
- "TLM_NPDP": 64,
22
- "TLM_GPDP": 16,
23
- "ID_NPDP": -1,
24
- "ID_OPRR": -1,
25
- "ID_GPDP": -1,
26
- "ID_CDLL": -1,
27
- "size_GNSS": 16,
28
- "Latitud": 32,
29
- "Longitud": 32,
30
- "Precision": 32,
31
- } # Agregar mas campos segun sea necesario
32
-
33
-
34
- def extraer_bits(trama, inicio, n_bits):
35
- try:
36
- byte_index = inicio // 8
37
- bit_offset = inicio % 8
38
-
39
- valor = 0
40
- bits_procesados = 0
41
- while bits_procesados < n_bits:
42
- byte_actual = trama[byte_index]
43
- bits_restantes = n_bits - bits_procesados
44
- bits_a_extraer = min(bits_restantes, 8 - bit_offset)
45
-
46
- mascara = (1 << bits_a_extraer) - 1
47
- bits_extraidos = (byte_actual >> (8 - bit_offset - bits_a_extraer)) & mascara
48
-
49
- valor = (valor << bits_a_extraer) | bits_extraidos
50
-
51
- bits_procesados += bits_a_extraer
52
- byte_index += 1
53
- bit_offset = 0
54
-
55
- return valor
56
- except IndexError as ex:
57
- raise ex
58
- except Exception as ex:
59
- print(f"Error inesperado en extraer_bits: {ex}")
60
- raise ex
61
-
62
-
63
- def process_dynamic_id(trama, inicio):
64
- # Lee el primer byte para determinar la longitud del ID
65
- longitud_id_bytes = extraer_bits(trama, inicio, 8) # 8 bits = 1 byte
66
- inicio += 8 # Avanza el indice de inicio 8 bits para pasar al contenido del ID
67
-
68
- # Ahora, extrae el ID basandose en la longitud obtenida
69
- id_value = extraer_bits(trama, inicio, longitud_id_bytes * 8) # Convierte la longitud a bits
70
- inicio += longitud_id_bytes * 8 # Avanza el indice de inicio para pasar al final del ID
71
-
72
- return id_value, inicio
73
-
74
-
75
- def process_data(trama):
76
-
77
- if not isinstance(trama, bytes):
78
- raise ValueError("La trama debe ser un bytearray")
79
-
80
- inicio = 0
81
- resultado = {}
82
- for campo, n_bits in estructura_datos.items():
83
- try:
84
- if n_bits == -1: # Verifica si el campo es dinamico
85
- resultado[campo], inicio = process_dynamic_id(trama, inicio)
86
- else:
87
- if campo == "TLM_NPDP" or campo == "TLM_GPDP":
88
- resultado[campo] = trama[inicio // 8: (inicio + n_bits) // 8]
89
- else:
90
- resultado[campo] = extraer_bits(trama, inicio, n_bits)
91
- inicio += n_bits
92
- if campo == "Precision":
93
- # Suponiendo que size_GNSS sigue inmediatamente despues de Precision
94
- raw = trama[inicio // 8: (inicio // 8 ) + resultado["size_GNSS"] - 12]
95
- resultado["RAW"] = raw
96
- except IndexError as ex:
97
- print(f"Error al procesar campo {campo}: {ex}. Posiblemente la trama es mas corta de lo esperado.")
98
- break # Salir del bucle en caso de un error de indice
99
- except Exception as ex:
100
- print(f"Error inesperado al procesar campo {campo}: {ex}")
101
- break # Salir del bucle en caso de errores inesperados
102
-
103
- if len(set(estructura_datos.keys()) - set(resultado.keys())) == 0:
104
-
105
- anio = 2020 + resultado["anio"]
106
- mes = str(resultado["mes"]).zfill(2)
107
- dia = str(resultado["dia"]).zfill(2)
108
- hora = str(resultado["hora"]).zfill(2)
109
- minutos = str(resultado["minutos"]).zfill(2)
110
- segundos = str(resultado["segundos"]).zfill(2)
111
- resultado["date_oprc"] = parser.parse(f"{anio}-{mes}-{dia}T{hora}:{minutos}:{segundos}+00:00")
112
-
113
- resultado["Latitud"] = (resultado["Latitud"] - 2 ** 32) / 10 ** 7
114
- resultado["Longitud"] = (resultado["Longitud"] - 2 ** 32) / 10 ** 7
115
-
116
- del resultado["anio"]
117
- del resultado["mes"]
118
- del resultado["dia"]
119
- del resultado["hora"]
120
- del resultado["minutos"]
121
- del resultado["segundos"]
122
- del resultado["size_GNSS"]
123
-
124
- return resultado
125
-
sarapy/utils/amg_ppk.py DELETED
@@ -1,38 +0,0 @@
1
- from base64 import b64decode
2
-
3
- from sarapy.utils import amg_decoder
4
-
5
-
6
- def main(hash_table, ppk_data):
7
-
8
- ppk_results = []
9
-
10
- for hash_table_entry_values in hash_table.values():
11
-
12
- try:
13
-
14
- serialized_datum = hash_table_entry_values["serialized_datum"]
15
- raw_datum = bytes(b64decode(serialized_datum.encode("utf-8"))) # 'trama'
16
- datum = amg_decoder.process_data(raw_datum)
17
-
18
- if datum:
19
-
20
- longitude, latitude, accuracy = "", "", 0 # ToDo: PPK (Fernando)
21
-
22
- if longitude:
23
- datum["Longitud"] = longitude
24
- if latitude:
25
- datum["Latitud"] = latitude
26
- if accuracy != 0:
27
- datum["Precision"] = accuracy
28
-
29
- ppk_results.append({
30
- "id_db_dw": hash_table_entry_values["id_db_dw"],
31
- "id_db_h": hash_table_entry_values["id_db_h"],
32
- **datum
33
- })
34
-
35
- except Exception as ex:
36
- print(ex)
37
-
38
- return ppk_results
@@ -1,20 +0,0 @@
1
- import pandas as pd
2
- from sarapy.utils import amg_ppk
3
- import os
4
- def getRawOperations(data, historical_data):
5
- """
6
- Args:
7
- data_file: Lista de diccionarios con la data
8
- historical_data_file: Lista de diccionarios con historical_data
9
-
10
- Returns the raw operations from the database.
11
- """
12
- hash_table = {}
13
- for datum in data:
14
- hash_table[datum["timestamp"]] = {"id_db_dw": datum["id"], "id_db_h": 0, "serialized_datum": ""}
15
- for historical_datum in historical_data:
16
- if historical_datum["timestamp"] in hash_table:
17
- hash_table[historical_datum["timestamp"]].update({"id_db_h": historical_datum["id"], "serialized_datum": historical_datum["datum"]})
18
- ppk_results = amg_ppk.main(hash_table, []) # ToDo: PPK (Fernando)
19
-
20
- return ppk_results
File without changes