Commit 1dd752e0 authored by harshavardhan.c's avatar harshavardhan.c

calculating the downtime based on UOM Type.

parent 289577a1
......@@ -33,15 +33,16 @@ class MachineOEECalculator:
self.data_push = DataPush()
def calculate_machine_oee(self, request_data: MachineOEERequest):
try:
hierarchy_dict = self.common_handler.get_valid_oee_monitoring_hierarchy(project_id=request_data.project_id)
now = datetime.today() - timedelta(days=3)
now = datetime.today() - timedelta(days=1)
oee_start_time = datetime.strptime(request_data.monitor_time, '%H:%M').replace(year=now.year,
month=now.month,
day=now.day).strftime(
CommonConstants.USER_META_TIME_FORMAT)
oee_end_time = datetime.now().astimezone(tz=pytz.timezone(request_data.tz)).strftime(CommonConstants.USER_META_TIME_FORMAT)
curr_end_time = datetime.now().astimezone(tz=pytz.timezone(request_data.tz))
curr_timestamp = int(curr_end_time.timestamp()) * 1000
oee_end_time = curr_end_time.strftime(CommonConstants.USER_META_TIME_FORMAT)
for k, v in hierarchy_dict.items():
site_id = k.split("$")[0]
if not v.get(TagCategoryConstants.OEE_CYCLE_DESIGN_CATEGORY):
......@@ -52,8 +53,9 @@ class MachineOEECalculator:
if isinstance(cycle_time, bool) and not cycle_time:
logger.debug(f"OEE Cycle Design parameter details not found for selected hierarchy")
continue
cal_type = self.common_util.get_uom_type(uom_type=os.environ.get("DEFAULT_UOM_TYPE", default="mins"))
downtime = self.common_util.get_downtime_details_by_hierarchy(
hierarchy=k, project_id=request_data.project_id)
hierarchy=k, project_id=request_data.project_id, uom_type=cal_type)
input_data = OEEDataInsertRequest(prod_start_time=oee_start_time,
prod_end_time=oee_end_time, downtime=downtime,
hierarchy=k, cycle_time=cycle_time,
......@@ -81,7 +83,7 @@ class MachineOEECalculator:
"gw_id": "",
"pd_id": "",
"p_id": request_data.project_id,
"timestamp": int(time.time() * 1000),
"timestamp": curr_timestamp,
"msg_id": 1,
"retain_flag": False
}
......@@ -102,4 +104,6 @@ if __name__ == '__main__':
MachineOEECalculator().calculate_machine_oee(
request_data=MachineOEERequest(project_id=project, monitor_time="00:00",
tz=project_dict.get(project, "Asia/Kolkata")))
time.sleep(10)
sleep_time_in_mins = int(os.environ.get("AUTOMATION_SLEEP_TIME_IN_MINS", default=1))
sleep_time_in_seconds = sleep_time_in_mins * 60
time.sleep(sleep_time_in_seconds)
......@@ -7,7 +7,7 @@ from scripts.constants import Endpoints, ResponseCodes
from scripts.core.handlers.api_handler import APIHandler
from scripts.core.handlers.layout_handler import LayoutHandler
from scripts.db.psql.databases import get_db
from scripts.errors import ILensError
from scripts.errors import ILensError, DataNotFound
from scripts.logging import logger
from scripts.schemas.batch_oee import BatchesGet, ChartRequest
from scripts.schemas.layout import GetLayoutRequest, SaveLayoutRequest
......@@ -47,6 +47,8 @@ async def get_chart_data(request_data: ChartRequest, db: Session = Depends(get_d
status=ResponseCodes.SUCCESS,
message="Chart data fetched successfully",
)
except DataNotFound:
return DefaultResponse(message="Data not Found for selected filters", status="info")
except ILensError as e:
return DefaultResponse(message=e.args[0], status="info")
except Exception as e:
......
......@@ -44,14 +44,15 @@ class CommonUtils:
logger.exception(f"Exception in getting data: {e}")
raise
def get_downtime_details_by_hierarchy(self, hierarchy, project_id, user_id=None):
def get_downtime_details_by_hierarchy(self, hierarchy, project_id, user_id=None, uom_type="minutes"):
connection_obj = ILensRequest(url=PathToServices.downtime_proxy,
project_id=project_id)
try:
cookies = {'login-token': self.create_token(user_id=user_id), "user_id": user_id}
downtime_response = connection_obj.post(path=EndpointConstants.hierarchy_downtime,
json={"project_id": project_id,
"hierarchy": hierarchy})
"hierarchy": hierarchy,
"display_type": uom_type}, cookies=cookies)
response = downtime_response.json()
return response.get("data", 0)
except AuthenticationError:
......
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