示例#1
0
    def insertTestData(self, sensor):
        t0 = time.time() - 4981 * 60
        for line in open("./apps/sensors/tests/mbmon.tsv").readlines():
            line = line.strip()
            if line == "":
                continue

            t1, t2, t3, rpm, vcore1, vcore2, v3, v5, v12, dt, uptime, users, load5, load15, load60 = line.split("\t")

            t1, t2, t3, vcore1, vcore2, v3, v5, v12, load5, load15, load60 = (
                float(t1),
                float(t2),
                float(t3),
                float(vcore1),
                float(vcore2),
                float(v3),
                float(v5),
                float(v12),
                float(load5),
                float(load15),
                float(load60),
            )

            rpm, users = int(rpm), int(users)

            #           dt = ' '.join(dt.split (' ')[:-3]) + " 2008"
            #           dt = datetime.datetime.strptime(dt, '%a %b %d %H:%M:%S %Y')
            t0 += 60
            # register.addData (sensor, float(t1), float(dt.strftime("%s")))
            register.addData(sensor, float(t1), t0)
示例#2
0
    def test_load_values_ok(self):
        self.insertTestData(1)
        self.insertTestData(2)
        self.assertEquals(len(register.objects.all()), 199)

        #       Insertar un registro con fecha en el futuro (WARNING)
        t1 = time.time() + 120
        register.addData(selSensor=1, value=23.14, t0=t1)
        r1 = register.objects.get(sensor__pk=1, time=datetime.datetime.fromtimestamp(t1))
        self.assertEquals(r1.value, 23.14)
        #       Insertar un registro con fecha en el pasado (OK)
        t1 = time.time() - 120
        register.addData(selSensor=1, value=23.24, t0=t1)
        r1 = register.objects.get(sensor__pk=1, time=datetime.datetime.fromtimestamp(t1))
        self.assertEquals(r1.value, 23.24)
        #       Insertar un registro    con el identificador textual del sensor correcto (OK)
        t2 = time.time()
        register.addData(selSensor=sensorTest.name, value=23.34, t0=t2)
        r2 = register.objects.get(sensor__name=sensorTest.name, time=datetime.datetime.fromtimestamp(t2))
        self.assertEquals(len(register.objects.all()), 202)

        alarmsLaunched = len(alarmLog.objects.all())
        self.assertEquals(alarmsLaunched, 2)

        sensor.objects.get(pk=1).graphRRD(name="testGraph", force=True, width=500, height=150)
        sensor.objects.get(pk=2).graphRRD(name="testGraph", force=True, width=500, height=150)
        sensor.objects.get(pk=2).graphRRDLastDay(force=True, width=500, height=150)
        sensor.objects.get(pk=2).graphRRDLastWeek(force=True, width=500, height=150)
        sensor.objects.get(pk=2).graphRRDLastMonth(force=True, width=500, height=150)
        sensor.objects.get(pk=2).graphRRDLastYear(force=True, width=500, height=150)