-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
319 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import json | ||
from flask import jsonify, Blueprint | ||
import os | ||
import shutil | ||
from flask_jwt_extended import jwt_required | ||
|
||
spectra_layout_api = Blueprint('spectra_layout_api', __name__) | ||
script_dir = os.path.dirname(__file__) | ||
data_type_json_path = os.path.join(script_dir, '../lib/converter/jcamp/data_type.json') | ||
|
||
def load_data_types(): | ||
try: | ||
with open(data_type_json_path, 'r') as mapping_file: | ||
return json.load(mapping_file) | ||
except FileNotFoundError: | ||
example_json_path = os.path.join(script_dir, '../lib/converter/jcamp/data_type.json.example') | ||
shutil.copy(example_json_path, data_type_json_path) | ||
with open(data_type_json_path, 'r') as mapping_file: | ||
return json.load(mapping_file) | ||
|
||
@spectra_layout_api.route('/api/v1/chemspectra/spectra_layouts', methods=['GET']) | ||
@jwt_required() | ||
def get_spectra_layouts(): | ||
existing_data_types = load_data_types() | ||
return jsonify(existing_data_types["datatypes"]), 200 |
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,56 @@ | ||
import json | ||
import os | ||
from flask import request, jsonify, Blueprint | ||
import shutil | ||
from flask_jwt_extended import jwt_required | ||
|
||
spectra_type_api = Blueprint('spectra_type_api', __name__) | ||
|
||
script_dir = os.path.dirname(__file__) | ||
data_type_json_path = os.path.join(script_dir, '../lib/converter/jcamp/data_type.json') | ||
|
||
def load_data_types(): | ||
try: | ||
with open(data_type_json_path, 'r') as mapping_file: | ||
return json.load(mapping_file) | ||
except FileNotFoundError: | ||
example_json_path = os.path.join(script_dir, '../lib/converter/jcamp/data_type.json.example') | ||
shutil.copy(example_json_path, data_type_json_path) | ||
with open(data_type_json_path, 'r') as mapping_file: | ||
return json.load(mapping_file) | ||
|
||
def save_data_types(data_types): | ||
with open(data_type_json_path, 'w') as mapping_file: | ||
json.dump(data_types, mapping_file, indent=4) | ||
|
||
@spectra_type_api.route('/api/v1/chemspectra/data_type', methods=['POST']) | ||
@jwt_required() | ||
def create_data_type(): | ||
request_data = request.get_json() | ||
new_data_type_mapping = request_data.get("new_data_type") | ||
existing_data_types = load_data_types() | ||
|
||
for layout, data_type in new_data_type_mapping.items(): | ||
if layout in existing_data_types["datatypes"] and data_type not in existing_data_types['datatypes'][layout]: | ||
existing_data_types["datatypes"][layout].append(data_type) | ||
elif layout in existing_data_types["datatypes"] and data_type in existing_data_types['datatypes'][layout]: | ||
return jsonify({"message": f"Data type '{data_type}' already exists"}), 400 | ||
else: | ||
return jsonify({"message": f"Layout '{layout}' does not exist"}), 400 | ||
|
||
save_data_types(existing_data_types) | ||
|
||
return jsonify({"message": "Data type created successfully"}), 200 | ||
|
||
@spectra_type_api.route('/api/v1/chemspectra/data_type/<data_type>', methods=['DELETE']) | ||
@jwt_required() | ||
def delete_data_type(data_type): | ||
existing_data_types = load_data_types() | ||
|
||
for layout, data_types in existing_data_types['datatypes'].items(): | ||
if data_type in data_types: | ||
data_types.remove(data_type) | ||
save_data_types(existing_data_types) | ||
return jsonify({"message": f"Data type '{data_type}' deleted successfully"}), 200 | ||
|
||
return jsonify({"message": f"Data type '{data_type}' not found"}), 404 |
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,19 @@ | ||
{ | ||
"datatypes": { | ||
"NMR": ["NMR SPECTRUM", "NMRSPECTRUM"], | ||
"INFRARED": ["INFRARED SPECTRUM"], | ||
"RAMAN": ["RAMAN SPECTRUM"], | ||
"MS": ["MASS SPECTRUM"], | ||
"HPLC UVVIS": ["HPLC UV/VIS SPECTRUM", "HPLC UV-VIS"], | ||
"UVVIS": ["UV/VIS SPECTRUM", "UV-VIS", "ULTRAVIOLET SPECTRUM"], | ||
"THERMOGRAVIMETRIC ANALYSIS": ["THERMOGRAVIMETRIC ANALYSIS"], | ||
"X-RAY DIFFRACTION": ["X-RAY DIFFRACTION"], | ||
"CYCLIC VOLTAMMETRY": ["CYCLIC VOLTAMMETRY"], | ||
"SIZE EXCLUSION CHROMATOGRAPHY": ["SIZE EXCLUSION CHROMATOGRAPHY"], | ||
"CIRCULAR DICHROISM SPECTROSCOPY": ["CIRCULAR DICHROISM SPECTROSCOPY"], | ||
"SORPTION-DESORPTION MEASUREMENT": ["SORPTION-DESORPTION MEASUREMENT"], | ||
"Emissions": ["Emissions", "EMISSIONS", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"], | ||
"DLS ACF": ["DLS ACF"], | ||
"DLS intensity": ["DLS INTENSITY", "DLS intensity"] | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"datatypes": { | ||
"NMR": ["NMR SPECTRUM", "NMRSPECTRUM"], | ||
"INFRARED": ["INFRARED SPECTRUM"], | ||
"RAMAN": ["RAMAN SPECTRUM"], | ||
"MS": ["MASS SPECTRUM"], | ||
"HPLC UVVIS": ["HPLC UV/VIS SPECTRUM", "HPLC UV-VIS"], | ||
"UVVIS": ["UV/VIS SPECTRUM", "UV-VIS", "ULTRAVIOLET SPECTRUM"], | ||
"THERMOGRAVIMETRIC ANALYSIS": ["THERMOGRAVIMETRIC ANALYSIS"], | ||
"X-RAY DIFFRACTION": ["X-RAY DIFFRACTION"], | ||
"CYCLIC VOLTAMMETRY": ["CYCLIC VOLTAMMETRY"], | ||
"SIZE EXCLUSION CHROMATOGRAPHY": ["SIZE EXCLUSION CHROMATOGRAPHY"], | ||
"CIRCULAR DICHROISM SPECTROSCOPY": ["CIRCULAR DICHROISM SPECTROSCOPY"], | ||
"SORPTION-DESORPTION MEASUREMENT": ["SORPTION-DESORPTION MEASUREMENT"], | ||
"Emissions": ["Emissions", "EMISSIONS", "FLUORESCENCE SPECTRUM", "FL SPECTRUM"], | ||
"DLS ACF": ["DLS ACF"], | ||
"DLS intensity": ["DLS INTENSITY", "DLS intensity"] | ||
} | ||
} |
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 |
---|---|---|
|
@@ -42,3 +42,5 @@ urllib3==1.26.5 | |
Werkzeug==2.2.3 | ||
zipp==0.5.2 | ||
pyopenms==2.6.0 | ||
PyJWT==2.8.0 | ||
flask-jwt-extended==4.5.2 |
Oops, something went wrong.