From 3b6d299816c8a57b358c2246a20c9990c02c9e72 Mon Sep 17 00:00:00 2001 From: ColsonZhang <784278850@qq.com> Date: Thu, 18 Mar 2021 20:54:06 +0800 Subject: [PATCH] add a new idea --- README.md | 3 +++ handler/sim_data_container.py | 8 ++++++ handler/spice.py | 2 ++ static/spice/show_result.js | 48 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 handler/sim_data_container.py create mode 100644 static/spice/show_result.js diff --git a/README.md b/README.md index 2f80480..bba6a22 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,9 @@ app.py ----服务器的主程序 ## 更新日志 +* 2021年3月18号,后端更新 + + * idea & todo:仿真结果数据可视化的基本思路为:在后端的python代码中,用一个自定义类封装的simulation result data container来容纳数据,并新增一个用于处理get/post请求的处理函数,当前端需要这些相关数据时,通过ajax发送过去;同时前端使用bokehjs封装一个通用的结果显示的“示波器”,向服务器后端发送请求,接收相关数据,并展示结果。 * 2021年3月17号,后端更新 * 新增:根据前端传入的电路数据和仿真参数,进行参数转换,调用pyspice执行电路仿真 diff --git a/handler/sim_data_container.py b/handler/sim_data_container.py new file mode 100644 index 0000000..1fb0ab9 --- /dev/null +++ b/handler/sim_data_container.py @@ -0,0 +1,8 @@ + +class Sim_Data_Container : + def __init__(self): + self.analysis = None + + def load_analysis(self,analysis): + self.analysis = analysis + \ No newline at end of file diff --git a/handler/spice.py b/handler/spice.py index 3977768..07cc520 100644 --- a/handler/spice.py +++ b/handler/spice.py @@ -3,9 +3,11 @@ from .js import js_import, js_code_1 import tornado.web from .MongoDB import * from .simulation import Simulator_CZ +from .sim_data_container import Sim_Data_Container # from bokeh.embed import server_document # from jinja2 import Environment, FileSystemLoader +Container_SimResult = Sim_Data_Container() class SpiceHandler(AuthBaseHandler): diff --git a/static/spice/show_result.js b/static/spice/show_result.js new file mode 100644 index 0000000..0a8fdeb --- /dev/null +++ b/static/spice/show_result.js @@ -0,0 +1,48 @@ +/* 基于bokeh.js库文件 + 使用该文件前请现在html加载相关js文件*/ + + + + +// create a data source to hold data +var source = new Bokeh.ColumnDataSource({ + data: { x: [], y: [] } +}); + +// make a plot with some tools +var plot = Bokeh.Plotting.figure({ + title:'Example of Random data', + tools: "pan,wheel_zoom,box_zoom,reset,save", + height: 300, + width: 300 +}); + +// add a line with data from the source +plot.line({ field: "x" }, { field: "y" }, { + source: source, + line_width: 2 +}); + +// show the plot, appending it to the end of the current section +Bokeh.Plotting.show(plot,'#bokeh_01'); + +function addPoint() { + // add data --- all fields must be the same length. + source.data.x.push(Math.random()) + source.data.y.push(Math.random()) + + // notify the DataSource of "in-place" changes + source.change.emit() +} + +function Callback_Button() { + addPoint(); +} + +var addDataButton = document.createElement("Button"); +addDataButton.appendChild(document.createTextNode("Add Some Data!!!")); +document.currentScript.parentElement.appendChild(addDataButton); +addDataButton.addEventListener("click", Callback_Button); + +addPoint(); +addPoint();