示例#1
0
    def __init__(self, msid, tstart='2000:001:00:00:00', tstop=None,
                 trendmonths = 36, numstddev=2, removeoutliers=True, 
                 maxoutlierstddev=5):

        self.msid = msid
        self.tstart = DateTime(tstart).date
        
        if tstop == None:
            self.tstop = DateTime().date
        else:
            self.tstop = DateTime(tstop).date
            
        self.trendmonths = trendmonths
        self.numstddev = numstddev
        self.removeoutliers = removeoutliers
        self.maxoutlierstddev = maxoutlierstddev
        self.telem = self._getMonthlyTelemetry()
        self.safetylimits = pylimmon.get_safety_limits(msid)

        db = pylimmon.open_sqlite_file()
        cursor = db.cursor()
        cursor.execute('''SELECT a.msid, a.setkey, a.default_set, a.warning_low, 
                          a.caution_low, a.caution_high, a.warning_high FROM limits AS a 
                          WHERE a.mlmenable=1 AND a.setkey = a.default_set AND a.msid = ?
                          AND a.modversion = (SELECT MAX(b.modversion) FROM limits AS b
                          WHERE a.msid = b.msid and a.setkey = b.setkey)''', [msid.lower(),])
        lims = cursor.fetchone()
        self.trendinglimits = {'warning_low':lims[3], 'caution_low':lims[4], 'caution_high':lims[5], 
                 'warning_high':lims[6]}
def check_limit_changes(t1, t2):

    db = pylimmon.open_sqlite_file()
    cursor = db.cursor()
    cursor.execute('''SELECT a.msid, a.setkey FROM limits AS a WHERE a.datesec>=? 
                      AND a.datesec <=? ''', [DateTime(t1).secs, DateTime(t2).secs])
    allchanges = cursor.fetchall()

    msid_sets = [(d[0], d[1]) for d in allchanges]
    msid_sets = set(msid_sets)

    changes = {}

    for msid, setval in list(msid_sets):

        try:
            if 'wide' in msid.lower():
                skamsid = msid[:-5]
            else:
                skamsid = msid

            data = fetch.Msid(skamsid, t1, DateTime(t1).secs + 3600, stat='5min')
            desc = data.tdb.technical_name
        except:
            desc = None

        cursor.execute('''SELECT a.msid, a.setkey, a.default_set, a.warning_low, 
                              a.caution_low, a.caution_high, a.warning_high, a.date, a.mlmenable, 
                              a.switchstate, a.mlimsw FROM limits AS a 
                              WHERE a.setkey = ? AND a.msid = ? AND a.datesec < ?
                              AND a.modversion = (SELECT MAX(b.modversion) FROM limits AS b
                              WHERE a.msid = b.msid and a.setkey = b.setkey and b.datesec < ?)''',
                       [setval, msid, DateTime(t1).secs, DateTime(t1).secs])
        b = cursor.fetchone()
        if not b:
            b = []

        cursor.execute('''SELECT a.msid, a.setkey, a.default_set, a.warning_low, 
                              a.caution_low, a.caution_high, a.warning_high, a.date, a.mlmenable, 
                              a.switchstate, a.mlimsw FROM limits AS a 
                              WHERE a.setkey = ? AND a.msid = ? AND a.datesec >= ? AND 
                              a.datesec <= ? AND a.modversion = (SELECT MAX(b.modversion) 
                              FROM limits AS b WHERE a.msid = b.msid AND a.setkey = b.setkey 
                              AND b.datesec >= ? AND b.datesec <= ?)''', [setval, msid, 
                              DateTime(t1).secs, DateTime(t2).secs, DateTime(t1).secs, 
                              DateTime(t2).secs])
        a = cursor.fetchone()

        changes[(msid, setval)] = {'before': b, 'after': a, 'description': desc}

    return changes
def check_limit_changes(t1, t2):

    db = pylimmon.open_sqlite_file()
    cursor = db.cursor()
    cursor.execute(
        '''SELECT a.msid, a.setkey FROM limits AS a WHERE a.datesec>=? 
                      AND a.datesec <=? ''',
        [DateTime(t1).secs, DateTime(t2).secs])
    allchanges = cursor.fetchall()

    msid_sets = [(d[0], d[1]) for d in allchanges]
    msid_sets = set(msid_sets)

    changes = {}

    for msid, setval in list(msid_sets):

        try:
            if 'wide' in msid.lower():
                skamsid = msid[:-5]
            else:
                skamsid = msid

            data = fetch.Msid(skamsid,
                              t1,
                              DateTime(t1).secs + 3600,
                              stat='5min')
            desc = data.tdb.technical_name
        except:
            desc = None

        cursor.execute(
            '''SELECT a.msid, a.setkey, a.default_set, a.warning_low, 
                              a.caution_low, a.caution_high, a.warning_high, a.date, a.mlmenable, 
                              a.switchstate, a.mlimsw FROM limits AS a 
                              WHERE a.setkey = ? AND a.msid = ? AND a.datesec < ?
                              AND a.modversion = (SELECT MAX(b.modversion) FROM limits AS b
                              WHERE a.msid = b.msid and a.setkey = b.setkey and b.datesec < ?)''',
            [setval, msid, DateTime(t1).secs,
             DateTime(t1).secs])
        b = cursor.fetchone()
        if not b:
            b = []

        cursor.execute(
            '''SELECT a.msid, a.setkey, a.default_set, a.warning_low, 
                              a.caution_low, a.caution_high, a.warning_high, a.date, a.mlmenable, 
                              a.switchstate, a.mlimsw FROM limits AS a 
                              WHERE a.setkey = ? AND a.msid = ? AND a.datesec >= ? AND 
                              a.datesec <= ? AND a.modversion = (SELECT MAX(b.modversion) 
                              FROM limits AS b WHERE a.msid = b.msid AND a.setkey = b.setkey 
                              AND b.datesec >= ? AND b.datesec <= ?)''', [
                setval, msid,
                DateTime(t1).secs,
                DateTime(t2).secs,
                DateTime(t1).secs,
                DateTime(t2).secs
            ])
        a = cursor.fetchone()

        changes[(msid, setval)] = {
            'before': b,
            'after': a,
            'description': desc
        }

    return changes