-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: updating reproschema commands to the new pydantic model (#36)
* add print for testing * update clear_header * remove print * fix order and other errors * change ui yesno to radio * fix typo * update context, field->item, fix isVis * remove useless due to failed validation * remove visibility at the item level & remove matrixInfo * fix choice * remove identifier * updating validate command to the new pydantic model * updating/fixing the tests; updating the model to use CreativeWork; changes in formating * fix conversion tests * remove test output * change test output directory * final improvments on tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * model version after adding Thing class * updating model after removing CreativeWork and ImageUrl * adding tests to initialize the model classes * fixing load_file; adding write_obj_jsonld function and expanding test_schema * changing redcap2reproschema to use ned pydantic classes; some small changes to the pydantic model * changing name from string to landstring with en as language * fixing jsonld files * Adding option to return compact schema to load_file * fixing the protocol jsonld file * changing reproschema2redcap to use the new model * adding contectfile to write_obj_jsonld function and improving test; improving compact option for load_file * fixing reproschema2redcap and tests * removing file with the context and fixing references to the context_url (for now the link rfom the ref/linkm branch * updating the reproschema2redcap to work for activity/items from urls * improving error message for file_load and validate; checking the suffix of the file before treating it as jsonld * fixing identify_model_class, so Item and Field are treated the same * fixing reproschema2redcap so it reads responseOptions from another file * rewriting parts of redcap2reproschema, fixing some bugs[wip] * fixing compute: removing isvis condition * fixing process_csv so it doesn't go multiple time through the same condition * changes to input and value mapping (mapping explicitly or raising errors if not found); fixing choices and adding slider; adding sql to compute types (this does not work properly right now); adding many comments * adding output for redcap2reproschema command; removing argparse * model without decimal; revert changes to valueType in the model * adding migrade command * fixing multiple issues with redcap2rp and rp2redcap: adding compute, fixing preamble (can be either activity level or issue level * WIP: addining test to test rp2redcap and redcap2repo using nimh exampl * fixing paths in the tests, should run now * ignore .DS_Store files in validation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: yibeichan <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
89c6337
commit 0988c20
Showing
52 changed files
with
2,280 additions
and
1,238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import json, os | ||
import shutil | ||
from pathlib import Path | ||
|
||
from .jsonldutils import load_file | ||
from .utils import fixing_old_schema | ||
|
||
|
||
def migrate2newschema(path, inplace=False, fixed_path=None): | ||
path = Path(path).resolve() | ||
if path.is_file(): | ||
print(f"migration of file: {path}") | ||
new_path = migrate2newschema_file(path, inplace, fixed_path) | ||
else: # path.is_dir | ||
if inplace: | ||
new_path = path | ||
elif fixed_path: | ||
new_path = Path(fixed_path).resolve() | ||
shutil.copytree(path, new_path) | ||
else: | ||
new_path = path.parent / f"{path.name}_after_migration" | ||
shutil.copytree(path, new_path) | ||
# fixing all files in new_path | ||
all_files = Path(new_path).rglob("*") | ||
for file in all_files: | ||
if file.is_file(): | ||
migrate2newschema_file(jsonld_path=file, inplace=True) | ||
return new_path | ||
|
||
|
||
def migrate2newschema_file(jsonld_path, inplace=False, fixed_path=None): | ||
print(f"Fixing {jsonld_path}") | ||
data = load_file(jsonld_path, started=False) | ||
data_fixed = [fixing_old_schema(data, copy_data=True)] | ||
if inplace: | ||
new_filename = jsonld_path | ||
elif fixedjsonld_path: | ||
new_filename = fixed_path | ||
else: | ||
root, ext = os.path.splitext(jsonld_path) | ||
new_filename = f"{root}_after_migration{ext}" | ||
with open(new_filename, "w") as f: | ||
json.dump(data_fixed, f, indent=4) | ||
return new_filename |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
from .protocol import Protocol | ||
from .activity import Activity | ||
from .item import Item | ||
from .model import Activity, Item, Protocol, ResponseOption, ResponseActivity, Response | ||
from .utils import write_obj_jsonld, identify_model_class |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.