Skip to content

Commit

Permalink
added CORS and fixed a bug converting floats with , as decimal sepaator
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hanke committed Nov 25, 2022
1 parent 780ceaf commit 107e38d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
3 changes: 2 additions & 1 deletion annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ def get_unit(self, string):
string = string.replace(k, self.superscripts_replace[k])
string=string.replace('N/mm\u00b2','N.m.m-2')
string=string.replace('Nm','N.m')
string=string.replace('sec','s')

found = get_entities_with_property_with_value(
units_graph, QUDT.Symbol, Literal(string)) \
Expand Down Expand Up @@ -358,7 +359,7 @@ def describe_value(self, value_string):
elif self.get_value_type(value_string) == 'BOOL':
return {"@type": "qudt:Quantity",'qudt:value': {'@value': bool(value_string), '@type': 'xsd:boolean'}}
elif self.get_value_type(value_string) == 'FLOAT':
return {"@type": "qudt:Quantity",'qudt:value': {'@value': float(value_string), '@type': 'xsd:decimal'}}
return {"@type": "qudt:Quantity",'qudt:value': {'@value': float(value_string.replace(',','.')), '@type': 'xsd:decimal'}}
elif self.get_value_type(value_string) == 'DATE':
return {"@type": "qudt:Quantity",'qudt:value': {'@value': str(parse(value_string).isoformat()), '@type': 'xsd:dateTime'}}
else:
Expand Down
10 changes: 7 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from flask_swagger_ui import get_swaggerui_blueprint
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap
from flask_cors import CORS, cross_origin

from wtforms import URLField, SelectField
from wtforms.validators import DataRequired
Expand All @@ -20,6 +21,8 @@

app = Flask(__name__)
app.config.from_object(config[config_name])
CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'

bootstrap = Bootstrap(app)

Expand Down Expand Up @@ -70,6 +73,7 @@ class StartForm(FlaskForm):


@app.route('/', methods=['GET', 'POST'])
@cross_origin()
def index():
logo = './static/resources/MatOLab-Logo.svg'
start_form = StartForm()
Expand All @@ -84,7 +88,7 @@ def index():
)


@app.route('/create_annotator', methods=['POST'])
@app.route('/annotate', methods=['GET','POST'])
def create_annotator():
logo = './static/resources/MatOLab-Logo.svg'
start_form = StartForm()
Expand All @@ -98,9 +102,8 @@ def create_annotator():
encoding=start_form.encoding_sel.data
)
if not start_form.data_url.data:
start_form.data_url.data='https://github.com/Mat-O-Lab/CSVToCSVW/raw/main/examples/example.csv'
start_form.data_url.data=start_form.data_url.render_kw['placeholder']
flash('URL Data File empty: using placeholder value for demonstration')

try:
meta_file_name, result = annotator.process(
start_form.data_url.data)
Expand Down Expand Up @@ -129,6 +132,7 @@ def create_annotator():


@app.route("/api", methods=["GET", "POST"])
@cross_origin()
def api():
if request.method == "POST":
content = request.get_json()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ flask
flask-bootstrap
flask_wtf
flask_swagger_ui
flask_cors
wtforms
pandas
html5lib
9 changes: 1 addition & 8 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
{{ super() }}
<link rel="shortcut icon" href="#">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'your_analytiks_tag');
</script>
{% endblock %}

{% block html_attribs %} lang="en"{% endblock %}
Expand Down Expand Up @@ -56,7 +49,7 @@ <h1 class="display-5 fw-bold">CSVtoCSVW</h1>
<div id="enc_help" class="form-text">{{ start_form.encoding_sel.description }}</div>

</div>
<button class="form-group btn btn-primary btn-lg" type="submit">Start Conversion</button>
<button id='submit' class="form-group btn btn-primary btn-lg" type="submit">Start Conversion</button>
</form>

</div>
Expand Down

0 comments on commit 107e38d

Please sign in to comment.