Exemplo n.º 1
0
 def regulator_update(self):
     ret_dict = {}
     controls = self.request.POST.items()
     reg_id = self.request.matchdict['reg_id']
     reg = DBSession.query(Regulator).filter_by(_id=reg_id).one()
     form = Form(EditRegulatorSchema().bind(regulator=reg),
                 formid='edit_regulator_form_' + reg_id,
                 action=self.request.route_url('regulator_update', reg_id=reg_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {edit_regulator(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['regulator'] = reg.serialize
         ret_dict['form'] = e.render()
         return ret_dict
     reg.algorithm_name = vals['algorithm']
     real_reg = regulator_factory(reg.algorithm_name)
     real_reg.initialize_db(reg)
     DBSession.flush()
     ret_dict['form'] = form.render(regulator=reg)
     ret_dict['regulator'] = reg.serialize
     ret_dict['regulator_panel'] = self.request.layout_manager.render_panel('regulator_panel', context=reg)
     self.request.redis.publish('regulator_changes', 'changed '+str(reg.id))
     return ret_dict
Exemplo n.º 2
0
 def parameter_save(self):
     """
     save new parameter
     """
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(NewParameterSchema().bind(),
                 formid='add_parameter_form',
                 action=self.request.route_url('parameter_save'),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { add_parameter(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     parameter_type = DBSession.query(ParameterType).filter_by(_id=vals['parameter_type']).one()
     new_parameter = Parameter(vals['name'], parameter_type, None, vals['description'])
     DBSession.add(new_parameter)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['parameter_panel'] = self.request.layout_manager.render_panel('parameter_panel', context=new_parameter)
     self.request.redis.publish('parameter_changes', 'added '+str(new_parameter.id))
     return ret_dict
Exemplo n.º 3
0
 def regulator_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(NewRegulatorSchema().bind(),
                 formid='add_regulator_form',
                 action=self.request.route_url('regulator_save'),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) {add_regulator(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['form'] = e.render()
         ret_dict['error'] = True
         return ret_dict
     new_reg = Regulator(vals['name'], vals['algorithm'], vals['description'])
     real_reg = regulator_factory(new_reg.algorithm_name)
     real_reg.initialize_db(new_reg)
     DBSession.add(new_reg)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['regulator_panel'] = self.request.layout_manager.render_panel('regulator_panel', context=new_reg)
     self.request.redis.publish('regulator_changes', 'added '+str(new_reg.id))
     return ret_dict
 def device_link_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     dis_id = self.request.matchdict['dis_id']
     form = Form(DeviceLinkSchema().bind(),
                 formid='add_device_link_form_' + dis_id,
                 action=self.request.route_url('device_link_save', dis_id=dis_id),
                 use_ajax=True,
                 ajax_options='{"success": function (rt, st, xhr, form) { add_device_link(rt);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     display = DBSession.query(Display).filter_by(_id=dis_id).one()
     device = DBSession.query(Device).filter_by(_id=vals['device']).one()
     new_device_link = DeviceLink(display, device, vals['target'], vals['color'])
     DBSession.add(new_device_link)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['device_link_panel'] = self.request.layout_manager.render_panel('device_link_panel',
                                                                              context=new_device_link)
     ret_dict['device_link'] = new_device_link.serialize
     return ret_dict
Exemplo n.º 5
0
 def log_diagram_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(
         LogDiagramSchema().bind(),
         formid='add_log_diagram_form',
         action=self.request.route_url('log_diagram_save'),
         use_ajax=True,
         ajax_options=
         '{"success": function (rText, sText, xhr, form) { add_log_diagram(rText);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     new_log_diagram = LogDiagram(vals['name'], vals['description'],
                                  vals['period'])
     DBSession.add(new_log_diagram)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict[
         'log_diagram_panel'] = self.request.layout_manager.render_panel(
             'log_diagram_panel', context=new_log_diagram)
     return ret_dict
Exemplo n.º 6
0
 def device_link_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     dis_id = self.request.matchdict['dis_id']
     form = Form(
         DeviceLinkSchema().bind(),
         formid='add_device_link_form_' + dis_id,
         action=self.request.route_url('device_link_save', dis_id=dis_id),
         use_ajax=True,
         ajax_options=
         '{"success": function (rt, st, xhr, form) { add_device_link(rt);}}',
         buttons=('Save', ))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     display = DBSession.query(Display).filter_by(_id=dis_id).one()
     device = DBSession.query(Device).filter_by(_id=vals['device']).one()
     new_device_link = DeviceLink(display, device, vals['target'],
                                  vals['color'])
     DBSession.add(new_device_link)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict[
         'device_link_panel'] = self.request.layout_manager.render_panel(
             'device_link_panel', context=new_device_link)
     ret_dict['device_link'] = new_device_link.serialize
     return ret_dict
Exemplo n.º 7
0
 def calendar_param_entry_save(self):
     """
     save new calendar entry
     """
     ret_dict = {}
     controls = self.request.POST.items()
     param = DBSession.query(Parameter).filter_by(_id=self.request.matchdict['param_id']).one()
     last_entry = DBSession.query(CalendarEntry).filter_by(parameter_id=param.id).order_by(
         desc(CalendarEntry.entry_number)).first()
     add_form = Form(CalendarEntrySchema().bind(),
                     formid='add_param_calender_entry',
                     action=self.request.route_url('calendar_param_entry_save', param_id=param.id),
                     use_ajax=True,
                     ajax_options='{"success": function(rt, st, xhr, form) { add_calendar_param_entry(rt);}}',
                     buttons=('Save',))
     try:
         vals = add_form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     inter = DBSession.query(SetpointInterpolation).filter_by(_id=vals['interpolation']).one()
     index = 1
     if last_entry is not None:
         index = last_entry.entry_number + 1
     new_entry = CalendarEntry(param, index, inter)
     DBSession.add(new_entry)
     DBSession.flush()
     ret_dict['form'] = add_form.render()
     ret_dict['entry_panel'] = self.request.layout_manager.render_panel('calendar_param_entry', context=new_entry)
     self.request.redis.publish('calendar_changes', 'param ' + str(param.id))
     return ret_dict
Exemplo n.º 8
0
 def interpolation_save(self):
     """
     save new setpoint interpolation
     """
     ret_dict = {}
     controls = self.request.POST.items()
     add_form = Form(SetpointInterpolationSchema().bind(),
                     formid='add_interpolation_form',
                     action=self.request.route_url('interpolation_save'),
                     use_ajax=True,
                     ajax_options='{"success": function(rText, sText, xhr, form) { add_interpolation(rText);}}',
                     buttons=('Save',))
     try:
         vals = add_form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     new_inter = SetpointInterpolation(vals['name'], vals['order'], vals['start_value'], vals['end_time'],
                                       vals['end_value'], vals['description'])
     DBSession.add(new_inter)
     DBSession.flush()
     ret_dict['form'] = add_form.render()
     ret_dict['interpolation_panel'] = self.request.layout_manager.render_panel('interpolation_panel',
                                                                                context=new_inter)
     filename = self.request.registry.settings['plot_directory'] + '/interpolation_' + str(new_inter.id) + '.png'
     new_inter.plot('', filename)
     self.request.redis.publish('calendar_changes', 'interpolation saved')
     return ret_dict
Exemplo n.º 9
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)

    engine = engine_from_config(settings, 'sqlalchemy.', echo=False)
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    # populate databases
    with transaction.manager:
        print('\ninit_setpoint_interpolations:\n')
        init_setpoint_interpolations(DBSession)
        print('\ninit_parameter_types:\n')
        init_parameter_types(DBSession)
        print('\ninit_device_types:\n')
        init_device_types(DBSession)
        print('\ninit_periphery_controllers:\n')
        DBSession.flush()
        init_periphery_controllers(DBSession)
        DBSession.flush()
        print('\ninit_parameters:\n')
        init_parameters(DBSession)
        print('\ninit_devices:\n')
        init_devices(DBSession)
        print('\ninit_field_settings:\n')
        init_field_settings(DBSession)
        print('\ninit_regulators:\n')
        DBSession.flush()
        init_regulators(DBSession)
        init_log_diagrams(DBSession)
Exemplo n.º 10
0
 def log_diagram_save(self):
     ret_dict = {}
     controls = self.request.POST.items()
     form = Form(LogDiagramSchema().bind(),
                 formid='add_log_diagram_form',
                 action=self.request.route_url('log_diagram_save'),
                 use_ajax=True,
                 ajax_options='{"success": function (rText, sText, xhr, form) { add_log_diagram(rText);}}',
                 buttons=('Save',))
     try:
         vals = form.validate(controls)
         ret_dict['error'] = False
     except ValidationFailure as e:
         ret_dict['error'] = True
         ret_dict['form'] = e.render()
         return ret_dict
     new_log_diagram = LogDiagram(vals['name'], vals['description'], vals['period'])
     DBSession.add(new_log_diagram)
     DBSession.flush()
     ret_dict['form'] = form.render()
     ret_dict['log_diagram_panel'] = self.request.layout_manager.render_panel('log_diagram_panel',
                                                                              context=new_log_diagram)
     return ret_dict