diff --git a/main/__pycache__/Decision.cpython-310.pyc b/main/__pycache__/Decision.cpython-310.pyc index 1d77cd921b83a35d7cc3672a2ca5f7f4f160f4ef..31410ac5b63ed1dafc47bab0ccf17b90fc033e4f 100644 Binary files a/main/__pycache__/Decision.cpython-310.pyc and b/main/__pycache__/Decision.cpython-310.pyc differ diff --git a/main/backend.py b/main/backend.py index 724be19da8592b09a8b87a0b5dc327ad9898584d..cb890d272110f3b934beda82749cdb1cc9b98553 100644 --- a/main/backend.py +++ b/main/backend.py @@ -430,6 +430,7 @@ def getResults(): dict['winrate'] = round(dec.export_result[0]['winrate']*100) dict['startBalance'] = dec.export_result[0]['StartBalance'] dict['endBalance'] = dec.export_result[0]['EndBalance'] + dict['market'] = dec.symbol dict['moneyProfits'] = {} dict['moneyLosses'] = {} for i in dict['startBalance']: diff --git a/main/templates/index.html b/main/templates/index.html index 7b7cb19050b9b553f96884e4a66e4f41170e3d95..b93db00284fa157bf523c36f1a94a443eded4243 100644 --- a/main/templates/index.html +++ b/main/templates/index.html @@ -319,7 +319,7 @@ </div> </div> <div class="col-sm mb-4 text-center"> - <button type="button" class="btn btn-success btn-lg"> + <button type="button" id="btnExportSimulation" class="btn btn-success btn-lg"> Enregistrer la simulation <i class="bi bi-save"></i> </button> </div> @@ -382,26 +382,38 @@ </div> </section> {% endif %} -<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> +<script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <script src="https://d3js.org/d3.v7.min.js"></script> <script src="https://cdn.canvasjs.com/canvasjs.min.js"></script> <script src="https://canvasjs.com/assets/script/jquery-1.11.1.min.js"></script> <script> const showMoreInfo = document.getElementById('btnShowMoreInfo'); + const exportSimulation = document.getElementById('btnExportSimulation'); const indicatorSelect = document.getElementById('indicatorSelect'); const SMA = document.getElementById('rowSMA'); const random = document.getElementById('rowRandom'); const test = document.getElementById('rowTest'); + var inProgress = {{ inProgress| lower }}; var chart = null; {% if fig != None %} chart = {{ fig | safe }}; - console.log(chart); Plotly.plot("chart", chart, {}); + showMoreInfo.addEventListener('click', function () { + if (moreResults.style.display === 'none') { + moreResults.style.display = 'block'; + showMoreInfo.innerHTML = 'Masquer les résultats'; + } else { + moreResults.style.display = 'none'; + showMoreInfo.innerHTML = 'Afficher plus de résultats'; + } + }); + exportSimulation.addEventListener('click', exportFile); + {% endif %} if (!inProgress && chart == null) { @@ -412,19 +424,6 @@ updateProgressBar(); } - - {% if fig != None %} - showMoreInfo.addEventListener('click', function () { - if (moreResults.style.display === 'none') { - moreResults.style.display = 'block'; - showMoreInfo.innerHTML = 'Masquer les résultats'; - } else { - moreResults.style.display = 'none'; - showMoreInfo.innerHTML = 'Afficher plus de résultats'; - } - }); - {% endif %} - function updateProgressBar() { $.ajax({ url: '/progress', @@ -455,5 +454,30 @@ random.style.display = 'none'; } } + + function exportFile() { + Plotly.toImage(document.getElementById('chart'), { format: 'png' }) + .then(function(dataUrl){ + const filename = "{{ res['market'] }}.json"; + const jsonData = { + image: dataUrl, + res: {{ res | tojson }}, + params: {{ stickyForm | tojson }} + } + const jsonStr = JSON.stringify(jsonData); + + let element = document.createElement('a'); + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(jsonStr)); + element.setAttribute('download', filename); + + element.style.display = 'none'; + document.body.appendChild(element); + + element.click(); + + document.body.removeChild(element); + }) + } + </script> {% endblock %} \ No newline at end of file