コード例 #1
0
    def alter_data(self, observation):
        observation = copy.deepcopy(observation)
        shift_specification = utils.returnunicode(self.dateshift_lineedit.text())

        step_steplength = shift_specification.split(u' ')
        failed = False

        bar_msg = u'Dateshift specification wrong format, se log message panel'
        log_msg = (u'Dateshift specification must be made using format ' +
                    '"step step_length", ex: "0 hours", "-1 hours", "-1 days" etc.\n' +
                    'Supported step lengths: microseconds, milliseconds, seconds, ' +
                    'minutes, hours, days, weeks.')

        if len(step_steplength) != 2:
            utils.MessagebarAndLog.warning(bar_msg=bar_msg, log_msg=log_msg)
            return Cancel()
        try:
            step = float(step_steplength[0])
            steplength = step_steplength[1]
        except:
            utils.MessagebarAndLog.warning(bar_msg=bar_msg, log_msg=log_msg)
            return Cancel()

        test_shift = dateshift('2015-02-01', step, steplength)
        if test_shift == None:
            utils.MessagebarAndLog.warning(bar_msg=bar_msg, log_msg=log_msg)
            return Cancel()

        observation[u'date_time'] = dateshift(observation[u'date_time'], step, steplength)

        return observation
コード例 #2
0
def fix_date(date_time, filename, tz_converter=None):
    try:
        dt = datetime.datetime.strptime(date_time[:-2].rstrip(), '%m/%d/%y %I:%M:%S')
    except ValueError:
        dt = date_utils.datestring_to_date(date_time)
        if dt is None:
            raise FileError(ru(QCoreApplication.translate('HobologgerImport',
                                                          '''Dateformat in file %s could not be parsed.''')) % filename)
    else:
        dt_end = date_time[-2:]
        if dt_end.lower() in ('em', 'pm'):
            dt = date_utils.dateshift(dt, 12, 'hours')

    if tz_converter is not None:
        dt = tz_converter.convert_datetime(dt)

    return dt
コード例 #3
0
def fix_date(date_time, filename, tz_converter=None):
    try:
        dt = datetime.datetime.strptime(date_time[:-2].rstrip(), '%m/%d/%y %I:%M:%S')
    except ValueError:
        dt = date_utils.datestring_to_date(date_time)
        if dt is None:
            raise FileError(ru(QCoreApplication.translate('HobologgerImport',
                                                          '''Dateformat in file %s could not be parsed.''')) % filename)
    else:
        dt_end = date_time[-2:]
        if dt_end.lower() in ('em', 'pm'):
            dt = date_utils.dateshift(dt, 12, 'hours')

    if tz_converter is not None:
        dt = tz_converter.convert_datetime(dt)

    return dt
コード例 #4
0
    def match_ts_values(self, meas_ts, logger_ts, tolerance):
        """ Matches two timeseries values for shared timesteps 
        
            For every measurement point, a mean of logger values inside 
            measurementpoint + x minutes to measurementpoint - x minutes
            is coupled together.

            At the first used measurement, only logger values greater than
            the set start date is used.
            At the last measurement, only logger values lesser than the set end
            date is used.
            This is done so that values from another logger reposition is not
            mixed with the chosen logger positioning. (Hard to explain).
        """
        coupled_vals = []
        
        #Get the tolerance, default to 10 minutes
        tol = int(tolerance[0])
        tol_period = tolerance[1]
  
        logger_gen = utils.ts_gen(logger_ts)
        try:
            l = next(logger_gen)
        except StopIteration:
            return None
        log_vals = []

        all_done = False
        #The .replace(tzinfo=None) is used to remove info about timezone. Needed for the comparisons. This should not be a problem though as the date scale in the plot is based on the dates from the database. 
        outer_begin = self.FromDateTime.dateTime().toPyDateTime().replace(tzinfo=None)
        outer_end = self.ToDateTime.dateTime().toPyDateTime().replace(tzinfo=None)
        logger_step = datestring_to_date(l[0]).replace(tzinfo=None)
        for m in meas_ts:
            if logger_step is None:
                break
            meas_step = datestring_to_date(m[0]).replace(tzinfo=None)

            step_begin = dateshift(meas_step, -tol, tol_period)
            step_end = dateshift(meas_step, tol, tol_period)

            if step_end < outer_begin:
                continue
            if step_begin > outer_end:
                break

            #Skip logger steps that are earlier than the chosen begin date or are not inside the measurement period.
            while logger_step < step_begin or logger_step < outer_begin:
                try:
                    l = next(logger_gen)
                except StopIteration:
                    all_done = True
                    break
                logger_step = datestring_to_date(l[0]).replace(tzinfo=None)

            log_vals = []

            while logger_step is not None and logger_step <= step_end and logger_step <= outer_end:
                if not math.isnan(float(l[1])) or l[1] == 'nan' or l[1] == 'NULL':
                    log_vals.append(float(l[1]))
                try:
                    l = next(logger_gen)
                except StopIteration:
                    all_done = True
                    break
                logger_step = datestring_to_date(l[0]).replace(tzinfo=None)                     

            if log_vals:
                mean = np.mean(log_vals)
                if not math.isnan(mean):
                    coupled_vals.append((m[1], mean))
            if all_done:
                break
        return coupled_vals