Commit be52d2ce authored by hemanthkumar.pasham's avatar hemanthkumar.pasham

Adding oee services

parent 15ccf0a8
...@@ -18,6 +18,11 @@ class Endpoints: ...@@ -18,6 +18,11 @@ class Endpoints:
api_hierarchy = "/hierarchy" api_hierarchy = "/hierarchy"
hierarchy_api = 'ilens_config/get_site_level_hierarchy' hierarchy_api = 'ilens_config/get_site_level_hierarchy'
#OEE SERVICES
oee_services="/oee"
oee_services="/oee_post"
class StatusCodes: class StatusCodes:
SUCCESS = [200, 201, 204] SUCCESS = [200, 201, 204]
......
from scripts.logging import logger
from scripts.utils.mongo_util import MongoCollectionBaseClass
from scripts.constants.db_connections import mongo_client
class Oee_services:
def __init__(self):
try:
self.connect = MongoCollectionBaseClass(mongo_client=mongo_client, database="ilens_configuration",
collection="oee_tag_mapping")
except Exception as e:
logger.exception("Error while connecting to mongodb")
async def oee_tag_mapping(self, oee_tag_mapping_list):
try:
return_json = {"message": "failure", "status": "failure", "message": "data not inserted in to mongodb"}
insert_json = {"hierarchy": oee_tag_mapping_list.get("hierarchy", ""),
"project_id": oee_tag_mapping_list.get("project_id", ""),
"meta": oee_tag_mapping_list.get("project_id", ""),
"oee_tag_mapping": oee_tag_mapping_list.get("oee_tag_mapping", {})
}
result = self.connect.insert_one(data=insert_json)
if result:
logger.info("Data inserted in to mongodb successfully")
return_json["message"] = "success"
return_json["status"] = "success"
else:
logger.info("Unable to insert data in to Mongodb")
except Exception as e:
logger.exception("Error occured while inserting data")
return return_json
async def get_oee_tag_mapping(self, get_oee_tag, ):
try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {'project_id': get_oee_tag.get("project_id", "")}
skips = get_oee_tag.get("page_size") * (get_oee_tag("page_num") - 1)
no_of_documents = self.connect.count_documents(query=query)
result = self.connect.find(query=query).skip(skips).limit(get_oee_tag.get("page_num"))
if result:
return_json["message"] = "success"
return_json["status"] = "success"
return_json["data"] = result
return_json["total_records"] = no_of_documents
if skips < no_of_documents:
return_json["endOfrecords"] = False
else:
return_json["endOfrecords"] = True
except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}")
return result
async def delete_oee_tags(self, project_id):
try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {"project_id": project_id}
result = self.connect.delete_one(query=query)
if result:
return_json["message"] = "success"
return_json["status"] = "success"
return_json["data"] = result
except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}")
return result
async def update_oee_tags(self, update_oee_tags):
try:
return_json = {"message": "failure", "status": "failure", "data": "data not found"}
query = {"project_id": update_oee_tags['projec_id']}
result = self.connect.update_one(query=query, data=return_json)
if result:
return_json["message"] = "success"
return_json["status"] = "success"
return_json["data"] = result
except Exception as e:
logger.exception(f"Exception occured while fetching data as {e}")
return return_json
...@@ -144,3 +144,10 @@ class GetOEERequestOneBatch(BaseModel): ...@@ -144,3 +144,10 @@ class GetOEERequestOneBatch(BaseModel):
class GetBatches(GetOEERequest): class GetBatches(GetOEERequest):
pass pass
class GetOeeServices(BaseModel):
hierarchy: str
project_id: str
meta: dict
oee_tag_mapping: str
from fastapi import APIRouter
from scripts.logging import logger
from scripts.constants import Endpoints
from scripts.schemas.batch_oee import GetOeeServices
from scripts.core.handlers import oee_handlers
oee_services = APIRouter(prefix=Endpoints.oee_services, tags=["OEE Calculator"])
@oee_services.post(Endpoints.oee_services)
async def oee_tag_mapping(oee_tag_mapping_list: GetOeeServices):
try:
tag_mapping = oee_tag_mapping_list.dict()
result = oee_handlers.Oee_services.oee_tag_mapping(tag_mapping)
except Exception as e:
logger.exception("Exception occured while inserting data")
return result
@oee_services.post(Endpoints.oee_services)
async def get_oee_tag_mapping(get_oee_tags: GetOeeServices):
try:
get_oee_tags = get_oee_tags.dict()
return_json = oee_handlers.Oee_services.get_oee_tag_mapping(get_oee_tags)
except Exception as e:
logger.exception(f"Error while getting information as {e}")
return return_json
@oee_services.post(Endpoints.oee_services)
async def delete_oee_tagging(delete_oee_tags: GetOeeServices):
try:
delete_oee_tags = delete_oee_tags.dict()
return_json = oee_handlers.Oee_services.delete_oee_tags(projec_id=delete_oee_tags["project_id"])
except Exception as e:
logger.exception(f"Error while getting information as {e}")
return return_json
@oee_services.post(Endpoints.oee_services)
async def updaye_oee_tagging(update_oee_tags: GetOeeServices):
try:
update_oee_tags = update_oee_tags.dict()
return_json = oee_handlers.Oee_services.update_oee_services(update_oee_tags)
except Exception as e:
logger.exception(f"Error while getting information as {e}")
return return_json
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