Ejemplo n.º 1
0
    def valuesChanged(self, minValue, maxValue):
        self.slider_values = (minValue, maxValue)
        self._delta = max(1, (maxValue - minValue))
        minTime = self.slider.scale(minValue)
        maxTime = self.slider.scale(maxValue)

        from_dt = QDateTime.fromMSecsSinceEpoch(minTime * 1000).toUTC()
        to_dt = QDateTime.fromMSecsSinceEpoch(maxTime * 1000).toUTC()
        with blockSignals(self.date_from, self.date_to):
            self.date_from.setDateTime(from_dt)
            self.date_to.setDateTime(to_dt)

        self.send_selection(minTime, maxTime)
Ejemplo n.º 2
0
    def valuesChanged(self, minValue, maxValue):
        self.slider_values = (minValue, maxValue)
        self._delta = max(1, (maxValue - minValue))
        minTime = self.slider.scale(minValue)
        maxTime = self.slider.scale(maxValue)

        from_dt = QDateTime.fromMSecsSinceEpoch(minTime * 1000).toUTC()
        to_dt = QDateTime.fromMSecsSinceEpoch(maxTime * 1000).toUTC()
        with blockSignals(self.date_from,
                          self.date_to):
            self.date_from.setDateTime(from_dt)
            self.date_to.setDateTime(to_dt)

        self.send_selection(minTime, maxTime)
Ejemplo n.º 3
0
    def set_data(self, data):
        slider = self.slider
        self.data = data = None if data is None else Timeseries.from_data_table(
            data)

        def disabled():
            slider.setFormatter(str)
            slider.setHistogram(None)
            slider.setScale(0, 0)
            slider.setValues(0, 0)
            slider.setDisabled(True)
            self.send('Subset', None)

        if data is None:
            disabled()
            return

        if not isinstance(data.time_variable, TimeVariable):
            self.Error.no_time_variable()
            disabled()
            return
        self.Error.clear()
        var = data.time_variable

        time_values = data.time_values

        slider.setDisabled(False)
        slider.setHistogram(time_values)
        slider.setFormatter(var.repr_val)
        slider.setScale(time_values.min(), time_values.max())
        self.valuesChanged(slider.minimumValue(), slider.maximumValue())

        # Update datetime edit fields
        min_dt = QDateTime.fromMSecsSinceEpoch(time_values[0] * 1000).toUTC()
        max_dt = QDateTime.fromMSecsSinceEpoch(time_values[-1] * 1000).toUTC()
        self.date_from.setDateTimeRange(min_dt, max_dt)
        self.date_to.setDateTimeRange(min_dt, max_dt)
        date_format = '   '.join(
            (self.DATE_FORMATS[0] if var.have_date else '',
             self.DATE_FORMATS[1] if var.have_time else '')).strip()
        self.date_from.setDisplayFormat(date_format)
        self.date_to.setDisplayFormat(date_format)
Ejemplo n.º 4
0
    def node_info_complete(self, future):
        assert self.thread() is QThread.currentThread()
        assert future.done()

        self._task = None
        self.progressBarFinished()

        self.setCursor(Qt.ArrowCursor)
        self.btn_connect.setText(self.LABEL_CONNECT)
        self.Information.fetching_node_info.clear()

        try:
            lst, min_time, max_time = future.result(
            )  # type: Tuple[List[List], pd.Timestamp, pd.Timestamp]
        except self.Cancelled:
            pass
        except Exception as e:
            log.exception("Error fetching node info")
            self.Error.fetching_node_info_failed(e)
        else:
            self.model.wrap(lst)
            CachedNodeInfoTable.dump_list(lst)
            self.btn_download.setEnabled(True)

            # Apply saved row selection
            if self.selection:
                try:
                    selection = QItemSelection()
                    for row in self.model.mapFromSourceRows(self.selection):
                        selection.select(self.model.index(row, 0))
                    self.view.selectionModel().select(selection)
                except Exception:
                    log.exception('Failed to restore selection')
                self.selection = []

            self.date_from.setDateTime(
                QDateTime.fromMSecsSinceEpoch(min_time.timestamp() * 1000,
                                              Qt.UTC))
            self.date_to.setDateTime(
                QDateTime.fromMSecsSinceEpoch(max_time.timestamp() * 1000,
                                              Qt.UTC))
Ejemplo n.º 5
0
    def set_data(self, data):
        slider = self.slider
        self.data = data = None if data is None else Timeseries.from_data_table(data)

        def disabled():
            slider.setFormatter(str)
            slider.setHistogram(None)
            slider.setScale(0, 0)
            slider.setValues(0, 0)
            self._set_disabled(True)
            self.Outputs.subset.send(None)

        if data is None:
            disabled()
            return

        if not isinstance(data.time_variable, TimeVariable):
            self.Error.no_time_variable()
            disabled()
            return
        self.Error.clear()
        var = data.time_variable

        time_values = data.time_values

        self._set_disabled(False)
        slider.setHistogram(time_values)
        slider.setFormatter(var.repr_val)
        slider.setScale(time_values.min(), time_values.max())
        self.valuesChanged(slider.minimumValue(), slider.maximumValue())

        # Update datetime edit fields
        min_dt = QDateTime.fromMSecsSinceEpoch(time_values[0] * 1000).toUTC()
        max_dt = QDateTime.fromMSecsSinceEpoch(time_values[-1] * 1000).toUTC()
        self.date_from.setDateTimeRange(min_dt, max_dt)
        self.date_to.setDateTimeRange(min_dt, max_dt)
        date_format = '   '.join((self.DATE_FORMATS[0] if var.have_date else '',
                                  self.DATE_FORMATS[1] if var.have_time else '')).strip()
        self.date_from.setDisplayFormat(date_format)
        self.date_to.setDisplayFormat(date_format)
Ejemplo n.º 6
0
    def dteditValuesChanged(self, minTime, maxTime):
        minValue = self.slider.unscale(minTime)
        maxValue = self.slider.unscale(maxTime)
        if minValue == maxValue:
            # maxValue's range is minValue's range shifted by one
            maxValue += 1
            maxTime = self.slider.scale(maxValue)
            to_dt = QDateTime.fromMSecsSinceEpoch(maxTime * 1000).toUTC()
            with blockSignals(self.date_to):
                self.date_to.setDateTime(to_dt)

        self._delta = max(1, (maxValue - minValue))

        if self.slider_values != (minValue, maxValue):
            self.slider_values = (minValue, maxValue)
            with blockSignals(self.slider):
                self.slider.setValues(minValue, maxValue)

        self.send_selection(minTime, maxTime)
Ejemplo n.º 7
0
 def format_time(i):
     dt = QDateTime.fromMSecsSinceEpoch(i * 1000).toUTC()
     return dt.toString(date_format)
Ejemplo n.º 8
0
    def __init__(self):
        self.model = None

        self._task = None  # type: Optional[self.Task]
        self._executor = ThreadExecutor(self)
        self.is_downloading = False

        box = gui.vBox(self.controlArea, 'Database Connection')
        gui.lineEdit(box,
                     self,
                     'con_hostname',
                     label='Hostname:',
                     orientation=Qt.Horizontal,
                     validator=Validator.Hostname())
        gui.lineEdit(box,
                     self,
                     'con_port',
                     label='Port:',
                     orientation=Qt.Horizontal,
                     validator=Validator.Port())
        gui.lineEdit(box,
                     self,
                     'con_username',
                     label='Username:'******'con_password',
                            label='Password:'******'con_database',
                     label='Database:',
                     orientation=Qt.Horizontal)
        gui.spin(box, self, 'con_timeout', 5, 300, 5, label='Timeout [s]:')
        self.btn_connect = gui.button(box,
                                      self,
                                      self.LABEL_CONNECT,
                                      callback=self.load_data)

        box = gui.vBox(self.controlArea, 'Download')

        def _dateTimeChanged(editted):
            def handler():
                minTime = self.date_from.dateTime().toMSecsSinceEpoch() / 1000
                maxTime = self.date_to.dateTime().toMSecsSinceEpoch() / 1000
                if minTime > maxTime:
                    minTime = maxTime = minTime if editted == self.date_from else maxTime

                    other = self.date_to if editted == self.date_from else self.date_from
                    with blockSignals(other):
                        other.setDateTime(editted.dateTime())

                    self.btn_download.setEnabled(minTime != maxTime)

                # Update saved settings
                self.sample_ts_from = minTime
                self.sample_ts_to = maxTime

            return handler

        kwargs = dict(calendarPopup=True,
                      displayFormat=' '.join(self.DATE_FORMATS),
                      timeSpec=Qt.UTC)
        date_from = self.date_from = QDateTimeEdit(self, **kwargs)
        date_to = self.date_to = QDateTimeEdit(self, **kwargs)
        date_from.setDateTime(
            QDateTime.fromMSecsSinceEpoch(self.sample_ts_from * 1000, Qt.UTC))
        date_to.setDateTime(
            QDateTime.fromMSecsSinceEpoch(self.sample_ts_to * 1000, Qt.UTC))
        date_from.dateTimeChanged.connect(_dateTimeChanged(date_from))
        date_to.dateTimeChanged.connect(_dateTimeChanged(date_to))

        hbox = gui.hBox(box)
        hbox.layout().addWidget(QLabel('From:'))
        hbox.layout().addWidget(date_from)
        hbox = gui.hBox(box)
        hbox.layout().addWidget(QLabel('To:'))
        hbox.layout().addWidget(date_to)

        self.box_include_data = gui.vBox(box, 'Include')

        gui.spin(box,
                 self,
                 'sample_size',
                 100,
                 20000,
                 100,
                 label='Sample size:')
        gui.comboBox(box,
                     self,
                     'sample_resolution',
                     label='Resolution:',
                     orientation=Qt.Horizontal,
                     items=tuple(self.RESOLUTION.keys()),
                     sendSelectedValue=True)
        gui.comboBox(box,
                     self,
                     'sample_interpolation',
                     label='Interpolation:',
                     orientation=Qt.Horizontal,
                     items=tuple(self.INTERPOLATION.keys()),
                     sendSelectedValue=True)

        self.btn_download = gui.button(box,
                                       self,
                                       self.LABEL_DOWNLOAD,
                                       callback=self.download)
        gui.rubber(self.controlArea)

        ## Main area

        class Model(PyTableModel):
            def update_row(self, i, row):
                self[i] = row

        model = self.model = Model(parent=self)
        model.setHorizontalHeaderLabels([
            'Node Id', 'Interfaces', 'Start Time', 'Stop Time',
            'Available Data'
        ])
        view = self.view = gui.TableView(self)
        view.horizontalHeader().setStretchLastSection(False)
        view.setModel(self.model)
        self.mainArea.layout().addWidget(view)

        # Restore node info table from cache, if any
        try:
            lst = CachedNodeInfoTable.load_list()
        except Exception:
            pass  # Cache not exists
        else:
            model.wrap(lst)

        # Restore tables checkboxes from cache
        try:
            tables = CachedNodeInfoTable.load_tables()
        except Exception:
            pass
        else:
            for table in tables:
                self.box_include_data.layout().addWidget(
                    QCheckBox(table, self, checked=table
                              in self.included_data))

        # Establish default database connection from settings
        set_connection_params(self.con_hostname,
                              self.con_port,
                              self.con_username,
                              self.con_password,
                              self.con_database,
                              timeout=self.con_timeout)