+ create_database()
+ store_info_db(inventory_info)
+
+
+def mock_table(inven_info):
+ current_count = 3
+ labels = "Bottles"
+ total_count = 6
+ inven_info.setcurrentcount(current_count)
+ inven_info.settotalcount(total_count)
+ inven_info.setlabel(labels)
+ inven_info.utime = time.time()
+ # store_data(inven_info)
+ local_store(inven_info)
+
+
+def shelf_inventory(video_capture, camera_info, true=None):
+ """
+ shelf_inventory
+ """
+ global count
+ global mock_func
+
+ labels = "bottles"
+ process_this_frame = 0
+ if mock_func == 1:
+ inven_info = inventory_info()
+ mock_table(inven_info)
+ else:
+ while True:
+ success, frame = video_capture.get_frame()
+ if not success:
+ break
+ if process_this_frame == 0:
+ url = config.detection_url + "/v1/obj_detection/detect"
+ # info1 = cv2.imencode(".jpg", rgb_small_frame)[1].tobytes()
+ data = json.loads(requests.post
+ (url, data=frame,
+ verify=config.ssl_cacertpath).text)
+ inven_info = inventory_info()
+ current_count = data[count]
+ labels = data[labels]
+ total_count = inven_info.current_count + inven_info.total_count
+ inven_info.setcurrentcount(current_count)
+ inven_info.settotalcount(total_count)
+ inven_info.setlabel(labels)
+ inven_info.utime = time.time()
+ # store_data(inven_info)
+ local_store(inven_info)
+
+
+def local_store(inven_info):
+ """
+ store "shelf" data to array
+
+ :param inven_info: Inventry object
+ :return: None
+ """
+ if len(listOfMsgs) >= 100:
+ listOfMsgs.pop()
+ newdict = {"shelfName": inven_info.type, "ObjType": inven_info.labels,
+ "currentCount": inven_info.current_count,
+ "totalCount": inven_info.total_count,
+ "time": time.time()}
+ listOfMsgs.insert(0, newdict)
+
+
+def store_info_db(inven_info):
+ """
+ Send "shelf" data to InfluxDB
+
+ :param inven_info: Inventry object
+ :return: None
+ """
+ global db_client
+ json_body = [
+ {
+ "measurement": inven_info.type,
+ "tags": {
+ "object": "bottles",
+ },
+ "fields": {
+ "time": inven_info.time,
+ "Current Count": inven_info.current_count,
+ "Total Count": inven_info.total_count,
+ }
+ }]
+ db_client.write_points(json_body)
+
+
+def create_database():
+ """
+ Connect to InfluxDB and create the database
+
+ :return: None
+ """
+ global db_client
+# proxy = {"http": "http://{}:{}".format(config.IPADDRESS, config.PORT)}
+# db_client = InfluxDBClient(host=config.IPADDRESS, port=config.PORT,
+# proxies=proxy, database=config.DATABASE_NAME)
+# db_client.create_database(config.DATABASE_NAME)