Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Commit

Permalink
Recording state (#331)
Browse files Browse the repository at this point in the history
* upload recording and set processing state

* updated api doc for track metadata
  • Loading branch information
GP authored Sep 27, 2020
1 parent 2ff85a9 commit 19ec5eb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ language: node_js
node_js:
- "lts/*"

python:
python:
- "3.6.1"

install:
Expand All @@ -16,6 +16,7 @@ install:
- npm install -g eslint
- sudo apt update
- sudo apt install python3-pip
- sudo apt-get install python3-setuptools
- python3 -m pip install -r test/requirements.txt
- docker-compose build
- docker-compose up --force-recreate &> dockerstart.log &
Expand Down
43 changes: 43 additions & 0 deletions api/V1/Recording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,40 @@ import config from "../../config";
export default (app: Application, baseUrl: string) => {
const apiUrl = `${baseUrl}/recordings`;

/**
* @apiDefine RecordingMetaData
*
* @apiParam {JSON} data[metadata] recording tracks and predictions:
*<ul>
* <li>(REQUIRED) tracks - array of track JSON, each track should have
* <ul>
* <li> positions - array of track positions
* a position is (time in seconds, [left, top, bottom, right])
* e.g. "positions":[[0.78,[6,3,16,13]],[0.89,[6,3,16,13]]
* <li> start_s - start time of track in seconds
* <li> end_s - end time of track in seconds
* <li>(OPTIONAL) confident_tag - if present create a track tag from this
* <li>(OPTIONAL) confidence - confidence of the tag
* <li>(OPTIONAL) all_class_confidences - dictionary of confidence per class
* </ul>
* <li> algorithm(OPTIONAL) - dictionary describing algorithm, model_name should be present
*</ul>
* @apiParamExample {JSON} Example recording track metadata:
* {
* "algorithm"{
* "model_name": "resnet-wallaby"
* },
* "tracks"{
* "start_s": 10,
* "end_s": 22.2,
* "confident_tag": "rodent",
* "all_class_confidences": {"rodent": 0.9, "else": 0.1},
* "confidence": 0.9,
*
* }
* }
*/

/**
* @apiDefine RecordingParams
*
Expand All @@ -50,6 +84,7 @@ export default (app: Application, baseUrl: string) => {
* <li>airplaneModeOn
* <li>additionalMetadata
* <li>comment
* <li>processingState - Initial processing state to set recording at
* </ul>
* @apiParam {File} file Recording file to upload
*/
Expand All @@ -65,6 +100,8 @@ export default (app: Application, baseUrl: string) => {
*
* @apiUse RecordingParams
*
* @apiUse RecordingMetaData
*
* @apiUse V1ResponseSuccess
* @apiSuccess {Number} recordingId ID of the recording.
* @apiuse V1ResponseError
Expand All @@ -87,6 +124,8 @@ export default (app: Application, baseUrl: string) => {
*
* @apiUse RecordingParams
*
* @apiUse RecordingMetaData
*
* @apiUse V1ResponseSuccess
* @apiSuccess {Number} recordingId ID of the recording.
* @apiuse V1ResponseError
Expand Down Expand Up @@ -116,6 +155,8 @@ export default (app: Application, baseUrl: string) => {
*
* @apiUse RecordingParams
*
* @apiUse RecordingMetaData
*
* @apiUse V1ResponseSuccess
* @apiSuccess {Number} recordingId ID of the recording.
* @apiuse V1ResponseError
Expand Down Expand Up @@ -159,6 +200,8 @@ export default (app: Application, baseUrl: string) => {
*
* @apiUse RecordingParams
*
* @apiUse RecordingMetaData
*
* @apiUse V1ResponseSuccess
* @apiSuccess {Number} recordingId ID of the recording.
* @apiuse V1ResponseError
Expand Down
10 changes: 7 additions & 3 deletions api/V1/recordingUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ function makeUploadHandler(mungeData?: (any) => any) {
if (data.metadata) {
await tracksFromMeta(recording, data.metadata);
}
recording.processingState = models.Recording.uploadedState(
data.type as RecordingType
);
if (data.processingState){
recording.processingState = data.processingState;
}else{
recording.processingState = models.Recording.uploadedState(
data.type as RecordingType
);
}
return recording;
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ python-dateutil
requests-toolbelt
pytest
attrs~=18.2.0
black
black~=20.8b1
6 changes: 3 additions & 3 deletions test/test_device_cacophony_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setup_class(cls):
"foo": "bar",
"analysis": {
"cacophony_index": [
{"end_s": 20, "begin_s": 0, "index_percent": hour + (day * 24)},
{"end_s": 20, "begin_s": 0, "index_percent": hour + (day * 24)}
]
},
},
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_get_cacophony_index(self, helper):
now_minus_twelve_hours = js_iso_format_with_utc(now - timedelta(hours=12))
print(f"Get cacophony index from 12 hours ago ({now_minus_twelve_hours}), going back 12 hours")
cacophony_index_from_twelve_hours_ago = johnny.get_cacophony_index_for_device(
self.get_device(), now_minus_twelve_hours, 12,
self.get_device(), now_minus_twelve_hours, 12
)
assert cacophony_index_from_twelve_hours_ago["cacophonyIndex"] == 17.5

Expand All @@ -104,7 +104,7 @@ def test_get_cacophony_index_histogram(self, helper):

now = self.now()
cacophony_index_from_twelve_hours_ago = johnny.get_cacophony_index_histogram_for_device(
self.get_device(), js_iso_format_with_utc(now - timedelta(hours=12)), 12,
self.get_device(), js_iso_format_with_utc(now - timedelta(hours=12)), 12
)
assert len(cacophony_index_from_twelve_hours_ago["cacophonyIndex"]) == 12

Expand Down
8 changes: 8 additions & 0 deletions test/test_file_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def test_thermal_video_with_meta(self, helper, file_processing):
assert track_tag["confidence"] == track_meta["confidence"]
assert track_tag["data"]["name"] == metadata["algorithm"]["model_name"]

# can upload meta data and mark as processed
self.process_all_recordings(file_processing)
props["processingState"] = "FINISHED"
processed_rec = helper.given_a_recording(self, props=props)
check_recording(user, processed_rec, processingState="FINISHED")
recording = file_processing.get("thermalRaw", "getMetadata")
assert recording is None

def test_metadata_update(self, helper, file_processing):
user = helper.admin_user()
helper.given_a_recording(self)
Expand Down

0 comments on commit 19ec5eb

Please sign in to comment.