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
9c8c4d96
Commit
9c8c4d96
authored
Jun 01, 2022
by
harshavardhan.c
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
automatic machine calculating of oee.
parent
12236604
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
257 additions
and
168 deletions
+257
-168
scripts/constants/__init__.py
scripts/constants/__init__.py
+13
-0
scripts/core/handlers/batch_oee_calc_handler.py
scripts/core/handlers/batch_oee_calc_handler.py
+5
-3
scripts/core/handlers/common_handler.py
scripts/core/handlers/common_handler.py
+66
-0
scripts/core/handlers/form_handler.py
scripts/core/handlers/form_handler.py
+0
-150
scripts/core/handlers/tag_handler.py
scripts/core/handlers/tag_handler.py
+27
-6
scripts/db/mongo/ilens_configuration/aggregations/tag_hierarchy.py
...b/mongo/ilens_configuration/aggregations/tag_hierarchy.py
+115
-2
scripts/db/mongo/ilens_configuration/collections/lookup_table.py
.../db/mongo/ilens_configuration/collections/lookup_table.py
+1
-1
scripts/db/mongo/schema/tag_hierarchy.py
scripts/db/mongo/schema/tag_hierarchy.py
+17
-0
scripts/schemas/batch_oee.py
scripts/schemas/batch_oee.py
+6
-0
scripts/services/oee_services.py
scripts/services/oee_services.py
+7
-6
No files found.
scripts/constants/__init__.py
View file @
9c8c4d96
...
@@ -73,6 +73,7 @@ class DBConstants:
...
@@ -73,6 +73,7 @@ class DBConstants:
collection_constants
=
"constants"
collection_constants
=
"constants"
collection_tag_hierarchy
=
"tag_hierarchy"
collection_tag_hierarchy
=
"tag_hierarchy"
collection_oee_layouts
=
"oee_layouts"
collection_oee_layouts
=
"oee_layouts"
collection_lookup_table
=
"lookup_table"
class
EndpointConstants
:
class
EndpointConstants
:
...
@@ -82,6 +83,18 @@ class EndpointConstants:
...
@@ -82,6 +83,18 @@ class EndpointConstants:
class
TagCategoryConstants
:
class
TagCategoryConstants
:
TOTAL_UNITS_CATEGORY
=
os
.
environ
.
get
(
"TOTAL_UNITS_CATEGORY"
,
default
=
"OEE - Total Produced Units"
)
TOTAL_UNITS_CATEGORY
=
os
.
environ
.
get
(
"TOTAL_UNITS_CATEGORY"
,
default
=
"OEE - Total Produced Units"
)
REJECT_UNITS_CATEGORY
=
os
.
environ
.
get
(
"TOTAL_UNITS_CATEGORY"
,
default
=
"OEE - Reject Units"
)
REJECT_UNITS_CATEGORY
=
os
.
environ
.
get
(
"TOTAL_UNITS_CATEGORY"
,
default
=
"OEE - Reject Units"
)
OEE_OUTPUT_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_CATEGORY"
,
default
=
"OEE Output Category"
)
OEE_OUTPUT_PERFORMANCE_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_PERFORMANCE_CATEGORY"
,
default
=
"OEE Output Performance Category"
)
OEE_OUTPUT_QUALITY_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_QUALITY_CATEGORY"
,
default
=
"OEE Output Quality Category"
)
OEE_OUTPUT_AVAILABILITY_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_AVAILABILITY_CATEGORY"
,
default
=
"OEE Output Availability Category"
)
OEE_OUTPUT_PERFORMANCE_LOSS_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_PERFORMANCE_CATEGORY"
,
default
=
"OEE Output Performance Loss Category"
)
OEE_OUTPUT_QUALITY_LOSS_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_QUALITY_LOSS_CATEGORY"
,
default
=
"OEE Output Quality Loss Category"
)
OEE_OUTPUT_AVAILABILITY_LOSS_CATEGORY
=
os
.
environ
.
get
(
"OEE_OUTPUT_AVAILABILITY_LOSS_CATEGORY"
,
default
=
"OEE Output Availability Loss Category"
)
class
CommonConstants
:
class
CommonConstants
:
...
...
scripts/core/handlers/batch_oee_calc_handler.py
View file @
9c8c4d96
...
@@ -9,6 +9,7 @@ from scripts.config import DBConf
...
@@ -9,6 +9,7 @@ from scripts.config import DBConf
from
scripts.constants
import
ResponseCodes
,
CommonConstants
,
TagCategoryConstants
from
scripts.constants
import
ResponseCodes
,
CommonConstants
,
TagCategoryConstants
from
scripts.core.engine.oee_calculator
import
OEEEngine
,
OEETagFinder
from
scripts.core.engine.oee_calculator
import
OEEEngine
,
OEETagFinder
from
scripts.core.handlers.tag_handler
import
TagHierarchyHandler
from
scripts.core.handlers.tag_handler
import
TagHierarchyHandler
from
scripts.db.mongo.schema.tag_hierarchy
import
GetTagsLists
from
scripts.db.psql.oee_discrete
import
DiscreteOEE
from
scripts.db.psql.oee_discrete
import
DiscreteOEE
from
scripts.db.redis_connections
import
oee_production_db
from
scripts.db.redis_connections
import
oee_production_db
from
scripts.errors
import
DataNotFound
from
scripts.errors
import
DataNotFound
...
@@ -125,9 +126,9 @@ class CalculateBatchOEEHandler:
...
@@ -125,9 +126,9 @@ class CalculateBatchOEEHandler:
end_epoch
=
int
(
end_epoch
=
int
(
datetime
.
strptime
(
input_data
.
prod_end_time
,
CommonConstants
.
USER_META_TIME_FORMAT
)
.
astimezone
(
datetime
.
strptime
(
input_data
.
prod_end_time
,
CommonConstants
.
USER_META_TIME_FORMAT
)
.
astimezone
(
tz
=
pytz
.
timezone
(
input_data
.
tz
))
.
timestamp
())
*
1000
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
=
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"
,
#
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"
}
#
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
)
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
)
reject_units_tag_id
=
self
.
oee_tag_finder
.
get_reject_units_tag_id
(
input_data
=
hierarchy_tags
)
kairos_util
=
KairosQuery
(
url
=
DBConf
.
KAIROS_URL
)
kairos_util
=
KairosQuery
(
url
=
DBConf
.
KAIROS_URL
)
...
@@ -155,4 +156,5 @@ class CalculateBatchOEEHandler:
...
@@ -155,4 +156,5 @@ class CalculateBatchOEEHandler:
reject_units_value
=
master_df
[
f
'{reject_units_tag_id}_diff'
]
.
sum
()
reject_units_value
=
master_df
[
f
'{reject_units_tag_id}_diff'
]
.
sum
()
return
total_units_value
,
reject_units_value
return
total_units_value
,
reject_units_value
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
exception
(
f
'Exception occurred while fetching tag details{e.args}'
)
raise
raise
scripts/core/handlers/common_handler.py
0 → 100644
View file @
9c8c4d96
import
os
from
scripts.constants
import
TagCategoryConstants
from
scripts.constants.db_connections
import
mongo_client
from
scripts.core.handlers.tag_handler
import
TagHierarchyHandler
from
scripts.db.mongo.ilens_configuration.collections.lookup_table
import
LookupTable
from
scripts.db.mongo.schema.tag_hierarchy
import
OutputTagsList
from
scripts.logging
import
logger
class
CommonHandler
:
def
__init__
(
self
,
project_id
=
None
):
self
.
lookup_table
=
LookupTable
(
project_id
=
project_id
,
mongo_client
=
mongo_client
)
self
.
tag_hierarchy_handler
=
TagHierarchyHandler
(
project_id
=
project_id
)
def
fetch_oee_hierarchy_from_look_up
(
self
,
project_id
):
oee_lookup_name
=
os
.
environ
.
get
(
"OEE_LOOKUP_NAME"
,
default
=
"oee_monitoring"
)
try
:
lookup_data
=
self
.
lookup_table
.
map_lookup_keys
(
lookup_name
=
oee_lookup_name
,
project_id
=
project_id
)
if
not
lookup_data
:
logger
.
debug
(
f
"Lookup details not found for OEE"
)
return
{}
return
lookup_data
except
Exception
as
e
:
logger
.
exception
(
f
"Failed to fetch hierarchy details from lookup {e.args}"
)
return
{}
def
get_valid_oee_monitoring_hierarchy
(
self
,
project_id
):
valid_hierarchies_dict
=
{}
try
:
oee_lookup_dict
=
self
.
fetch_oee_hierarchy_from_look_up
(
project_id
=
project_id
)
hierarchy_list
=
list
(
oee_lookup_dict
.
values
())
if
not
hierarchy_list
:
logger
.
debug
(
f
'Hierarchy details not found for the project {project_id} for OEE Monitoring!!!!'
)
return
{}
tags_dict_by_hierarchy
=
self
.
tag_hierarchy_handler
.
get_output_tags_for_oee
(
OutputTagsList
(
project_id
=
project_id
,
hierarchy_list
=
hierarchy_list
))
for
each_hierarchy
in
tags_dict_by_hierarchy
:
if
not
tags_dict_by_hierarchy
.
get
(
each_hierarchy
):
logger
.
debug
(
f
'Tag details not found for the hierarchy {each_hierarchy} for OEE Monitoring!!!!'
)
continue
updated_dict
=
self
.
validate_hierarchy_tags
(
tags_dict_by_hierarchy
[
each_hierarchy
])
if
not
updated_dict
:
continue
valid_hierarchies_dict
.
update
({
each_hierarchy
:
updated_dict
})
return
valid_hierarchies_dict
except
Exception
as
e
:
logger
.
exception
(
f
"Exception Occurred while fetching hierarchy details for monitoring oee {e.args}"
)
return
{}
@
staticmethod
def
validate_hierarchy_tags
(
request_dict
:
dict
):
hierarchy_dict
=
{}
category_constants_list
=
[
v
for
k
,
v
in
TagCategoryConstants
.
__dict__
.
items
()
if
not
k
.
startswith
(
"__"
)]
try
:
for
_each_tag
in
category_constants_list
:
if
_each_tag
in
{
TagCategoryConstants
.
TOTAL_UNITS_CATEGORY
,
TagCategoryConstants
.
REJECT_UNITS_CATEGORY
}:
continue
if
not
request_dict
.
get
(
_each_tag
):
logger
.
debug
(
f
"OEE Output Tag not configured for the hierarchy{list(request_dict.keys())[0]}"
)
return
{}
hierarchy_dict
.
update
({
_each_tag
:
request_dict
[
_each_tag
]})
return
hierarchy_dict
except
Exception
as
e
:
logger
.
exception
(
f
'Exception Occurred while validating the tags for a hierarchy {e.args}'
)
return
{}
scripts/core/handlers/form_handler.py
deleted
100644 → 0
View file @
12236604
from
datetime
import
datetime
import
pandas
as
pd
import
pytz
from
sqlalchemy
import
create_engine
from
scripts.config
import
DBConf
from
scripts.config
import
Metadata
from
scripts.core.engine.automation_engine
import
AutomationEngine
from
scripts.core.handlers.batch_oee_calc_handler
import
CalculateBatchOEEHandler
,
OEEDataInsertRequest
from
scripts.db.mongo.dbs.siam_oee
import
SiamOEE
from
scripts.db_layer.job_table
import
JobTable
from
scripts.logging.logging
import
logger
as
logging
from
scripts.models.db_models
import
JobTable
as
JobSkeleton
from
scripts.schemas.form
import
(
GetRDBValues
,
CustomQuery
,
StartProductionRequest
,
EndProductionRequest
,
StartProdJobModel
,
EndProdJobModel
,
CalculateOEE
,
FormSaveRequest
,
FormDetails
,
EndProdJobDB
)
from
scripts.utils.common_utils
import
CommonUtils
class
FormHandler
:
def
__init__
(
self
):
self
.
oee_mongo
=
SiamOEE
()
self
.
automation_engine
=
AutomationEngine
()
@
staticmethod
async
def
fetch_last_values
(
request_data
:
GetRDBValues
):
try
:
base_engine
=
create_engine
(
f
"{DBConf.CLIENT_URI}{request_data.db_name}"
)
query
=
f
"SELECT * from {request_data.table_name}"
if
request_data
.
primary_conditions
:
query
+=
" WHERE "
for
column
,
val
in
request_data
.
primary_conditions
.
items
():
query
+=
f
"{column}='{val}'"
query
+=
" LIMIT 1"
table_data_df
=
pd
.
read_sql
(
query
,
base_engine
)
del
base_engine
table_data_df
.
rename
(
columns
=
request_data
.
column_to_property
,
inplace
=
True
)
return
table_data_df
.
to_dict
(
orient
=
"records"
)[
0
]
except
Exception
as
e
:
logging
.
exception
(
e
)
@
staticmethod
async
def
custom_query_fetch
(
request_data
:
CustomQuery
):
try
:
base_engine
=
create_engine
(
f
"{DBConf.CLIENT_URI}{request_data.db_name}"
)
table_data_df
=
pd
.
read_sql
(
request_data
.
query
,
base_engine
)
del
base_engine
table_data_df
.
rename
(
columns
=
request_data
.
column_to_property
,
inplace
=
True
)
automation_eng
=
AutomationEngine
()
current_time
=
datetime
.
now
()
abs_start_time
=
automation_eng
.
get_absolute_start_time
(
button_click_time
=
current_time
)
erp_table_data
=
table_data_df
.
to_dict
(
orient
=
"records"
)[
0
]
erp_table_data
.
update
({
"start_time"
:
abs_start_time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M"
)
})
return
erp_table_data
except
Exception
as
e
:
logging
.
exception
(
e
)
async
def
start_production
(
self
,
request_data
:
StartProductionRequest
,
db_session
):
try
:
table_data
=
JobTable
(
db_session
)
request_data
.
submitted_data
.
update
(
tz
=
request_data
.
tz
)
job_model
=
StartProdJobModel
(
**
request_data
.
submitted_data
.
get
(
"data"
,
{}))
job_data
=
job_model
.
dict
(
exclude_none
=
True
)
job_data
.
pop
(
"tz"
,
None
)
row_data
=
JobSkeleton
(
**
job_data
)
table_data
.
add_data
(
row_data
)
# TODO: Create mongo record with job details
job_data
.
update
(
form_details
=
FormDetails
(
**
request_data
.
dict
())
.
dict
(),
prod_status
=
"started"
)
self
.
oee_mongo
.
update_oee
(
job_data
,
job_model
.
job
,
job_model
.
uf_process
)
except
Exception
as
e
:
logging
.
exception
(
e
)
async
def
end_production
(
self
,
request_data
:
EndProductionRequest
,
db_session
,
request_cookies
):
try
:
table_data
=
JobTable
(
db_session
)
job_model
,
db_data
=
await
self
.
get_job_data
(
request_data
)
table_data
.
update_record
(
job_model
.
job
,
job_model
.
uf_process
,
db_data
.
dict
(
exclude_none
=
True
))
calculate_oee_payload
=
CalculateOEE
(
batch_start_time
=
job_model
.
prod_start_time
,
batch_end_time
=
job_model
.
prod_end_time
,
batch_id
=
job_model
.
job
,
setup_time
=
job_model
.
setup_time
,
cycle_time
=
job_model
.
cycle_time
,
total_units
=
job_model
.
qty_released
)
calculate_oee_payload
.
downtime
=
await
self
.
get_oee_downtime
(
request_data
.
submitted_data
[
"data"
],
job_model
.
prod_end_time
,
job_model
.
tz
)
_
=
await
CalculateBatchOEEHandler
()
.
calculate_oee
(
db_session
,
OEEDataInsertRequest
(
**
calculate_oee_payload
.
dict
()))
form_response
=
await
self
.
save_to_form
(
request_data
,
request_cookies
,
job_model
)
logging
.
info
(
f
"FORM SAVE RESPONSE, {form_response}"
)
return
"Form values updated successfully"
except
Exception
as
e
:
logging
.
exception
(
e
)
return
f
"Server encountered an error during op: {e}"
async
def
get_job_data
(
self
,
request_data
:
EndProductionRequest
):
request_data
.
submitted_data
.
update
(
tz
=
request_data
.
tz
)
form_data
=
request_data
.
submitted_data
.
get
(
"data"
,
{})
job
=
form_data
.
get
(
"job"
)
uf_process
=
form_data
.
get
(
"uf_process"
)
data_from_mongo
=
self
.
oee_mongo
.
find_record
(
job
,
uf_process
)
form_data
.
update
(
data_from_mongo
)
job_model
=
EndProdJobModel
(
**
form_data
)
if
not
job_model
.
setup_time
:
job_model
.
setup_time
=
0
if
data_from_mongo
.
get
(
"units_produced"
):
job_model
.
qty_released
=
data_from_mongo
.
get
(
"units_produced"
)
db_data
=
EndProdJobDB
(
**
job_model
.
dict
())
return
job_model
,
db_data
async
def
save_to_form
(
self
,
request_data
:
EndProductionRequest
,
request_cookies
,
job_model
:
EndProdJobModel
):
end_date_time
=
datetime
.
fromtimestamp
(
job_model
.
prod_end_time
//
1000
,
tz
=
pytz
.
timezone
(
request_data
.
tz
))
end_str
=
end_date_time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M"
)
start_date_time
=
datetime
.
fromtimestamp
(
job_model
.
prod_start_time
//
1000
,
tz
=
pytz
.
timezone
(
request_data
.
tz
))
start_str
=
start_date_time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M"
)
tag_data
=
self
.
automation_engine
.
get_all_tags
(
end_date_time
)
tag_data
.
update
(
**
job_model
.
dict
(
exclude_none
=
True
))
form_save_payload
=
FormSaveRequest
(
**
request_data
.
dict
())
form_save_payload
.
submitted_data
[
"data"
]
.
update
(
**
tag_data
)
form_save_payload
.
submitted_data
[
"data"
]
.
update
(
end_time
=
end_str
,
start_time
=
start_str
)
form_response
=
await
CommonUtils
.
hit_external_service
(
api_url
=
f
"{Metadata.FORM_API}render/form?save=True"
,
payload
=
form_save_payload
.
dict
(),
request_cookies
=
request_cookies
)
form_save_payload
.
submitted_data
[
"data"
]
.
update
({
"prod_status"
:
"completed"
})
self
.
oee_mongo
.
update_oee
(
form_save_payload
.
submitted_data
[
"data"
],
job_model
.
job
,
job_model
.
uf_process
)
return
form_response
async
def
get_oee_downtime
(
self
,
data
,
end_time
,
tz
):
if
isinstance
(
end_time
,
int
):
end_time
=
datetime
.
fromtimestamp
(
end_time
//
1000
,
tz
=
pytz
.
timezone
(
tz
))
run_start_time
=
data
.
get
(
"start_time"
)
if
not
data
.
get
(
"run_start_time"
)
else
data
.
get
(
"run_start_time"
)
if
isinstance
(
run_start_time
,
int
):
run_start_time
=
datetime
.
fromtimestamp
(
run_start_time
//
1000
,
tz
=
pytz
.
timezone
(
tz
))
else
:
run_start_time
=
datetime
.
strptime
(
run_start_time
,
"
%
Y-
%
m-
%
d
%
H:
%
M"
)
run_start_time
=
run_start_time
.
replace
(
tzinfo
=
pytz
.
timezone
(
tz
))
return
self
.
automation_engine
.
get_downtime
(
run_start_time
,
end_time
)
scripts/core/handlers/tag_handler.py
View file @
9c8c4d96
import
re
from
scripts.constants.db_connections
import
mongo_client
from
scripts.constants.db_connections
import
mongo_client
from
scripts.db.mongo.ilens_configuration.aggregations.tag_hierarchy
import
TagHierarchyAggregate
from
scripts.db.mongo.ilens_configuration.aggregations.tag_hierarchy
import
TagHierarchyAggregate
from
scripts.db.mongo.ilens_configuration.collections.tag_hierarchy
import
TagHierarchy
from
scripts.db.mongo.ilens_configuration.collections.tag_hierarchy
import
TagHierarchy
from
scripts.db.mongo.schema.tag_hierarchy
import
GetTagsLists
from
scripts.db.mongo.schema.tag_hierarchy
import
GetTagsLists
,
OutputTagsList
from
scripts.logging
import
logger
class
TagHierarchyHandler
:
class
TagHierarchyHandler
:
...
@@ -11,9 +14,27 @@ class TagHierarchyHandler:
...
@@ -11,9 +14,27 @@ class TagHierarchyHandler:
def
get_tags_list_by_hierarchy
(
self
,
input_data
:
GetTagsLists
):
def
get_tags_list_by_hierarchy
(
self
,
input_data
:
GetTagsLists
):
try
:
try
:
aggregate_query
=
TagHierarchyAggregate
.
tag_aggregate
(
project_id
=
input_data
.
project_id
,
aggregate_query
=
TagHierarchyAggregate
.
tag_aggregate
(
project_id
=
input_data
.
project_id
,
hierarchy_id
=
input_data
.
hierarchy
)
hierarchy_id
=
re
.
escape
(
f
'{input_data.hierarchy}$tag'
))
tag_lists
=
self
.
tag_hierarchy_conn
.
get_tag_hierarchy_by_aggregate
(
query
=
aggregate_query
)
tags_list
=
self
.
tag_hierarchy_conn
.
get_tag_hierarchy_by_aggregate
(
query
=
aggregate_query
)
tag_lists
=
tag_lists
[
0
]
if
tag_lists
else
{}
tags_list
=
tags_list
[
0
]
if
tags_list
else
{}
return
tag_lists
return
tags_list
except
Exception
:
except
Exception
as
e
:
logger
.
exception
(
f
"failed to fetch tags_list by hierarchy {e.args}"
)
raise
def
get_output_tags_for_oee
(
self
,
input_data
:
OutputTagsList
):
try
:
if
input_data
.
hierarchy_list
:
hierarchy_str
=
re
.
escape
(
"|"
.
join
([
f
'{_each}$tag'
for
_each
in
input_data
.
hierarchy_list
]))
elif
input_data
.
hierarchy_level
:
hierarchy_str
=
input_data
.
hierarchy_level
else
:
return
{}
aggregate_query
=
TagHierarchyAggregate
.
tag_aggregate_by_hierarchy_list
(
project_id
=
input_data
.
project_id
,
hierarchy_str
=
hierarchy_str
)
tags_list
=
self
.
tag_hierarchy_conn
.
get_tag_hierarchy_by_aggregate
(
query
=
aggregate_query
)
tags_list
=
tags_list
[
0
]
if
tags_list
else
{}
return
tags_list
except
Exception
as
e
:
logger
.
exception
(
f
"failed to fetch output tags list by hierarchy {e.args}"
)
raise
raise
scripts/db/mongo/ilens_configuration/aggregations/tag_hierarchy.py
View file @
9c8c4d96
...
@@ -6,7 +6,7 @@ class TagHierarchyAggregate:
...
@@ -6,7 +6,7 @@ class TagHierarchyAggregate:
'$match'
:
{
'$match'
:
{
'project_id'
:
project_id
,
'project_id'
:
project_id
,
'id'
:
{
'id'
:
{
'$regex'
:
f
'{hierarchy_id}
\\
$tag
'
'$regex'
:
f
'{hierarchy_id}'
}
}
}
}
},
{
},
{
...
@@ -25,7 +25,7 @@ class TagHierarchyAggregate:
...
@@ -25,7 +25,7 @@ class TagHierarchyAggregate:
'_id'
:
None
,
'_id'
:
None
,
'data'
:
{
'data'
:
{
'$push'
:
{
'$push'
:
{
'k'
:
'$tag_category.tag_category_name'
,
'k'
:
{
'$ifNull'
:
[
'$tag_category.tag_category_name'
,
""
]}
,
'v'
:
'$id'
'v'
:
'$id'
}
}
}
}
...
@@ -39,3 +39,116 @@ class TagHierarchyAggregate:
...
@@ -39,3 +39,116 @@ class TagHierarchyAggregate:
}
}
]
]
return
query
return
query
@
staticmethod
def
tag_aggregate_by_hierarchy_list
(
project_id
,
hierarchy_str
):
query_json
=
[
{
'$match'
:
{
'project_id'
:
project_id
,
'id'
:
{
'$regex'
:
hierarchy_str
}
}
},
{
'$addFields'
:
{
'new_hierarchy'
:
{
'$slice'
:
[
{
'$split'
:
[
'$id'
,
{
'$literal'
:
'$'
}
]
},
0
,
{
'$subtract'
:
[
{
'$size'
:
{
'$split'
:
[
'$id'
,
{
'$literal'
:
'$'
}
]
}
},
1
]
}
]
}
}
},
{
'$addFields'
:
{
'hierarchy_id'
:
{
'$reduce'
:
{
'input'
:
'$new_hierarchy'
,
'initialValue'
:
''
,
'in'
:
{
'$cond'
:
{
'if'
:
{
'$eq'
:
[
{
'$indexOfArray'
:
[
'$new_hierarchy'
,
'$$this'
]
},
0
]
},
'then'
:
{
'$concat'
:
[
'$$value'
,
'$$this'
]
},
'else'
:
{
'$concat'
:
[
'$$value'
,
{
'$literal'
:
'$'
},
'$$this'
]
}
}
}
}
}
}
},
{
'$lookup'
:
{
'from'
:
'tag_category'
,
'localField'
:
'tag_category_id'
,
'foreignField'
:
'tag_category_id'
,
'as'
:
'tag_category'
}
},
{
'$unwind'
:
{
'path'
:
'$tag_category'
}
},
{
'$group'
:
{
'_id'
:
'$hierarchy_id'
,
'data'
:
{
'$push'
:
{
'k'
:
{
'$ifNull'
:
[
'$tag_category.tag_category_name'
,
""
]},
'v'
:
'$id'
}
}
}
},
{
'$group'
:
{
'_id'
:
None
,
'data'
:
{
'$push'
:
{
'k'
:
'$_id'
,
'v'
:
{
'$arrayToObject'
:
'$data'
}
}
}
}
},
{
'$replaceRoot'
:
{
'newRoot'
:
{
'$arrayToObject'
:
'$data'
}
}
}
]
return
query_json
scripts/db/mongo/ilens_configuration/collections/lookup_table.py
View file @
9c8c4d96
...
@@ -26,7 +26,7 @@ class LookupTable(MongoCollectionBaseClass):
...
@@ -26,7 +26,7 @@ class LookupTable(MongoCollectionBaseClass):
@
property
@
property
def
key_type
(
self
):
def
key_type
(
self
):
return
CommonKeys
.
KEY_TYPE
return
"lookup_name"
def
find_constant_by_dict
(
self
,
_type
):
def
find_constant_by_dict
(
self
,
_type
):
"""
"""
...
...
scripts/db/mongo/schema/tag_hierarchy.py
View file @
9c8c4d96
from
typing
import
Optional
,
List
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
class
GetTagsLists
(
BaseModel
):
class
GetTagsLists
(
BaseModel
):
project_id
:
str
project_id
:
str
hierarchy
:
str
hierarchy
:
str
class
OutputTagsList
(
BaseModel
):
project_id
:
str
hierarchy_list
:
Optional
[
List
]
hierarchy_level
:
Optional
[
str
]
class
Config
:
schema_extra
=
{
"example"
:
{
"project_id"
:
"project_099"
,
"hierarchy_list"
:
[
"site_101"
,
"site_102"
],
"hierarchy_level"
:
"equipment"
}
}
scripts/schemas/batch_oee.py
View file @
9c8c4d96
...
@@ -228,3 +228,9 @@ class GetOeeServices(BaseModel):
...
@@ -228,3 +228,9 @@ class GetOeeServices(BaseModel):
project_id
:
str
project_id
:
str
meta
:
dict
meta
:
dict
oee_tag_mapping
:
str
oee_tag_mapping
:
str
class
MachineOEERequest
(
BaseModel
):
project_id
:
str
monitor_time
:
Optional
[
str
]
=
"00:00"
tz
:
Optional
[
str
]
=
"Asia/Kolkata"
scripts/services/oee_services.py
View file @
9c8c4d96
from
fastapi
import
APIRouter
from
fastapi
import
APIRouter
from
scripts.logging
import
logger
from
scripts.constants
import
Endpoints
from
scripts.constants
import
Endpoints
from
scripts.schemas.batch_oee
import
GetOeeServices
from
scripts.core.handlers
import
oee_handlers
from
scripts.core.handlers
import
oee_handlers
from
scripts.logging
import
logger
from
scripts.schemas.batch_oee
import
GetOeeServices
oee_services
=
APIRouter
(
prefix
=
Endpoints
.
oee_services
,
tags
=
[
"OEE Calculator"
])
oee_services
=
APIRouter
(
prefix
=
Endpoints
.
oee_services
,
tags
=
[
"OEE Calculator"
])
...
@@ -11,7 +12,7 @@ oee_services = APIRouter(prefix=Endpoints.oee_services, tags=["OEE Calculator"])
...
@@ -11,7 +12,7 @@ oee_services = APIRouter(prefix=Endpoints.oee_services, tags=["OEE Calculator"])
async
def
oee_tag_mapping
(
oee_tag_mapping_list
:
GetOeeServices
):
async
def
oee_tag_mapping
(
oee_tag_mapping_list
:
GetOeeServices
):
try
:
try
:
tag_mapping
=
oee_tag_mapping_list
.
dict
()
tag_mapping
=
oee_tag_mapping_list
.
dict
()
result
=
oee_handlers
.
O
ee_
Services
.
oee_tag_mapping
(
oee_tag_mapping_list
)
result
=
oee_handlers
.
O
EE
Services
.
oee_tag_mapping
(
oee_tag_mapping_list
)
return
result
return
result
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -22,7 +23,7 @@ async def oee_tag_mapping(oee_tag_mapping_list: GetOeeServices):
...
@@ -22,7 +23,7 @@ async def oee_tag_mapping(oee_tag_mapping_list: GetOeeServices):
async
def
get_oee_tag_mapping
(
get_oee_tags
:
GetOeeServices
):
async
def
get_oee_tag_mapping
(
get_oee_tags
:
GetOeeServices
):
try
:
try
:
get_oee_tags
=
get_oee_tags
.
dict
()
get_oee_tags
=
get_oee_tags
.
dict
()
return_json
=
oee_handlers
.
O
ee_
Services
.
get_oee_tag_mapping
(
get_oee_tags
)
return_json
=
oee_handlers
.
O
EE
Services
.
get_oee_tag_mapping
(
get_oee_tags
)
return
return_json
return
return_json
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -33,7 +34,7 @@ async def get_oee_tag_mapping(get_oee_tags: GetOeeServices):
...
@@ -33,7 +34,7 @@ async def get_oee_tag_mapping(get_oee_tags: GetOeeServices):
async
def
delete_oee_tagging
(
delete_oee_tags
:
GetOeeServices
):
async
def
delete_oee_tagging
(
delete_oee_tags
:
GetOeeServices
):
try
:
try
:
delete_oee_tags
=
delete_oee_tags
.
dict
()
delete_oee_tags
=
delete_oee_tags
.
dict
()
return_json
=
oee_handlers
.
O
ee_
Services
.
delete_oee_tags
(
project_id
=
delete_oee_tags
[
"project_id"
])
return_json
=
oee_handlers
.
O
EE
Services
.
delete_oee_tags
(
project_id
=
delete_oee_tags
[
"project_id"
])
return
return_json
return
return_json
except
Exception
as
e
:
except
Exception
as
e
:
...
@@ -44,7 +45,7 @@ async def delete_oee_tagging(delete_oee_tags: GetOeeServices):
...
@@ -44,7 +45,7 @@ async def delete_oee_tagging(delete_oee_tags: GetOeeServices):
async
def
update_oee_tagging
(
update_oee_tags
:
GetOeeServices
):
async
def
update_oee_tagging
(
update_oee_tags
:
GetOeeServices
):
try
:
try
:
update_oee_tags
=
update_oee_tags
.
dict
()
update_oee_tags
=
update_oee_tags
.
dict
()
return_json
=
oee_handlers
.
O
ee_
Services
.
update_oee_tags
(
update_oee_tags
)
return_json
=
oee_handlers
.
O
EE
Services
.
update_oee_tags
(
update_oee_tags
)
return
return_json
return
return_json
except
Exception
as
e
:
except
Exception
as
e
:
...
...
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