Ejemplo n.º 1
0
    def testCalculateTimer(self):
        nowTime = datetime.now()
        alertTime = nowTime + timedelta(hours=3, days=2)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "2Day3H")

        # nowTime = apitimer.getAlertTime(2015, 1, 30, 10, 20)
        ret = nowTime is None
        self.assertEqual(ret, False)

        alertTime = nowTime + timedelta(hours=0, days=2)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "2Day")

        alertTime = nowTime + timedelta(hours=0, days=0, seconds=60)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "1M")

        alertTime = nowTime + timedelta(hours=12, days=2, seconds=60)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "2Day12H1M")

        alertTime = nowTime + timedelta(hours=0, days=0, seconds=30)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "1M")

        alertTime = nowTime + timedelta(days=10, hours=0, seconds=0)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "10Day")

        alertTime = nowTime + timedelta(days=0, hours=5, seconds=0)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "5H")

        alertTime = nowTime + timedelta(days=0, hours=5, minutes=10)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, "5H10M")

        alertTime = nowTime - timedelta(days=0, hours=5, minutes=10)
        stringTime = apitimer.get_interval(nowTime, alertTime)
        self.assertEqual(stringTime, None)

        alertTime = apitimer.get_alarm_time(2015, 2, 10, 23, 49)
        ret = alertTime is None
        self.assertEqual(ret, False)
        testTime = apitimer.get_now_time_without_second()
        ret = testTime is None
        self.assertEqual(ret, False)
Ejemplo n.º 2
0
    def testListInforTimerEnable(self):

        dev = accessdb.get_device_from_pk(1)
        if dev is None:
            dev = accessdb.create_device("dev1", 1)

        alerTimer = accessdb.get_specified_alarm_time(1, 1)
        if alerTimer is None:
            alerTimer = accessdb.create_alarm_using_time(
                dev, "on", apitimer.get_now_time_without_second() + timedelta(hours=1), 1
            )
            alerTimer = accessdb.create_alarm_using_time(
                dev, "on", apitimer.get_now_time_without_second() + timedelta(hours=1), 2
            )

        timerList = accessdb.get_enabled_alarm_time_list()
        self.assertEqual(len(timerList), 2)
        if timerList is None:
            return

        devList = accessdb.get_device_list()
        if devList is None:
            return

        inforList = {}
        for dev in devList:

            timerList = accessdb.get_alarm_time_list_from_device_pk(dev.id)

            if timerList is None:
                return
            detailTimerList = {}
            for timer in timerList:
                nowTime = apitimer.get_now_time_without_second()
                remainTime = apitimer.get_interval(nowTime, timer.time)
                action = timer.action
                if remainTime is None:
                    remainTime = ""
                    action = ""

                detail = {}
                detail["action"] = action
                detail["remain"] = remainTime

                key = "timer%s" % timer.timer
                detailTimerList[key] = detail

            key = "dev%s" % dev.id
            inforList[key] = detailTimerList

        jsonObj = json.dumps(inforList)

        print jsonObj[1]
        print inforList
Ejemplo n.º 3
0
def template(request):
    logger.debug(apitimer.get_real_time())
    device_list = accessdb.get_device_list()
    # device_list = dbapi.get_all_device()

    timer_list = settings.TIMER_LIST

    # Detail timer
    detail_alarm_by_time_list = []

    # Get detail info off all timer
    for dev in device_list:
        result_list = accessdb.get_alarm_time_list_from_device_pk(dev.id)
        for row in result_list:
            timer = timerview.Timer()
            timer.dev_id = dev.id
            timer.timer = row.timer
            now_time = apitimer.get_now_time_without_second()
            remain_time = apitimer.get_interval(now_time, row.time)

            # If timer is expire
            if remain_time is None or remain_time == '':
                timer.action = ''
                timer.remain = ''
            else:
                timer.action = changeview.change_action_view(row.action)
                timer.remain = remain_time
            detail_alarm_by_time_list.append(timer)




    # if device_list is None or len(device_list) == 0:
    #    device_list = settings.DEV_LIST

    alarm_temp_list = accessdb.get_alarm_by_temp_list()
    detail_alarm_temp_list = []
    for row in alarm_temp_list:
        detail = alarmtemp.AlarmTemp()
        if row.active is False:
            detail.action = ''
            detail.dev_id = row.dev.id
            detail.condition = ''
            detail.temp_value = ''

        else:
            detail.action = changeview.change_action_view(row.action)
            detail.dev_id = row.dev.id
            detail.condition = row.condition
            detail.temp_value = row.value
        detail_alarm_temp_list.append(detail)


    logger.debug(apitimer.get_real_time())

    size_option_list = accessdb.get_option_list_with_specified_type('size')
    kbitrate_option_list = accessdb.get_option_list_with_specified_type('bitrate')
    frame_psecond_option_list = accessdb.get_option_list_with_specified_type('fps')

    return render(request, 'viewcam/template.html', {'devList': device_list, 'timerList': timer_list,
        'detailList': detail_alarm_by_time_list, 'alarmTempList': detail_alarm_temp_list,
                        'test_value': 10,
                        'size_option_list': size_option_list,
                        'kbitrate_option_list': kbitrate_option_list,
                        'frame_psecond_option_list': frame_psecond_option_list})