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

Sample for customizing start time #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions analytics/common/rec2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from configuration import env
import requests
import os
import datetime

office=list(map(float,env["OFFICE"].split(",")))
sthost=env["STHOST"]
Expand All @@ -15,7 +16,7 @@ def __init__(self, sensor):
self._sensor = sensor
self._last_file = None
self._requests=requests.Session()

def on_created(self, event):
print("on_created: "+event.src_path, flush=True)
if event.is_directory: return
Expand All @@ -29,9 +30,17 @@ def on_created(self, event):
self._last_file = event.src_path

def _process_file(self, filename):

video_base = 1008235783042570420
# Real base 1638326863379333614
# Filename example: '/tmp/rec/5ocgc30BswPB8WWEg2ml/2021/11/30/1638314060090100076_239493104.mp4'
file_offset=int(os.path.splitext(os.path.basename(filename))[0].split('_')[-1])
custom_time = str(int((file_offset + video_base)/1000000))
print("filename is {}, time is {}".format(filename, custom_time))
with open(filename,"rb") as fd:
r=self._requests.post(sthost,data={
"time":str(int(int(os.path.basename(filename).split('_')[-2])/1000000)),
"time": custom_time,
"orig_time":str(int(int(os.path.basename(filename).split('_')[-2])/1000000)),
"office":str(office[0])+","+str(office[1]),
"sensor":self._sensor,
},files={
Expand Down
13 changes: 8 additions & 5 deletions analytics/common/runva.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _test_mqtt_connection(self):
time.sleep(5)
print("mqtt connected", flush=True)
mqtt.disconnect()

def __init__(self, pipeline, version="2", stop=Event()):
super(RunVA, self).__init__()
self._test_mqtt_connection()
Expand Down Expand Up @@ -62,13 +62,16 @@ def loop(self, sensor, location, uri, algorithm, algorithmName, options={}, topi
"topic": topic
}
tags={
"sensor": sensor,
"location": location,
"sensor": sensor,
"location": location,
"algorithm": algorithmName,
"office": {
"lat": office[0],
"lat": office[0],
"lon": office[1]
},
# Setting a custom time, this can be passed in like sensor, location etc
"custom_start_time": 1008235783042570420

}
parameters = {
"inference-interval": every_nth_frame,
Expand All @@ -93,7 +96,7 @@ def loop(self, sensor, location, uri, algorithm, algorithmName, options={}, topi

if status.state.stopped():
print("Pipeline {} Version {} Instance {} Ended with {}".format(
self._pipeline, self._version, instance_id, status.state.name),
self._pipeline, self._version, instance_id, status.state.name),
flush=True)
break

Expand Down
11 changes: 10 additions & 1 deletion analytics/mqtt2db/mqtt2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,18 @@ def on_message(self, client, userdata, message):
r.update(r["tags"])
del r["tags"]

if ("time" not in r) and ("real_base" in r) and ("timestamp" in r):
print(r)

if ("time" not in r) and ("real_base" in r) and ("timestamp" in r):
real_base=r["real_base"] if "real_base" in r else 0
r["time"] = int((real_base + r["timestamp"]) / 1000000)
print("time based on real_base={}".format(r['time']))

if ("custom_start_time" in r) and ("timestamp" in r):
video_base = r["custom_start_time"] if "custom_start_time" in r else 0
r["time"] = int((video_base + r["timestamp"]) / 1000000)
print("time based on custom_start_time={}".format(r['time']))


if "objects" in r and scenario == "traffic":
r["nobjects"] = int(len(r["objects"]))
Expand Down