2021-02-08 16:05:18 +08:00
|
|
|
|
from .main import AuthBaseHandler
|
|
|
|
|
from .js import js_import, js_code_1
|
|
|
|
|
import tornado.web
|
|
|
|
|
from .MongoDB import *
|
2021-03-16 20:46:30 +08:00
|
|
|
|
from .simulation import Simulator_CZ
|
2021-03-18 20:54:06 +08:00
|
|
|
|
from .sim_data_container import Sim_Data_Container
|
2021-03-20 15:45:00 +08:00
|
|
|
|
from tornado.escape import json_decode, json_encode, utf8
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
2021-02-08 16:05:18 +08:00
|
|
|
|
# from bokeh.embed import server_document
|
|
|
|
|
# from jinja2 import Environment, FileSystemLoader
|
|
|
|
|
|
2021-03-18 20:54:06 +08:00
|
|
|
|
Container_SimResult = Sim_Data_Container()
|
2021-02-08 16:05:18 +08:00
|
|
|
|
|
|
|
|
|
class SpiceHandler(AuthBaseHandler):
|
|
|
|
|
|
|
|
|
|
@tornado.web.authenticated #@tornado.web.authenticated装饰器包裹get方法时,表示这个方法只有在用户合法时才会调用,authenticated装饰器会调用get_current_user()方法获取current_user的值,若值为False,则重定向到登录url装饰器判断有没有登录,如果没有则跳转到配置的路由下去,但是要在app.py里面设置login_url
|
|
|
|
|
def post(self,*args,**kwargs):
|
|
|
|
|
username = self.get_current_user()
|
|
|
|
|
message = self.get_argument('spice')
|
|
|
|
|
|
2021-03-16 19:09:58 +08:00
|
|
|
|
print('SpiceHandler: '+username+' \n'+message)
|
2021-02-08 16:05:18 +08:00
|
|
|
|
Mongo.connect(DataBase='example',Collection=username)
|
|
|
|
|
Mongo.update(behavior=message,tags='spice')
|
|
|
|
|
|
|
|
|
|
self.write("success")
|
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
|
2021-03-16 19:09:58 +08:00
|
|
|
|
class SimulationHandler(AuthBaseHandler):
|
2021-03-20 15:45:00 +08:00
|
|
|
|
|
2021-03-16 19:09:58 +08:00
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def post(self,*args,**kwargs):
|
2021-03-31 17:06:07 +08:00
|
|
|
|
username = self.get_current_user()
|
|
|
|
|
|
2021-03-16 19:09:58 +08:00
|
|
|
|
sim_type = self.get_argument('sim_type')
|
2021-03-16 20:46:30 +08:00
|
|
|
|
properties_str = self.get_argument('properties')
|
|
|
|
|
spice = self.get_argument('spice')
|
|
|
|
|
|
|
|
|
|
properties = properties_transform(properties_str)
|
2021-02-08 16:05:18 +08:00
|
|
|
|
|
2021-03-17 15:07:37 +08:00
|
|
|
|
# print("sim type:",sim_type)
|
|
|
|
|
# print("property:",properties_str)
|
|
|
|
|
# print("spice :\n",spice)
|
2021-04-01 13:10:17 +08:00
|
|
|
|
try:
|
|
|
|
|
simulator = Simulator_CZ()
|
|
|
|
|
simulator.Get_Spice(spice)
|
|
|
|
|
analysis = simulator.Sim(sim_type,properties)
|
|
|
|
|
print('properties:\n',properties)
|
|
|
|
|
print('simulation finished !')
|
|
|
|
|
|
|
|
|
|
Container_SimResult.load_analysis(sim_type,analysis)
|
|
|
|
|
print('data container load data successfully!! ')
|
|
|
|
|
message = "Simulation: Success \n"
|
2021-04-01 13:20:55 +08:00
|
|
|
|
message += "Sim_Type="+ sim_type + "\n Properties=" +properties_str
|
|
|
|
|
Mongo.connect(DataBase='example',Collection=username)
|
|
|
|
|
Mongo.update(behavior=message,tags='simulation',spice=spice)
|
|
|
|
|
self.write("success")
|
2021-04-01 13:10:17 +08:00
|
|
|
|
except:
|
|
|
|
|
message = "Simulation: Fail \n"
|
2021-04-01 13:20:55 +08:00
|
|
|
|
message += "Sim_Type="+ sim_type + "\n Properties=" +properties_str
|
|
|
|
|
Mongo.connect(DataBase='example',Collection=username)
|
|
|
|
|
Mongo.update(behavior=message,tags='simulation',spice=spice)
|
|
|
|
|
self.write("Fail! 请检查电路元件!!!元件名字是否有重复?")
|
2021-04-01 13:10:17 +08:00
|
|
|
|
|
2021-02-08 16:05:18 +08:00
|
|
|
|
|
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
# 将properties 从字符串类型解析出来
|
|
|
|
|
# todo: 转换为json解析
|
2021-03-16 20:46:30 +08:00
|
|
|
|
def properties_transform(properties_str):
|
|
|
|
|
properties = {}
|
|
|
|
|
attributes = properties_str.split(";")
|
|
|
|
|
# print(attributes)
|
|
|
|
|
for attr in attributes:
|
|
|
|
|
if(attr != ''):
|
|
|
|
|
term = attr.split("=")
|
|
|
|
|
properties[term[0]] = term[1]
|
|
|
|
|
return properties
|
|
|
|
|
|
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
class SimulationInfoRequest_Handler(AuthBaseHandler):
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def post(self,*args,**kwargs):
|
2021-03-31 17:06:07 +08:00
|
|
|
|
username = self.get_current_user()
|
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
sim_type = self.get_argument('sim_type')
|
|
|
|
|
|
2021-03-23 20:49:24 +08:00
|
|
|
|
print(sim_type)
|
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
sim_info = Container_SimResult.simulation_info_request(sim_type)
|
2021-03-24 14:39:23 +08:00
|
|
|
|
|
|
|
|
|
# print(sim_info)
|
2021-03-23 20:49:24 +08:00
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
sim_info_json = json.dumps( sim_info )
|
2021-03-24 14:39:23 +08:00
|
|
|
|
# print('json transform ok !!')
|
2021-03-31 17:06:07 +08:00
|
|
|
|
|
|
|
|
|
message = "Sim_Type="+ sim_type
|
|
|
|
|
Mongo.connect(DataBase='example',Collection=username)
|
|
|
|
|
Mongo.update(behavior=message,tags='show_result')
|
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
self.write( sim_info_json )
|
2021-03-24 14:39:23 +08:00
|
|
|
|
# print("send the simulation info request successfully!!!")
|
2021-03-23 20:49:24 +08:00
|
|
|
|
|
2021-03-20 15:45:00 +08:00
|
|
|
|
# self.write(json_decode(sim_info))
|
|
|
|
|
# self.write("successful")
|
|
|
|
|
|
|
|
|
|
|
2021-03-16 20:46:30 +08:00
|
|
|
|
|
2021-02-08 16:05:18 +08:00
|
|
|
|
class Schematic_Handler(AuthBaseHandler):
|
|
|
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def get(self,*args,**kwargs):
|
2021-03-31 17:06:07 +08:00
|
|
|
|
username = self.get_current_user()
|
|
|
|
|
message = 'Open the Schematic'
|
|
|
|
|
Mongo.connect(DataBase='example',Collection=username)
|
|
|
|
|
Mongo.update(behavior=message,tags='schematic')
|
|
|
|
|
|
2021-02-08 16:05:18 +08:00
|
|
|
|
self.render('schematic/schematic.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Spice_1_Handler(AuthBaseHandler):
|
|
|
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def get(self,*args,**kwargs):
|
|
|
|
|
self.render('spice/spice1.html')
|
|
|
|
|
# script = server_document('http://localhost:5006/bkapp')
|
|
|
|
|
# self.render('spice/spice1.html',script=script)
|
|
|
|
|
|
|
|
|
|
class Spice_2_Handler(AuthBaseHandler):
|
|
|
|
|
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def get(self,*args,**kwargs):
|
|
|
|
|
self.render('spice/spice2.html',js_import=js_import,js_code=js_code_1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Spice_3_Handler(AuthBaseHandler):
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def get(self,*args,**kwargs):
|
|
|
|
|
self.render('spice/spice3.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Spice_4_Handler(AuthBaseHandler):
|
|
|
|
|
@tornado.web.authenticated
|
|
|
|
|
def get(self,*args,**kwargs):
|
|
|
|
|
self.render('spice/spice4.html')
|