json_file = os.path.join(app.config['UPLOAD_FOLDER'], "{}.json".format(filename))
if os.path.exists(f) and os.path.isfile(json_file):
- try:
- with open(json_file) as json_f:
- json_content = json.load(json_f)
- return render_template('analyze_file.html', filename=filename, json=json_content)
- except ValueError as e:
- abort(503)
+ return render_template('analyze_file.html', filename=filename)
else:
abort(404)
+@app.route('/ajax/analysis/')
+def ajax_get_analysis():
+ filename = request.args.get('filename')
+ try:
+ json_file = os.path.join(app.config['UPLOAD_FOLDER'], "{}.json".format(filename))
+ with open(json_file) as json_f:
+ json_content = json.load(json_f)
+ return jsonify(**json_content)
+
+ except ValueError as e:
+ abort(503)
if __name__ == "__main__":
app.run(debug=True)
<script src="{{ url_for('static', filename='wavesurfer.js/dist/wavesurfer.min.js') }}"></script>
<script src="{{ url_for('static', filename='wavesurfer.js/dist/plugin/wavesurfer.regions.min.js') }}"></script>
<script>
-
-var json_file = {{ json | safe }};
+var analysis;
var wavesurfer = Object.create(WaveSurfer);
function lancementOrdres() {
- periode = json_file["période"] * 1000;
+ periode = analysis["période"] * 1000;
var ordres = $('<ul></ul>');
$('#ordres').append(ordres);
var currentItemIndex = 0;
var interval = setInterval(function() {
- order = json_file["orders"][currentItemIndex];
+ order = analysis["orders"][currentItemIndex];
console.log(order);
ordres.append(`<li class="ordre"><span class="index">${currentItemIndex}</span> <span class="type_ordre">${order['action']}</span> <span class="valeur">${order['valeur du CAC']}</span> <span class="order_details">(${order['cote']} × ${order['number']} actions)</span></li>`);
currentItemIndex += 1
- if(currentItemIndex >= json_file["nombre d'ordres"]) {
+ if(currentItemIndex >= analysis["nombre d'ordres"]) {
clearInterval(interval);
}
}, periode);
});
});
});
+
+$(document).ready(function() {
+ $.getJSON('{{ url_for('ajax_get_analysis') }}',
+ { filename: '{{ filename }}' },
+ function(data) {
+ analysis = data;
+ }
+ );
+});
</script>
{% endblock %}