Skip to content

Commit

Permalink
Fixing issues and conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
deoyani committed Dec 18, 2023
1 parent 4bd71d2 commit 3c6621c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 12 additions & 9 deletions python/nistoar/rmm/mongo/nerdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .loader import ValidationError, SchemaError, RefResolutionError
from nistoar.nerdm import utils
from nistoar.nerdm.convert.rmm import NERDmForRMM
import pdb


DEF_BASE_SCHEMA = "https://data.nist.gov/od/dm/nerdm-schema/v0.5#"
DEF_SCHEMA = DEF_BASE_SCHEMA + "/definitions/Resource"
Expand Down Expand Up @@ -298,6 +298,7 @@ def init_metrics_for(db, nerdm):
"""
#Convert nderm dict to an array of dict
#nerdm_use = [nerdm]

record_collection_fields = {
"pdrid": None,
"ediid":None,
Expand All @@ -313,7 +314,7 @@ def init_metrics_for(db, nerdm):
record_fields = ['pdrid', 'ediid']

files_collection_fields = {
"pdrid": None,
"pdrid": None,
"ediid":None,
"filesize": 0,
"success_get" : 0,
Expand All @@ -326,8 +327,8 @@ def init_metrics_for(db, nerdm):
"last_time_logged" : None,
"downloadURL": None
}

nerdm['pdrid'] = nerdm.pop('@id')

records = {}
#Copy fields
for field in record_fields:
Expand All @@ -342,10 +343,13 @@ def init_metrics_for(db, nerdm):

#Get files from record components
files = flatten_records(nerdm, record_fields, files_collection_fields)
files_to_update = []
current_files = db["fileMetrics"].find({"ediid": nerdm["ediid"]})
pdb.set_trace()

db["fileMetrics"].insert_many(files)
current_files_filepaths = [x["filepath"] for x in current_files]
for file_item in files:
if file_item['filepath'] not in current_files_filepaths:
files_to_update.append(file_item)
db["fileMetrics"].insert_many(files_to_update)


def flatten_records(record, record_fields, initialize_fields):
Expand All @@ -371,8 +375,7 @@ def flatten_records(record, record_fields, initialize_fields):
file_dict[key] = record[key]
#Initialize other fields
for key in initialize_fields.keys():
if(key not in file_dict.keys()):
file_dict[key] = initialize_fields[key]
files.append(file_dict)
file_dict[key] = initialize_fields[key]
files.append(file_dict)
return files

4 changes: 1 addition & 3 deletions python/tests/nistoar/rmm/mongo/test_nerdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ def test_load_from_file(self):
def test_init_metrics_for(self):
with open(pdrfile) as fd:
rec = json.load(fd)

# print(" **** TEST ****", rec)

# this record has files in it
self.assertTrue(any(['/od/ds/' in f.get('downloadURL','') for f in rec.get('components',[])]))

Expand All @@ -199,7 +198,6 @@ def test_init_metrics_for(self):
c = self.ldr._client.get_database().recordMetrics.find()
self.assertEqual(c[0]['pdrid'], 'ark:/88434/mds2-2106')
c = self.ldr._client.get_database().fileMetrics.find()
# print(" TEST ****", c[0])
self.assertEqual(c[0]['pdrid'], 'ark:/88434/mds2-2106')
# replace this with checks of successful loading into the database
#self.fail("Tests not implemented")
Expand Down

0 comments on commit 3c6621c

Please sign in to comment.