-
Notifications
You must be signed in to change notification settings - Fork 2
Made changes to updates in response to code review comments #85
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ | |
|
|
||
|
|
||
| def create_experiments_and_inventories(parsed_experiments, collection): | ||
| """Compiles a dictionary of cript Experiment objects. If a parsed experiment is able to be turned | ||
| into an Experiment object it is added to an experiments dictionary and that dictionary is returned. | ||
| """Compiles dictionaries of CRIPT Experiment objects and CRIPT Inventory objects. If a parsed experiment/inventory is able to be turned | ||
| into an Experiment/Inventory object it is added to an experiments dictionary and that dictionary is returned. | ||
| parsed_...-dict of dicts | ||
| group-object | ||
| collection-object | ||
|
|
@@ -25,13 +25,13 @@ def create_experiments_and_inventories(parsed_experiments, collection): | |
| cell_type = parsed_cell["type"] | ||
| cell_key = parsed_cell["key"] | ||
| cell_value = parsed_cell["value"] | ||
| # Only attribute types should be in Experiment | ||
| # Only attribute and that specific identifier should be in experiment | ||
| if cell_type == "attribute": | ||
| experiment_dict[cell_key] = cell_value | ||
| inventory_dict[cell_key] = cell_value | ||
| if cell_type == "identifier": | ||
| elif cell_type == "identifier": | ||
| if cell_key == "Experiment or Inventory": | ||
| if cell_value == "I": | ||
| if cell_value.lower() == "i": | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine, but if we wanted to make the code shorter we could do
|
||
| inventory = True | ||
| if inventory: | ||
| invObj = _create_object(cript.Inventory, inventory_dict, parsed_cell) | ||
|
|
@@ -49,8 +49,8 @@ def create_experiments_and_inventories(parsed_experiments, collection): | |
| def create_citations(parsed_citations, group): | ||
| """Compiles dictionaries with Data and File cript objects. | ||
| parsed_...-dict of dicts | ||
| group-obj | ||
| returns-tuple of dicts of objs | ||
| group-cript Group node | ||
| returns-tuple of dicts of reference nodes and citation nodes | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good docstrings! |
||
| """ | ||
|
|
||
| references = {} | ||
|
|
@@ -176,7 +176,7 @@ def create_materials(parsed_materials, project, data, citations): | |
|
|
||
| elif cell_type == "property": | ||
| if parsed_cell["key"] == "use_existing": | ||
| use_existing = cellToBool(parsed_cell["value"]) | ||
| use_existing = is_cell_true(parsed_cell["value"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. beautiful! |
||
| continue | ||
| property = _create_property(parsed_cell, data, citations) | ||
| material_dict["properties"].append(property) | ||
|
|
@@ -189,11 +189,11 @@ def create_materials(parsed_materials, project, data, citations): | |
|
|
||
| try: | ||
| # try to get the material using its name | ||
| name_ = parsed_material["name"]["value"] | ||
| newProject = cript.Project.get( | ||
| mat_name = parsed_material["name"]["value"] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not have known what |
||
| new_project = cript.Project.get( | ||
| name=parsed_material["use_existing"]["value"] | ||
| ) | ||
| material = cript.Material.get(name=name_, project=newProject.uid) | ||
| material = cript.Material.get(name=mat_name, project=new_project.uid) | ||
|
|
||
| # If there is a get error add it to the errors sheet | ||
| except ValueError as e: | ||
|
|
@@ -205,23 +205,11 @@ def create_materials(parsed_materials, project, data, citations): | |
| # If the material had a successful GET request, add properties, identifiers, | ||
| # and select attributes as written in the excel | ||
| else: | ||
| if newProject.name != project.name: | ||
| material.project = project | ||
| material.url = None | ||
| material.uid = None | ||
| if material.group.name != project.group.name: | ||
| for property in material.properties: | ||
| property.citations = [] | ||
| material.group = project.group | ||
|
|
||
| newProperties = [] | ||
| for property in material.properties: | ||
| if "+" not in property.key: | ||
| newProperties.append(property) | ||
| material.properties = newProperties | ||
|
|
||
| for property in material_dict["properties"]: | ||
| material = copyMaterial(material, new_project, project) | ||
|
|
||
| # Add properties,identifiers, and attributes to material | ||
| for property in material_dict["properties"]: | ||
| material.add_property(property) | ||
| for identifier in material_dict["identifiers"]: | ||
| material.add_identifier(identifier) | ||
|
|
@@ -236,6 +224,7 @@ def create_materials(parsed_materials, project, data, citations): | |
| material.notes += material_dict["notes"] | ||
| else: | ||
| material.notes = material_dict["notes"] | ||
|
|
||
| # create new material object otherwise | ||
| else: | ||
| material = _create_object(cript.Material, material_dict, parsed_cell) | ||
|
|
@@ -481,7 +470,7 @@ def _create_property(parsed_property, data, citations): | |
| property_dict["conditions"].append(condition) | ||
|
|
||
| elif cell_type == "method": | ||
| if cellToBool(parsed_cell["value"]): | ||
| if is_cell_true(parsed_cell["value"]): | ||
| property_dict["method"] = parsed_cell["key"] | ||
|
|
||
| elif cell_type == "relation": | ||
|
|
@@ -578,6 +567,37 @@ def _get_relation(related_objs, cell_value, parsed_cell): | |
| return None | ||
|
|
||
|
|
||
| def cellToBool(val): | ||
| def is_cell_true(val): | ||
| """Converts a cell value to a useable boolean""" | ||
| return True if str(val).lower() != "false" else False | ||
| return str(val).lower() != "false" | ||
|
|
||
|
|
||
| def copyMaterial(material, new_project, project): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| """ | ||
| Takes a material node and adjusts values to get rid of legacy code and incompatible features | ||
| inputs: | ||
| material - cript material node | ||
| new_project - cript project node | ||
| project - cript project node | ||
|
|
||
| returns - cript material node | ||
| """ | ||
| if new_project.name != project.name: | ||
| # Sets new project and gets rid of url and uid to make new node object | ||
| material.project = project | ||
| material.url = None | ||
| material.uid = None | ||
| # Gets rid of citations that would cause permissions errors | ||
| if material.group.name != project.group.name: | ||
| for property in material.properties: | ||
| property.citations = [] | ||
| material.group = project.group | ||
|
|
||
| newProperties = [] | ||
| # Gets rid of any legacy properties/custom that won't upload | ||
| for property in material.properties: | ||
| if "+" not in property.key: | ||
| newProperties.append(property) | ||
| material.properties = newProperties | ||
|
|
||
| return material | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend stripping it of white spaces as well