Skip to content

Commit ab995ea

Browse files
authored
Merge pull request #30 from ATNoG/hotfix/none_values_on_query
Fixed FluxTable to raw conversion
2 parents 63377b5 + 4c798b0 commit ab995ea

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

src/routers/v1/raw_router.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,27 @@ def get_raw_data(
2222
limited to a maximum of 50 per request.
2323
"""
2424
try:
25+
import sys
2526
query_params = {
2627
"start_time": start_time,
2728
"end_time": end_time,
2829
"cell_index": cell_index,
2930
"batch_number": batch_number,
3031
}
32+
print(f"API called with: start={start_time}, end={end_time}, cell={cell_index}"); sys.stdout.flush()
3133

3234
results,has_next = Influx.service.query_raw_data(**query_params)
35+
print(f"Router got {len(results)} results"); sys.stdout.flush()
36+
37+
with_data = [r for r in results if r.get('mean_latency')]
38+
print(f"Rows with data: {len(with_data)}"); sys.stdout.flush()
3339

3440
for row in results:
3541
for k, v in row.items():
3642
if isinstance(v, datetime):
3743
row[k] = v.isoformat()
3844

45+
print(f"Returning {len(results)} results"); sys.stdout.flush()
3946
return {"data": results, "has_next": has_next}
4047

4148
except Exception as e:

src/services/influx.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from posix import times
2+
from influxdb_client.client.flux_table import FluxRecord, FluxTable
13
from influxdb_client.client.influxdb_client import InfluxDBClient
24
from influxdb_client.client.write_api import ASYNCHRONOUS
35
from src.configs.influx_conf import InfluxConf
46
from src.models.raw import Raw, RAW_MEASUREMENT
57
from src.services.influx_query import QueryIF
8+
import logging
9+
10+
logger = logging.getLogger(__name__)
611

712
class InfluxService:
813
def __init__(self) -> None:
@@ -32,15 +37,28 @@ def query_raw_data(self, start_time: int, end_time: int, cell_index: int, batch_
3237
limit=_LIMIT+1,
3338
offset=offset
3439
)
35-
36-
result = self.query_api.query(query)
37-
40+
print(query)
41+
result:list[FluxTable] = self.query_api.query(query)
42+
print(result)
3843
# Convert FluxTable to list of dicts
39-
rows = []
44+
rows = {}
45+
table:FluxTable
46+
record:FluxRecord
4047
for table in result:
4148
for record in table.records:
42-
rows.append(record.values)
43-
49+
timestamp = record.get_time()
50+
if timestamp not in rows:
51+
rows[timestamp] = {k: v for k, v in record.values.items() if not k.startswith('_')}
52+
rows[timestamp]["timestamp"] = timestamp
53+
for col in record.values.keys():
54+
if col.startswith('_'):
55+
rows[timestamp][col] = None
56+
57+
field = record.get_field()
58+
value = record.get_value()
59+
rows[timestamp][field] = value
60+
61+
rows = list(rows.values())
4462
return rows, len(rows)>_LIMIT
4563

4664

0 commit comments

Comments
 (0)