Commit 513178d5 authored by Sikhin VC's avatar Sikhin VC

removing mongo dependency

parent 9faa06a5
Pipeline #68894 canceled with stage
import os import os
#os.environ["config"]="{\"TZ\": \"Asia/Kolkata\", \"MONGO_URI\": \"mongodb://svc-ilens:svc2345@192.168.3.220:21017\", \"MONGO_DATABASE\": \"ilens_wps\", \"MONGO_COLLECTION\": \"janusDeployment\", \"MONGO_KEY\": \"deploymentId\", \"MONGO_VALUE\": \"_acc_test_7b5692781\", \"MONGO_COLL\": \"serviceConfiguration\", \"MONGO_DB\": \"ilens_wps\"}" # os.environ["config"]="{\"MONGO_VALUE\": \"jkv1_dba3e4e8\"}"
from edge_engine.edge_processor import ExecutePipeline from edge_engine.edge_processor import ExecutePipeline
from edge_engine.edge_processor import Pubs from edge_engine.edge_processor import Pubs
from scripts import CementBagCounter from scripts import CementBagCounter
......
...@@ -22,38 +22,11 @@ def licence_validator(payload): ...@@ -22,38 +22,11 @@ def licence_validator(payload):
return False return False
def get_config_from_mongo(mongo_uri, dbname, basecollection,
key, value):
mongo = MongoClient(mongo_uri)
db = mongo[dbname]
config = db[basecollection].find_one({key: value}, {"_id": False})
return config
def load_conf(config,mongo_uri, dbname):
mongo = MongoClient(mongo_uri)
db = mongo[dbname]
pub_configs = []
for conf in config['pubConfigs']:
if conf["type"].lower() in ["mqtt","mongo",]:
key= conf["key"]
value=conf["value"]
collection = conf["conectionCollection"]
pub_conf = db[collection].find_one({key: value}, {"_id": False})
pub_conf.update(conf)
pub_configs.append(pub_conf)
else :
pub_configs.append(conf)
config['pubConfigs'] = pub_configs
return config
# """ # """
# { # {
...@@ -81,35 +54,16 @@ CONFIG_ENV = json.loads(os.environ.get('config', default=None)) ...@@ -81,35 +54,16 @@ CONFIG_ENV = json.loads(os.environ.get('config', default=None))
# MONGO_COLLECTION = CONFIG_ENV.get('MONGO_COLLECTION', None) # MONGO_COLLECTION = CONFIG_ENV.get('MONGO_COLLECTION', None)
# MONGO_KEY = CONFIG_ENV.get('MONGO_KEY', None) # MONGO_KEY = CONFIG_ENV.get('MONGO_KEY', None)
DEPLOYMENT_ID = CONFIG_ENV.get('MONGO_VALUE',None) DEPLOYMENT_ID = CONFIG_ENV.get('MONGO_VALUE',None)
#
# if MONGO_URI == None \
# or MONGO_DATABASE is None \
# or MONGO_COLLECTION is None \
# or MONGO_KEY is None \
# or MONGO_VALUE is None:
# sys.stderr.write("invalid mongo config \n")
# sys.exit(1)
#
# EDGE_CONFIG = get_config_from_mongo(
# mongo_uri=MONGO_URI,
# dbname=MONGO_DATABASE, basecollection=MONGO_COLLECTION,
# key=MONGO_KEY, value=MONGO_VALUE
# )
#
# print("edge config1 , : ", EDGE_CONFIG)
# if EDGE_CONFIG is None:
# sys.stderr.write("invalid EDGE_CONFIG config \n")
# sys.exit(1)
#
# EDGE_CONFIG=load_conf(EDGE_CONFIG, mongo_uri=MONGO_URI,
# dbname=MONGO_DATABASE)
# deployment_id = "jkoverlappingremoval_e4958a70" # deployment_id = "jkoverlappingremoval_e4958a70"
# deployment_id = os.environ.get('deployment_id') # deployment_id = os.environ.get('deployment_id')
# print("deployment id", DEPLOYMENT_ID) # print("deployment id", DEPLOYMENT_ID)
url = f'http://192.168.2.228:2325/custom/get_janus?deploymentId={DEPLOYMENT_ID}' url = f'http://192.168.2.228:2325/custom/get_janus?deploymentId={DEPLOYMENT_ID}'
EDGE_CONFIG = requests.get(url).json()["data"] EDGE_CONFIG = requests.get(url).json()["data"]
LAST_COUNT = requests.get(url).json()["latest_count"] LAST_COUNT = requests.get(url).json()["latest_count"]
print("EDGE CONFIG")
print(EDGE_CONFIG)
# print("edge config2 , : ", EDGE_CONFIG) # print("edge config2 , : ", EDGE_CONFIG)
DEVICE_ID = EDGE_CONFIG["deviceId"] DEVICE_ID = EDGE_CONFIG["deviceId"]
DATA_PATH = EDGE_CONFIG["inputConf"].get('dataPath',os.path.join(os.getcwd(), "data".format())) DATA_PATH = EDGE_CONFIG["inputConf"].get('dataPath',os.path.join(os.getcwd(), "data".format()))
......
...@@ -9,18 +9,18 @@ import numpy as np ...@@ -9,18 +9,18 @@ import numpy as np
from edge_engine.ai.model.modelwraper import ModelWrapper from edge_engine.ai.model.modelwraper import ModelWrapper
from edge_engine.common.logsetup import logger from edge_engine.common.logsetup import logger
from expiringdict import ExpiringDict from expiringdict import ExpiringDict
from pymongo import MongoClient from scripts.common.config import MONGO_URI
# from scripts.common.config import MONGO_URI
from scripts.common.constants import JanusDeploymentConstants from scripts.common.constants import JanusDeploymentConstants
from scripts.utils.centroidtracker import CentroidTracker from scripts.utils.centroidtracker import CentroidTracker
from scripts.utils.edge_utils import get_extra_fields # from scripts.utils.edge_utils import get_extra_fields
from scripts.utils.helpers import box_iou2 from scripts.utils.helpers import box_iou2
from scripts.utils.image_utils import draw_circles_on_frame, resize_to_64_64 from scripts.utils.image_utils import draw_circles_on_frame, resize_to_64_64
from scripts.utils.infocenter import MongoLogger from scripts.utils.infocenter import MongoLogger
from scripts.utils.tracker import Tracker from scripts.utils.tracker import Tracker
from scripts.utils.yolov5_trt import YoloV5TRT # from scripts.utils.yolov5_trt import YoloV5TRT
# from sklearn.utils.linear_assignment_ import linear_assignment # from sklearn.utils.linear_assignment_ import linear_assignment
from scipy.optimize import linear_sum_assignment as linear_assignment from scipy.optimize import linear_sum_assignment as linear_assignment
from edge_engine.common.config import EDGE_CONFIG
class CementBagCounter(ModelWrapper): class CementBagCounter(ModelWrapper):
...@@ -34,12 +34,11 @@ class CementBagCounter(ModelWrapper): ...@@ -34,12 +34,11 @@ class CementBagCounter(ModelWrapper):
logger.info(f"Config Received {self.config}") logger.info(f"Config Received {self.config}")
self.device_id = device_id self.device_id = device_id
self.rtp = pubs.rtp_write self.rtp = pubs.rtp_write
self.mongo_logger = MongoLogger()
self.frame_skip = self.config.get('frame_skip', False) self.frame_skip = self.config.get('frame_skip', False)
engine_file_path = "data/jk_v5_cam_42.engine" engine_file_path = "data/jk_v5_cam_42.engine"
self.classes = {0: 'cement_bag'} self.classes = {0: 'cement_bag'}
self.yolo_v5_wrapper = YoloV5TRT(engine_file_path, model_config.get('conf_thresh', 0.7), # self.yolo_v5_wrapper = YoloV5TRT(engine_file_path, model_config.get('conf_thresh', 0.7),
model_config.get('iou_thresh', 0.15)) # model_config.get('iou_thresh', 0.15))
# TRT Additions stop # TRT Additions stop
...@@ -57,8 +56,7 @@ class CementBagCounter(ModelWrapper): ...@@ -57,8 +56,7 @@ class CementBagCounter(ModelWrapper):
self.uncounted_objects = ExpiringDict(max_len=model_config.get("uncounted_obj_length", 50), self.uncounted_objects = ExpiringDict(max_len=model_config.get("uncounted_obj_length", 50),
max_age_seconds=model_config.get("uncounted_obj_age", 60)) max_age_seconds=model_config.get("uncounted_obj_age", 60))
self.janus_metadata = ExpiringDict(max_age_seconds=120, max_len=1) self.janus_metadata = ExpiringDict(max_age_seconds=120, max_len=1)
# self.mongo_alarm_coll = MongoClient(MONGO_URI)['ilens_events']['triggered_alarms'] # self.camera_details = EDGE_CONFIG[self.device_id]
self.camera_details = self.mongo_logger.get_camera_details(self.device_id)
self.frame_count = 0 self.frame_count = 0
self.frame = None self.frame = None
self.centroid_distance = 10 self.centroid_distance = 10
...@@ -240,7 +238,7 @@ class CementBagCounter(ModelWrapper): ...@@ -240,7 +238,7 @@ class CementBagCounter(ModelWrapper):
Get the line coordinates from the deployment JSON Get the line coordinates from the deployment JSON
""" """
if not self.janus_metadata.get('metadata'): if not self.janus_metadata.get('metadata'):
self.janus_metadata['metadata'] = get_extra_fields(self.device_id) self.janus_metadata['metadata'] = EDGE_CONFIG["extra_fields"]
_coordinates = [self.janus_metadata['metadata'].get(coordinate_key) for coordinate_key in _coordinates = [self.janus_metadata['metadata'].get(coordinate_key) for coordinate_key in
JanusDeploymentConstants.LINE_COORDINATES] JanusDeploymentConstants.LINE_COORDINATES]
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -2,7 +2,6 @@ import os ...@@ -2,7 +2,6 @@ import os
import sys import sys
import json import json
from pymongo import MongoClient
MAIN_OS_VARIABLE = json.loads(os.environ.get('config')) MAIN_OS_VARIABLE = json.loads(os.environ.get('config'))
if MAIN_OS_VARIABLE is None: if MAIN_OS_VARIABLE is None:
...@@ -14,8 +13,3 @@ MONGO_URI = MAIN_OS_VARIABLE.get('MONGO_URI') ...@@ -14,8 +13,3 @@ MONGO_URI = MAIN_OS_VARIABLE.get('MONGO_URI')
MONGO_SERVICE_DB = MAIN_OS_VARIABLE.get('MONGO_DB') MONGO_SERVICE_DB = MAIN_OS_VARIABLE.get('MONGO_DB')
MONGO_SERVICE_COLL = MAIN_OS_VARIABLE.get('MONGO_COLL') MONGO_SERVICE_COLL = MAIN_OS_VARIABLE.get('MONGO_COLL')
PASS_KEY = MAIN_OS_VARIABLE.get('PASS_KEY') PASS_KEY = MAIN_OS_VARIABLE.get('PASS_KEY')
MONGO_DB_OBJ = MongoClient(MONGO_URI)[MONGO_SERVICE_DB]
HOST_CONFIG = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'hostConfig'}).get('config')
APP_MONGO_COLLECTION = MONGO_DB_OBJ[MONGO_SERVICE_COLL].find_one({'configId': 'appMongoConfig'}).get('config')
from scripts.common.constants import JanusDeploymentConstants # from scripts.common.constants import JanusDeploymentConstants
from scripts.common.config import MONGO_DB_OBJ, APP_MONGO_COLLECTION #
# import cv2
import cv2 #
# from edge_engine.common.logsetup import logger
from edge_engine.common.logsetup import logger # #from scripts.common.config import MONGO_DB_OBJ, APP_MONGO_COLLECTION
#from scripts.common.config import MONGO_DB_OBJ, APP_MONGO_COLLECTION # #from scripts.common.constants import JanusDeploymentConstants
#from scripts.common.constants import JanusDeploymentConstants #
#
# class Utilities:
class Utilities: #
# @classmethod
@classmethod # def get_extra_fields(
def get_extra_fields( # cls,
cls, # device_id,
device_id, # ):
): # _janus_deployment = MONGO_DB_OBJ[
_janus_deployment = MONGO_DB_OBJ[ # APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)].find_one(
APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)].find_one( # {JanusDeploymentConstants.DEPLOYMENT_ID: device_id}).get(
{JanusDeploymentConstants.DEPLOYMENT_ID: device_id}).get( # JanusDeploymentConstants.EXTRA_FIELDS_KEY)
JanusDeploymentConstants.EXTRA_FIELDS_KEY) # if _janus_deployment is None:
if _janus_deployment is None: # raise ValueError("Janus deployment configuration is not found/corrupted")
raise ValueError("Janus deployment configuration is not found/corrupted") #
# _key_dictionary = dict()
_key_dictionary = dict() # for each_field in _janus_deployment:
for each_field in _janus_deployment: # _key_dictionary[each_field['key']] = each_field['value']
_key_dictionary[each_field['key']] = each_field['value'] # return _key_dictionary
return _key_dictionary #
# @classmethod
@classmethod # def get_direction(
def get_direction( # cls,
cls, # device_id,
device_id, # ):
): # logger.debug("Getting the direction from DB")
logger.debug("Getting the direction from DB") # return MONGO_DB_OBJ[APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)].find_one(
return MONGO_DB_OBJ[APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)].find_one( # {JanusDeploymentConstants.DEPLOYMENT_ID: device_id}).get(
{JanusDeploymentConstants.DEPLOYMENT_ID: device_id}).get( # JanusDeploymentConstants.DIRECTION_KEY)
JanusDeploymentConstants.DIRECTION_KEY) #
# @classmethod
@classmethod # def set_direction(
def set_direction( # cls,
cls, # device_id: str,
device_id: str, # direction: bool,
direction: bool, # ):
): # logger.debug("Updating the direction in DB")
logger.debug("Updating the direction in DB") # updated_values = {"$set": {JanusDeploymentConstants.DIRECTION_KEY: direction}}
updated_values = {"$set": {JanusDeploymentConstants.DIRECTION_KEY: direction}} # MONGO_DB_OBJ[APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)].update_one(
MONGO_DB_OBJ[APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)].update_one( # {JanusDeploymentConstants.DEPLOYMENT_ID: device_id}, updated_values)
{JanusDeploymentConstants.DEPLOYMENT_ID: device_id}, updated_values) #
# @classmethod
@classmethod # def draw_circles_on_frame(
def draw_circles_on_frame( # cls,
cls, # frame,
frame, # point,
point, # radius=3,
radius=3, # color=(255, 255, 255),
color=(255, 255, 255), # thickness=1,
thickness=1, # ):
): # """
""" # draw circle on the objects
draw circle on the objects # :param radius: radius of the circle
:param radius: radius of the circle # :param frame: frame to draw on
:param frame: frame to draw on # :param point: co-ordinate to draw on
:param point: co-ordinate to draw on # :param color: color of the circle
:param color: color of the circle # :param thickness: thickness of the circle
:param thickness: thickness of the circle # :return: frame
:return: frame # """
""" # return cv2.circle(frame, tuple(point), radius, color, thickness)
return cv2.circle(frame, tuple(point), radius, color, thickness) #
# @classmethod
@classmethod # def resize_to_64_64(
def resize_to_64_64( # cls,
cls, # frame,
frame, # ):
): # """
""" # resize the from
resize the from # :param frame: frame
:param frame: frame # :return: frame
:return: frame # """
""" # return cv2.resize(frame, (64, 64))
return cv2.resize(frame, (64, 64)) #
#
# def get_extra_fields(device_id):
def get_extra_fields(device_id): # # _janus_deployment = [
# _janus_deployment = [ # # {
# { # # "type": "number",
# "type": "number", # # "key": "x1",
# "key": "x1", # # "value": 1000
# "value": 1000 # # },
# }, # # {
# { # # "type": "number",
# "type": "number", # # "key": "y1",
# "key": "y1", # # "value": 0
# "value": 0 # # },
# }, # # {
# { # # "type": "number",
# "type": "number", # # "key": "x2",
# "key": "x2", # # "value": 1001
# "value": 1001 # # },
# }, # # {
# { # # "type": "number",
# "type": "number", # # "key": "y2",
# "key": "y2", # # "value": 720
# "value": 720 # # },
# }, # # {
# { # # "type": "dropdown",
# "type": "dropdown", # # "key": "alignment",
# "key": "alignment", # # "value": "vertical"
# "value": "vertical" # # }
# } # # ]
# ] # _janus_deployment = MONGO_DB_OBJ[APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)]. \
_janus_deployment = MONGO_DB_OBJ[APP_MONGO_COLLECTION.get(JanusDeploymentConstants.JANUS_DEPLOYMENT_COLLECTION)]. \ # find_one({JanusDeploymentConstants.DEPLOYMENT_ID: device_id}).get(JanusDeploymentConstants.EXTRA_FIELDS_KEY)
find_one({JanusDeploymentConstants.DEPLOYMENT_ID: device_id}).get(JanusDeploymentConstants.EXTRA_FIELDS_KEY) #
# if _janus_deployment is None:
if _janus_deployment is None: # raise ValueError("Janus deployment configuration is not found/corrupted")
raise ValueError("Janus deployment configuration is not found/corrupted") #
# _key_dictionary = dict()
_key_dictionary = dict() # for each_field in _janus_deployment:
for each_field in _janus_deployment: # _key_dictionary[each_field['key']] = each_field['value']
_key_dictionary[each_field['key']] = each_field['value'] # return _key_dictionary
return _key_dictionary
...@@ -9,7 +9,7 @@ from scripts.utils.ilens_request_handler import post ...@@ -9,7 +9,7 @@ from scripts.utils.ilens_request_handler import post
from uuid import uuid1 from uuid import uuid1
from urllib.parse import urljoin from urllib.parse import urljoin
from edge_engine.common.logsetup import logger from edge_engine.common.logsetup import logger
from scripts.common.config import MONGO_DB_OBJ, APP_MONGO_COLLECTION
class MongoLogger: class MongoLogger:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment