Пример #1
0
    def check_configured(self):
        """Check if compute package has been configured and that and that the
        state of the ReducerControl is not in setup otherwise render setup template. 
        Check if initial model has been configured, otherwise render setup_model template.
        :return: Rendered html template or None
        """
        if not self.check_compute_context():
            return render_template('setup.html',
                                   client=self.name,
                                   state=ReducerStateToString(
                                       self.control.state()),
                                   logs=None,
                                   refresh=False,
                                   message='Please set the compute package')

        if self.control.state() == ReducerState.setup:
            return render_template(
                'setup.html',
                client=self.name,
                state=ReducerStateToString(self.control.state()),
                logs=None,
                refresh=True,
                message=
                'Warning. Reducer is not base-configured. please do so with config file.'
            )

        if not self.check_initial_model():
            return render_template('setup_model.html',
                                   message="Please set the initial model.")

        return None
Пример #2
0
    def run(self):

        threading.Thread(target=self.rest.run, daemon=True).start()

        import time
        from datetime import datetime
        try:
            old_state = self.control.state()

            t1 = datetime.now()
            while True:
                time.sleep(1)
                if old_state != self.control.state():
                    delta = datetime.now() - t1
                    print(
                        "Reducer in state {} for {} seconds. Entering {} state"
                        .format(ReducerStateToString(old_state), delta.seconds,
                                ReducerStateToString(self.control.state())),
                        flush=True)
                    t1 = datetime.now()
                    old_state = self.control.state()

                self.control.monitor()
        except (KeyboardInterrupt, SystemExit):
            print("Exiting..", flush=True)
Пример #3
0
        def start():

            if request.method == 'POST':
                timeout = request.form.get('timeout', 180)
                rounds = int(request.form.get('rounds', 1))

                task = (request.form.get('task', ''))
                active_clients = request.form.get('active_clients', 2)
                clients_required = request.form.get('clients_required', 2)
                clients_requested = request.form.get('clients_requested', 8)

                latest_model_id = self.control.get_latest_model()
                config = {'round_timeout': timeout, 'model_id': latest_model_id,
                          'rounds': rounds, 'active_clients': active_clients, 'clients_required': clients_required,
                          'clients_requested': clients_requested, 'task': task}

                self.control.instruct(config)
                return redirect(url_for('index', message="Sent execution plan."))

            else:
                # Select rounds UI
                rounds = range(1, 100)
                latest_model_id = self.control.get_latest_model()
                return render_template('index.html', round_options=rounds, latest_model_id=latest_model_id)

            client = self.name
            state = ReducerStateToString(self.control.state())
            logs = None
            refresh = False
            return render_template('index.html', client=client, state=state, logs=logs, refresh=refresh)
Пример #4
0
    def run(self):

        threading.Thread(target=self.rest.run, daemon=True).start()

        import time
        try:
            while True:
                time.sleep(1)
                print("Reducer in {} state".format(
                    ReducerStateToString(self.control.state())),
                      flush=True)
                self.control.monitor()
        except (KeyboardInterrupt, SystemExit):
            print("Exiting..", flush=True)