Exemplo n.º 1
0
 def get_allimages_path(self):
     res = []
     if self.metainfo.has_key('db_key'):
         db_key = self.metainfo['db_key']
         return redisc.zrange(db_key, 0, -1)
     else:
         common.write_log("no infor")
     return res
Exemplo n.º 2
0
    def process(self, item_id):
	# 获得查询item的cat
	(cat_id, words) = self.dim_items_index.get(item_id, (-1, -1))
	if cat_id == -1 : return []

	# 获得这个cat的相似cat
	sim_cat_ids = self.cat_sim_rindex.get(cat_id, -1)
	if sim_cat_ids == -1 : return []

	write_log(msg = 'process item_id:%d, sim_cat_ids size:%d' % (item_id, len(sim_cat_ids)) )
	return self.__get_rec_item_ids(item_id, sim_cat_ids)
Exemplo n.º 3
0
def run(log_path):
    test_project = "12v"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 600
    pass_num = 0
    fail_num = 0
    url_di = "http://" + host_ip + ":" + host_ip + "/gs-robot/data/device_status"
    for i in range(count_num):
        common.write_log(log_path, test_project, "info", url_di)
        data = common.getUrlData(url_di)
        time.sleep(1)
        di_value = int(data["data"]["detailedDi"])
        one_list = []
        common.check_value(di_value, one_list)
        if 3 in one_list:
            common.write_log(log_path, test_project, "info", str(data))
            pass_num += 1
        else:
            common.write_log(log_path, test_project, "error", str(data))
            state = False
            fail_num += 1
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 4
0
 def add_dir(self, dir_path):
     '''
         note: Only support one dir at same time.
     '''
     # get image info from dir
     file_list = common.get_filelist(dir_path)
     # update image info in redis
     res = self._insert_images(file_list)
     if res is not None:
         common.write_log(common.REDIS_ERROR)
         return
     num = len(file_list)
     # update metainfo in object and redis
     self.metainfo["dir_path"] = dir_path
     self.metainfo["img_num"] = num
     self._update_metainfo()
     return
Exemplo n.º 5
0
def run(log_path):
    test_project = "扫地图"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 10
    pass_num = 0
    fail_num = 0
    time.sleep(1)
    return {
        test_project: {
            "state": True,
            "count_num": 10,
            "pass_num": 9,
            "fail_num": 1
        }
    }
Exemplo n.º 6
0
    def __get_rec_item_ids(self, item_id, sim_cat_ids):
	"""
	获取推荐item_id
	Args:
	    item_id: query的item_id
	    sim_cat_ids : item_id的相似cat_id列表
	Returns:
	    [(rec_item_id, sim_value), (rec_item_id, sim_value), ...],长度为strategy.get_total_rec_num()
	"""

	target_item = self.dim_items_index.get(item_id, -1)
	if target_item == -1:
	    write_log(sys._getframe().f_lineno, "cannot get info of item_id:%d" % (item_id) )
	    return

	rec_items = []
	sim_cat_ids = sim_cat_ids[0: self.strategy.get_max_sim_cat_process()]
	count = 0
	timer_total = Timer()
	for i in range(0, len(sim_cat_ids)):
	    (cat_id, sim_value) = sim_cat_ids[i]
	    sim_item_ids = self.cat_to_item_rindex.get(cat_id, [])
	    if len(sim_item_ids) == 0 : 
		write_log(sys._getframe().f_lineno, "cat_id:%d has no item" % (cat_id) )
		continue
	    timer = Timer()
	    count += len(sim_item_ids)
	    res_list = self.__find_sim_item_from_a_list(target_item, sim_item_ids, i)
	    write_log(msg = "__find_sim_item_from_a_list cost time:%f, sim_item_ids size:%d, i:%d" % (timer.get_diff(), len(sim_item_ids), i))
	    rec_items.extend(res_list)
	write_log(msg = "all__find_sim_item_from_a_list cost time:%f, all_sim_item_ids size:%d" % (timer_total.get_diff(), count))

	write_log(msg = 'process item_id:%d, rec_items size:%d' % (item_id, len(rec_items)) )
	rec_items.sort(lambda y,x : cmp(x[1], y[1]))
	rec_items = rec_items[0: self.strategy.get_total_rec_num()]

	final_res = []
	for (id, value) in rec_items:
	    final_res.append(id)

	return final_res
Exemplo n.º 7
0
def run(log_path):
    test_project = "can"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    url = common.get_url(
        "/gs-robot/real_time_data/ultrasonic_raw?frame_id=ultrasonic0")
    state = True
    count_num = 600
    pass_num = 0
    fail_num = 0
    for i in range(count_num):
        data = common.getUrlData(url)
        if data == 1:
            state = False
            fail_num += 1
            common.write_log(log_path, test_project, "error", str(data))
        else:
            pass_num += 1
            common.write_log(log_path, test_project, "info", str(data))
        time.sleep(1)
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 8
0
    def __create_a_sample(self, item_id_a, item_id_b):

	item_a = self.dim_items_index.get(item_id_a, None)
	if not item_a != None: 
	    write_log(msg = '__create_a_sample get no item, id:%d' % item_id_a)
	    return

	item_b = self.dim_items_index.get(item_id_b, None)
	if not item_b != None:
	    write_log(msg = '__create_a_sample get no item, id:%d' % item_id_a)
	    return

	item_a.pos = 1
	item_b.pos = 2
	fea_a = self.feature_builder.get_feature(item_a)
	fea_b = self.feature_builder.get_feature(item_b)
	fea = fea_a + fea_b
	if len(fea) == 0 : write_log(msg = 'fea len is 0, item_id %d %d' % (item_id_a, item_id_b) )
	fea = sorted(fea)
	self.__add_to_dis(fea)
	self.__add_to_map(fea, 1)
	self.__print_feature(fea, 1)


	item_a.pos = 2
	item_b.pos = 1
	fea_a = self.feature_builder.get_feature(item_a)
	fea_b = self.feature_builder.get_feature(item_b)
	fea = fea_a + fea_b
	fea = sorted(fea)
	self.__add_to_dis(fea)
	self.__add_to_map(fea, 1)
	self.__print_feature(fea, 1)
Exemplo n.º 9
0
    def __find_sim_item_from_a_list(self, target_item, sim_item_ids, idx):
	target_title = target_item[1]
	
	count = 0
	rec_items = []
	for sim_id in sim_item_ids:
	    sim_item = self.dim_items_index.get(sim_id, -1)
	    if sim_item == -1 : continue

	    count += 1
	    if count > 20000: break

	    sim_title = sim_item[1]
	    timer = Timer()
	    val = self.__cal_title_sim(target_title, sim_title)
	    write_log(msg = "__cal_title_sim cost time:%f, target_title size:%d, sim_title size:%d" % (timer.get_diff(), len(target_title), len(sim_title)))
	    rec_items.append( (sim_id, val) )

	num_to_get = self.strategy.num_to_return_of_this_sim_cat(idx)
	if len(rec_items) > num_to_get:
	    rec_items.sort(lambda y,x : cmp(x[1], y[1]))
	    rec_items = rec_items[0: num_to_get]
	return rec_items
Exemplo n.º 10
0
def run(log_path):
    test_project = "motor"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 600
    pass_num = 0
    fail_num = 0
    url = common.get_url("/gs-robot/data/health_status")
    for i in range(count_num):
        common.write_log(log_path, test_project, "info", url)
        data = common.getUrlData(url)
        time.sleep(1)
        if data["rightMotor"] and data["leftMotor"]:
            common.write_log(log_path, test_project, "info", str(data))
            pass_num += 1
        else:
            common.write_log(log_path, test_project, "error", str(data))
            fail_num += 1
    return {test_project:{"state":state, "count_num":count_num, "pass_num":pass_num, "fail_num":fail_num}}
Exemplo n.º 11
0
def run(log_path):
    test_project = "lan_wan"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    ips = [
        "10.7.5.1", "10.7.5.88", "10.7.5.199", "10.7.5.100", "www.baidu.com"
    ]
    ip_t = []
    respons = []
    for ip in ips:
        t = MyThread(ping_ip, args=(ip))
        ip_t.append(t)
        t.start()

    for t in ip_t:
        t.join()
        respons.append(t.get_result())

    count_num = 0
    fail_num = 0
    for i in respons:
        count_num = count_num + i[0]
        fail_num = fail_num + i[1]
        if not i[1]:
            common.write_log(log_path, test_project, "info", str(i[2]))
        else:
            common.write_log(log_path, test_project, "error", str(i[2]))
    pass_num = count_num - fail_num
    state = None
    if fail_num == 0:
        state = True
    else:
        state = False
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 12
0
    def create_a_test(self, test_id, match_id):

	test_item = self.dim_items_index.get(test_id, None)
	if not test_item != None: 
	    write_log(msg = '__create_a_test get no item, id:%d' % test_id)
	    return

	match_item = self.dim_items_index.get(match_id, None)
	if not match_item != None:
	    write_log(msg = '__create_a_test get no item, id:%d' % match_id)
	    return

	test_item.pos = 1
	match_item.pos = 2
	fea_a = self.feature_builder.get_feature(test_item)
	fea_b = self.feature_builder.get_feature(match_item)
	fea = fea_a + fea_b
	if fea == None or len(fea) == 0 : write_log(msg = 'fea len is 0, item_id %d %d' % (test_id, match_id) )
	fea = sorted(fea)
	self.__print_feature(test_id, match_id, fea)
	return fea
Exemplo n.º 13
0
def run(log_path):
    test_project = "input"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    url = common.get_url("/gs-robot/data/device_status")
    state = True
    count_num = 10
    pass_num = 0
    fail_num = 0
    do_value_dict = {}
    for i in range(8):
        do_value = pow(2, i)
        do_value_key = "do" + str(i + 1)
        do_value_dict[do_value_key] = do_value

    all_do_value_comb = combination_all(do_value_dict.keys())
    all_do_value_comb_list = []
    for i in all_do_value_comb:
        value = 0
        for j in do_value_dict.keys():
            if j in i:
                value += do_value_dict[j]
        all_do_value_comb_list.append(value)
    all_do_value_comb_list.append(0)
    all_do_value_comb_list = sorted(all_do_value_comb_list)
    count_num = len(all_do_value_comb_list) * 2
    for j in range(2):
        for i in all_do_value_comb_list:
            do_commond = 'rosservice call /device/operate_device \"operation:\n- key: \'do\'\n  value: \'%d\'\"' % i
            common.write_log(log_path, test_project, "info", do_commond)
            res = os.popen(do_commond).read()
            if "True" in res:
                common.write_log(log_path, test_project, "info", res)
            else:
                common.write_log(log_path, test_project, "error", res)
            time.sleep(1)
            data = common.getUrlData(url)
            di_value = int(data["data"]["detailedDi"])
            if di_value != i:
                state = False
                common.write_log(log_path, test_project, "error", str(data))
                fail_num += 1
            else:
                common.write_log(log_path, test_project, "info", str(data))
                pass_num += 1
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 14
0
def gen_disk_light_topo_tb(infile, rn, outdir, outfile0, cth_file, log_file,
                           json_file):

    # {{{
    outfile = outdir + outfile0
    common.write_log(log_file, 'START disk_light_topo_tb')
    lat_fy4a = gdal.Open(
        './lut4k_1.tif').\
        ReadAsArray(0, 0, 2748, 2748)  # 纬度数据
    lon_fy4a = gdal.Open(
        './lut4k_2.tif').\
        ReadAsArray(0, 0, 2748, 2748)  # 经度数据

    f = h5.File(infile, 'r')
    Channel = 12
    NOMChannel = f['NOMChannel%s' % (Channel)][:]
    CALChannel = f['CALChannel%s' % (Channel)][:]
    tb = Data_Cal(NOMChannel, CALChannel)
    bln = f.attrs[u'Begin Line Number'][0]
    eln = f.attrs[u'End Line Number'][0]
    bpn = f.attrs[u'Begin Pixel Number'][0]
    epn = f.attrs[u'End Pixel Number'][0]
    f.close()

    if False:
        cth_file = re.sub(r'\.HDF', r'.NC', infile)
        cth_file = re.sub(r'FDI', r'CTH', cth_file)
        cth_file = re.sub(r'L1', r'L2', cth_file)
        cth_file = re.sub(r'\/DISK\/', '/DISK/NOM/', cth_file)
    f = h5.File(cth_file, 'r')
    cth = f['CTH'][:]
    f.close()

    tb0 = lon_fy4a * 0 - 100
    tb0[bln:eln + 1, bpn:epn + 1] = tb
    tb = tb0
    cth0 = lon_fy4a * 0
    cth0[bln:eln + 1, bpn:epn + 1] = cth
    cth = cth0

    f = h5.File('topo_fy4a_4km.nc', 'r')
    topo = f['topo'][:]
    topo = np.flip(topo.T, 0)
    f.close()

    # tb[np.where(tb < 50)] = np.nan
    print(tb.dtype)
    # tb[np.where(cth < 0)] = tb[np.where(cth < 0)]+100

    if False:
        tb = cv2.resize(tb.astype(np.double), (2748 * 2, 2748 * 2))
        lon_fy4a = cv2.resize(lon_fy4a.astype(np.double), (2748 * 2, 2748 * 2))
        lat_fy4a = cv2.resize(lat_fy4a.astype(np.double), (2748 * 2, 2748 * 2))
        print(tb.shape)

    if True:
        x4 = np.linspace(0, 10, num=2748)
        y4 = np.linspace(0, 10, num=2748)
        x42, y42 = np.meshgrid(x4, y4)
        xo = np.linspace(0, 10, num=2748 * rn)
        yo = np.linspace(0, 10, num=2748 * rn)
        # id = np.where((tb > 0) & (lon_fy4a > -190) & (lat_fy4a > -100))
        sn = 4
        if rn > 2:
            sn = 8
        tb = griddata.stb(sn, x42, y42, tb, xo, yo).transpose()
        topo = griddata.stb(sn, x42, y42, topo, xo, yo).transpose()
        lon_fy4a = griddata.stb(sn, x42, y42, lon_fy4a, xo, yo)
        lat_fy4a = griddata.stb(sn, x42, y42, lat_fy4a, xo, yo)
        cth = griddata.stb(sn, x42, y42, cth, xo, yo).transpose()

    topo[np.where(cth > 0)] = cth[np.where(cth > 0)]
    topo = topo / 1000
    # cth = 10-tb/20/100*50
    # topo[np.where(tb < -10+273.15)] = cth[np.where(tb < -10+273.15)]

    # imshow total
    # tb[np.where(tb < 50)] = np.nan
    rg = [-110 + 273.15, 50 + 100 + 273.15]
    # rg = [-90+273.15, 60+273.15]
    tb3 = num2rgb(tb, ch8, rg)

    if True:
        tb_nocloud = tb
        tb3_nocloud = num2rgb(tb_nocloud, tcc, [-50 + 273.15, 20 + 273.15])
        r = tb3[:, :, 0]
        g = tb3[:, :, 1]
        b = tb3[:, :, 2]
        rn = tb3_nocloud[:, :, 0]
        gn = tb3_nocloud[:, :, 1]
        bn = tb3_nocloud[:, :, 2]
        rn[np.where(cth > 0)] = r[np.where(cth > 0)]
        gn[np.where(cth > 0)] = g[np.where(cth > 0)]
        bn[np.where(cth > 0)] = b[np.where(cth > 0)]
        # tb3[np.where(tb3_nocloud > 0)] = tb3_nocloud[np.where(tb3_nocloud > 0)]
        tb3[:, :, 0] = rn
        tb3[:, :, 1] = gn
        tb3[:, :, 2] = bn
        # tb3 = tb3_nocloud
        print(tb3.shape)
        print(cth.shape)

    lt = light.point(lon_fy4a, lat_fy4a, topo, np.array([-1, 1, 1]))
    if True:
        lt[lt < 0] = 0
        lt = lt + 0.3
        lt[lt > 1] = 1

    g = 3
    for i in range(0, 2):
        lt = cv2.filter2D(lt, -1, np.ones((g, g))) /\
            cv2.filter2D(np.ones(lt.shape), -1, np.ones((g, g)))

    tb4 = tb3 + 0
    # lt = lt*0+1
    tb4[:, :, 0] = tb3[:, :, 2] * lt
    tb4[:, :, 1] = tb3[:, :, 1] * lt
    tb4[:, :, 2] = tb3[:, :, 0] * lt
    cv2.imwrite(outfile, (tb4 * 255).astype(np.int32))
    common.write_log(log_file, 'FINISH disk_light_topo_tb')
    out_info = common.OutInfo(json_file)
    out_info.update_file_info(outfile0, 'LIGHT', 'R')
    return out_info
Exemplo n.º 15
0
    shms = tmp.group(4)
    setime = tmp.group(5)

    out_file0 = '/FY4A/AGRI/L3/'+reg+'/HHMM/LIGHT-/NOM/' + \
            syear+'/'+syear+smonth+sdom+'/FY4A-_AGRI--_N_'+reg+\
            '_1047E_L3_LIGHT-_MULT_NOM_'+syear+smonth+sdom+shms+\
            '_'+setime+'_'+str(int(4/rn))+'000M_HHMM_ADS_V0001.TIFF'
    out_file = output_dir + out_file0
    out_path = re.sub(r'[^\/]+$', '', out_file)
    if os.path.exists(out_path):
        pass
    else:
        os.system('mkdir -p ' + out_path)

    try:
        common.write_log(log_file, 'run LIGHT')
        t1 = time.process_time()
        out_info = gen_disk_light_topo_tb(infile, rn, output_dir, out_file0,
                                          cth_file, log_file, json_file)
    except Exception as inst:
        # msg = ' '.join(['Fire_Detection:', str(inst.args)])
        msg = traceback.format_exc()  # 捕捉异常消息
        out_info = common.OutInfo(json_file)
        out_info.update('1', msg)
        common.write_log(log_file, msg)
    finally:
        t2 = time.process_time()
        lapse_time = t2 - t1
        msg = ' '.join(['program run', str(round(lapse_time, 2)), 'seconds'])
        common.write_log(log_file, msg)
        out_info.write_json()
Exemplo n.º 16
0
	feature_builder.add_an_item(item)
    print 'feature_builder item_feature_map size:%d' % (len(feature_builder.item_feature) )
    #print feature_builder.item_feature


    import test_builder
    from test_builder import *
    test_builder = TestBuilder(common.test_data_output, feature_builder, dim_items_index)

    input_fd  = open(common.test_items_file)
    for line in input_fd:
	item_id = (int)(line.strip())

	test_item = dim_items_index.get(item_id)
	if not test_item != None:
	    write_log(sys._getframe().f_lineno, "cannot get info of item_id:%d" % (item_id) )
	    continue

	sim_cat_ids = cat_sim_rindex.get(test_item.cat_id, -1)
	if sim_cat_ids == -1 : continue 


	sim_cat_ids = sim_cat_ids[0: strategy.get_max_sim_cat_process()]
	rec_items = []
	for i in range(0, len(sim_cat_ids)):

	    (cat_id, sim_value) = sim_cat_ids[i]
	    sim_item_ids = cat_to_item_rindex.get(cat_id, [])
	    if len(sim_item_ids) == 0 : 
		write_log(sys._getframe().f_lineno, "cat_id:%d has no item" % (cat_id) )
		continue
Exemplo n.º 17
0
def fetch_stores(data):
    """
    获得门店信息
    :param data:
    :return:
    """
    url = data['url']
    try:
        html = common.get_data(data['url'])
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {
            'level': 1,
            'time': common.format_time(),
            'data': {
                'url': url
            },
            'brand_id': brand_id
        }
        common.dump(dump_data)
        return []

    # 第二个<ul>...</ul>
    start = 0
    for i in xrange(2):
        start = html.find('<ul>', start)
        if start == -1:
            return []
        start += len('<ul>')
    end = html.find('</ul>', start)
    html = html[start:end]

    store_list = []
    for m in re.findall(ur'<li>(.+?)</li>', html, re.S):
        entry = common.init_store_entry(brand_id, brandname_e, brandname_c)
        entry[common.store_type] = 'FASHION'
        m1 = re.findall(ur'<h2>(.+?)</h2>', m)
        if len(m1) > 0:
            entry[common.name_e] = common.reformat_addr(m1[0])

        # Google Maps网址
        m1 = re.findall(ur'href="(https://maps.google.com/maps[^\s]+?)"', m)
        if len(m1) > 0:
            entry[common.url] = m1[0]

        addr = common.reformat_addr('\n\r'.join(
            [m1 for m1 in re.findall(ur'<p>(.+?)</p>', m)]))
        entry[common.addr_e] = addr
        terms = addr.split(',')

        # 是否所有的geosensing都未命中?
        hit_flag = False

        # 最后一项是否为国家
        country = ''
        ret = gs.look_up(terms[-1], 1)
        if ret is not None:
            entry[common.country_e] = ret['name_e']
            country = ret['name_e']
            terms = terms[:-1]
            hit_flag = True

        # 查找州和城市
        m = re.match(ur'.*(\d{5,})', terms[-1])
        zip_cdt = ''
        if m is not None:
            zip_cdt = m.group(1)
        tmp = re.sub(ur'\d{5,}', '', terms[-1]).strip().upper()
        ret = gs.look_up(terms[-1], 2)
        if ret is not None:
            entry[common.province_e] = ret['name_e']
            entry[common.zip_code] = zip_cdt
            terms = terms[:-1]
            hit_flag = True

        ret = gs.look_up(terms[-1], 3)
        if ret is not None:
            entry[common.city_e] = ret['name_e']
            entry[common.zip_code] = zip_cdt
            hit_flag = True

        if not hit_flag:
            # 所有都未命中,输出:
            common.write_log('Failed in geosensing: %s' % addr)

        gs.field_sense(entry)

        print '%s Found store: %s, %s (%s, %s)' % (
            brandname_e, entry[common.name_e], entry[common.addr_e],
            entry[common.country_e], entry[common.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)
Exemplo n.º 18
0
def fetch_stores(data):
    """
    获得门店信息
    :param data:
    :return:
    """
    url = data['url']
    try:
        html = common.get_data(data['url'])
    except Exception:
        print 'Error occured: %s' % url
        dump_data = {'level': 1, 'time': common.format_time(), 'data': {'url': url}, 'brand_id': brand_id}
        common.dump(dump_data)
        return []

    # 第二个<ul>...</ul>
    start = 0
    for i in xrange(2):
        start = html.find('<ul>', start)
        if start == -1:
            return []
        start += len('<ul>')
    end = html.find('</ul>', start)
    html = html[start:end]

    store_list = []
    for m in re.findall(ur'<li>(.+?)</li>', html, re.S):
        entry = common.init_store_entry(brand_id, brandname_e, brandname_c)
        entry[common.store_type] = 'FASHION'
        m1 = re.findall(ur'<h2>(.+?)</h2>', m)
        if len(m1) > 0:
            entry[common.name_e] = common.reformat_addr(m1[0])

        # Google Maps网址
        m1 = re.findall(ur'href="(https://maps.google.com/maps[^\s]+?)"', m)
        if len(m1) > 0:
            entry[common.url] = m1[0]

        addr = common.reformat_addr('\n\r'.join([m1 for m1 in re.findall(ur'<p>(.+?)</p>', m)]))
        entry[common.addr_e] = addr
        terms = addr.split(',')

        # 是否所有的geosensing都未命中?
        hit_flag = False

        # 最后一项是否为国家
        country = ''
        ret = gs.look_up(terms[-1], 1)
        if ret is not None:
            entry[common.country_e] = ret['name_e']
            country = ret['name_e']
            terms = terms[:-1]
            hit_flag = True

        # 查找州和城市
        m = re.match(ur'.*(\d{5,})', terms[-1])
        zip_cdt = ''
        if m is not None:
            zip_cdt = m.group(1)
        tmp = re.sub(ur'\d{5,}', '', terms[-1]).strip().upper()
        ret = gs.look_up(terms[-1], 2)
        if ret is not None:
            entry[common.province_e] = ret['name_e']
            entry[common.zip_code] = zip_cdt
            terms = terms[:-1]
            hit_flag = True

        ret = gs.look_up(terms[-1], 3)
        if ret is not None:
            entry[common.city_e] = ret['name_e']
            entry[common.zip_code] = zip_cdt
            hit_flag = True

        if not hit_flag:
            # 所有都未命中,输出:
            common.write_log('Failed in geosensing: %s' % addr)

        gs.field_sense(entry)

        print '%s Found store: %s, %s (%s, %s)' % (
            brandname_e, entry[common.name_e], entry[common.addr_e], entry[common.country_e],
            entry[common.continent_e])
        db.insert_record(entry, 'stores')
        store_list.append(entry)
Exemplo n.º 19
0
def run(log_path):
    test_project = "charge"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 100
    pass_num = 0
    fail_num = 0
    url_di = "http://" + host_ip + ":" + host_ip + "/gs-robot/data/device_status"
    url_auto = common.get_url("/gs-robot/cmd/start_charge")
    url_hand = common.get_url("/gs-robot/cmd/stop_charge")
    for i in range(count_num):
        common.write_log(log_path, test_project, "info", url_hand)
        data = common.getUrlData(url_hand)
        time.sleep(1)
        if data["successed"]:
            common.write_log(log_path, test_project, "info", url_di)
            data = common.getUrlData(url_di)
            time.sleep(1)
            di_value = int(data["data"]["detailedDi"])
            one_list = []
            common.check_value(di_value, one_list)
            if 1 in one_list and 2 not in one_list:
                common.write_log(log_path, test_project, "info", str(data))
                common.write_log(log_path, test_project, "info", url_auto)
                data = common.getUrlData(url_auto)
                time.sleep(1)
                if data["successed"]:
                    common.write_log(log_path, test_project, "info", str(data))
                    common.write_log(log_path, test_project, "info", url_di)
                    data = common.getUrlData(url_di)
                    time.sleep(1)
                    di_value = int(data["data"]["detailedDi"])
                    one_list = []
                    common.check_value(di_value, one_list)
                    if 2 in one_list and 1 not in one_list:
                        common.write_log(log_path, test_project, "info",
                                         str(data))
                        common.write_log(log_path, test_project, "info",
                                         url_hand)
                        data = common.getUrlData(url_hand)
                        time.sleep(1)
                        if data["successed"]:
                            common.write_log(log_path, test_project, "info",
                                             str(data))
                            common.write_log(log_path, test_project, "info",
                                             url_di)
                            data = common.getUrlData(url_di)
                            time.sleep(1)
                            di_value = int(data["data"]["detailedDi"])
                            if di_value == 1:
                                common.write_log(log_path, test_project,
                                                 "info", str(data))
                                pass_num += 1
                            else:
                                common.write_log(log_path, test_project,
                                                 "error", str(data))
                                state = False
                                fail_num += 1
                        else:
                            common.write_log(log_path, test_project, "error",
                                             str(data))
                            state = False
                            fail_num += 1
                    else:
                        common.write_log(log_path, test_project, "error",
                                         str(data))
                        state = False
                        fail_num += 1
                else:
                    common.write_log(log_path, test_project, "error",
                                     str(data))
                    state = False
                    fail_num += 1
            else:
                common.write_log(log_path, test_project, "error", str(data))
                state = False
                fail_num += 1
        else:
            common.write_log(log_path, test_project, "error", str(data))
            state = False
            fail_num += 1
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 20
0
def run(log_path):
    test_project = "emergency"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 10
    pass_num = 0
    fail_num = 0
    url = "http://" + host_ip + ":" + host_ip + "/gs-robot/cmd/operate_device"
    url_emerg = common.get_url("/gs-robot/data/device_status")
    open_value = str(int("01010101", 2))
    close_value = str(int("01010110", 2))
    for i in range(count_num):
        value = [{
            "name": "relay",
            "type": "int",
            "value": close_value,
            "delayTime": 0
        }]
        common.write_log(log_path, test_project, "info", url)
        common.write_log(log_path, test_project, "info", value)
        data = common.postUrlData(url, value)
        time.sleep(1)
        if data["successed"]:
            common.write_log(log_path, test_project, "info", data)
            common.write_log(log_path, test_project, "info", url_emerg)
            data = common.get_url(url_emerg)
            time.sleep(1)
            if not data["data"]["emergency"]:
                common.write_log(log_path, test_project, "info", data)
                value = [{
                    "name": "relay",
                    "type": "int",
                    "value": open_value,
                    "delayTime": 0
                }]
                common.write_log(log_path, test_project, "info", url)
                common.write_log(log_path, test_project, "info", value)
                data = common.postUrlData(url, value)
                time.sleep(1)
                if data["successed"]:
                    common.write_log(log_path, test_project, "info", data)
                    common.write_log(log_path, test_project, "info", url_emerg)
                    data = common.get_url(url_emerg)
                    time.sleep(1)
                    if data["data"]["emergency"]:
                        common.write_log(log_path, test_project, "info", data)
                        value = [{
                            "name": "relay",
                            "type": "int",
                            "value": close_value,
                            "delayTime": 0
                        }]
                        common.write_log(log_path, test_project, "info", url)
                        common.write_log(log_path, test_project, "info", value)
                        data = common.postUrlData(url, value)
                        time.sleep(1)
                        if data["successed"]:
                            common.write_log(log_path, test_project, "info",
                                             data)
                            common.write_log(log_path, test_project, "info",
                                             url_emerg)
                            data = common.get_url(url_emerg)
                            time.sleep(1)
                        if not data["data"]["emergency"]:
                            common.write_log(log_path, test_project, "info",
                                             data)
                            pass_num += 1
                        else:
                            common.write_log(log_path, test_project, "error",
                                             "No Data...")
                            state = False
                            fail_num += 1
                    else:
                        common.write_log(log_path, test_project, "error",
                                         "No Data...")
                        state = False
                        fail_num += 1
                else:
                    common.write_log(log_path, test_project, "error",
                                     "No Data...")
                    state = False
                    fail_num += 1
            else:
                common.write_log(log_path, test_project, "error", "No Data...")
                state = False
                fail_num += 1
        else:
            common.write_log(log_path, test_project, "error", "No Data...")
            state = False
            fail_num += 1
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 21
0
    word_iterm_based_builder.build_from_file(common.dim_fashion_matchsets_file)

    word_iterm_based_rindex_builder = WordItermBasedRindexBuilder()
    word_iterm_based_rindex_builder.build_from_WordItermBasedBuilder(word_iterm_based_builder)

    dim_items_index_builder.clear_notimportant_word_from_title(word_iterm_based_rindex_builder)

    #sys.exit(0)
    
    predictor = Predictor(dim_items_index_builder,
			  cat_to_item_rindex_builder,
			  cat_sim_builder,
			  cat_sim_rindex_builder,
			  word_iterm_based_builder)



    write_log(msg = 'begin predict')
    input_fd  = open(common.test_items_file)
    output_fd = open(common.res_test_items_file, 'w')
    for line in input_fd:
	item_id = (int)(line.strip())
	res = predictor.process(item_id)
	if len(res) > 0:
	    res_str = ",".join( map(str, res) )
	    print >> output_fd, "%d %s" % (item_id, res_str)
	else:
	    print >> output_fd, "%d" % item_id


Exemplo n.º 22
0
def run(log_path):
    test_project = "key"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 10
    pass_num = 0
    fail_num = 0
    url = "http://" + host_ip + ":" + host_ip + "/gs-robot/cmd/operate_device"
    open_value = str(int("01010110", 2))
    close_value = str(int("01011010", 2))
    for i in range(count_num):
        value = [{
            "name": "relay",
            "type": "int",
            "value": open_value,
            "delayTime": 0
        }]
        common.write_log(log_path, test_project, "info", url)
        common.write_log(log_path, test_project, "info", value)
        commond = "ping -c 1 10.7.5.88"
        data = common.postUrlData(url, value)
        time.sleep(1)
        if data["successed"]:
            common.write_log(log_path, test_project, "info", data)
            try:
                common.write_log(log_path, test_project, "info", commond)
                backinfo = subprocess.check_output([commond], shell=True)
                common.write_log(log_path, test_project, "info", backinfo)
                value = [{
                    "name": "relay",
                    "type": "int",
                    "value": close_value,
                    "delayTime": 0
                }]
                common.write_log(log_path, test_project, "info", url)
                common.write_log(log_path, test_project, "info", value)
                data = common.postUrlData(url, value)
                time.sleep(5)
                if data["successed"]:
                    common.write_log(log_path, test_project, "info", data)
                    try:
                        common.write_log(log_path, test_project, "info",
                                         commond)
                        backinfo = subprocess.check_output([commond],
                                                           shell=True)
                        if backinfo:
                            common.write_log(log_path, test_project, "error",
                                             str(backinfo))
                            state = False
                            fail_num += 1
                    except:
                        common.write_log(log_path, test_project, "info",
                                         "No Data...")
                        value = [{
                            "name": "relay",
                            "type": "int",
                            "value": open_value,
                            "delayTime": 0
                        }]
                        common.write_log(log_path, test_project, "info", url)
                        common.write_log(log_path, test_project, "info", value)
                        data = common.postUrlData(url, value)
                        time.sleep(60)
                        if data["successed"]:
                            common.write_log(log_path, test_project, "info",
                                             data)
                            try:
                                common.write_log(log_path, test_project,
                                                 "info", commond)
                                backinfo = subprocess.check_output([commond],
                                                                   shell=True)
                                common.write_log(log_path, test_project,
                                                 "info", backinfo)
                                pass_num += 1
                            except:
                                common.write_log(log_path, test_project,
                                                 "error", "No Data...")
                                state = False
                                fail_num += 1
                        else:
                            common.write_log(log_path, test_project, "error",
                                             "No Data...")
                            state = False
                            fail_num += 1
                else:
                    common.write_log(log_path, test_project, "error",
                                     "No Data...")
                    state = False
                    fail_num += 1
            except:
                common.write_log(log_path, test_project, "error", "No Data...")
                state = False
                fail_num += 1
        else:
            common.write_log(log_path, test_project, "error", str(data))
            state = False
            fail_num += 1
    return {
        test_project: {
            "state": state,
            "count_num": count_num,
            "pass_num": pass_num,
            "fail_num": fail_num
        }
    }
Exemplo n.º 23
0
def run(log_path):
    test_project = "relay"
    log_content = test_project + " test start"
    common.write_log(log_path, test_project, "info", log_content)
    state = True
    count_num = 75
    pass_num = 0
    fail_num = 0
    url_relay = common.get_url("/gs-robot/cmd/operate_device")
    url_di = "http://" + host_ip + ":" + host_ip + "/gs-robot/data/device_status"
    for i in range(count_num):
        value = [{"name" : "do","type" : "int","value" : "0","delayTime" : 0}]
        common.write_log(log_path, test_project, "info", url_relay)
        common.write_log(log_path, test_project, "info", str(value))
        data = common.postUrlData(url_relay, value)
        time.sleep(1)
        if data["successed"]:
            common.write_log(log_path, test_project, "info", str(data))
            common.write_log(log_path, test_project, "info", url_di)
            data = common.getUrlData(url_di)
            time.sleep(1)
            di_value = int(data["data"]["detailedDi"])
            one_list = []
            common.check_value(di_value, one_list)
            if 4 not in one_list and 5 not in one_list:
                common.write_log(log_path, test_project, "info", str(data))
                value = [{"name" : "do","type" : "int","value" : "1","delayTime" : 0}]
                common.write_log(log_path, test_project, "info", url_relay)
                data = common.postUrlData(url_relay, value)
                time.sleep(1)
                if data["successed"]:
                    common.write_log(log_path, test_project, "info", str(data))
                    common.write_log(log_path, test_project, "info", url_di)
                    data = common.getUrlData(url_di)
                    time.sleep(1)
                    di_value = int(data["data"]["detailedDi"])
                    one_list = []
                    common.check_value(di_value, one_list)
                    if 4 in one_list and 5 not in one_list:
                        common.write_log(log_path, test_project, "info", str(data))
                        value = [{"name" : "do","type" : "int","value" : "2","delayTime" : 0}]
                        common.write_log(log_path, test_project, "info", url_relay)
                        data = common.postUrlData(url_relay, value)
                        time.sleep(1)
                        if data["successed"]:
                            common.write_log(log_path, test_project, "info", str(data))
                            common.write_log(log_path, test_project, "info", url_di)
                            data = common.getUrlData(url_di)
                            time.sleep(1)
                            di_value = int(data["data"]["detailedDi"])
                            one_list = []
                            common.check_value(di_value, one_list)
                            if 4 not in one_list and 5 in one_list:
                                common.write_log(log_path, test_project, "info", str(data))
                                value = [{"name" : "do","type" : "int","value" : "3","delayTime" : 0}]
                                common.write_log(log_path, test_project, "info", url_relay)
                                data = common.postUrlData(url_relay, value)
                                time.sleep(1)
                                if data["successed"]:
                                    common.write_log(log_path, test_project, "info", str(data))
                                    common.write_log(log_path, test_project, "info", url_di)
                                    data = common.getUrlData(url_di)
                                    time.sleep(1)
                                    di_value = int(data["data"]["detailedDi"])
                                    one_list = []
                                    common.check_value(di_value, one_list)
                                    if 4 in one_list and 5 in one_list:
                                        common.write_log(log_path, test_project, "info", str(data))
                                        pass_num += 1
                                    else:
                                        common.write_log(log_path, test_project, "error", str(data))
                                        state = False
                                        fail_num += 1
                                else:
                                    common.write_log(log_path, test_project, "error", str(data))
                                    state = False
                                    fail_num += 1
                            else:
                                common.write_log(log_path, test_project, "error", str(data))
                                state = False
                                fail_num += 1
                        else:
                            common.write_log(log_path, test_project, "error", str(data))
                            state = False
                            fail_num += 1
                    else:
                        common.write_log(log_path, test_project, "error", str(data))
                        state = False
                        fail_num += 1
                else:
                    common.write_log(log_path, test_project, "error", str(data))
                    state = False
                    fail_num += 1
            else:
                common.write_log(log_path, test_project, "error", str(data))
                state = False
                fail_num += 1
        else:
            common.write_log(log_path, test_project, "error", str(data))
            state = False
            fail_num += 1

    time.sleep(1)
    return {test_project:{"state":state, "count_num":count_num, "pass_num":pass_num, "fail_num":fail_num}}
Exemplo n.º 24
0
 def load(self):
     metainfo = self._get_metainfo()
     if metainfo is None:
         common.write_log("get metainfo fail")
     else:
         self.metainfo = metainfo