Insert datapoints
Validates and pushes datapoints into task queue, so they are processed by one of DP3 workers.
Source code in dp3/api/routers/root.py
| @router.post(DATAPOINTS_INGESTION_URL_PATH, tags=["Data ingestion"])
def insert_datapoints(dps: list[DataPoint], request: Request) -> SuccessResponse:
"""Insert datapoints
Validates and pushes datapoints into task queue, so they are processed by one of DP3 workers.
"""
# Convert to DP3 datapoints
# This should not fail as all datapoints are already validated
dp3_dps = [api_to_dp3_datapoint(dp.model_dump()) for dp in dps]
# Group datapoints by etype-eid
tasks_dps = defaultdict(list)
for dp in dp3_dps:
key = (dp.etype, dp.eid)
tasks_dps[key].append(dp)
# Create tasks
tasks = []
with task_context(MODEL_SPEC):
for k in tasks_dps:
etype, eid = k
# This shouldn't fail either
tasks.append(DataPointTask(etype=etype, eid=eid, data_points=tasks_dps[k]))
# Push tasks to task queue
for task in tasks:
TASK_WRITER.put_task(task, False)
# Log datapoints
DP_LOGGER.log_good(dp3_dps, src=request.client.host)
return SuccessResponse()
|