Ejemplo n.º 1
0
 def updateTaskProgressCallback(self, taskInfo, inProgressList):
     taskId = taskInfo.split(':')[0].split('-')[1]
     taskProgress = int(float(taskInfo.split(':')[1]))
     return [
         Output(f'progress-{taskId}', 'value', taskProgress),
         Output(f'progress-{taskId}', 'children',
                f'{taskProgress}%' if taskProgress >= 5 else '')
     ]
Ejemplo n.º 2
0
def createRefreshComponent(app, componentId, callback):
    app.callback([
        Output('in-queue-list', 'children'),
        Output('in-progress-list', 'children'),
        Output('in-completed-list', 'children'),
        Output('in-aborted-list', 'children'),
    ], [Input(componentId, 'children')])(callback)

    return html.Div(id=componentId, style={'display': 'none'})
Ejemplo n.º 3
0
    def updateReportListCallback(self, taskInfo):
        taskId = taskInfo.split(':')[0].split('-')[1]
        taskStatus = taskInfo.split(':')[1]

        if taskStatus == 'in-queue':
            sp().moveElement(toList='in-queue', value=taskId)
            return Output('in-queue-list', 'children', cc.createInQueueList())

        elif taskStatus == 'in-progress':
            sp().moveElement(fromList='in-queue', toList='in-progress', value=taskId)
            return [
                Output('in-queue-list', 'children', cc.createInQueueList()),
                Output('in-progress-list', 'children',
                       cc.createInProgressList())
            ]
        elif taskStatus == 'in-completed':
            sp().moveElement(fromList='in-progress', toList='in-completed', value=taskId)
            return [
                Output('in-progress-list', 'children',
                       cc.createInProgressList()),
                Output('in-completed-list', 'children',
                       cc.createInCompletedList())
            ]
        elif taskStatus == 'in-aborted':
            sp().moveElement(fromList=[
                'in-progress', 'in-queue'], toList='in-aborted', value=taskId)
            return [
                Output('in-queue-list', 'children', cc.createInQueueList()),
                Output('in-progress-list', 'children',
                       cc.createInProgressList()),
                Output('in-aborted-list', 'children',
                       cc.createInAbortedList()),
            ]
        else:
            print(f'Bad task status {taskStatus} for task {taskId}')
def card(id: str, *, header: str, childs: list, app=None):
    @app.callback(Output(f'collapse-{id}',
                         'is_open'), [Input(f'toggle-{id}', 'n_clicks')],
                  [State(f'collapse-{id}', 'is_open')])
    def toggleButtonCallback(n_click, is_open):
        return not is_open if n_click else is_open

    return dbc.Card(id=id,
                    children=[
                        dbc.CardHeader(
                            html.H6(
                                dbc.Button(header,
                                           color="link",
                                           id=f'toggle-{id}',
                                           className='text-body'))),
                        dbc.Collapse(id=f'collapse-{id}',
                                     children=childs,
                                     style={
                                         'padding': '15px',
                                     }),
                    ],
                    className='shadow',
                    style={
                        'margin': '10px 0',
                    })
Ejemplo n.º 5
0
def createCallbackForClick(app, inputsList, outputsList, statesList, func):
    outputsList = [Output(item['id'], item['prop'])
                   for item in outputsList] if len(outputsList) else None
    inputsList = [Input(item['id'], item['prop'])
                  for item in inputsList] if len(inputsList) else [None]
    statesList = [State(item['id'], item['prop'])
                  for item in statesList] if len(statesList) else [None]

    app.callback(outputsList, inputsList, statesList)(func)
Ejemplo n.º 6
0
    def make(monitor, room):
        view = RoomView(monitor, room)

        @monitor.view.callback(Output(view.tank.id, 'max'),
                               [Input(view.input.id, 'value')])
        def update_max(value):
            try:
                room.occupancy_max = value
                return room.occupancy_max
            except Exception as e:
                print(e)
                raise (e)

        monitor.view.clientside_callback(
            """
            function(value, max) {
                if (value < max) {
                    return 'lightgreen';
                } else if (value == max) {
                    return 'lemonchiffon';
                } else {
                    return 'lightcoral';
                }
            }
            """, Output(view.tank.id, 'color'),
            [Input(view.tank.id, 'value'),
             Input(view.tank.id, 'max')])

        monitor.view.clientside_callback(
            """
            function(value, max) {
                return value + "/" + max + " people"
            }
            """, Output(view.label.id, 'children'),
            [Input(view.tank.id, 'value'),
             Input(view.tank.id, 'max')])

        return view
Ejemplo n.º 7
0
 def createCallbacks(self):
     @self.app.callback(
         Output({'type': 'abort-button', 'index': MATCH}, 'id'),
         [
             Input({'type': 'abort-button', 'index': MATCH}, 'n_clicks')
         ],
         [
             State({'type': 'abort-button', 'index': MATCH}, 'id'),
         ],
     )
     def f(n_clicks, buttonId):
         if (n_clicks):
             taskId = buttonId['index']
             self.wm.restartWorkerByTask(taskId)
             sp().updateTaskStatus(taskId, 'in-aborted')
         return buttonId
Ejemplo n.º 8
0
 def callbacks(self):
     @app.callback(Output('tasklist', 'data'),
                   [Input('tabs-tasks', 'value')])
     def render_content(tab):
         return self.tasks_ended
Ejemplo n.º 9
0
def taskCard(app, info, submitButtonCallback):
    @app.callback(Output(f'collapse-{info["name"]}', 'is_open'),
                  [Input(f'toggle-{info["name"]}', 'n_clicks')],
                  [State(f'collapse-{info["name"]}', 'is_open')])
    def toggleButtonCallback(n_click, is_open):
        return not is_open if n_click else is_open

    app.callback(None, [
        Input(f'start-button-{info["name"]}', 'n_clicks'),
    ], [
        State(f'input-rep-{info["name"]}', 'value'),
        State(f'file-uploader-{info["name"]}', 'contents'),
        State(f'{info["name"]}', 'id')
    ])(submitButtonCallback)
    # def func(n_clicks, reprValue, contents):
    #     print('!@#, Hello', n_clicks, reprValue, contents)

    collapseChildrenList = [
        dcc.Upload(id=f'file-uploader-{info["name"]}',
                   children=html.Div([
                       'Drag and Drop or ',
                       html.A('Select Files', className='text-primary')
                   ]),
                   style={
                       'height': '60px',
                       'lineHeight': '60px',
                       'borderWidth': '1px',
                       'borderStyle': 'dashed',
                       'borderRadius': '5px',
                       'textAlign': 'center',
                       'margin': '10px'
                   },
                   multiple=True),
        html.Label(children=[
            "Number of repetitions:",
            dcc.Input(id=f'input-rep-{info["name"]}',
                      type='number',
                      placeholder='>=1',
                      min=1,
                      style={
                          'margin-left': '20px',
                          'width': '60px',
                      }),
        ],
                   style={'margin-left': '10px'}),
        dbc.Button('Start task',
                   color='link',
                   id=f'start-button-{info["name"]}',
                   className='text-body bg-success',
                   style={
                       'display': 'block',
                       'margin': '10px auto',
                       'font-size': '1.2em'
                   }),
    ]

    return dbc.Card(id=info['name'],
                    children=[
                        dbc.CardHeader(
                            html.H6(
                                dbc.Button(info['header'],
                                           color="link",
                                           id=f'toggle-{info["name"]}',
                                           className='text-body'))),
                        dbc.Collapse(id=f'collapse-{info["name"]}',
                                     children=collapseChildrenList,
                                     style={
                                         'padding': '15px',
                                     }),
                    ],
                    className='shadow',
                    style={
                        'margin': '10px 0',
                    })
Ejemplo n.º 10
0
                                           className='text-body'))),
                        dbc.Collapse(id=f'collapse-{info["name"]}',
                                     children=collapseChildrenList,
                                     style={
                                         'padding': '15px',
                                     }),
                    ],
                    className='shadow',
                    style={
                        'margin': '10px 0',
                    })


def createReportList(app, /, listId='empty-id', listName='empty name'):
    @app.callback([
        Output(f'{listId}-p', 'children'),
        Output(f'{listId}-wrapper', 'style')
    ], [Input(f'{listId}-list', 'children')])
    def func(childList):
        return f'Task count: {len(childList)}', {
            'display': 'none'
        } if len(childList) == 0 else {
            'display': 'block'
        }

    return html.Div(
        id=f'{listId}-wrapper',
        children=[
            html.Div(children=[
                html.H6(listName,
                        style={'margin': '10px 0'},
Ejemplo n.º 11
0
    def __init__(self, app, mongo):
        self.config = Config()
        self.app = app
        self.mongo = mongo
        self.scraper = PlantScraper(mongo)

        @app.callback(None, [Input('remove_plant', 'n_clicks')], [
            State('remove_plant', 'value'),
            State('plant_name', 'value'),
            State('x_coordinate', 'value'),
            State('y_coordinate', 'value'),
            State('sensor_id', 'value')
        ])
        def remove_plant(n_clicks, button_value, plant_name, x, y, sensor):
            if n_clicks > 0:
                print(f'Removing plant!!: {plant_name} ({x}, {y})')
                self.mongo.plants.list.remove(dict(name=plant_name, x=x, y=y),
                                              dict(justOne=True))
            return self.plot_plants()

        @app.callback(Output('plant_map', 'figure'),
                      [Input('add_plant', 'n_clicks')], [
                          State('add_plant', 'value'),
                          State('plant_name', 'value'),
                          State('x_coordinate', 'value'),
                          State('y_coordinate', 'value'),
                          State('sensor_id', 'value')
                      ])
        def add_plant(n_clicks, button_value, plant_name, x, y, sensor):
            if n_clicks > 0:
                print(f'Adding plant!!: {plant_name} ({x}, {y})')
                n = self.mongo.plants.list.count()
                self.mongo.plants.list.insert_one(
                    dict(name=plant_name, x=x, y=y, sensor=sensor, n=n))
            else:
                pass
            return self.plot_plants()

        @app.callback(Output('description', 'children'),
                      [Input('add_plant', 'n_clicks')], [
                          State('add_plant', 'value'),
                          State('plant_name', 'value'),
                          State('x_coordinate', 'value'),
                          State('y_coordinate', 'value')
                      ])
        def update_description(n_clicks, button_value, plant_name, x, y):
            if n_clicks > 0:
                entry = self.scraper.get(plant_name)
                return P(entry['summary'])
            else:
                return P(
                    'When new plants are added, wikipedia entries about them will appear here'
                )

        @app.callback(Output('needs_description', 'children'),
                      [Input('add_plant', 'n_clicks')], [
                          State('add_plant', 'value'),
                          State('plant_name', 'value'),
                          State('x_coordinate', 'value'),
                          State('y_coordinate', 'value')
                      ])
        def update_description(n_clicks, button_value, plant_name, x, y):
            if n_clicks > 0:
                entry = self.scraper.get(plant_name)
                latin = entry['latin_name']
                common = entry['common_name'][0]
                habitat = entry['habitat']
                height = entry['height']
                soil = ' or '.join(entry['soil'])
                shade = ' or '.join(s if s != 'none' else 'no'
                                    for s in entry['shade'])
                moist = ' or '.join(entry['moisture'])

                description = f'''The {latin}, or {common} lives in a {habitat} habitat, grows to around {height}m, prefers {soil} and {moist} soil with {shade} shade'''

                return P(description)
            else:
                return P(
                    'When new plants are added, wikipedia entries about them will appear here'
                )