Skip to content

[ENH] add code and test to help create schemas #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 78 commits into from
Closed
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
e9dcc29
Merge pull request #12 from sanuann/schema-creator
satra Dec 18, 2020
2bbb27d
update examples
sanuann Mar 19, 2021
385eed5
update shacl shape too
sanuann Mar 19, 2021
5a9ee74
Merge branch 'master' into remi_schema_creator
Remi-Gau Jun 5, 2021
139eb23
fix call to base class set default method
Remi-Gau Jun 5, 2021
418eb40
update default schema version
Remi-Gau Jun 5, 2021
ab9ff7f
add possibility to choose extension of filename
Remi-Gau Jun 5, 2021
471c8bd
add some jsonld to test against
Remi-Gau Jun 5, 2021
b4c1c2c
add response options class
Remi-Gau Jun 5, 2021
a41106a
implement response option class
Remi-Gau Jun 5, 2021
53d97e7
implement float and integer and refactor
Remi-Gau Jun 5, 2021
c235e3a
add tests for select and languages
Remi-Gau Jun 5, 2021
1d0c64b
add tests for multiresponse items
Remi-Gau Jun 6, 2021
43395e7
add test for slider and multitext
Remi-Gau Jun 6, 2021
19768c2
simplify add_choice API
Remi-Gau Jun 6, 2021
f5eb4c1
create set_context method
Remi-Gau Jun 6, 2021
df56174
refactor sorting
Remi-Gau Jun 6, 2021
62226fd
add read only item
Remi-Gau Jun 6, 2021
fe7dc95
add test for email, id, date, year and time range
Remi-Gau Jun 6, 2021
4118fbe
refactor
Remi-Gau Jun 6, 2021
1b656a5
add test for state and country
Remi-Gau Jun 6, 2021
13c0de4
refactor using preset response choices
Remi-Gau Jun 6, 2021
d72da8a
add tests for activity creation
Remi-Gau Jun 6, 2021
f633b89
refactor
Remi-Gau Jun 6, 2021
e4b1085
use default context for activity test
Remi-Gau Jun 6, 2021
892e8ee
change item default value
Remi-Gau Jun 6, 2021
0cc8599
add tests for response options
Remi-Gau Jun 6, 2021
77e36e4
add default test for protocols
Remi-Gau Jun 6, 2021
8c14829
use language for preferred label by default
Remi-Gau Jun 6, 2021
cf1b3ce
get variable name for item in activity from their basename
Remi-Gau Jun 6, 2021
b7804cc
add test for protocols
Remi-Gau Jun 6, 2021
5cf4587
add clean up
Remi-Gau Jun 6, 2021
122a5f6
fix copy paste error
Remi-Gau Jun 6, 2021
fb29ac2
Add comments to tests
Remi-Gau Jun 7, 2021
92427b6
comment code
Remi-Gau Jun 7, 2021
3fad95c
Merge pull request #7 from ReproNim/schema-creator
sanuann Jun 7, 2021
1b05a2f
Merge pull request #8 from Remi-Gau/remi_schema_creator
sanuann Jun 7, 2021
580db63
wip classes
sanuann Jun 7, 2021
953f1c9
add more todo to item class
Remi-Gau Jun 7, 2021
e3e3e98
refactor classes to add remi's changes
sanuann Jun 8, 2021
9ccb4b8
Merge branch 'convertors' into schema-creator
sanuann Jun 8, 2021
ff6c950
add text area and refactor
Remi-Gau Dec 2, 2021
9391fc1
add tests for new schema
Remi-Gau Jul 30, 2022
ebf9527
Merge branch 'master' of https://github.com/ReproNim/reproschema-py i…
Remi-Gau Jul 30, 2022
f1fdf65
tmp commit
Remi-Gau Jul 30, 2022
c60ba27
remove attr new and restart refactoring
Remi-Gau Jul 30, 2022
ea68185
start using attr
Remi-Gau Jul 30, 2022
03fe296
refactor
Remi-Gau Jul 31, 2022
01e159e
remove test outputs
Remi-Gau Jul 31, 2022
6594cb0
parametrize tests
Remi-Gau Jul 31, 2022
c711d83
refactor
Remi-Gau Jul 31, 2022
45a7413
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 31, 2022
42cf00f
remove clutter
Remi-Gau Jul 31, 2022
cfe7e60
do not include test in package
Remi-Gau Aug 1, 2022
c963fc7
Merge branch 'master' into remi_schema_creator
satra Aug 1, 2022
faaf104
refactor
Remi-Gau Aug 14, 2022
dd4df02
add test for protocol from reproschema repo
Remi-Gau Aug 14, 2022
5536b6a
refactor
Remi-Gau Aug 15, 2022
6772c20
create new response option class
Remi-Gau Aug 15, 2022
ccb0df8
refactor
Remi-Gau Aug 15, 2022
e43f6ea
Merge remote-tracking branch 'origin/remi_schema_creator' into remi_s…
Remi-Gau Aug 15, 2022
dc2d69f
refactor
Remi-Gau Aug 15, 2022
cab0f74
add additional property class
Remi-Gau Aug 15, 2022
a9838f0
refactor
Remi-Gau Aug 15, 2022
dc1def0
add limit
Remi-Gau Aug 15, 2022
a724eb3
add schedule and randomMAxDelay
Remi-Gau Aug 15, 2022
6365fe1
add messages
Remi-Gau Aug 15, 2022
5c5c8f0
add audio and video
Remi-Gau Aug 15, 2022
743fd34
add additionalNotesObj
Remi-Gau Aug 15, 2022
55bf186
add unitOption
Remi-Gau Aug 15, 2022
7fd2450
read response_options from file
Remi-Gau Aug 15, 2022
746d0e4
refactor
Remi-Gau Aug 15, 2022
1c1b333
undo
Remi-Gau Aug 15, 2022
61310c8
update doc
Remi-Gau Aug 17, 2022
4d50964
adapt for tests
Remi-Gau May 11, 2024
70bd3af
lint
Remi-Gau May 11, 2024
931d586
Merge branch 'eCobidas_valid' into remi_schema_creator
Remi-Gau May 11, 2024
c75504a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
**/tmp
Pipfile

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black

- repo: https://github.com/asottile/reorder_python_imports
rev: "v3.8.2"
hooks:
- id: reorder-python-imports
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cSpell.words": [
"reproschema"
],
"autoDocstring.docstringFormat": "numpy"
}
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[tool.pytest.ini_options]
minversion = "4.4.0"
addopts = "-ra -vv"
3 changes: 0 additions & 3 deletions reproschema/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
# feature). Distribution tarballs (built by setup.py sdist) and build
# directories (produced by setup.py build) will contain a much shorter file
# that just contains the computed version number.

# This file is released into the public domain. Generated by
# versioneer-0.18 (https://github.com/warner/python-versioneer)

"""Git implementation of _version.py."""

import errno
import os
import re
Expand Down
4 changes: 3 additions & 1 deletion reproschema/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os

import click

from . import get_logger, set_logger_level
from . import __version__
from . import get_logger
from . import set_logger_level

lgr = get_logger()

Expand Down
10 changes: 7 additions & 3 deletions reproschema/jsonldutils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from pyld import jsonld
from pyshacl import validate as shacl_validate
import json
import os
from .utils import start_server, stop_server, lgr

from pyld import jsonld
from pyshacl import validate as shacl_validate

from .utils import lgr
from .utils import start_server
from .utils import stop_server


def load_file(path_or_url, started=False, http_kwargs={}):
Expand Down
8 changes: 8 additions & 0 deletions reproschema/models/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# README

## reproschema file creation

The creation reproschema protocols, activities and items (or Field) are handled
by 3 python classes with the same names contained in their dedicated modules.

They all inherit from the same base class.
2 changes: 1 addition & 1 deletion reproschema/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .protocol import Protocol
from .activity import Activity
from .item import Item
from .protocol import Protocol
124 changes: 65 additions & 59 deletions reproschema/models/activity.py
Original file line number Diff line number Diff line change
@@ -1,67 +1,73 @@
from pathlib import Path
from typing import Dict
from typing import Optional
from typing import Union

from .base import COMMON_SCHEMA_ORDER
from .base import DEFAULT_LANG
from .base import SchemaBase
from .item import Item


class Activity(SchemaBase):
"""
class to deal with reproschema activities
"""

schema_type = "reproschema:Activity"

def __init__(self, version=None):
super().__init__(version)
self.schema["ui"] = {"shuffle": [], "order": [], "addProperties": []}

def set_ui_shuffle(self, shuffle=False):
self.schema["ui"]["shuffle"] = shuffle

def set_URI(self, URI):
self.URI = URI

def get_URI(self):
return self.URI

# TODO
# preamble
# compute
# citation
# image

def set_defaults(self, name):
self._ReproschemaSchema__set_defaults(name) # this looks wrong
self.set_ui_shuffle(False)

def update_activity(self, item_info):

# TODO
# - remove the hard coding on visibility and valueRequired

# update the content of the activity schema with new item

item_info["URI"] = "items/" + item_info["name"]

append_to_activity = {
"variableName": item_info["name"],
"isAbout": item_info["URI"],
"isVis": item_info["visibility"],
"valueRequired": False,
}

self.schema["ui"]["order"].append(item_info["URI"])
self.schema["ui"]["addProperties"].append(append_to_activity)

def sort(self):
schema_order = [
"@context",
"@type",
"@id",
"prefLabel",
"description",
"schemaVersion",
"version",
"ui",
]
self.sort_schema(schema_order)

ui_order = ["shuffle", "order", "addProperties"]
self.sort_ui(ui_order)
def __init__(
self,
name: Optional[str] = "activity",
schemaVersion: Optional[str] = None,
prefLabel: Optional[str] = "activity",
altLabel: Optional[Dict[str, str]] = None,
description: Optional[str] = "",
preamble: Optional[str] = None,
citation: Optional[str] = None,
image: Optional[Union[str, Dict[str, str]]] = None,
audio: Optional[Union[str, Dict[str, str]]] = None,
video: Optional[Union[str, Dict[str, str]]] = None,
messages: Optional[Dict[str, str]] = None,
suffix: Optional[str] = "_schema",
visible: Optional[bool] = True,
required: Optional[bool] = False,
skippable: Optional[bool] = True,
limit: Optional[str] = None,
randomMaxDelay: Optional[str] = None,
schedule: Optional[str] = None,
ext: Optional[str] = ".jsonld",
output_dir: Optional[Union[str, Path]] = Path.cwd(),
lang: Optional[str] = DEFAULT_LANG(),
):

schema_order = COMMON_SCHEMA_ORDER() + ["citation", "compute", "messages"]

super().__init__(
at_id=name,
schemaVersion=schemaVersion,
at_type="reproschema:Activity",
prefLabel={lang: prefLabel},
altLabel=altLabel,
description=description,
preamble=preamble,
citation=citation,
messages=messages,
image=image,
audio=audio,
video=video,
schema_order=schema_order,
visible=visible,
required=required,
skippable=skippable,
limit=limit,
randomMaxDelay=randomMaxDelay,
schedule=schedule,
suffix=suffix,
ext=ext,
output_dir=output_dir,
lang=lang,
)
self.ui.shuffle = False
self.update()

def append_item(self, item: Item):
self.ui.append(obj=item, variableName=item.get_basename())
Loading