def test_editor_sets_fixed_resolution_time_series_in_parent_model(self):
     start = dateutil.parser.parse("2019-07-03T12:22")
     resolution = [duration_to_relativedelta("4 years")]
     values = np.array([23.0, 5.0])
     time_series = TimeSeriesFixedResolution(start, resolution, values,
                                             False, True)
     self._check_parent_model_updated_when_closed(time_series)
Esempio n. 2
0
    def __init__(self, parent=None):
        from ..ui.duration_editor import Ui_DurationEditor  # pylint: disable=import-outside-toplevel

        super().__init__(parent)
        self._value = Duration(duration_to_relativedelta("1 hour"))
        self._ui = Ui_DurationEditor()
        self._ui.setupUi(self)
        self._ui.duration_edit.editingFinished.connect(self._change_duration)
        self._ui.duration_edit.setText(str(self._value))
Esempio n. 3
0
    def __init__(self, parent=None):
        from ..ui.duration_editor import Ui_DurationEditor

        super().__init__(parent)
        self._value = Duration(duration_to_relativedelta("1 hour"))
        self._ui = Ui_DurationEditor()
        self._ui.setupUi(self)
        self._ui.duration_edit.editingFinished.connect(self._change_duration)
        self._ui.duration_edit.setText(self._value.to_text())
Esempio n. 4
0
 def _change_duration(self):
     """Updates the value being edited."""
     text = self._ui.duration_edit.text()
     tokens = text.split(',')
     try:
         durations = [
             duration_to_relativedelta(token.strip()) for token in tokens
         ]
     except ParameterValueFormatError:
         self._ui.duration_edit.setText(self._value.to_text())
         return
     self._value = Duration(durations)
    def _change_parameter_type(self, selector_index):
        """
        Handles switching between value types.

        Does a rude conversion between fixed and variable resolution time series.
        In other cases, a default 'empty' value is used.

        Args:
            selector_index (int): an index to the selector combo box
        """
        old_index = self._ui.editor_stack.currentIndex()
        if (selector_index == self._editor_indexes[
                ValueType.TIME_SERIES_VARIABLE_RESOLUTION] and old_index ==
                self._editor_indexes[ValueType.TIME_SERIES_FIXED_RESOLUTION]):
            fixed_resolution_value = self._editors[
                ValueType.TIME_SERIES_FIXED_RESOLUTION].value()
            stamps = fixed_resolution_value.indexes
            values = fixed_resolution_value.values
            variable_resolution_value = TimeSeriesVariableResolution(
                stamps, values, fixed_resolution_value.ignore_year,
                fixed_resolution_value.repeat)
            self._editors[ValueType.TIME_SERIES_VARIABLE_RESOLUTION].set_value(
                variable_resolution_value)
        elif (selector_index
              == self._editor_indexes[ValueType.TIME_SERIES_FIXED_RESOLUTION]
              and old_index == self._editor_indexes[
                  ValueType.TIME_SERIES_VARIABLE_RESOLUTION]):
            variable_resolution_value = self._editors[
                ValueType.TIME_SERIES_VARIABLE_RESOLUTION].value()
            stamps = variable_resolution_value.indexes
            start = stamps[0]
            difference = stamps[1] - start
            resolution = [duration_to_relativedelta(str(difference))]
            fixed_resolution_value = TimeSeriesFixedResolution(
                start,
                resolution,
                variable_resolution_value.values,
                variable_resolution_value.ignore_year,
                variable_resolution_value.repeat,
            )
            self._editors[ValueType.TIME_SERIES_FIXED_RESOLUTION].set_value(
                fixed_resolution_value)
        self._ui.editor_stack.setCurrentIndex(selector_index)
        if selector_index == self._editor_indexes[ValueType.PLAIN_VALUE]:
            self._editors[ValueType.PLAIN_VALUE].set_value("")
Esempio n. 6
0
    def __init__(self, parent=None):
        from ..ui.time_series_fixed_resolution_editor import Ui_TimeSeriesFixedResolutionEditor

        super().__init__(parent)
        start = datetime(year=2000, month=1, day=1)
        resolution = [duration_to_relativedelta("1 hour")]
        values = 2 * [0.0]
        initial_value = TimeSeriesFixedResolution(start, resolution, values,
                                                  False, False)
        self._model = TimeSeriesModelFixedResolution(initial_value)
        self._model.dataChanged.connect(self._update_plot)
        self._model.modelReset.connect(self._update_plot)
        self._model.rowsInserted.connect(self._update_plot)
        self._model.rowsRemoved.connect(self._update_plot)
        self._ui = Ui_TimeSeriesFixedResolutionEditor()
        self._ui.setupUi(self)
        self._plot_widget = PlotWidget()
        self._ui.splitter.insertWidget(1, self._plot_widget)
        self._ui.start_time_edit.setText(str(initial_value.start))
        self._ui.start_time_edit.editingFinished.connect(
            self._start_time_changed)
        self._ui.calendar_button.clicked.connect(self._show_calendar)
        self._ui.resolution_edit.setText(
            _resolution_to_text(initial_value.resolution))
        self._ui.resolution_edit.editingFinished.connect(
            self._resolution_changed)
        self._time_series_table = TimeSeriesFixedResolutionTableView(
            self._ui.splitter)
        self._ui.left_layout.addWidget(self._time_series_table)
        self._time_series_table.setModel(self._model)
        self._time_series_table.setContextMenuPolicy(Qt.CustomContextMenu)
        self._time_series_table.customContextMenuRequested.connect(
            self._show_table_context_menu)
        self._ui.ignore_year_check_box.setChecked(
            self._model.value.ignore_year)
        self._ui.ignore_year_check_box.toggled.connect(
            self._model.set_ignore_year)
        self._ui.repeat_check_box.setChecked(self._model.value.repeat)
        self._ui.repeat_check_box.toggled.connect(self._model.set_repeat)
        self._calendar = QCalendarWidget(self)
        self._calendar.setMinimumDate(QDate(100, 1, 1))
        self._calendar.setWindowFlags(Qt.Popup)
        self._calendar.activated.connect(self._select_date)
        self._update_plot()
 def test_editor_sets_duration_in_parent_model(self):
     duration = Duration(duration_to_relativedelta('3 months'))
     self._check_parent_model_updated_when_closed(duration)