Skip to content

Commit

Permalink
Merge pull request #127 from hed-standard/develop
Browse files Browse the repository at this point in the history
Removed HED-2G from the interface
  • Loading branch information
VisLab committed Jun 13, 2023
2 parents 994fcc9 + 19ae74a commit f1ccd49
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 32 deletions.
7 changes: 4 additions & 3 deletions hedweb/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from hedweb.constants import base_constants, page_constants
from hedweb.constants import route_constants, file_constants
from hedweb.web_util import handle_http_error, handle_error, package_results
from hedweb.web_util import convert_hed_versions, handle_http_error, handle_error, package_results
from hedweb import sidecar as sidecar
from hedweb import events as events
from hedweb import spreadsheet as spreadsheet
Expand Down Expand Up @@ -110,8 +110,9 @@ def schema_versions_results():

try:
hedschema.cache_xml_versions()
hed_info = {base_constants.SCHEMA_VERSION_LIST: hedschema.get_hed_versions()}
return json.dumps(hed_info)
hed_info = {base_constants.SCHEMA_VERSION_LIST: hedschema.get_hed_versions(get_libraries=True)}
hed_list = convert_hed_versions(hed_info)
return json.dumps(hed_list)
except Exception as ex:
return handle_error(ex)

Expand Down
9 changes: 7 additions & 2 deletions hedweb/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ def get_input_from_form(request):
}
if base_constants.SIDECAR_FILE in request.files:
f = request.files[base_constants.SIDECAR_FILE]
fb = io.StringIO(f.read(file_constants.BYTE_LIMIT).decode('ascii'))
arguments[base_constants.SIDECAR] = Sidecar(files=fb, name=secure_filename(f.filename))
if not f.filename:
fb = [io.StringIO('{}')]
filename = 'empty.json'
else:
fb = [io.StringIO(f.read(file_constants.BYTE_LIMIT).decode('ascii'))]
filename = secure_filename(f.filename)
arguments[base_constants.SIDECAR] = Sidecar(files=fb, name=filename)
if base_constants.SPREADSHEET_FILE in request.files and \
request.files[base_constants.SPREADSHEET_FILE].filename:
filename = request.files[base_constants.SPREADSHEET_FILE].filename
Expand Down
8 changes: 6 additions & 2 deletions hedweb/templates/js/sidecar-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ $('#sidecar_file').change(function() {
* Submit the form if schema and json file specified.
*/
$('#sidecar_submit').on('click', function () {
if (fileIsSpecified('#sidecar_file', 'sidecar_flash', 'Sidecar file is not specified.' ) &&
schemaSpecifiedWhenOtherIsSelected()) {
if (!schemaSpecifiedWhenOtherIsSelected()) {
return;
}
// let selectedElement = document.getElementById("process_actions");
if ($('#process_actions').val() === "merge_spreadsheet" ||
fileIsSpecified('#sidecar_file', 'sidecar_flash', 'Sidecar file is not specified.' )) {
submitForm();
}
});
Expand Down
16 changes: 15 additions & 1 deletion hedweb/web_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
TIME_FORMAT = '%Y_%m_%d_T_%H_%M_%S_%f'


def convert_hed_versions(hed_info):
hed_list = []
for key, key_list in hed_info['schema_version_list'].items():
if key is None:
hed_list = hed_list + key_list
else:
hed_list = hed_list + [key+ '_' + element for element in key_list ]
return {'schema_version_list': hed_list}


def file_extension_is_valid(filename, accepted_extensions=None):
""" Return True if the file extension is an accepted one.
Expand Down Expand Up @@ -248,7 +258,11 @@ def get_hed_schema_from_pull_down(request):
if base_constants.SCHEMA_VERSION not in request.form:
raise HedFileError("NoSchemaError", "Must provide a valid schema or schema version", "")
elif request.form[base_constants.SCHEMA_VERSION] != base_constants.OTHER_VERSION_OPTION:
hed_file_path = hedschema.get_path_from_hed_version(request.form[base_constants.SCHEMA_VERSION])
version = request.form[base_constants.SCHEMA_VERSION].split('_')
if len(version) == 1:
hed_file_path = hedschema.get_path_from_hed_version(version[0])
else:
hed_file_path = hedschema.get_path_from_hed_version(version[1], library_name=version[0])
hed_schema = hedschema.load_schema(hed_file_path)
elif request.form[base_constants.SCHEMA_VERSION] == \
base_constants.OTHER_VERSION_OPTION and base_constants.SCHEMA_PATH in request.files:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_routes/test_routes_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_events_results_assemble_valid(self):
events_buffer.close()

def test_events_results_assemble_invalid(self):
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.json')
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events_bad.json')
events_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.tsv')

with open(json_path, 'r') as sc:
Expand All @@ -58,9 +58,9 @@ def test_events_results_assemble_invalid(self):
events_buffer = io.BytesIO(bytes(y, 'utf-8'))

with self.app.app_context():
input_data = {base_constants.SCHEMA_VERSION: '7.2.0',
input_data = {base_constants.SCHEMA_VERSION: '8.2.0',
base_constants.COMMAND_OPTION: base_constants.COMMAND_ASSEMBLE,
base_constants.SIDECAR_FILE: (json_buffer, 'bids_events.json'),
base_constants.SIDECAR_FILE: (json_buffer, 'bids_events_bad.json'),
base_constants.EVENTS_FILE: (events_buffer, 'bids_events.tsv'),
base_constants.CHECK_FOR_WARNINGS: 'on'}
response = self.app.test.post('/events_submit', content_type='multipart/form-data', data=input_data)
Expand Down Expand Up @@ -162,7 +162,7 @@ def test_events_results_validate_valid(self):
events_buffer.close()

def test_events_results_validate_invalid(self):
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.json')
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events_bad.json')
events_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.tsv')

with open(json_path, 'r') as sc:
Expand All @@ -174,9 +174,9 @@ def test_events_results_validate_invalid(self):
events_buffer = io.BytesIO(bytes(y, 'utf-8'))

with self.app.app_context():
input_data = {base_constants.SCHEMA_VERSION: '7.2.0',
input_data = {base_constants.SCHEMA_VERSION: '8.2.0',
base_constants.COMMAND_OPTION: base_constants.COMMAND_VALIDATE,
base_constants.SIDECAR_FILE: (json_buffer, 'bids_events.json'),
base_constants.SIDECAR_FILE: (json_buffer, 'bids_events_bad.json'),
base_constants.EVENTS_FILE: (events_buffer, 'events_file'),
base_constants.CHECK_FOR_WARNINGS: 'on'}
response = self.app.test.post('/events_submit', content_type='multipart/form-data', data=input_data)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_routes/test_routes_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_schema_results_convert_xml_valid(self):

def test_schema_results_convert_xml_url_valid(self):
schema_url = \
'https://raw.githubusercontent.com/hed-standard/hed-specification/master/hedxml/HED8.0.0.xml'
'https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/HED8.0.0.xml'
with self.app.app_context():
input_data = {'schema_upload_options': 'schema_url_option',
'command_option': 'convert_schema',
Expand All @@ -110,7 +110,7 @@ def test_schema_results_convert_xml_url_valid(self):

def test_schema_results_convert_xml_url_valid2(self):
schema_url = \
'https://raw.githubusercontent.com/hed-standard/hed-specification/master/hedxml/HED8.0.0.xml'
'https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/HED8.0.0.xml'
with self.app.app_context():
input_data = {'schema_upload_options': 'schema_url_option',
'command_option': 'convert_schema',
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_schema_results_validate_xml_valid(self):

def test_schema_results_validate_xml_url_invalid(self):
schema_url = \
'https://raw.githubusercontent.com/hed-standard/hed-specification/master/hedxml/HED7.2.0.xml'
'https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/deprecated/HED7.2.0.xml'
with self.app.app_context():
input_data = {'schema_upload_options': 'schema_url_option',
'command_option': 'validate',
Expand All @@ -209,7 +209,7 @@ def test_schema_results_validate_xml_url_invalid(self):

def test_schema_results_validate_xml_url_valid(self):
schema_url = \
'https://raw.githubusercontent.com/hed-standard/hed-specification/master/hedxml/HED8.1.0.xml'
'https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/HED8.1.0.xml'
with self.app.app_context():
input_data = {'schema_upload_options': 'schema_url_option',
'command_option': 'validate',
Expand Down
14 changes: 7 additions & 7 deletions tests/test_routes/test_routes_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ def test_sidecar_results_to_long_valid(self):
sidecar_buffer.close()

def test_sidecar_results_to_long_invalid(self):
sidecar_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.json')
sidecar_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events_bad.json')
with open(sidecar_path, 'r') as sc:
x = sc.read()
sidecar_buffer = io.BytesIO(bytes(x, 'utf-8'))
with self.app.app_context():
input_data = {base_constants.SCHEMA_VERSION: '7.2.0',
input_data = {base_constants.SCHEMA_VERSION: '8.2.0',
base_constants.COMMAND_OPTION: base_constants.COMMAND_TO_LONG,
base_constants.SIDECAR_FILE: (sidecar_buffer, 'HED7.2.0.xml'),
base_constants.SIDECAR_FILE: (sidecar_buffer, 'bids_events_bad.json'),
base_constants.CHECK_FOR_WARNINGS: 'on'}

response = self.app.test.post('/sidecar_submit', content_type='multipart/form-data', data=input_data)
Expand Down Expand Up @@ -134,12 +134,12 @@ def test_sidecar_results_validate_valid_other(self):

def test_sidecar_results_to_short_invalid(self):
with self.app.app_context():
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.json')
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events_bad.json')
with open(json_path, 'r') as sc:
x = sc.read()
json_buffer = io.BytesIO(bytes(x, 'utf-8'))

input_data = {base_constants.SCHEMA_VERSION: '7.2.0',
input_data = {base_constants.SCHEMA_VERSION: '8.2.0',
base_constants.COMMAND_OPTION: base_constants.COMMAND_TO_SHORT,
base_constants.SIDECAR_FILE: (json_buffer, 'bids_events.json'),
base_constants.CHECK_FOR_WARNINGS: 'on'}
Expand All @@ -156,11 +156,11 @@ def test_sidecar_results_to_short_invalid(self):

def test_sidecar_results_validate_invalid(self):
with self.app.app_context():
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events.json')
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/bids_events_bad.json')
with open(json_path, 'r') as sc:
x = sc.read()
json_buffer = io.BytesIO(bytes(x, 'utf-8'))
input_data = {base_constants.SCHEMA_VERSION: '7.2.0',
input_data = {base_constants.SCHEMA_VERSION: '8.2.0',
base_constants.COMMAND_OPTION: base_constants.COMMAND_VALIDATE,
base_constants.SIDECAR_FILE: (json_buffer, 'bids_events.json'),
base_constants.CHECK_FOR_WARNINGS: 'on'}
Expand Down
17 changes: 10 additions & 7 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ def test_process_services_sidecar_a(self):
data = json.load(f)
json_text = json.dumps(data)
fb = io.StringIO(json_text)
schema_url = 'https://raw.githubusercontent.com/hed-standard/hed-specification/master/' \
+ 'hedxml/HED8.0.0.xml'
schema_url = 'https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/' \
+ 'hedxml/HED8.2.0.xml'
hed_schema = hedschema.load_schema(schema_url)
json_sidecar = models.Sidecar(files=fb, name='JSON_Sidecar')
arguments = {base_constants.SERVICE: 'sidecar_validate', base_constants.SCHEMA: hed_schema,
Expand All @@ -119,19 +119,22 @@ def test_process_services_sidecar_a(self):
results = response['results']
self.assertEqual('success', results['msg_category'],
"sidecar_validation services has success on bids_events.json")
self.assertEqual('8.0.0', results[base_constants.SCHEMA_VERSION], 'Version 8.0.0 was used')
self.assertEqual('8.2.0', results[base_constants.SCHEMA_VERSION], 'Version 8.2.0 was used')

schema_url = 'https://raw.githubusercontent.com/hed-standard/hed-specification/master/' \
+ 'hedxml/HED7.2.0.xml'
arguments[base_constants.SCHEMA] = hedschema.load_schema(schema_url)
json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events_bad.json')
with open(json_path) as f:
data = json.load(f)
json_text = json.dumps(data)
fb = io.StringIO(json_text)
arguments[base_constants.SIDECAR] = models.Sidecar(files=fb, name='JSON_Sidecar_BAD')
with self.app.app_context():
response = process(arguments)
self.assertFalse(response['error_type'],
'sidecar_validation services should not have a error when file is valid')
results = response['results']
self.assertTrue(results['data'], 'sidecar_validation produces errors when file not valid')
self.assertEqual('warning', results['msg_category'], "sidecar_validation did not valid with 7.2.0")
self.assertEqual('7.2.0', results['schema_version'], 'Version 7.2.0 was used')
self.assertEqual('8.2.0', results['schema_version'], 'Version 7.2.0 was used')

def test_services_get_sidecar(self):
from hedweb.services import get_sidecar
Expand Down

0 comments on commit f1ccd49

Please sign in to comment.