def get(self): device = request.args.get('device') start = time_manager.date_to_timestamp(request.args.get('date')) end = time_manager.datetime_to_timestamp( time_manager.get_cur_datetime()) # today params = {'start': start, 'end': end} response = requests.get(info.URL + 'devices/' + device + '/usages/periodic', headers=info.headers, params=params) json_obj = json.loads(response.text) json_obj['usage'] = unit_conversion.convert(json_obj['usage']) return json_obj
def get(self): # 오늘 에너지 사용량 조회 site_id = info.site_ids[request.args.get('where')] start = time_manager.date_to_timestamp(request.args.get('date')) end = time_manager.datetime_to_timestamp( time_manager.get_cur_datetime()) params = {'start': start, 'end': end} response = requests.get(info.URL + 'sites/' + site_id + '/usages/periodic', headers=info.headers, params=params) json_obj = json.loads(response.text) print(json_obj) json_obj['usage'] = unit_conversion.convert(json_obj['usage']) return json_obj
def get(self): # 이번 달 1일부터 현재까지 device의 전기 사용량 조회 device = request.args.get('device') first_date_of_month = time_manager.date_to_timestamp( datetime.datetime.now().strftime('%Y-%m-' + '01')) # 이번 달 1일의 날짜 now = time_manager.datetime_to_timestamp( time_manager.get_cur_datetime()) # 현재 timestamp params = {'start': first_date_of_month, 'end': now} response = requests.get(info.URL + 'devices/' + device + '/usages/billing', headers=info.headers, params=params) json_obj = json.loads(response.text) data = {'charge': json_obj['bill']['charge']} return data
def run(self): usages = {} sender = fcm_sender.FCMSender('AAAAI9HJHSc:APA91bEb1Y87VH-0RV5eNUDFu9faMikVY4NoUFVEVEAoZzdadtkWLs0dl1wt4BMCgEt3YRMGYgpeolYDPB0nvy9SJMWcARAsuEgMvTolxGAU7aQSAfOTjzQxUL4ndKl2zrzv_v5xbPQ4') for id in info.site_ids.keys(): usages[id] = None while True: now = time_manager.get_cur_datetime() now_stamp = time_manager.datetime_to_timestamp(now) before_1minute_stamp = int(now_stamp) - 900000 params = {'start': before_1minute_stamp, 'end': now_stamp} for id in info.site_ids.keys(): response = requests.get(info.URL + 'sites/' + info.site_ids[id] + '/usages/periodic', headers=info.headers, params=params) json_obj = json.loads(response.text) if usages[id] is None: usages[id] = json_obj['usage'] else: if usages[id] * 1.15 < json_obj['usage'] or usages[id] * 0.85 > json_obj['usage']: sender.send(info.site_ids[id], id) pass else: usages[id] = (int(usages[id]) + int(json_obj['usage'])) / 2 time.sleep(900)