# blockchain_optimization_platform **Repository Path**: ryanbq/blockchain_optimization_platform ## Basic Information - **Project Name**: blockchain_optimization_platform - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-06-12 - **Last Updated**: 2024-07-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # blockchain_optimization_platform ## 更新倉庫進展 ### 2024-06-16 需要修改頁面二中的三個圖,並且對圖顯示時間邏輯進行修改 **新增三張圖,分別是階段、空間、階段與空間熵** 構造新的``dataframe``的過程在``utils.py``文件中定義,具體函數分別為:``get_space_entropy(), get_stage_n_space_entropy(), get_stage_entropy()`` > 由於數據文件(files/result/entropy/...)中每一行長度不一,故首先使用填充的方式將dataframe正確構造,再匹配。在輸出csv文件時df會存在index和header擾亂正常讀取的現象,所以存文件時需要忽略index和header 目前暫時將圖更新到page2中,時間邏輯還未修改。 ![image](files/picture/240616-新增三張圖.png) ### 2024-06-19 已完成对页面二中对离开页面的时间的获取,记录在local storage为``elapsedTime`` 但是在``app2.py``中对五个图的line_all相关函数均改写完毕,使用的方法参考图 ![image](files/picture/240619-line_all逻辑.jpeg) ``` python global tx_conflict_rate_idx timediff = request.args.get('elapsedTime') tx_conflict_rate_idx = tx_conflict_rate_idx + int(timediff) ``` **!! 但是观察网页似乎还是没有实现离开页面也在更新的效果** > 对比:作者在commit图中先尝试直接在localstorage内记录chart数据,在实现时间记录后已完成该效果,只是由于**每一个图维护一个记录**有些过于冗杂所以按照上段代码修改 **HINT**:在网页中出现了如下报错 ![image](files/picture/240619-报错信息.png) 且该报错只出现在打开app2.py对应的网页时,所以猜测无法实现效果与之相关。 ### 2024-06-19-No.2 完成时间逻辑修改: 1. 前后端不通的问题: 采用ajax的方式发送数据: ```js // frontend html if (localStorage.isFirstClick == 'false') { // important:!!need the firstclick tag, or commit and txconflict will be wrong!! const elapsedTime = localStorage.getItem('elapsedTime'); // use ajax send each timediff $.ajax({ url : "http://127.0.0.1:5000/send_timediff_data", type: "post", data: JSON.stringify({ "elapsedTime": elapsedTime }), contentType: "application/json", dataType: "JSON", success: function (data){ console.log('Success:', elapsedTime); }, error: function (errorMsg){ console.error('Error:', errorMsg); } }); commit_getStaticData(); setInterval(commit_dynamicdata, hz); tx_conflict_rate_getStaticData(); setInterval(tx_conflict_rate_dynamicdata, hz); getStaticData(); setInterval(entropy_dynamicdata, hz); space_getStaticData(); setInterval(space_entropy_dynamicdata, hz); stage_n_space_getStaticData(); setInterval(stage_n_space_entropy_dynamicdata, hz); } ``` ```python # backend timediff = 0 # global variable, whole page has a same timediff, after get new timediff, each func in page2 get new line update @bp.route("/send_timediff_data", methods=['POST']) def send_data(): global timediff try: data = request.get_json() elapsed_time = data.get('elapsedTime') timediff = int(elapsed_time) print("get the timediff : ", timediff) return jsonify({"status": "success", "receivedTime": elapsed_time}), 200 except Exception as e: return jsonify({"status": "error", "message": str(e)}), 400 ``` 2. 作者在尝试发送数据时,url回报出现报错``400 Bad Request``,这是因为flask只接受数据报文内容格式为``application/json``,在ajax内修改即可 最终成功实现。 @ryanbq 20240612