Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
oee-services
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harshavardhan.c
oee-services
Commits
f85e10e2
Commit
f85e10e2
authored
May 30, 2022
by
harshavardhan.c
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated oee changes pushed to develop
parent
afaf91ef
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
50 deletions
+85
-50
scripts/core/engine/chart_creators.py
scripts/core/engine/chart_creators.py
+4
-5
scripts/core/engine/oee_calculator.py
scripts/core/engine/oee_calculator.py
+12
-8
scripts/core/handlers/batch_oee_calc_handler.py
scripts/core/handlers/batch_oee_calc_handler.py
+63
-3
scripts/db/db_models/__init__.py
scripts/db/db_models/__init__.py
+1
-2
scripts/schemas/batch_oee.py
scripts/schemas/batch_oee.py
+4
-31
scripts/utils/common_utils.py
scripts/utils/common_utils.py
+1
-1
No files found.
scripts/core/engine/chart_creators.py
View file @
f85e10e2
...
...
@@ -3,7 +3,6 @@ from copy import deepcopy
from
scripts.constants.db_connections
import
mongo_client
from
scripts.constants.ui_constants
import
DonutChart
,
BaseWaterChart
from
scripts.db.mongo.ilens_configuration.collections.constants
import
Constants
from
scripts.schemas.batch_oee
import
WaterFallChart
...
...
@@ -11,10 +10,10 @@ class ChartMaker:
def
__init__
(
self
,
project_id
=
None
):
self
.
constants_con
=
Constants
(
mongo_client
=
mongo_client
)
def
main_creator
(
self
,
data
,
activity_length
,
overall
=
True
):
def
main_creator
(
self
,
data
,
overall
=
True
):
chart_data
=
dict
()
chart_data
[
"waterfall"
]
=
self
.
waterfall_chart
(
WaterFallChart
(
**
data
))
return
self
.
donut_chart
(
data
,
chart_data
,
activity_length
,
overall
)
return
self
.
donut_chart
(
data
,
chart_data
,
overall
)
@
staticmethod
def
waterfall_chart
(
data
:
WaterFallChart
):
...
...
@@ -40,7 +39,7 @@ class ChartMaker:
return
waterfall_base
[
"data"
]
@
staticmethod
def
donut_chart
(
data
,
chart_data
,
activity_length
,
overall
:
bool
):
def
donut_chart
(
data
,
chart_data
,
overall
:
bool
):
base
=
DonutChart
.
base
chart_keys
=
DonutChart
.
chart_keys
for
each
in
chart_keys
:
...
...
@@ -65,7 +64,7 @@ class ChartMaker:
for
k
,
v
in
data
.
items
():
if
k
not
in
do_not_display
:
if
k
in
[
"total_units"
,
"good_units"
]
and
not
overall
:
v
=
round
(
v
-
activity_length
,
2
)
v
=
round
(
v
,
2
)
chart_data
.
update
(
{
k
:
dict
(
label
=
k
.
capitalize
()
.
replace
(
"_"
,
" "
),
value
=
v
)
...
...
scripts/core/engine/oee_calculator.py
View file @
f85e10e2
from
datetime
import
datetime
import
pendulum
import
pytz
from
scripts.constants
import
UOM
,
TagCategoryConstants
from
scripts.errors
import
ErrorCodes
from
scripts.logging
import
logger
...
...
@@ -201,7 +204,7 @@ class OEEEngine:
batch_oee
=
BatchOEEData
(
**
request_data
.
dict
(),
calculated_on
=
datetime
.
now
()
.
astimezone
(
tz
=
request_data
.
tz
)
.
isoformat
(),
calculated_on
=
datetime
.
now
()
.
astimezone
(
tz
=
pytz
.
timezone
(
request_data
.
tz
)
)
.
isoformat
(),
productive_time
=
productive_time
,
availability
=
availability
*
100
,
performance
=
performance
*
100
,
...
...
@@ -213,18 +216,19 @@ class OEEEngine:
)
return
batch_oee
except
Exception
:
except
Exception
as
e
:
logger
.
exception
(
f
"Exception occurred while calculating batch oee {e.args}"
)
raise
@
staticmethod
def
get_updated_planned_production_time
(
input_time
,
return_type
):
def
get_updated_planned_production_time
(
input_time
:
pendulum
.
Duration
,
return_type
):
if
return_type
==
"minutes"
:
return
input_time
.
minutes
return
input_time
.
in_minutes
()
elif
return_type
==
"seconds"
:
return
input_time
.
seconds
return
input_time
.
in_seconds
()
elif
return_type
==
"hours"
:
return
input_time
.
hours
return
input_time
.
in_hours
()
elif
return_type
==
"microseconds"
:
return
input_time
.
microseconds
return
input_time
.
total_seconds
()
else
:
return
input_time
.
seconds
return
input_time
.
in_minutes
()
scripts/core/handlers/batch_oee_calc_handler.py
View file @
f85e10e2
import
json
from
datetime
import
datetime
import
pandas
as
pd
import
pytz
from
sqlalchemy.orm
import
Session
from
scripts.constants
import
ResponseCodes
from
scripts.core.engine.oee_calculator
import
OEEEngine
from
scripts.config
import
DBConf
from
scripts.constants
import
ResponseCodes
,
CommonConstants
,
TagCategoryConstants
from
scripts.core.engine.oee_calculator
import
OEEEngine
,
OEETagFinder
from
scripts.core.handlers.tag_handler
import
TagHierarchyHandler
from
scripts.db.psql.oee_discrete
import
DiscreteOEE
from
scripts.db.redis_connections
import
oee_production_db
from
scripts.errors
import
DataNotFound
from
scripts.logging
import
logger
from
scripts.schemas.batch_oee
import
OEEDataInsertRequest
,
BatchOEEData
,
OEEDataSaveRequest
from
scripts.schemas.response_models
import
DefaultResponse
from
scripts.utils.common_utils
import
CommonUtils
from
scripts.utils.kairos_db_util
import
BaseQuery
from
scripts.utils.kairos_db_util.df_formation_util
import
create_kairos_df
from
scripts.utils.kairos_db_util.query_kairos
import
KairosQuery
oee_engine
=
OEEEngine
()
...
...
@@ -20,6 +27,9 @@ class CalculateBatchOEEHandler:
def
__init__
(
self
,
project_id
=
None
):
self
.
common_util
=
CommonUtils
()
self
.
base_query
=
BaseQuery
()
self
.
oee_tag_finder
=
OEETagFinder
()
self
.
tag_hierarchy_handler
=
TagHierarchyHandler
(
project_id
=
project_id
)
def
calculate_oee
(
self
,
db
,
request_data
:
OEEDataInsertRequest
):
table_obj
=
DiscreteOEE
(
db
=
db
)
...
...
@@ -27,12 +37,20 @@ class CalculateBatchOEEHandler:
record_presence
=
table_obj
.
get_oee_data_by_reference_id
(
reference_id
=
request_data
.
reference_id
,
hierarchy
=
request_data
.
hierarchy
,
project_id
=
request_data
.
project_id
)
request_data
.
total_units
,
request_data
.
reject_units
=
self
.
get_data_for_tags
(
input_data
=
request_data
)
redis_key
=
f
"{request_data.project_id}${request_data.reference_id}"
if
not
record_presence
:
if
not
request_data
.
prod_start_time
:
request_data
.
prod_start_time
=
datetime
.
now
()
.
astimezone
(
tz
=
pytz
.
timezone
(
request_data
.
tz
))
.
isoformat
()
else
:
request_data
.
prod_start_time
=
datetime
.
strptime
(
request_data
.
prod_start_time
,
CommonConstants
.
USER_META_TIME_FORMAT
)
.
astimezone
(
tz
=
pytz
.
timezone
(
request_data
.
tz
))
.
isoformat
()
if
request_data
.
prod_end_time
:
request_data
.
prod_end_time
=
datetime
.
strptime
(
request_data
.
prod_end_time
,
CommonConstants
.
USER_META_TIME_FORMAT
)
.
astimezone
(
tz
=
pytz
.
timezone
(
request_data
.
tz
))
.
isoformat
()
request_data
=
OEEDataSaveRequest
(
**
request_data
.
dict
(
exclude_none
=
True
))
request_data
.
downtime
=
self
.
common_util
.
get_downtime_details_by_hierarchy
(
hierarchy
=
request_data
.
hierarchy
,
project_id
=
request_data
.
project_id
)
...
...
@@ -95,3 +113,45 @@ class CalculateBatchOEEHandler:
return
True
except
Exception
as
e
:
raise
e
def
get_data_for_tags
(
self
,
input_data
:
OEEDataInsertRequest
):
total_units_value
=
0
reject_units_value
=
0
try
:
start_epoch
=
int
(
datetime
.
strptime
(
input_data
.
prod_start_time
,
CommonConstants
.
USER_META_TIME_FORMAT
)
.
astimezone
(
tz
=
pytz
.
timezone
(
input_data
.
tz
))
.
timestamp
())
*
1000
end_epoch
=
int
(
datetime
.
strptime
(
input_data
.
prod_end_time
,
CommonConstants
.
USER_META_TIME_FORMAT
)
.
astimezone
(
tz
=
pytz
.
timezone
(
input_data
.
tz
))
.
timestamp
())
*
1000
# hierarchy_tags = self.tag_hierarchy_handler.get_tags_list_by_hierarchy(GetTagsLists(**input_data.dict()))
hierarchy_tags
=
{
TagCategoryConstants
.
TOTAL_UNITS_CATEGORY
:
"site_114$line_1306$equipment_5812$tag_100"
,
TagCategoryConstants
.
REJECT_UNITS_CATEGORY
:
"site_114$line_1306$equipment_5812$tag_60538"
}
total_units_tag_id
=
self
.
oee_tag_finder
.
get_total_units_tag_id
(
input_data
=
hierarchy_tags
)
reject_units_tag_id
=
self
.
oee_tag_finder
.
get_reject_units_tag_id
(
input_data
=
hierarchy_tags
)
kairos_util
=
KairosQuery
(
url
=
DBConf
.
KAIROS_URL
)
data
=
kairos_util
.
query
(
self
.
base_query
.
form_generic_query
(
tags_list
=
[
total_units_tag_id
,
reject_units_tag_id
],
project_id
=
input_data
.
project_id
,
start_epoch
=
start_epoch
,
end_epoch
=
end_epoch
))
master_df
=
pd
.
DataFrame
()
data
=
[
data
]
if
not
isinstance
(
data
,
list
)
else
data
for
each_data
in
data
:
master_df
=
create_kairos_df
(
master_df
=
master_df
,
response_data
=
each_data
,
tags_list
=
[
total_units_tag_id
,
reject_units_tag_id
],
group_by_tags
=
[
total_units_tag_id
,
reject_units_tag_id
,
DBConf
.
KAIROS_DEFAULT_FULL_TAG
],
tz
=
input_data
.
tz
)
if
master_df
.
empty
:
raise
DataNotFound
master_df_columns
=
list
(
master_df
.
columns
)
if
f
'{total_units_tag_id}_diff'
not
in
master_df_columns
:
return
total_units_value
,
reject_units_value
total_units_value
=
master_df
[
f
'{total_units_tag_id}_diff'
]
.
sum
()
if
f
'{reject_units_tag_id}_diff'
in
master_df_columns
:
reject_units_value
=
master_df
[
f
'{reject_units_tag_id}_diff'
]
.
sum
()
return
total_units_value
,
reject_units_value
except
Exception
as
e
:
raise
scripts/db/db_models/__init__.py
View file @
f85e10e2
...
...
@@ -12,8 +12,7 @@ class OEEDiscreteTable(Base):
reference_id
=
Column
(
String
,
nullable
=
True
,
unique
=
True
)
prod_start_time
=
Column
(
TIMESTAMP
(
timezone
=
True
),
nullable
=
False
)
prod_end_time
=
Column
(
TIMESTAMP
(
timezone
=
True
),
nullable
=
True
)
total_downtime
=
Column
(
Float
,
default
=
0
)
planned_units
=
Column
(
Float
,
nullable
=
False
)
downtime
=
Column
(
Float
,
default
=
0
)
total_units
=
Column
(
Float
)
reject_units
=
Column
(
Float
,
default
=
0
)
cycle_time
=
Column
(
Float
)
...
...
scripts/schemas/batch_oee.py
View file @
f85e10e2
...
...
@@ -2,7 +2,6 @@ from typing import Optional, Union, List
from
pydantic
import
BaseModel
,
validator
from
scripts.utils.common_utils
import
CommonUtils
common_utils
=
CommonUtils
()
...
...
@@ -101,7 +100,7 @@ class OEEDataInsertRequest(BaseModel):
prod_status
:
Optional
[
str
]
=
"running"
downtime
:
Optional
[
Union
[
float
,
int
]]
hierarchy
:
str
reference_id
:
str
reference_id
:
Optional
[
str
]
setup_time
:
Optional
[
Union
[
float
,
int
]]
cycle_time
:
Optional
[
Union
[
float
,
int
]]
total_units
:
Optional
[
Union
[
float
,
int
]]
...
...
@@ -143,6 +142,7 @@ class OEEDataInsertRequest(BaseModel):
class
OEEDataSaveRequest
(
BaseModel
):
prod_start_time
:
str
prod_end_time
:
str
prod_status
:
Optional
[
str
]
=
"running"
downtime
:
Optional
[
Union
[
float
,
int
]]
=
0
hierarchy
:
Optional
[
str
]
reference_id
:
Optional
[
str
]
...
...
@@ -152,38 +152,11 @@ class OEEDataSaveRequest(BaseModel):
reject_units
:
Optional
[
Union
[
float
,
int
]]
=
0
uom
:
Optional
[
str
]
=
"mins"
tz
:
Optional
[
str
]
=
'Asia/Kolkata'
trigger_by
:
Optional
[
str
]
project_id
:
str
class
Config
:
schema_extra
=
{
"example"
:
{
"hierarchy"
:
"site_100$dept_100$line_100$equipment_100"
,
"prod_start_time"
:
"2022-04-22 19:49:00"
,
"prod_end_time"
:
"2022-04-22 19:49:00"
,
"tz"
:
"Asia/Kolkata"
,
"project_id"
:
"project_099"
,
"reference_id"
:
"reference_id"
,
"downtime"
:
""
,
"setup_time"
:
""
,
"cycle_time"
:
""
,
"total_units"
:
""
,
"reject_units"
:
""
,
"uom"
:
"'"
}
}
# @validator('prod_start_time')
# def date_format_validator_start_date(cls, v):
# common_utils.check_date_format(v, "%Y-%m-%d %H:%M:%S")
# return v
#
# @validator('prod_end_time')
# def date_format_validator_end_date(cls, v):
# common_utils.check_date_format(v, "%Y-%m-%d %H:%M:%S")
# return v
class
BatchOEEData
(
OEEData
Insert
Request
):
class
BatchOEEData
(
OEEData
Save
Request
):
calculated_on
:
str
productive_time
:
float
availability
:
float
...
...
scripts/utils/common_utils.py
View file @
f85e10e2
...
...
@@ -39,7 +39,7 @@ class CommonUtils:
diff
=
to_time
-
from_time
if
difference
:
return
diff
return
f
"{int(diff.in_hours())} hours {int(diff.
minutes
)} minutes"
return
f
"{int(diff.in_hours())} hours {int(diff.
in_hours()
)} minutes"
except
Exception
as
e
:
logger
.
exception
(
f
"Exception in getting data: {e}"
)
raise
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment