Esempio n. 1
0
    def update_run_model(self, form):

        from flask import flash
        if form.get('name') != "":
            plg = Plugin.query.filter_by(name=self.name).first()
            icfg = Config.query.filter_by(plugin_id=plg.id,
                                          role="Runtime",
                                          name=form.get("name")).first()
            if icfg is None:
                icfg = Config(plugin=plg,
                              role="Runtime",
                              name=form.get('name'))
            #TODO we need to validate this as usable dict
            #update config obj with formdata
            new_args = form.get("args")
            icfg.args = ast.literal_eval(new_args)
            try:
                self.app.db.session.add(icfg)
                self.app.db.session.commit()
            except:
                flash("Run Config  submission failed", "error")
                return 'run'
            else:
                flash("Run Config %s submitted" % form.get("name"), "message")
                return 'main'
        else:
            flash("You must submit name and args", "error")
            return 'run'
Esempio n. 2
0
 def get_configs(self):
     cfg = Config(name="HDR 10 Shot",
                  role="Runtime",
                  args={
                      'file_prefix':
                      'hdr',
                      'pixel_format':
                      'BayerGB8',
                      'sequence': [{
                          'exposure_time': 977
                      }, {
                          'exposure_time': 1953
                      }, {
                          'exposure_time': 3906
                      }, {
                          'exposure_time': 7813
                      }, {
                          'exposure_time': 15625
                      }, {
                          'exposure_time': 31250
                      }, {
                          'exposure_time': 62500
                      }, {
                          'exposure_time': 125000
                      }, {
                          'exposure_time': 250000
                      }, {
                          'exposure_time': 500000
                      }, {
                          'exposure_time': 1000000
                      }]
                  })
     return [cfg]
Esempio n. 3
0
    def update_init_form(self):
        #load init config stored

        icfg = Config.query.join(Plugin).filter(
            Plugin.name == self.name).filter(
                Config.role == "Initalize").first()
        if icfg is None:
            plg = Plugin.query.filter_by(name=self.name).first()
            icfg = Config(plugin=plg,
                          role="Initalize",
                          args={},
                          name="PhenoCam Init")
#        form  = InitArgsForm(id="init")
        sensors = {}
        sl = icfg.args.get("sensors", None)
        if sl is not None:
            for s in sl:
                sensors[s.get('name')] = s.get('mac')

        form = InitArgsForm(id='init',
                            rgb=sensors.get('rgb', ""),
                            nir=sensors.get('nir', ""))

        if 'relay_name' in icfg.args:
            form.use_relay.data = True
            form.relay_name.data = Plugin.query.filter_by(
                name=icfg.args.get("relay_name")).first()
            form.relay_delay.data = int(icfg.args.get("relay_delay", ""))
            form.relay_port.data = int(icfg.args.get("relay_port", ""))
        else:
            form.use_relay = False
        return form
Esempio n. 4
0
    def update_init_model(self, form):
        from flask import flash
        #load init config stored
        icfg = Config.query.join(Plugin).filter(
            Plugin.name == self.name).filter(
                Config.role == "Initalize").first()
        if icfg is None:
            plg = Plugin.query.filter_by(name=self.name).first()
            icfg = Config(plugin=plg,
                          role="Initalize",
                          args={},
                          name="PhenoCam Init")
        #update config obj with formdata
        new_args = icfg.args.copy()
        new_args['sensors'] = ({
            "name": "rgb",
            "mac": form.get('rgb')
        }, {
            "name": "nir",
            "mac": form.get('nir')
        })
        # if using relay then add to args else remove from args
        if form.get('use_relay') == 'y':
            plugin_name = Plugin.query.get(int(form.get('relay_name'))).name
            new_args['relay_name'] = plugin_name
            new_args['relay_port'] = int(form.get('relay_port'))
            new_args['relay_delay'] = int(form.get('relay_delay'))
        else:
            for arg in ('relay_name', 'relay_port', 'relay_delay'):
                new_args.pop(arg, None)

        icfg.args = new_args
        try:
            self.app.db.session.add(icfg)
            self.app.db.session.commit()
        except:
            flash("Init form submission failed", "danger")
            return 'init'
        else:
            self.configure(**icfg.args)
            flash("Camera Settings Updated, Initialization Completed",
                  "message")
            return 'main'
Esempio n. 5
0
 def get_configs(self):
     cfg = Config(name="HDR 10 Shot",
                  role="Runtime",
                  args={
                      'rgb': {
                          'pixel_format': 'BayerRG8',
                          'ob_mode': False
                      },
                      'nir': {
                          'pixel_format': 'Mono8',
                          'ob_mode': False
                      },
                      'file_prefix':
                      'hdr',
                      'image_type':
                      'jpg',
                      'sequence': [
                          {
                              'exposure_time': 20
                          },
                          {
                              'exposure_time': 40
                          },
                          {
                              'exposure_time': 120
                          },
                          {
                              'exposure_time': 240
                          },
                          {
                              'exposure_time': 480
                          },
                          {
                              'exposure_time': 960
                          },
                          {
                              'exposure_time': 1920
                          },
                          {
                              'exposure_time': 3840
                          },
                          {
                              'exposure_time': 7680
                          },
                          {
                              'exposure_time': 15360
                          },
                          {
                              'exposure_time': 30720
                          },
                      ]
                  })
     return [cfg]
Esempio n. 6
0
    def update_init_form(self):
        #load init config stored
        plg = Plugin.query.filter_by(name=self.name).first()
        icfg = Config.query.filter_by(plugin_id=plg.id,
                                      role="Initalize").first()
        if icfg is None:
            icfg = Config(plugin=plg,
                          role="Initalize",
                          args={},
                          name="SkyImager Init")

        form = InitArgsForm(id='init')

        if 'relay_name' in icfg.args:
            form.use_relay.data = True
            form.relay_name.data = Plugin.query.filter_by(
                name=icfg.args.get("relay_name")).first()
            form.relay_delay.data = int(icfg.args.get("relay_delay", ""))
            form.relay_port.data = int(icfg.args.get("relay_port", ""))
        else:
            form.use_relay = False
        return form
Esempio n. 7
0
    def plugin_view(self):

        from flask.ext.admin import helpers as h
        from flask import flash, request
        active_tab = 'main'
        if h.is_form_submitted():
            form_data = request.form
            form_type = form_data.get('id')
            if form_type == 'init':
                #load init config stored
                icfg = Config.query.join(Plugin).filter(
                    Plugin.name == self.name).filter(
                        Config.role == "Initalize").first()
                if icfg is None:
                    plg = Plugin.query.filter_by(name=self.name).first()
                    icfg = Config(plugin=plg,
                                  role="Initalize",
                                  args={},
                                  name="Test_Task Init")
                #update config obj with formdata
                new_args = icfg.args.copy()

                #icfg.args = new_ar
                new_args['arg1'] = form_data.get('arg1')  #this one is a string
                new_args['arg2'] = form_data.get(
                    'arg2')  #this one should be a dict
                icfg.args = new_args
                try:
                    self.app.db.session.add(icfg)
                    self.app.db.session.commit()
                except:
                    flash("Init form submission failed, bad data in form",
                          "danger")
                    active_tab = 'init'
                else:
                    flash("Init Form submitted", "message")

            elif form_type == 'run':
                #load init config stored
                plg = Plugin.query.filter_by(name=self.name).first()
                icfg = Config(name=form_data.get('name'),
                              role="Runtime",
                              plugin=plg)
                #update config obj with formdata
                icfg.args = dict()
                icfg.args['arg1'] = form_data.get('arg1')
                icfg.args['arg2'] = form_data.get('arg2')
                try:
                    self.app.db.session.add(icfg)
                    self.app.db.session.commit()
                except ValueError:
                    flash("Run form submission failed, bad data in arg2",
                          "danger")
                    active_tab = 'run'
                except:
                    flash("Run form submission failed", "danger")
                    active_tab = 'run'
                else:
                    flash("Run Form submitted", "message")

        #load init config stored
        icfg = Config.query.join(Plugin).filter(
            Plugin.name == self.name).filter(
                Config.role == "Initalize").first()
        if icfg is None:
            plg = Plugin.query.filter_by(name=self.name).first()
            icfg = Config(plugin=plg,
                          role="Initalize",
                          args={},
                          name="Test_Task Init")

        init_form = InitArgsForm(id="init",
                                 name=icfg.name,
                                 arg1=icfg.args.get('arg1', ""),
                                 arg2=icfg.args.get('arg2', ""))

        run_form = RunArgsForm(id="run")

        ##render page
        return self.render(self.view_template,
                           init_form=init_form,
                           active_tab=active_tab,
                           return_url="/test_task/",
                           run_form=run_form)
Esempio n. 8
0
    def update_cap_model(self, data):
        from flask import flash
        form = CaptureParamsForm(data)
        action = data.get("submit")
        cap_panel = 'file'
        exfname = self.get_file_name()
        if action == "Delete":
            plg = Plugin.query.filter_by(name=self.name).first()
            icfg = Config.query.filter_by(plugin_id=plg.id,
                                          role="Runtime",
                                          name=data.get("name")).first()
            try:
                self.app.db.session.delete(icfg)
                self.app.db.session.commit()
            except:  # bad delete return to cap
                flash("Could not delete config %s" % data.get('name'), "error")
            else:  #good delete flash and return to main
                flash("Config %s has been deleted" % data.get('name'),
                      "message")
                form = None
                icfg.id = None
        else:
            if form.validate():
                plg = Plugin.query.filter_by(name=self.name).first()
                icfg = Config.query.filter_by(plugin_id=plg.id,
                                              role="Runtime",
                                              name=data.get("name")).first()
                if icfg is None:
                    icfg = Config(plugin_id=plg.id,
                                  role="Runtime",
                                  name=data.get('name'))
                icfg.args = {}
                icfg.args['sub_dir'] = form.file_settings.sub_dir.data
                icfg.args['date_dir'] = form.file_settings.date_dir.data
                icfg.args[
                    'date_dir_nested'] = form.file_settings.date_dir_nested.data
                icfg.args['image_type'] = form.file_settings.image_type.data
                icfg.args['file_prefix'] = form.file_settings.file_prefix.data
                exfname = self.get_file_name(**icfg.args)
                icfg.args['rgb'] = {
                    'pixel_format': form.rgb_settings.pixel_format.data,
                    'ob_mode': form.rgb_settings.ob_mode.data
                }
                icfg.args['nir'] = {
                    'pixel_format': form.nir_settings.pixel_format.data,
                    'ob_mode': form.nir_settings.ob_mode.data
                }
                exp_vals = [
                    s.strip()
                    for s in form.shot_settings.exposure.data.splitlines()
                ]
                gain_vals = [
                    s.strip()
                    for s in form.shot_settings.gain.data.splitlines()
                ]
                icfg.args['sequence'] = []
                gains = len(gain_vals)
                for e in exp_vals:
                    i = exp_vals.index(e)
                    gain = 0
                    # default if nothing specified
                    if gains == 1:  # on val for all exposures
                        gain = gain_vals[0]
                    elif gains > 1 and i < gains:  #use whats specd
                        gain = gain_vals[i]
                    icfg.args['sequence'].append({
                        'exposure_time': int(e),
                        'gain': int(gain)
                    })
                try:
                    self.app.db.session.add(icfg)
                    self.app.db.session.commit()
                except:  # failed submit return to cap with form as is
                    flash("Shot Config  submission failed", "error")
                else:
                    flash("Shot Config %s updated" % data.get("name"),
                          "message")

            else:  # form didn't validate return with form for inspection
                errmsg = "Check your config for errors:\n"
                for n in form.errors.keys():
                    if n == "file_settings":
                        cap_panel = 'file'
                    elif n == "shot_settings":
                        cap_panel = 'shot'
                flash(errmsg, "error")
        return (icfg.id, exfname, cap_panel, form)