Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cgmeyer committed Jun 6, 2023
1 parent cd61900 commit cda549f
Showing 1 changed file with 42 additions and 14 deletions.
56 changes: 42 additions & 14 deletions expansion/expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,9 @@ def delete_records(self, uuids, project_id, chunk_size=200, backup=False):
results["responses"] = responses
results["errors"] = errors
print("\tFinished record deletion script.")

if len(success) > 0:
print("Successfully deleted {} records.".format(len(success)))
self.nuked()
return results

def delete_node(self, node, project_id, chunk_size=200):
Expand Down Expand Up @@ -1043,6 +1045,7 @@ def delete_project(self, project_id, root_node="project", chunk_size=200, nuke_p
print("Successfully deleted the project '{}'".format(project_id))
self.nuked()
else:
self.nuked()
print("\n\nSuccessfully deleted all nodes in the project '{}'.\nIf you'd like to delete the project node itself, then add the flag 'nuke_project=True'.".format(project_id))


Expand Down Expand Up @@ -2781,6 +2784,9 @@ def delete_indexd_records(self,irecs):
else:
failure.append(guid)
print("{}/{} {}: Failed to delete '{}'.".format(count,total,response.status_code,guid))
if len(success) > 0:
print("Successfully deleted {} indexd records.".format(len(success)))
self.nuked()
return {'success':success,'failure':failure}


Expand Down Expand Up @@ -3137,6 +3143,9 @@ def delete_uploaded_files(self, guids):
print("({}/{}) Error deleting GUID {}:".format(count,total,guid))
print(response.reason)
failed.append(guid)
if len(deleted) > 0:
print("Successfully deleted {} uploaded files.".format(len(deleted)))
self.nuked()
return({'deleted':deleted,'failed':failed})


Expand Down Expand Up @@ -4101,7 +4110,9 @@ def delete_mds(self,guids):
else:
failed.append(guid)
print("({}/{}) FAILED to delete '{}' from MDS.".format(count, total, guid))

if len(deleted) > 0:
print("Successfully deleted {} metadata records.".format(len(deleted)))
self.nuked()
return {"deleted":deleted,"failed":failed}


Expand Down Expand Up @@ -5045,7 +5056,9 @@ def create_mock_tsv(self,
"object_id",
"storage_urls"],
mfiles=None,
submit_tsv=False
submit_tsv=False,
minimum=1,
maximum=20
):
"""
Create mock / simulated data in a submission TSV for a node in the data dictionary.
Expand All @@ -5060,22 +5073,25 @@ def create_mock_tsv(self,
excluded_props(list): a list of properties in data dictionary to ignore / exclude from the TSV columns
mfiles(dict): a dictionary of mock data files created using func create_mock_files()
submit_tsv(boolean): if true, will use sdk to submit the file via sheepdog
"""
############################################################
############################################################
# Use these settings for testing, comment out when actually running as function or in SDK.
############################################################
# node = 'cr_series_file'
# count = 3
# outdir = "/Users/christopher/Documents/Notes/MIDRC/annotations/sample_data/DEV-test/script_tsvs"
# filename = "{}_mock_{}.tsv".format(node,dd_version) # override for testing, comment out
# links = self.list_links(node, dd)
# parent_tsvs = {link:"{}_mock_{}.tsv".format(link_targets[link],dd_version) for link in links}
# links = None # for testing comment this out later
dd = sub.get_dictionary_all()
dd_version = dd["_settings"]["_dict_version"]
node = 'cr_series_file'
count = 3
outdir = "/Users/christopher/Documents/Notes/MIDRC/annotations/sample_data/DEV-test/script_tsvs"
filename = "{}_mock_{}.tsv".format(node,dd_version) # override for testing, comment out
links = self.list_links(node, dd)
parent_tsvs = {link:"{}/{}_mock_{}.tsv".format(outdir,link_targets[link],dd_version) for link in links}
links = None # for testing comment this out later
############################################################
############################################################
############################################################

"""
# get the data dictionary and version number
dd_version = dd["_settings"]["_dict_version"]

Expand Down Expand Up @@ -5155,6 +5171,10 @@ def create_mock_tsv(self,
array_type = dd[node]['properties'][prop]['items']
if 'type' in dd[node]['properties'][prop]['items']:
array_type = dd[node]['properties'][prop]['items']['type']
if 'minimum' in dd[node]['properties'][prop]['items']:
minimum = dd[node]['properties'][prop]['items']['minimum']
if 'maximum' in dd[node]['properties'][prop]['items']:
maximum = dd[node]['properties'][prop]['items']['maximum']
if array_type == "string":
data[prop] = ["test {}, test {}".format(prop,prop)] * count
# array_values = ["test {}, test {}".format(prop,prop)] * count
Expand All @@ -5179,9 +5199,17 @@ def create_mock_tsv(self,
available_types = cycle([True,False])
data[prop] = [next(available_types)for i in range(count)]
elif prop_type == "integer":
data[prop] = list(np.random.randint(low=1, high=89, size=(count)))
if 'minimum' in dd[node]['properties'][prop]:
minimum = dd[node]['properties'][prop]['minimum']
if 'maximum' in dd[node]['properties'][prop]:
maximum = dd[node]['properties'][prop]['maximum']
data[prop] = list(np.random.randint(low=minimum, high=maximum, size=(count)))
elif prop_type == "number":
data[prop] = [ '%.2f' % elem for elem in list(np.random.uniform(low=1, high=89, size=count))]
if 'minimum' in dd[node]['properties'][prop]:
minimum = dd[node]['properties'][prop]['minimum']
if 'maximum' in dd[node]['properties'][prop]:
maximum = dd[node]['properties'][prop]['maximum']
data[prop] = [ '%.2f' % elem for elem in list(np.random.uniform(low=minimum, high=maximum, size=count))]

elif 'enum' in dd[node]['properties'][prop]:
enums = dd[node]['properties'][prop]['enum']
Expand Down

0 comments on commit cda549f

Please sign in to comment.