Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
replace_property_keys
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
suraksha.pv
replace_property_keys
Commits
81d4c41f
Commit
81d4c41f
authored
Aug 21, 2023
by
suraksha.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated script
parent
8a1aeb46
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
42 deletions
+51
-42
replace_mongo_properties.py
replace_mongo_properties.py
+51
-42
sterlite.xlsx
sterlite.xlsx
+0
-0
No files found.
replace_mongo_properties.py
View file @
81d4c41f
import
json
from
pymongo
import
MongoClient
from
pymongo
import
MongoClient
import
pandas
as
pd
MONGO_URI
=
"mongodb://ilens:ilens4321@192.168.0.220:2717/"
# PERIODIC sheet---step_id,old_property_name,new_property_name,step_type
database_ilens_assistant
=
"ilens_assistant"
# NON-PERIODIC sheet-----logbook_id,project_id,step_id,old_property_name,new_property_name,step_type
database_ilens_configuration
=
"ilens_configuration"
input_json_file_name
=
'input_json.json'
# input_json_file
# give input file,sheet name,input details here
input_project_id
=
"project_099"
input_logbook_id
=
[
"logbook_131"
]
input_step_id
=
[
'step_182'
]
step_type
=
"NON-PERIODIC"
# NON-PERIODIC,PERIODIC
CONNECTION_STRING
=
MONGO_URI
input_file_name
=
'sterlite.xlsx'
client
=
MongoClient
(
CONNECTION_STRING
)
sheet_name
=
'PERIODIC'
CONNECTION_STRING
=
"mongodb://ilens:ilens4321@192.168.0.220:2717/"
# --------------------------------main code -------------------------------------------
ilens_assistant
=
client
[
database_ilens_assistant
]
client
=
MongoClient
(
CONNECTION_STRING
)
ilens_configuration
=
client
[
database_ilens_configuration
]
ilens_assistant
=
client
[
"project_384__ilens_assistant"
]
ilens_configuration
=
client
[
"project_384__ilens_configuration"
]
task_instances
=
ilens_assistant
[
'task_instances'
]
task_instances
=
ilens_assistant
[
'task_instances'
]
task_instance_data
=
ilens_assistant
[
'task_instance_data'
]
task_instance_data
=
ilens_assistant
[
'task_instance_data'
]
periodic_data
=
ilens_configuration
[
'periodic_data'
]
periodic_data
=
ilens_configuration
[
'periodic_data'
]
# ---------------------------code execution---------------------------------------#
with
open
(
input_json_file_name
)
as
user_file
:
input_json
=
user_file
.
read
()
input_dict
=
json
.
loads
(
input_json
)
def
replace_keys
(
data
,
replacements
):
def
replace_keys
(
data
,
replacements
):
if
not
isinstance
(
data
,
dict
):
if
not
isinstance
(
data
,
dict
):
...
@@ -40,15 +33,43 @@ def replace_keys(data, replacements):
...
@@ -40,15 +33,43 @@ def replace_keys(data, replacements):
return
new_data
return
new_data
if
step_type
==
'NON-PERIODIC'
:
file_path
=
input_file_name
json_values
=
pd
.
read_excel
(
file_path
,
sheet_name
=
sheet_name
)
for
logbook_id
in
input_logbook_id
:
json_values
.
columns
=
json_values
.
columns
.
str
.
strip
()
query
=
{
"logbook_id"
:
input_logbook_id
,
"project_id"
:
input_project_id
}
for
index
,
row
in
json_values
.
iterrows
():
step_id
=
row
[
'step_id'
]
input_project_id
=
row
.
get
(
'project_id'
,
None
)
input_dict
=
{
row
[
'old_property_name'
]:
row
[
'new_property_name'
]}
step_type
=
row
[
'step_type'
]
logbook_id
=
row
.
get
(
'logbook_id'
,
None
)
print
(
f
"Processing row for step_id: {step_id}, step_type: {step_type}"
)
if
step_type
==
"PERIODIC"
:
query
=
{
"step_id"
:
step_id
}
periodic_step_data
=
list
(
ilens_assistant
.
periodic_data
.
find
(
query
))
updated_y
=
[]
if
periodic_step_data
:
for
each
in
periodic_step_data
:
if
'manual_data'
in
each
:
each
[
'manual_data'
]
=
replace_keys
(
each
[
'manual_data'
],
input_dict
)
updated_y
.
append
(
each
)
for
item
in
updated_y
:
update_query
=
{
"step_id"
:
item
[
'step_id'
],
"_id"
:
item
[
"_id"
]}
ilens_assistant
.
periodic_data
.
update_one
(
update_query
,
{
"$set"
:
item
})
print
(
f
"Executed the script for step_id: {step_id}, step_type: {step_type}"
)
elif
step_type
==
'NON-PERIODIC'
:
query
=
{
"logbook_id"
:
logbook_id
,
"project_id"
:
input_project_id
}
data
=
[]
data
=
[]
if
logbook_data
:
=
list
(
ilens_assistant
.
task_instances
.
find
(
query
)):
if
logbook_data
:
=
list
(
ilens_assistant
.
task_instances
.
find
(
query
)):
data
.
extend
(
each
[
'task_id'
]
for
each
in
logbook_data
)
data
.
extend
(
each
[
'task_id'
]
for
each
in
logbook_data
)
task_details
=
list
(
ilens_assistant
.
task_instance_data
.
find
(
task_details
=
list
(
ilens_assistant
.
task_instance_data
.
find
(
{
"step_id"
:
input_
step_id
,
"project_id"
:
input_project_id
,
"task_id"
:
{
"$in"
:
data
}}))
{
"step_id"
:
step_id
,
"project_id"
:
input_project_id
,
"task_id"
:
{
"$in"
:
data
}}))
updated_y
=
[]
updated_y
=
[]
if
task_details
:
if
task_details
:
for
item
in
task_details
:
for
item
in
task_details
:
...
@@ -57,20 +78,8 @@ if step_type == 'NON-PERIODIC':
...
@@ -57,20 +78,8 @@ if step_type == 'NON-PERIODIC':
updated_y
.
append
(
item
)
updated_y
.
append
(
item
)
for
item
in
updated_y
:
for
item
in
updated_y
:
if
item
[
'task_id'
]
in
data
:
if
item
[
'task_id'
]
in
data
:
update_query
=
{
"task_id"
:
item
[
'task_id'
],
"step_id"
:
input_
step_id
,
update_query
=
{
"task_id"
:
item
[
'task_id'
],
"step_id"
:
step_id
,
"project_id"
:
input_project_id
}
"project_id"
:
input_project_id
}
ilens_assistant
.
task_instance_data
.
update_one
(
update_query
,
{
"$set"
:
item
})
ilens_assistant
.
task_instance_data
.
update_one
(
update_query
,
{
"$set"
:
item
})
elif
step_type
==
"PERIODIC"
:
print
(
f
"Executed the script for step_id: {step_id}, step_type: {step_type}"
)
for
step_id
in
input_step_id
:
query
=
{
"step_id"
:
step_id
}
periodic_step_data
=
list
(
ilens_assistant
.
periodic_data
.
find
(
query
))
updated_y
=
[]
if
periodic_step_data
:
for
each
in
periodic_step_data
:
if
'manual_data'
in
each
:
each
[
'manual_data'
]
=
replace_keys
(
each
[
'manual_data'
],
input_dict
)
updated_y
.
append
(
each
)
for
item
in
updated_y
:
update_query
=
{
"step_id"
:
item
[
'step_id'
],
"_id"
:
item
[
"_id"
]}
ilens_assistant
.
periodic_data
.
update_one
(
update_query
,
{
"$set"
:
item
})
sterlite.xlsx
0 → 100644
View file @
81d4c41f
File added
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