def edit_stencil(request, stencil_index_number): hb_if = HBASE_interface() list_str = LIST_to_STR() tablename = "stencil_config" table = hb_if.table(tablename) result_scan_dict = table.row(stencil_index_number) print result_scan_dict result_list = [result_scan_dict] result_json = json.dumps(result_list) print result_scan_dict['c1:WQAR256_IDC'] print result_scan_dict['c1:WQAR512_IDC'] list_WQAR256_model = list_str.str_to_int( result_scan_dict['c1:WQAR256_IDC']) list_WQAR512_model = list_str.str_to_int( result_scan_dict['c1:WQAR512_IDC']) list_WQAR256_para_index, list_WQAR512_para_index = list_str.make_para_id_list( ) result_list_256_id = [] result_list_512_id = [] for each_id_number in list_WQAR256_model: result_list_256_id.append(list_WQAR256_para_index[int(each_id_number)]) for each_id_number in list_WQAR512_model: result_list_512_id.append(list_WQAR512_para_index[int(each_id_number)]) print result_list_256_id, result_list_512_id return render( request, 'edit_stencil.html', { 'result_json': result_json, 'result_json_256': result_list_256_id, 'result_json_512': result_list_512_id, 'stencil_index_number': stencil_index_number })
def edit_stencil(request, stencil_index_number): hb_if = HBASE_interface() list_str = LIST_to_STR() tablename = "stencil_config" table = hb_if.table(tablename) result_scan_dict = table.row(stencil_index_number) print result_scan_dict result_list = [result_scan_dict] result_json = json.dumps(result_list) print result_scan_dict['c1:WQAR256_IDC'] print result_scan_dict['c1:WQAR512_IDC'] list_WQAR256_model = list_str.str_to_int(result_scan_dict['c1:WQAR256_IDC']) list_WQAR512_model = list_str.str_to_int(result_scan_dict['c1:WQAR512_IDC']) list_WQAR256_para_index, list_WQAR512_para_index = list_str.make_para_id_list() result_list_256_id = [] result_list_512_id = [] for each_id_number in list_WQAR256_model: result_list_256_id.append(list_WQAR256_para_index[int(each_id_number)]) for each_id_number in list_WQAR512_model: result_list_512_id.append(list_WQAR512_para_index[int(each_id_number)]) print result_list_256_id,result_list_512_id return render(request, 'edit_stencil.html',{'result_json': result_json, 'result_json_256':result_list_256_id, 'result_json_512':result_list_512_id, 'stencil_index_number':stencil_index_number})
def save_decode_list_to_hbase(list_all_para_turn, file): hbase_interface = HBASE_interface() connection = happybase.Connection(host='10.210.180.43', port=9090, timeout = None, autoconnect=True, compat='0.94', ) # 向索引表中插入数据分表的表头信息 table_tablename_index = connection.table("tablename_index") pro_Aircraft_Identification = file[0:6] pro_updata_Date = file[7:11] + '-' + file[11:13] + '-' + file[13:15] pro_updata_Time = file[15:17] + ':' + file[17:19] + ':' + file[19:21] dic_table_info = {'c1:Aircraft_Identification': pro_Aircraft_Identification, 'c1:updata_Date': pro_updata_Date, 'c1:updata_Time':pro_updata_Time} table_tablename_index.put(file[0:21], dic_table_info) # 测试速度时用 #hbase_interface.delete_table(file[0:21]) #建立分表,并向分表中插入数据 hbase_interface.create_table(file[0:21]) table = connection.table(file[0:21]) print table happybase_start_time = datetime.datetime.now() b = table.batch() counter_list_all_para = len(list_all_para_turn) counter_list_columns = len(list_all_para_turn[0]) # 按python list 标号从零开始改为从一开始,以符合数据库设计 counter_list_columns_app_1 = counter_list_columns + 1 put_table_data = [] for i in range(0, counter_list_all_para): #print u"第 %s 行"%i if i == 0: str_i = str(i).zfill(5) elif i == 1: str_i = 'UNITS' else: str_i = str(i - 1).zfill(5) dic_j = {} for j in range(1, counter_list_columns_app_1): str_value = str(list_all_para_turn[i][j-1]) #对应在list中的下标要减一 dic_j['c1:'+ str(j)] = str_value put_table_data.append([str_i, dic_j]) print u"%s 开始HBASE插入" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) start_put_time = datetime.datetime.now() put_data(file[0:21], put_table_data, counter_list_all_para) end_put_time = datetime.datetime.now() print u"%s 结束HBASE插入" % time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) print u"插入耗时: %s s" %((end_put_time - start_put_time).seconds) #b.send() #进行GMT的处理 second_storing = Second_Storing() second_storing.merge_GMT_time(file[0:21]) happybase_end_time = datetime.datetime.now()
def storing_stencil_ajax(request): #前端传入参数 ata = request.GET.get('stencil_ATA', None) name = request.GET.get('stencil_name', None) para_256 = request.GET.get('stencil_256_para', None) para_512 = request.GET.get('stencil_512_para', None) creator = request.GET.get('stencil_creator', None) #对传入进行解码 name_decode = name.encode('utf-8') creator_decode = creator.encode('utf-8') para_256_decode = para_256.split(',') para_512_decode = para_512.split(',') #防输错设计,前端多输入了,号,列表中有空值即去掉 while '' in para_256_decode: para_256_decode.remove('') while '' in para_512_decode: para_512_decode.remove('') #存入数据库 ''' stencil.objects.create(configuration = conf, ATA = ata, \ stencil_name = name_decode, list_para = para_decode) ''' hb_if = HBASE_interface() list_str = LIST_to_STR() table = hb_if.table('stencil_config') str_stencil_name = name_decode str_para_256 = list_str.int_to_str(para_256_decode) str_para_512 = list_str.int_to_str(para_512_decode) dict_cf_data = { 'c1:NAME': str_stencil_name, 'c1:WQAR512_IDC': str_para_512, 'c1:WQAR256_IDC': str_para_256, 'c1:ATA': ata, 'c1:creator': creator_decode, 'c1:ECHARTS_256': ';;', 'c1:ECHARTS_512': ';;' } cf_set = ['c1:NAME'] dict = hb_if.query_table('stencil_config', cf_set) table_max_index = len(dict.items()) print "table max index: %s" % table_max_index rowkey = (str(table_max_index + 1)).zfill(3) print rowkey print dict_cf_data table.put(rowkey, dict_cf_data) #回传前端,反馈结果 para_256_post = ','.join(para_256_decode) para_512_post = ','.join(para_512_decode) text = '<br>已录入<br>模版:' + str(name_decode) + \ '<br>参数256:' + str(para_256_post) + \ '<br>参数512:' + str(para_512_post) + \ '<br>章节:' + str(ata) return HttpResponse(text)
def storing_stencil_ajax(request): #前端传入参数 ata = request.GET.get('stencil_ATA', None) name = request.GET.get('stencil_name', None) para_256 = request.GET.get('stencil_256_para', None) para_512 = request.GET.get('stencil_512_para', None) creator = request.GET.get('stencil_creator', None) #对传入进行解码 name_decode = name.encode('utf-8') creator_decode = creator.encode('utf-8') para_256_decode = para_256.split(',') para_512_decode = para_512.split(',') #防输错设计,前端多输入了,号,列表中有空值即去掉 while '' in para_256_decode: para_256_decode.remove('') while '' in para_512_decode: para_512_decode.remove('') #存入数据库 ''' stencil.objects.create(configuration = conf, ATA = ata, \ stencil_name = name_decode, list_para = para_decode) ''' hb_if = HBASE_interface() list_str = LIST_to_STR() table = hb_if.table('stencil_config') str_stencil_name = name_decode str_para_256 = list_str.int_to_str(para_256_decode) str_para_512 = list_str.int_to_str(para_512_decode) dict_cf_data = {'c1:NAME': str_stencil_name, 'c1:WQAR512_IDC': str_para_512, 'c1:WQAR256_IDC': str_para_256, 'c1:ATA': ata, 'c1:creator':creator_decode, 'c1:ECHARTS_256':';;', 'c1:ECHARTS_512':';;'} cf_set = ['c1:NAME'] dict = hb_if.query_table('stencil_config', cf_set) table_max_index = len(dict.items()) print "table max index: %s" % table_max_index rowkey = (str(table_max_index + 1)).zfill(3) print rowkey print dict_cf_data table.put(rowkey, dict_cf_data) #回传前端,反馈结果 para_256_post = ','.join(para_256_decode) para_512_post = ','.join(para_512_decode) text = '<br>已录入<br>模版:' + str(name_decode) + \ '<br>参数256:' + str(para_256_post) + \ '<br>参数512:' + str(para_512_post) + \ '<br>章节:' + str(ata) return HttpResponse(text)
def all_childtable_index_list(request): hbase_interface = HBASE_interface() tablename = "tablename_index" cf_set = ['c1:Aircraft_Identification', 'c1:updata_Date', 'c1:updata_Time'] result_scan_dict = hbase_interface.query_table(tablename,cf_set) result_list = [] for key, value in result_scan_dict.items(): single = {'index' : key, 'Aircraft_Identification' : value['c1:Aircraft_Identification'], 'updata_Date':value['c1:updata_Date'], 'updata_Time':value['c1:updata_Time'],} result_list.append(single) result_json = json.dumps(result_list) return render(request, 'all_childtable_index_list.html',{'result_json': result_json})
def stencil_echarts(request): stencil_index_number = request.GET.get('stencil_index_number', None) post_string_256 = request.GET.get('post_string_256', None) post_string_512 = request.GET.get('post_string_512', None) rowkey = (str(stencil_index_number)).zfill(3) print rowkey hb_if = HBASE_interface() list_str = LIST_to_STR() table = hb_if.table('stencil_config') dict_cf_data = { 'c1:ECHARTS_256': post_string_256, 'c1:ECHARTS_512': post_string_512 } table.put(rowkey, dict_cf_data) return HttpResponse("已录入")
def childtable(request, flight_id): list = [flight_id] json_list = json.dumps(list) hbase_interface = HBASE_interface() table_name = "stencil_config" cf_set = ['c1:WQAR512_IDC', 'c1:WQAR256_IDC', 'c1:NAME'] result_scan_dict = hbase_interface.query_table(table_name, cf_set) result_list = [] for key, value in result_scan_dict.items(): single = {'index': key, 'NAME': value['c1:NAME']} result_list.append(single) return render(request, 'childtable.html', { 'json_list': json_list, 'stencil_option': result_list })
def all_childtable_index_list(request): hbase_interface = HBASE_interface() tablename = "tablename_index" cf_set = ['c1:Aircraft_Identification', 'c1:updata_Date', 'c1:updata_Time'] result_scan_dict = hbase_interface.query_table(tablename, cf_set) result_list = [] for key, value in result_scan_dict.items(): single = { 'index': key, 'Aircraft_Identification': value['c1:Aircraft_Identification'], 'updata_Date': value['c1:updata_Date'], 'updata_Time': value['c1:updata_Time'], } result_list.append(single) result_json = json.dumps(result_list) return render(request, 'all_childtable_index_list.html', {'result_json': result_json})
def childtable(request, flight_id): list = [flight_id] json_list = json.dumps(list) hbase_interface = HBASE_interface() table_name = "stencil_config" cf_set = ['c1:WQAR512_IDC', 'c1:WQAR256_IDC', 'c1:NAME'] result_scan_dict = hbase_interface.query_table(table_name, cf_set) result_list = [] for key, value in result_scan_dict.items(): single = {'index' : key, 'NAME' : value['c1:NAME'] } result_list.append(single) return render(request, 'childtable.html', {'json_list': json_list, 'stencil_option': result_list})
def stencil_echarts(request): stencil_index_number = request.GET.get('stencil_index_number', None) post_string_256 = request.GET.get('post_string_256', None) post_string_512 = request.GET.get('post_string_512', None) rowkey = (str(stencil_index_number)).zfill(3) print rowkey hb_if = HBASE_interface() list_str = LIST_to_STR() table = hb_if.table('stencil_config') dict_cf_data = {'c1:ECHARTS_256': post_string_256, 'c1:ECHARTS_512': post_string_512 } table.put(rowkey, dict_cf_data) return HttpResponse("已录入")
def stencil_list(request): hb_if = HBASE_interface() list_str = LIST_to_STR() table = hb_if.table('stencil_config') tablename = "stencil_config" cf_set = ['c1:NAME', 'c1:ATA', 'c1:creator', ] result_scan_dict = hb_if.query_table(tablename,cf_set) result_list = [] for key, value in result_scan_dict.items(): print key, value single = {'index' : key, 'NAME' : value['c1:NAME'], 'ATA':value['c1:ATA'], 'creator':value['c1:creator'], } result_list.append(single) result_json = json.dumps(result_list) return render(request, 'stencil_list.html',{'result_json': result_json})
def stencil_list(request): hb_if = HBASE_interface() list_str = LIST_to_STR() table = hb_if.table('stencil_config') tablename = "stencil_config" cf_set = [ 'c1:NAME', 'c1:ATA', 'c1:creator', ] result_scan_dict = hb_if.query_table(tablename, cf_set) result_list = [] for key, value in result_scan_dict.items(): print key, value single = { 'index': key, 'NAME': value['c1:NAME'], 'ATA': value['c1:ATA'], 'creator': value['c1:creator'], } result_list.append(single) result_json = json.dumps(result_list) return render(request, 'stencil_list.html', {'result_json': result_json})
#coding=utf-8 from hbase_function import HBASE_interface hb_if = HBASE_interface() connection = hb_if.connect_hbase print connection.tables() hb_if.create_table('stencil_config') print connection.tables()
def ajax_some_para(request): hbase_interface = HBASE_interface() list_str = LIST_to_STR() post_index = request.GET.get('value_conf', None) print post_index post_flight_id = request.GET.get('flight_id', None) aircraft_id = post_flight_id[0:6] # 读取模版表的存储详情 table_stencil_name = "stencil_config" cf_set_stencil = [ 'c1:WQAR512_IDC', 'c1:WQAR256_IDC', 'c1:NAME', 'c1:ECHARTS_256', 'c1:ECHARTS_512' ] result_scan_dict = hbase_interface.query_table(table_stencil_name, cf_set_stencil) dict_stencil_config = result_scan_dict[post_index] str_WQAR256 = dict_stencil_config['c1:WQAR256_IDC'] str_WQAR512 = dict_stencil_config['c1:WQAR512_IDC'] list_WQAR256 = list_str.str_to_int(str_WQAR256) list_WQAR512 = list_str.str_to_int(str_WQAR512) #取出echarts option echarts_option_256 = dict_stencil_config['c1:ECHARTS_256'] echarts_option_512 = dict_stencil_config['c1:ECHARTS_512'] # 机号构型判断 ac_wqar_config = AC_WQAR_CONFIG() if aircraft_id in ac_wqar_config.WQAR512_SERISE_list: model = list_WQAR512 str_echarts_option = echarts_option_512 elif aircraft_id in ac_wqar_config.WQAR256_SERISE_list: model = list_WQAR256 str_echarts_option = echarts_option_256 else: return HttpResponse("无此机号") tablename = post_flight_id cf_set = [] for item in model: cf_set.append('c1:' + str(item)) result_scan_dict = hbase_interface.query_table(tablename, cf_set) result_list = [] para_name_dic = result_scan_dict['00000'] for key, value in result_scan_dict.items(): single = {'index': key} for key_para, value_para in value.items(): para_name = para_name_dic[key_para] single[para_name] = value_para result_list.append(single) #查询出C2的值 cf_set_c2 = ['c2:1'] dict_c2_scan = hbase_interface.query_table(tablename, cf_set_c2) dict_c2_para_name = dict_c2_scan['00000'] list_c1_c2 = [] i = 0 for key, value in dict_c2_scan.items(): single = result_list[i] for key_para, value_para in value.items(): para_name = dict_c2_para_name[key_para] single[para_name] = value_para list_c1_c2.append(single) i = i + 1 # 传递echarts设置信息 ec_op = Echarts_option() echarts_config_option = ec_op.str_to_obj(str_echarts_option) # 得出echarts_option中的逻辑值参数表列表 list_index_of_logic_echarts = ec_op.judge_logic_echart( echarts_config_option) result_json = json.dumps( [list_c1_c2, echarts_config_option, list_index_of_logic_echarts]) return HttpResponse(result_json)
#coding=utf-8 from hbase_function import HBASE_interface from hbase_function import LIST_to_STR hb_if = HBASE_interface() list_str = LIST_to_STR() connection = hb_if.connect_hbase print connection.tables() table = hb_if.table("B-2613_20160205052208")
def __init__(self): self.hb_if = HBASE_interface() self.list_str = LIST_to_STR() self.ac_config = AC_WQAR_CONFIG() pass
#coding=utf-8 from hbase_function import HBASE_interface hb_if = HBASE_interface() connection = hb_if.connect_hbase table_tablename_index = connection.table("tablename_index") for key, data in table_tablename_index.scan(): print key, data ''' list_1 = ["B-2613_20160220084007","B-5327_20160206214451"] flight_name_list =["B-1527_20160213052822", ] for flight_name in flight_name_list: table_tablename_index.delete(row=flight_name) hb_if.delete_table(flight_name) table_tablename_index.delete(row="B-1768_20160117035039") table_tablename_index.delete(row="B-2612_20160117031715") table_tablename_index.delete(row="B-5203_20160117112110") table_tablename_index.delete(row="B-5329_20160117085658") ''' for key, data in table_tablename_index.scan(): table_tablename_index.delete(row = key) hb_if.delete_table(key) print u"删除表和ROW:" + key print u"当前数据表内值:" for key, data in table_tablename_index.scan(): print key, data
#coding=utf-8 from hbase_function import HBASE_interface hb_if = HBASE_interface() table_list = ['B-1527_20160201073858'] for item in table_list: hb_if.delete_table(item)
#coding=utf-8 from hbase_function import HBASE_interface hb_if = HBASE_interface() connection = hb_if.connect_hbase() table_tablename_index = connection.table("tablename_index") for key, data in table_tablename_index.scan(): #table_tablename_index.delete(key) value = data['c2:pro_updata_Time'] col_set = ['c1:pro'] table_tablename_index.put(key,) print key, data
def ajax_some_para(request): hbase_interface = HBASE_interface() list_str = LIST_to_STR() post_index = request.GET.get('value_conf', None) print post_index post_flight_id = request.GET.get('flight_id', None) aircraft_id = post_flight_id[0:6] # 读取模版表的存储详情 table_stencil_name = "stencil_config" cf_set_stencil = ['c1:WQAR512_IDC', 'c1:WQAR256_IDC', 'c1:NAME', 'c1:ECHARTS_256', 'c1:ECHARTS_512'] result_scan_dict = hbase_interface.query_table(table_stencil_name,cf_set_stencil) dict_stencil_config = result_scan_dict[post_index] str_WQAR256 = dict_stencil_config['c1:WQAR256_IDC'] str_WQAR512 = dict_stencil_config['c1:WQAR512_IDC'] list_WQAR256 = list_str.str_to_int(str_WQAR256) list_WQAR512 = list_str.str_to_int(str_WQAR512) #取出echarts option echarts_option_256 = dict_stencil_config['c1:ECHARTS_256'] echarts_option_512 = dict_stencil_config['c1:ECHARTS_512'] # 机号构型判断 ac_wqar_config = AC_WQAR_CONFIG() if aircraft_id in ac_wqar_config.WQAR512_SERISE_list: model = list_WQAR512 str_echarts_option = echarts_option_512 elif aircraft_id in ac_wqar_config.WQAR256_SERISE_list: model = list_WQAR256 str_echarts_option = echarts_option_256 else: return HttpResponse("无此机号") tablename = post_flight_id cf_set = [] for item in model: cf_set.append('c1:' + str(item)) result_scan_dict = hbase_interface.query_table(tablename,cf_set) result_list = [] para_name_dic = result_scan_dict['00000'] for key, value in result_scan_dict.items(): single = {'index' : key} for key_para, value_para in value.items(): para_name = para_name_dic[key_para] single[para_name] = value_para result_list.append(single) #查询出C2的值 cf_set_c2 = ['c2:1'] dict_c2_scan = hbase_interface.query_table(tablename,cf_set_c2) dict_c2_para_name = dict_c2_scan['00000'] list_c1_c2 = [] i = 0 for key, value in dict_c2_scan.items(): single = result_list[i] for key_para, value_para in value.items(): para_name = dict_c2_para_name[key_para] single[para_name] = value_para list_c1_c2.append(single) i = i + 1 # 传递echarts设置信息 ec_op = Echarts_option() echarts_config_option = ec_op.str_to_obj(str_echarts_option) # 得出echarts_option中的逻辑值参数表列表 list_index_of_logic_echarts = ec_op.judge_logic_echart(echarts_config_option) result_json = json.dumps([list_c1_c2, echarts_config_option, list_index_of_logic_echarts]) return HttpResponse(result_json)
# coding:utf-8 from hbase_function import HBASE_interface from hbase_function import LIST_to_STR table_name = 'tablename_index' hb_if = HBASE_interface() table = hb_if.table(table_name) print table for key,value in table.scan(): print key print hb_if.list_make_columns_family('c2',[1,2,66,88])
def save_decode_list_to_hbase(list_all_para_turn, file): hbase_interface = HBASE_interface() connection = happybase.Connection( host='10.210.180.43', port=9090, timeout=None, autoconnect=True, compat='0.94', ) # 向索引表中插入数据分表的表头信息 table_tablename_index = connection.table("tablename_index") pro_Aircraft_Identification = file[0:6] pro_updata_Date = file[7:11] + '-' + file[11:13] + '-' + file[13:15] pro_updata_Time = file[15:17] + ':' + file[17:19] + ':' + file[19:21] dic_table_info = { 'c1:Aircraft_Identification': pro_Aircraft_Identification, 'c1:updata_Date': pro_updata_Date, 'c1:updata_Time': pro_updata_Time } table_tablename_index.put(file[0:21], dic_table_info) # 测试速度时用 #hbase_interface.delete_table(file[0:21]) #建立分表,并向分表中插入数据 hbase_interface.create_table(file[0:21]) table = connection.table(file[0:21]) print table happybase_start_time = datetime.datetime.now() b = table.batch() counter_list_all_para = len(list_all_para_turn) counter_list_columns = len(list_all_para_turn[0]) # 按python list 标号从零开始改为从一开始,以符合数据库设计 counter_list_columns_app_1 = counter_list_columns + 1 put_table_data = [] for i in range(0, counter_list_all_para): #print u"第 %s 行"%i if i == 0: str_i = str(i).zfill(5) elif i == 1: str_i = 'UNITS' else: str_i = str(i - 1).zfill(5) dic_j = {} for j in range(1, counter_list_columns_app_1): str_value = str(list_all_para_turn[i][j - 1]) #对应在list中的下标要减一 dic_j['c1:' + str(j)] = str_value put_table_data.append([str_i, dic_j]) print u"%s 开始HBASE插入" % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) start_put_time = datetime.datetime.now() put_data(file[0:21], put_table_data, counter_list_all_para) end_put_time = datetime.datetime.now() print u"%s 结束HBASE插入" % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) print u"插入耗时: %s s" % ((end_put_time - start_put_time).seconds) #b.send() #进行GMT的处理 second_storing = Second_Storing() second_storing.merge_GMT_time(file[0:21]) happybase_end_time = datetime.datetime.now()