def delete_selected_range(self, table_name): """ Deletes the current selected range from the database from w_levels_logger :return: De """ current_loaded_obsid = self.obsid selected_obsid = self.load_obsid_and_init() if current_loaded_obsid != selected_obsid: utils.pop_up_info("Error!\n The obsid selection has been changed but the plot has not been updated. No deletion done.\nUpdating plot.") self.update_plot() return fr_d_t = str((self.FromDateTime.dateTime().toPyDateTime() - datetime.datetime(1970,1,1)).total_seconds()) to_d_t = str((self.ToDateTime.dateTime().toPyDateTime() - datetime.datetime(1970,1,1)).total_seconds()) sql_list = [] sql_list.append(r"""delete from "%s" """%table_name) sql_list.append(r"""where obsid = '%s' """%selected_obsid) sql_list.append(r"""AND CAST(strftime('%s', date_time) AS NUMERIC) """) sql_list.append(r""" >= '%s' """%fr_d_t) sql_list.append(r"""AND CAST(strftime('%s', date_time) AS NUMERIC) """) sql_list.append(r""" <= '%s' """%to_d_t) sql = ''.join(sql_list) really_delete = utils.askuser("YesNo", "Do you want to delete the period " + str(self.FromDateTime.dateTime().toPyDateTime()) + " to " + str(self.ToDateTime.dateTime().toPyDateTime()) + " for obsid " + selected_obsid + " from table " + table_name + "?").result if really_delete: utils.sql_alter_db(sql) self.update_plot()
def calc_best_fit(self): """ Calculates the self.LoggerPos from self.meas_ts and self.head_ts First matches measurements from self.meas_ts to logger values from self.head_ts. This is done by making a mean of all logger values inside self.meas_ts date - tolerance and self.meas_ts date + tolerance. (this could probably be change to get only the closest logger value inside the tolerance instead) (Tolerance is gotten from self.get_tolerance()) Then calculates the mean of all matches and set to self.LoggerPos. """ obsid = self.load_obsid_and_init() self.reset_plot_selects_and_calib_help() tolerance = self.get_tolerance() really_calibrate_question = utils.askuser("YesNo", """This will calibrate all values inside the chosen period\nusing the mean difference between logger values and measurements.\n\nTime tolerance for matching logger and measurement nodes set to '""" + ' '.join(tolerance) + """'\n\nContinue?""") if really_calibrate_question.result == 0: # if the user wants to abort return PyQt4.QtGui.QApplication.setOverrideCursor(PyQt4.QtCore.Qt.WaitCursor) if self.loggerpos_masl_or_offset_state == 1: logger_ts = self.head_ts else: logger_ts = self.level_masl_ts coupled_vals = self.match_ts_values(self.meas_ts, logger_ts, tolerance) if not coupled_vals: utils.pop_up_info("There was no matched measurements or logger values inside the chosen period.\n Try to increase the tolerance!") else: self.LoggerPos.setText(str(utils.calc_mean_diff(coupled_vals))) self.calibrateandplot() PyQt4.QtGui.QApplication.restoreOverrideCursor()
def calc_best_fit(self): """ Calculates the self.LoggerPos from self.meas_ts and self.head_ts First matches measurements from self.meas_ts to logger values from self.head_ts. This is done by making a mean of all logger values inside self.meas_ts date - search_radius and self.meas_ts date + search_radius. (this could probably be change to get only the closest logger value inside the search_radius instead) (search_radius is gotten from self.get_search_radius()) Then calculates the mean of all matches and set to self.LoggerPos. """ obsid = self.load_obsid_and_init() self.reset_plot_selects_and_calib_help() search_radius = self.get_search_radius() if self.loggerpos_masl_or_offset_state == 1:# UPDATE TO RELEVANT TEXT logger_ts = self.head_ts text_field = self.LoggerPos calib_func = self.set_logger_pos really_calibrate_question = utils.askuser("YesNo", """This will calibrate all values inside the chosen period\nusing the mean difference between head_cm and w_levels measurements.\n\nSearch radius for matching logger and measurement nodes set to '""" + ' '.join(search_radius) + """'\n\nContinue?""") else:# UPDATE TO RELEVANT TEXT logger_ts = self.level_masl_ts text_field = self.Add2Levelmasl calib_func = self.add_to_level_masl really_calibrate_question = utils.askuser("YesNo", """This will calibrate all values inside the chosen period\nusing the mean difference between level_masl and w_levels measurements.\n\nSearch radius for matching logger and measurement nodes set to '""" + ' '.join(search_radius) + """'\n\nContinue?""") if really_calibrate_question.result == 0: # if the user wants to abort return PyQt4.QtGui.QApplication.setOverrideCursor(PyQt4.QtCore.Qt.WaitCursor) coupled_vals = self.match_ts_values(self.meas_ts, logger_ts, search_radius) if not coupled_vals: utils.pop_up_info("There was no matched measurements or logger values inside the chosen period.\n Try to increase the search radius!") else: text_field.setText(str(utils.calc_mean_diff(coupled_vals))) calib_func() PyQt4.QtGui.QApplication.restoreOverrideCursor()
def test_askuser_dateshift_cancel(self): question = utils.askuser('DateShift') assert question.result == u'cancel'
def test_askuser_dateshift(self): question = utils.askuser('DateShift') assert question.result == ['-1', 'hours']