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
18f3c1c0
Commit
18f3c1c0
authored
Aug 02, 2023
by
suraksha.pv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace keys
parent
f69dea60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
replace_mongo_properties.py
replace_mongo_properties.py
+69
-0
No files found.
replace_mongo_properties.py
0 → 100644
View file @
18f3c1c0
import
json
from
pymongo
import
MongoClient
input_json_file_name
=
'input_json.json'
input_project_id
=
"project_099"
input_logbook_id
=
"logbook_131"
input_step_id
=
'step_182'
step_type
=
"NON-PERIODIC"
# NON-PERIODIC,PERIODIC
CONNECTION_STRING
=
"mongodb://ilens:ilens4321@192.168.0.220:2717/"
client
=
MongoClient
(
CONNECTION_STRING
)
# add correct database names below
ilens_assistant
=
client
[
"ilens_assistant"
]
ilens_configuration
=
client
[
"ilens_configuration"
]
task_instances
=
ilens_assistant
[
'task_instances'
]
task_instance_data
=
ilens_assistant
[
'task_instance_data'
]
periodic_data
=
ilens_configuration
[
'periodic_data'
]
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
):
if
not
isinstance
(
data
,
dict
):
return
data
new_data
=
{}
for
key
,
value
in
data
.
items
():
if
key
in
replacements
:
new_data
[
replacements
[
key
]]
=
replace_keys
(
value
,
replacements
)
else
:
new_data
[
key
]
=
replace_keys
(
value
,
replacements
)
return
new_data
if
step_type
==
'NON-PERIODIC'
:
query
=
{
"logbook_id"
:
input_logbook_id
,
"project_id"
:
input_project_id
}
data
=
[]
if
logbook_data
:
=
list
(
ilens_assistant
.
task_instances
.
find
(
query
)):
data
.
extend
(
each
[
'task_id'
]
for
each
in
logbook_data
)
task_details
=
list
(
ilens_assistant
.
task_instance_data
.
find
(
{
"step_id"
:
input_step_id
,
"project_id"
:
input_project_id
,
"task_id"
:
{
"$in"
:
data
}}))
updated_y
=
[]
if
task_details
:
for
item
in
task_details
:
if
'step_data'
in
item
and
'data'
in
item
[
'step_data'
]:
item
[
'step_data'
]
=
replace_keys
(
item
[
'step_data'
],
input_dict
)
updated_y
.
append
(
item
)
for
item
in
updated_y
:
if
item
[
'task_id'
]
in
data
:
update_query
=
{
"task_id"
:
item
[
'task_id'
],
"step_id"
:
input_step_id
,
"project_id"
:
input_project_id
}
ilens_assistant
.
task_instance_data
.
update_one
(
update_query
,
{
"$set"
:
item
})
elif
step_type
==
"PERIODIC"
:
query
=
{
"step_id"
:
input_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
})
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