Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ble labeling #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions app/controller/dataset_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,11 @@ def getDatasetTimeSeriesStartEnd(self, dataset_id, ts_id, project_id, start, end
def append(self, id, project, body, projectId):
dataset = self.dbm.getDatasetById(id, project)
datasetIds = [x["_id"] for x in dataset["timeSeries"]]
sendIds = [ObjectId(x["_id"]) for x in body]
sendIds = [ObjectId(x["_id"]) for x in body["timeSeries"]]
if set(datasetIds) != set(sendIds):
raise HTTPException(status.HTTP_401_UNAUTHORIZED, detail="Authentication failed")


for ts in body:
for ts in body['timeSeries']:
binStore = BinaryStore(ts["_id"])
binStore.loadSeries()
tmpStart, tmpEnd, sampling_rate, length = binStore.append(ts["data"])
Expand All @@ -203,6 +202,35 @@ def append(self, id, project, body, projectId):
dataset["timeSeries"][idx]["end"] = max(oldEnd, tmpEnd) if oldEnd is not None else tmpEnd
dataset["timeSeries"][idx]["length"] = length
dataset["timeSeries"][idx]["samplingRate"] = sampling_rate

labelings = []
for label in body["labels"]:
labeling = next((l for l in labelings if l["labelingId"] == label["labelingId"]), None)
if labeling is None:
labelings.append({"labelingId": label["labelingId"],
"labels": [{
"start": label["start"],
"end": label["end"],
"type": label["labelType"], "metadata": {}
}]})
else:
labeling["labels"].append({
"start": label["start"],
"end": label["end"],
"type": label["labelType"],
"metadata": {}
})

for labeling in labelings:
dataset_labeling = next((l for l in dataset["labelings"] if ObjectId(labeling["labelingId"]) == l["labelingId"]), None)
if dataset_labeling is None:
dataset["labelings"].append(labeling)
elif dataset_labeling["labels"][-1]["end"] == labeling["labels"][0]["start"]:
dataset_labeling["labels"][-1]["end"] = labeling["labels"][0]["start"]
dataset_labeling["labels"].extend(labeling["labels"][1:])
else:
dataset_labeling["labels"].extend(labeling["labels"])

self.dbm.updateDataset(id, project, dataset=dataset)
return

Expand Down