def upd_items(self): ''' Update data folder with what needs to be changed (as a result of an action taken). ''' # Retrieving data/corpuses from data and corp folders self.chda = json.loads(open(self.chda_path).read()) self.chenv = json.loads(open(self.chenv_path).read()) self.event = json.loads(open(self.event_path).read()) self.final = json.loads(open(self.final_path).read()) # Get lists of item names and new values self.conseq = self.final["conseq"] # Set variables chda = chdam.ChDa(self.chda) chenv = chenvm.ChEnv(self.chenv) event = eventm.Event(self.event) # noqa # For each variable that needs to be changed, execute a command # designated in the event file (this will change something in # either chda or chenv) for i in range(len(self.conseq)): exec(self.conseq[i]) # Save changes to data files with open(self.chda_path, 'w') as f: json.dump(chda.get_json(), f) with open(self.chenv_path, 'w') as f: json.dump(chenv.get_json(), f)
def sum_node(events, _): _data = {"val": 0.} for _e in events: if _e.get_status(): _val = _e.get_data() _data["val"] += _val["val"] _e = event.Event(events[0].get_time_scale(), _data) return _e
def check_colls(self, saucer, sim_time): for dish in self.particles: t_disk = saucer.disk_coll(dish) if self.time + t_disk <= sim_time: event = ev.Event(self.time + t_disk, saucer, dish) pq.heappush(self.minpq, event) t_vert = saucer.vert_wall_coll() t_horz = saucer.horz_wall_coll() if self.time + t_vert <= sim_time: event = ev.Event(self.time + t_vert, saucer, None) pq.heappush(self.minpq, event) if self.time + t_horz <= sim_time: event = ev.Event(self.time + t_horz, None, saucer) pq.heappush(self.minpq, event)
def z_func(events, _): """ 一阶z函数 :param events: 输入事件 :param _: :return: 延迟事件 """ """延迟一个时标""" return event.Event(events[0].get_time_scale()+1, {"val": events[0].get_data()["val"]})
def multi_func(events, _): # (">>> func11"), _data = {"val": 1.0} for _e in events: if _e.get_status(): _val = _e.get_data() # print _val["val"], _data["val"] *= _val["val"] # print _data["val"] _e = event.Event(events[0].get_time_scale(), _data) return _e
def q_func(_event, sn): global sin_W0, A """ 单位脉冲信号发生器 :param _event: :param sn: :return: """ _data = { "val": A * sin_W0, } return event.Event(sn, _data)
def node_c(_events, _): global cos_W0 _data = _events[0].get_data() _e = event.Event(_events[0].get_time_scale(), {"val": _data["val"] * (2.0 * cos_W0)}) return _e
import sys from event import event from PyQt5.QtWidgets import QApplication, QMainWindow if __name__ == '__main__': app = QApplication(sys.argv) MainWindow = QMainWindow() ui = event.Event(MainWindow) MainWindow.show() sys.exit(app.exec_())
def node_a(_events, _): _data = _events[0].get_data() _e = event.Event(z_func(_events[0]).get_time_scale(), _data) return _e
def cos_w0(val, sn): global cos_W0 return event.Event(sn, {"val": val*cos_W0})
def sin_w0(val, sn): global sin_W0 return event.Event(sn, {"val": val*sin_W0})
def init_event(): return [event.Event(0, {"val": 1.})]
def init_node_a(): return [event.Event(0, {"val": 0.})]
def node_b(_events, sn): _data = _events[0].get_data() _e = event.Event( z_func(_events[0]).get_time_scale(), {"val": -1. * _data["val"]}) return _e
def noise(_event, sn): # print(">>> noise") _data = { "val": 1. + 0.2 * random.uniform(-1, 1), } return event.Event(sn, _data)
def cos_func(_event, sn): # print(">>> func1") _data = { "val": 5.*numpy.cos(2*numpy.pi*float(sn)/10.), } return event.Event(sn, _data)
def sin_func(_event, sn): # print(">>> func1") _data = { "val": 1.2 + 0.8*numpy.sin(2*numpy.pi*float(sn)/100.), } return event.Event(sn, _data)
def init_node_b(): return [ event.Event(0, {"val": 0.}), event.Event(1, {"val": 0.}), ]