コード例 #1
0
def query_report(request):
    qtype_get = request.GET.get('qtype')
    room_id_get = request.GET.get('room_id')
    date_get = request.GET.get('date')
    date_get_sp = date_get.split("-")
    date_get_da = datetime.datetime(int(date_get_sp[0]), int(date_get_sp[1]),
                                    int(date_get_sp[2]))
    try:
        controller = Controller.instance()
        content = controller.dispatch(service='REPORT',
                                      operation='query report',
                                      room_id=room_id_get,
                                      date=date_get_da,
                                      qtype=qtype_get)
        content = {
            'message': "OK",
            'result': {
                'room_id': content.room_id,
                'on_off_times': content.times_of_on_off,
                'service_time': content.duration,
                'fee': content.fee,
                'dispatch_times': content.times_of_dispatch,
                'rdr_number': content.number_of_detail,
                'change_temp_times': content.times_of_change_temp,
                'change_speed_times': content.times_of_change_speed,
            }
        }
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #2
0
def init_param(request):
    highest_temper_get = float(request.GET.get('highest_temper'))
    lowest_temper_get = float(request.GET.get('lowest_temper'))
    low_speed_fee_get = float(request.GET.get('low_speed_fee'))
    middle_speed_fee_get = float(request.GET.get('middle_speed_fee'))
    high_speed_fee_get = float(request.GET.get('high_speed_fee'))
    default_temper_get = float(request.GET.get('default_temper'))
    default_speed_get = int(request.GET.get('default_speed'))
    mode_get = int(request.GET.get('mode'))
    if mode_get == 0:
        mode_get = "制冷"
    else:
        mode_get = "制热"

    try:
        controller = Controller.instance()
        controller.dispatch(service='ADMINISTRATOR',
                            operation='set param',
                            mode=mode_get,
                            temp_low_limit=lowest_temper_get,
                            temp_high_limit=highest_temper_get,
                            default_target_temp=default_temper_get,
                            default_speed=default_speed_get,
                            fee_rate=(low_speed_fee_get, middle_speed_fee_get,
                                      high_speed_fee_get))
        content = {'message': "OK", 'result': None}
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #3
0
    def test_on_off(self):
        # 取得控制器对象
        controller = Controller.instance()
        # 主机开机
        controller.dispatch(service='ADMINISTRATOR', operation='power on')
        # 参数初始化
        controller.dispatch(service='ADMINISTRATOR',
                            operation='set param',
                            mode=master_machine_mode.COOL,
                            temp_low_limit=16,
                            temp_high_limit=30,
                            default_target_temp=24,
                            default_speed=fan_speed.NORMAL,
                            fee_rate=(0.5, 0.75, 1.5))
        # 开始执行
        controller.dispatch(service='ADMINISTRATOR', operation='start')
        time.sleep(10)
        controller.dispatch(service='ADMINISTRATOR', operation='stop')

        # 主机开机
        controller.dispatch(service='ADMINISTRATOR', operation='power on')
        # 参数初始化
        controller.dispatch(service='ADMINISTRATOR',
                            operation='set param',
                            mode=master_machine_mode.COOL,
                            temp_low_limit=16,
                            temp_high_limit=30,
                            default_target_temp=24,
                            default_speed=fan_speed.NORMAL,
                            fee_rate=(0.5, 0.75, 1.5))
        # 开始执行
        controller.dispatch(service='ADMINISTRATOR', operation='start')
        time.sleep(10)
        controller.dispatch(service='ADMINISTRATOR', operation='stop')
コード例 #4
0
def close(request):
    try:
        controller = Controller.instance()
        controller.dispatch(service='ADMINISTRATOR', operation='stop')
        content = {'message': 'OK', 'result': None}
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #5
0
def start_up(request):
    try:
        controller = Controller.instance()
        controller.dispatch(service='ADMINISTRATOR', operation='start')
        content = {'message': 'OK', 'result': None}
        return JsonResponse(content, safe=False)
    except RuntimeError as error:
        logger.error(error)
        return JsonResponse({'message': str(error)})
コード例 #6
0
def request_off(request):
    room_id_get = request.GET.get('room_id')
    try:
        controller = Controller.instance()
        controller.dispatch(service='POWER',
                            operation='power off',
                            room_id=room_id_get)
        content = {'message': "OK", 'result': None}
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #7
0
def check_out(request):
    room_id_get = request.GET.get('room_id')
    try:
        controller = Controller.instance()
        controller.dispatch(service='ADMINISTRATOR',
                            operation='check out',
                            room_id=room_id_get)
        content = {'message': "OK", 'result': None}
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #8
0
def request_fee(request):
    room_id_get = request.GET.get('room_id')
    try:
        controller = Controller.instance()
        content = {
            'message': 'OK',
            'result': controller.dispatch(service='GET_FEE',
                                          room_id=room_id_get)
        }
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #9
0
def change_speed(request):
    room_id_get = request.GET.get('room_id')
    speed_get = int(request.GET.get('speed'))
    try:
        controller = Controller.instance()
        controller.dispatch(service='SLAVE',
                            operation='change speed',
                            room_id=room_id_get,
                            target_speed=speed_get)
        content = {'message': 'OK', 'result': None}
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #10
0
def check_room_state(request):
    try:
        controller = Controller.instance()
        content = {
            'message':
            'OK',
            'result':
            controller.dispatch(service='ADMINISTRATOR',
                                operation='get status')
        }
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #11
0
def request_on(request):
    room_id_get = request.GET.get('room_id')
    current_temp_get = float(request.GET.get('current_temper'))
    try:
        controller = Controller.instance()
        content = controller.dispatch(service='POWER',
                                      operation='power on',
                                      room_id=room_id_get,
                                      current_temp=current_temp_get)
        content = {'message': "OK", 'result': content}
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #12
0
def print_invoice(request):
    room_id_get = request.GET.get('room_id')
    try:
        controller = Controller.instance()
        filename = controller.dispatch(service='INVOICE',
                                       operation='print invoice',
                                       room_id=room_id_get)
        file = open(filename, 'r')
        response = StreamingHttpResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        response[
            'Content-Disposition'] = 'attachment;filename="' + filename + '"'
        return response
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #13
0
def query_rdr(request):
    room_id_get = request.GET.get('room_id')
    try:
        controller = Controller.instance()
        content = controller.dispatch(service='DETAIL',
                                      operation='query detail',
                                      room_id=room_id_get)
        content = {
            'message':
            'OK',
            'result': [{
                'room_id': c.room_id,
                'start_time': c.start_time.strftime('%Y-%m-%d %H:%M:%S'),
                'end_time': c.finish_time.strftime('%Y-%m-%d %H:%M:%S'),
                'speed': c.target_speed,
                'fee_rate': c.fee_rate,
                'fee': round(c.fee, 2)
            } for c in content]
        }
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #14
0
def print_report(request):
    qtype_get = request.GET.get('qtype')
    room_id_get = request.GET.get('room_id')
    date_get = request.GET.get('date')
    date_get_sp = date_get.split("-")
    date_get_da = datetime.datetime(int(date_get_sp[0]), int(date_get_sp[1]),
                                    int(date_get_sp[2]))
    try:
        controller = Controller.instance()
        filename = controller.dispatch(service='REPORT',
                                       operation='print report',
                                       room_id=room_id_get,
                                       date=date_get_da,
                                       qtype=qtype_get)
        file = open(filename, 'r')
        response = StreamingHttpResponse(file)
        response['Content-Type'] = 'application/octet-stream'
        response[
            'Content-Disposition'] = 'attachment;filename="' + filename + '"'
        return response
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #15
0
def query_invoice(request):
    room_id_get = request.GET.get('room_id')
    try:
        controller = Controller.instance()
        content = controller.dispatch(service='INVOICE',
                                      operation='query invoice',
                                      room_id=room_id_get)
        content = {
            'message': 'OK',
            'result': {
                'room_id':
                content.room_id,
                'check_in_time':
                content.check_in_time.strftime('%Y-%m-%d %H:%M:%S'),
                'check_out_time':
                content.check_out_time.strftime('%Y-%m-%d %H:%M:%S'),
                'fee':
                content.total_fee
            }
        }
        return JsonResponse(content)
    except RuntimeError as error:
        return JsonResponse({'message': str(error)})
コード例 #16
0
 def test_api(self):
     # 取得控制器对象
     controller = Controller.instance()
     # 主机开机
     controller.dispatch(service='ADMINISTRATOR', operation='power on')
     # 参数初始化
     controller.dispatch(service='ADMINISTRATOR',
                         operation='set param',
                         mode=master_machine_mode.COOL,
                         temp_low_limit=16,
                         temp_high_limit=30,
                         default_target_temp=24,
                         default_speed=fan_speed.NORMAL,
                         fee_rate=(0.5, 0.75, 1.5))
     # 开始执行
     controller.dispatch(service='ADMINISTRATOR', operation='start')
     # 监视空调
     room_status = controller.dispatch(service='ADMINISTRATOR',
                                       operation='get status')
     print(room_status)
     # 主机关机
     # controller.dispatch(service='ADMINISTRATOR', operation='stop')
     # 入住
     controller.dispatch(service='ADMINISTRATOR',
                         operation='check in',
                         room_id='309c')
     # 房间开机
     room_status = controller.dispatch(service='POWER',
                                       operation='power on',
                                       room_id='309c',
                                       current_temp=25)
     print(room_status)
     time.sleep(5)
     # 改变目标温度
     controller.dispatch(service='SLAVE',
                         operation='change temp',
                         room_id='309c',
                         target_temp=21)
     time.sleep(5)
     # 改变目标风速
     controller.dispatch(service='SLAVE',
                         operation='change speed',
                         room_id='309c',
                         target_speed=2)
     time.sleep(5)
     # 获取费用
     room_status = controller.dispatch(service='GET_FEE', room_id='309c')
     print(room_status)
     # 房间关机
     controller.dispatch(service='POWER',
                         operation='power off',
                         room_id='309c')
     # 退房
     controller.dispatch(service='ADMINISTRATOR',
                         operation='check out',
                         room_id='309c')
     # 获取详单
     details = controller.dispatch(service='DETAIL',
                                   operation='query detail',
                                   room_id='309c')
     # 打印详单
     filename = controller.dispatch(service='DETAIL',
                                    operation='print detail',
                                    room_id='309c')
     # 获取账单
     invoice = controller.dispatch(service='INVOICE',
                                   operation='query invoice',
                                   room_id='309c')
     # 打印账单
     filename = controller.dispatch(service='INVOICE',
                                    operation='print invoice',
                                    room_id='309c')
     # 获取报表
     report = controller.dispatch(service='REPORT',
                                  operation='query report',
                                  room_id='309c',
                                  date=datetime.datetime.now(),
                                  qtype='day')
     filename = controller.dispatch(service='REPORT',
                                    operation='print report',
                                    room_id='309c',
                                    date=datetime.datetime.now(),
                                    qtype='day')
     # 主机关机
     controller.dispatch(service='ADMINISTRATOR', operation='stop')
コード例 #17
0
    def test_run(self):
        controller = Controller.instance()

        # 主机开机
        controller.dispatch(service='ADMINISTRATOR', operation='power on')
        # 参数初始化
        controller.dispatch(service='ADMINISTRATOR',
                            operation='set param',
                            mode=master_machine_mode.COOL,
                            temp_low_limit=16,
                            temp_high_limit=30,
                            default_target_temp=24,
                            default_speed=fan_speed.NORMAL,
                            fee_rate=(0.5, 0.75, 1.5))
        controller.dispatch(service='ADMINISTRATOR', operation='start')
        timer = RepeatTimer(1, self.get_status)
        timer.start()

        # 入住
        controller.dispatch(service='ADMINISTRATOR',
                            operation='check in',
                            room_id='309c')
        # 房间开机
        controller.dispatch(service='POWER',
                            operation='power on',
                            room_id='309c',
                            current_temp=29)
        time.sleep(5)

        # 入住
        controller.dispatch(service='ADMINISTRATOR',
                            operation='check in',
                            room_id='310c')
        # 房间开机
        controller.dispatch(service='POWER',
                            operation='power on',
                            room_id='310c',
                            current_temp=27)
        time.sleep(3)

        # 入住
        controller.dispatch(service='ADMINISTRATOR',
                            operation='check in',
                            room_id='311c')
        # 房间开机
        controller.dispatch(service='POWER',
                            operation='power on',
                            room_id='311c',
                            current_temp=30)
        time.sleep(4)

        # 入住
        controller.dispatch(service='ADMINISTRATOR',
                            operation='check in',
                            room_id='312c')
        # 房间开机
        controller.dispatch(service='POWER',
                            operation='power on',
                            room_id='312c',
                            current_temp=25)
        controller.dispatch(service='SLAVE',
                            operation='change speed',
                            room_id='312c',
                            target_speed=2)
        time.sleep(70)

        for room_id in ('309c', '310c', '311c', '312c'):
            controller.dispatch(service='POWER',
                                operation='power off',
                                room_id=room_id)
            controller.dispatch(service='ADMINISTRATOR',
                                operation='check out',
                                room_id=room_id)
            controller.dispatch(service='DETAIL',
                                operation='print detail',
                                room_id=room_id)
コード例 #18
0
 def get_status(self):
     controller = Controller.instance()
     # 监视空调
     room_status = controller.dispatch(service='ADMINISTRATOR',
                                       operation='get status')
     print(room_status)