Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #32 from C-Accel-CRIPT/develop
Browse files Browse the repository at this point in the history
updates and Bug fix
  • Loading branch information
rjmello authored Sep 24, 2022
2 parents 6441700 + b9c2255 commit 058aac3
Show file tree
Hide file tree
Showing 12 changed files with 496 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ dmypy.json
# Cython debug symbols
cython_debug/

# Custom
config.yaml

# IDE config folder
.idea/
.idea/

# Local
config.yaml
6 changes: 0 additions & 6 deletions config.yaml

This file was deleted.

11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import requests

import ascii_art
import parse
import create
from create import error_list
import upload
import src.parse as parse
import src.create as create
from src.create import error_list
import src.upload as upload


###
Expand Down Expand Up @@ -204,8 +204,9 @@
upload.upload(api, data, "Data")
upload.upload(api, materials, "Material")
upload.upload(api, processes, "Process")
upload.add_sample_preparation_to_process(api, parsed_sheets["data"], data, processes)
upload.upload(api, files, "File")
upload.add_sample_preparation_to_process(parsed_sheets["data"], data, processes, api)


###
# Finish
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cript==0.4.1
cript==0.4.7
openpyxl==3.0.10
pandas==1.4.3
pandas==1.4.4
PyYAML==6.0
tqdm==4.64.0
File renamed without changes.
6 changes: 4 additions & 2 deletions parse.py → src/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def __init__(self, path, sheet_name, required_columns, unique_columns):
self.df.dropna(how="all", inplace=True)
self.columns = self.df.columns

# TODO should be tested last, once component functions are found to be working.
# Check against manually created parsed objects.
def parse(self):
"""Parses a DataFrame conversion of an excel sheet and returns parsed information as a
dictionary of dictionaries. Each dictionary within the main dictionary contains relevant cell
Expand Down Expand Up @@ -78,7 +80,7 @@ def _skip_column(self, key, value):
value-any
return-boolean"""
# Check if col starts with '#'
if key[0] == "#":
if key.startswith("#"):
return True

# Check if val empty
Expand Down Expand Up @@ -165,5 +167,5 @@ def _clean_key(self, raw_key):
For example, *name -> name or [3]temperature-> temperature
raw_key-string
return-string"""
raw_key.strip()
raw_key = raw_key.strip()
return re.sub("\[.*\]", "", raw_key.strip("*"))
7 changes: 5 additions & 2 deletions upload.py → src/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ def upload(api, obj_dict, obj_type):
unit="item",
)
for key, obj in obj_dict.items():
api.save(obj, update_existing=True)
# Creates name for File object made from external source
if obj_type == "File" and obj.name is None:
obj.name = obj.source
api.save(obj, update_existing=True, max_level=0)
pbar.update(1) # Increment progress bar

pbar.close()


def add_sample_preparation_to_process(parsed_data, data, processes, api):
def add_sample_preparation_to_process(api, parsed_data, data, processes):
"""Adds Process Nodes to a Data nodes "sample_preparation" field if applicable and saves updated node.
parsed_data-dict
data-dict of CRIPT Data objects
Expand Down
5 changes: 5 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# TESTING

Download "testing_template_v0.xlsx" from cript google drive.
Put it in the "tests" folder and make sure to use it as path
variable when running unit tests.
72 changes: 72 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import src.create as create
from src.create import error_list
import pytest

"""
TODO
Will have to make related_objs(dict of dicts), cell_value(str), parsed_cell(dict).
Test for succesful and exception part of the try and except statement.
"""


def test_get_relation():
pass


"""
TODO
for each create_ check that each if statement is going off fine. Will double as checking
the create_object function since pretty much all of them end in calling create_object.
"""


def test_create_experiments():
pass


def test_create_citations():
pass


def test_create_data():
pass


def test_create_materials():
pass


def test_create_mixtures():
pass


def test_create_processes():
pass


def test_create_mixtures():
pass


def test_create_prerequisites():
pass


def test_create_ingredients():
pass


def test_create_products():
pass


def test_create_equipment():
pass


def test_create_property():
pass


def test_create_condition():
pass
8 changes: 8 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import src.main as main
import pytest

"""
TODO -wait until Brilant is done.
Multiple upload tests, use different small excel sheets.
Also have an upload with config empty and config filled out.
"""
Loading

0 comments on commit 058aac3

Please sign in to comment.