def get_data(times=None): if times == '1': start = TimeFormat.get_month_ago(1) end = TimeFormat.get_day_end_time(-7) elif times == '3': start = TimeFormat.get_month_ago(3) end = TimeFormat.get_month_ago(2) elif times == '6': start = TimeFormat.get_month_ago(6) end = TimeFormat.get_month_ago(5) elif times == '7': start, end = TimeFormat.get_day_start_time(-6), TimeFormat.getnow() else: start, end = TimeFormat.get_day_start_time(-6), TimeFormat.getnow() return start, end
def get_time_step2(time_day, time_step): # 前开后闭 if time_step == '早晨': start_time, end_time = time_day + " " + "5:30:00", time_day + " " + "11:30:00" elif time_step == '中午': start_time, end_time = time_day + " " + "11:30:00", time_day + " " + "13:30:00" elif time_step == '下午': start_time, end_time = time_day + " " + "13:30:00", time_day + " " + "17:30:00" elif time_step == '晚上': start_time, end_time = time_day + " " + "17:30:00", time_day + " " + "23:30:00" elif time_step == '凌晨': start_time1, end_time1 = time_day + " " + "23:30:00", time_day + " " + "23:59:59" start_time2, end_time2 = time_day + " " + "00:00:00", time_day + " " + "05:30:00" start_time, end_time = random.choice( ((start_time1, end_time1), (start_time2, end_time2))) else: start_time, end_time = time_day + " " + "13:30:00", time_day + " " + "17:30:00" e_time = TimeFormat.random_time(start_time, end_time) e_day, e_hms = e_time.split(' ') now = TimeFormat.getnow() n_hms = now.split(' ')[-1] e_time_num = int(TimeFormat.string_toTimestamp_13(e_time)) n_time_num = int(TimeFormat.string_toTimestamp_13(e_day + ' ' + n_hms)) if e_time_num <= n_time_num: e_time = TimeFormat.get_day_around(1, e_day) + ' ' + e_hms return e_time
def modif_date(data): """ 初始化请求时修改时间 :param data: :return: """ data["order"][0]['inserttime'] = TimeFormat.getnow() start, end = get_data() data["order"][0]["dealtime"] = TimeFormat.random_time(start, end)
def get_time_step07(time_day): # 前开后闭 start_time, end_time = time_day + " " + "00:00:00", time_day + " " + "07:00:00" e_time = TimeFormat.random_time(start_time, end_time) e_day, e_hms = e_time.split(' ') now = TimeFormat.getnow() n_hms = now.split(' ')[-1] e_time_num = int(TimeFormat.string_toTimestamp_13(e_time)) n_time_num = int(TimeFormat.string_toTimestamp_13(e_day + ' ' + n_hms)) if e_time_num <= n_time_num: e_time = TimeFormat.get_day_around(1, e_day) + ' ' + e_hms return e_time
def test_sht_login(): """ 商户通 获取 token :return: """ redis_keys = redisDB.get_keys() for redis_key in redis_keys: if wx_name in redisDB.redis_get(redis_key): redisDB.del_name(redis_key) uuid_str = str(uuid.uuid4()).replace("-", "") wx_name_prefix = 'wxuser_' + wx_open_id wx_token = hashlib.md5( (wx_name_prefix + uuid_str).encode("utf-8")).hexdigest() wx_user_name = wx_name_prefix + wx_token wx_phone = 'https://wx.qlogo.cn/mmopen/vi_32' \ '/Q0j4TwGTfTJInkWfFr8ftFB8TYjb78xiamRc9bqRDkJKZHliaeHLdldQjeGdtqIzl659XHEcBxicBeRHQq5wBOvpw/132' c_time = TimeFormat.getnow() state = 'enabled' created = TimeFormat.string_toTimestamp_13(c_time) rows = ms.select_rows(DB, 'Tbl_WX_User', 'id', 'name="{}" AND state="enabled"'.format(wx_name)) if rows == 0: insert_dict = { "wx_user_uuid": wxUserUuid, "merchant_uuid": "", "name": wx_name, "phone": wx_phone, "open_id": wx_open_id, "is_master": wx_isMaster, "created": c_time, "updated": c_time, "state": state } ms.insert(DB, 'Tbl_WX_User', insert_dict) m_id = ms.select_one(DB, 'Tbl_WX_User', 'id', 'name="{}" AND state="enabled"'.format(wx_name)) wx_user_info = { 'created': created, 'id': m_id, 'isMaster': wx_isMaster, 'merchantUuid': '', 'name': wx_name, 'openId': wx_open_id, 'phone': wx_phone, 'state': state, 'token': wx_token, 'updated': created, 'wxUserUuid': wxUserUuid } redisDB.redis_set(wx_user_name, json.dumps(json.dumps(wx_user_info))) return wx_token
def get_days(month, premise, params): """ 几月距离今天的天数 :param month: 几月 :param premise: 请求参数 :param params: 请求参数 :return: """ calls_items = list() for items in params['calls']: calls_items.extend(items['items']) calls_days = list() if premise == 'no_dial_day': dial_calls_days = list( filter(lambda x: x['dial_type'] == 'dial', calls_items)) calls_days = [t['time'] for t in dial_calls_days] elif premise == 'no_call_day': calls_days = [t['time'] for t in calls_items] elif premise in ('power_off_day', 'continue_power_off_days'): calls_days = [t['time'] for t in calls_items] smses_items = list() for items in params['smses']: smses_items.extend(items['items']) smses_days = [ '-'.join(t['time'].split('-')[:3]) + ' ' + t['time'].split('-')[-1] for t in smses_items ] calls_days.extend(smses_days) on_days = list(set(calls_days)) now, times = TimeFormat.getnow().split(' ') now_time = TimeFormat.get_now_time_13() if month == '7': day = TimeFormat.get_day_around(-7) else: time_day = TimeFormat.get_month_ago(int(month)) day = time_day.split(' ')[0] day_time = TimeFormat.string_toTimestamp_13(day + ' ' + times) days_num = len( list( filter( lambda x: day_time < int(TimeFormat.string_toTimestamp_13(x)) <= now_time, on_days))) return str(TimeFormat.time_between_day(day, now) - days_num)
def get_result(result, result_key, params): """ 获取 测试结果数据 :param result: 请求结果数据 :param result_key: 结果key值 :param params: 请求数据 :return: address_max_city_1m:最近1个月订单中收货最多的收货地址所在市 address_max_city_3m:最近3个月订单中收货最多的收货地址所在市 address_max_city_6m:最近6个月订单中收货最多的收货地址所在市 address_max_detail_1m:最近1个月订单中收货最多的收货地址 address_max_detail_3m:最近3个月订单中收货最多的收货地址 address_max_detail_6m:最近6个月订单中收货最多的收货地址 address_max_district_1m:最近1个月订单中收货最多的收货地址所在区县 address_max_district_3m:最近3个月订单中收货最多的收货地址所在区县 address_max_district_6m:最近6个月订单中收货最多的收货地址所在区县 address_max_name_1m:最近1个月订单中收货最多的收货人 address_max_name_3m:最近3个月订单中收货最多的收货人 address_max_name_6m:最近6个月订单中收货最多的收货人 address_max_phone_1m:最近1个月订单中收货最多的手机号码 address_max_phone_3m:最近3个月订单中收货最多的手机号码 address_max_phone_6m:最近6个月订单中收货最多的手机号码 address_max_province_1m:最近1个月订单中收货最多的收货地址所在省 address_max_province_3m:最近3个月订单中收货最多的收货地址所在省 address_max_province_6m:最近6个月订单中收货最多的收货地址所在省 order_avg_amount_1m:最近1个月订单的平均金额 order_avg_amount_3m:最近3个月订单的平均金额 order_avg_amount_6m:最近6个月订单的平均金额 order_avg_pkg_1m:最近1个月订单的平均商品数 order_avg_pkg_3m:最近3个月订单的平均商品数 order_avg_pkg_6m:最近6个月订单的平均商品数 order_max_amount_1m:最近1个月订单的最高金额 order_max_amount_3m:最近3个月订单的最高金额 order_max_amount_6m:最近6个月订单的最高金额 order_max_pkg_1m:最近1个月订单的最高商品数 order_max_pkg_3m:最近3个月订单的最高商品数 order_max_pkg_6m:最近6个月订单的最高商品数 order_sum_1m:最近1个月订单的总订单数 order_sum_3m:最近3个月订单的总订单数 order_sum_6m:最近6个月订单的总订单数 order_sum_amount_1m:最近1个月订单的总金额 order_sum_amount_3m:最近3个月订单的总金额 order_sum_amount_6m:最近6个月订单的总金额 order_sum_pkg_1m:最近1个月订单的总商品数 order_sum_pkg_3m:最近3个月订单的总商品数 order_sum_pkg_6m:最近6个月订单的总商品数 all_fee:订单总额 all_cnt:订单数量 all_prd_cnt:订单商品数量 personal_fee:本人订单总额 personal_cnt:本人订单数量 personal_proportion:本人订单商品占比 personal_prd_cnt:本人订单商品数量 virtual_fee:虚拟物品订单总额 virtual_cnt:虚拟物品订单数量 virtual_prd_cnt:虚拟物品订单商品数量 virtual_proportion:虚拟物品订单总额占比 telephone_cnt_dict:收货人联系电话次数统计字典 telephone_proportion_dict:收货人联系电话占比统计字典 telephone_list:收货人联系电话列表 """ orders = params["order"] if any(filter(lambda x: x['status'] in ['充值成功', '已完成'], orders)): status_num = 0 for i in range(len(orders)): if orders[i]['status'] in ['充值成功', '已完成']: status_num = i month = "".join(orders[status_num]["dealtime"].split('-')[:2]) else: month = ''.join(TimeFormat.getnow().split('-')[:2]) consumption_analysis_dict = result["consumption_analysis_dict"][month] if result_key in ( "order_sum_1m", "order_sum_amount_1m", "order_max_amount_1m", "order_avg_amount_1m", "order_sum_pkg_1m", "order_max_pkg_1m", "order_avg_pkg_1m", "address_max_name_1m", "address_max_phone_1m", "address_max_detail_1m", "address_max_province_1m", "address_max_city_1m", "address_max_district_1m", "order_sum_3m", "order_sum_amount_3m", "order_max_amount_3m", "order_avg_amount_3m", "order_sum_pkg_3m", "order_max_pkg_3m", "order_avg_pkg_3m", "address_max_name_3m", "address_max_phone_3m", "address_max_detail_3m", "address_max_province_3m", "address_max_city_3m", "address_max_district_3m", "order_sum_6m", "order_sum_amount_6m", "order_max_amount_6m", "order_avg_amount_6m", "order_sum_pkg_6m", "order_max_pkg_6m", "order_avg_pkg_6m", "address_max_name_6m", "address_max_phone_6m", "address_max_detail_6m", "address_max_province_6m", "address_max_city_6m", "address_max_district_6m"): return str(result["order_result_dict"][result_key]) elif result_key in ("all_fee", "all_cnt", "all_prd_cnt", "personal_fee", "personal_cnt", "personal_prd_cnt", "virtual_fee", "virtual_cnt", "virtual_prd_cnt", "personal_proportion", "virtual_proportion"): return str(consumption_analysis_dict[result_key]) elif result_key in ("telephone_cnt_dict", "telephone_proportion_dict"): result_dict = consumption_analysis_dict[result_key] value_list = [t for t in result_dict.values()] if len(result_dict) >= 1: return str(value_list[0]) else: return '' elif result_key == "telephone_list": telephone_list = consumption_analysis_dict["telephone_list"] if len(telephone_list) >= 1: return str(telephone_list[0]) else: return '' elif result_key in ("top_n_address", "receiver_name", "receiver_phone", "first_create_time", "last_create_time", "order_sum_fee", "order_cnt"): top_address_dict = result["top_address_dict"] if "top_1" in top_address_dict.keys(): return str(top_address_dict["top_1"][result_key]) else: return '' elif result_key == "first_deal_delta_monhs": return str(result["base_analyse_dict"][result_key])
def modif(data, modif_key, modif_value): """ 修改请求数据 :param data: 请求数据 :param modif_key: 修改请求数据参数 :param modif_value: 修改值 :return: carrier: 运营商类型 (联通、移动、电信) open_time: 开户时长 (天) sex:男,女 age: 年龄 total_fee:账期内所有费用 web_fee:网络流量消费金额(分) voice_fee:通话消费金额(分) sms_fee:短信消费金额(分) extra_service_fee:增值业务消费金额(分) extra_fee:其它消费金额(分) base_fee:基础消费金额 sms_cnt:短信次数 (数字) sms_fees:短信费用 location:朋友圈中心城市 peer_number:朋友联系数量 location_type:号码类型;国内通话 dial_type:主叫,被叫 DAIL,DAILED duration: 通话时长(秒) fee: 通话费用 time: 通话时段 (早晨,上午,中午,下午,傍晚,晚上,凌晨,深夜) 早晨(5:30:00-9:00:00) 上午(9:00:00-11:30:00) 中午(11:30:00-13:30:00) 下午(13:30:00-17:30:00) 傍晚(17:30:00-19:30:00) 晚上(19:30:00-23:30:00) 凌晨(23:30:00-01:30:00) 深夜(01:30:00-05:30:00) time2: 通话时段 早晨(5:30-11:30) 中午(11:30-13:30) 下午(13:30-17:30) 晚上(17:30-23:30) 凌晨(23:30-5:30) time3: 通话时段 0-7点,不用输入参数修改值 total_size:通话次数 bill_month:通话月份 (7,1,3,6) calls: 通话信息条数 (数字) """ if re.sub('\s+', '', modif_value) == '': modif_value = 'null' if modif_key == 'carrier': # modif_value 输入 联通、移动、电信 if modif_value in carriers.keys(): modif_value = carriers[modif_value] data["carrier"] = modif_value elif modif_key == 'open_time': # 输入数字,距离当前时间的天数 if modif_value.isdigit(): modif_value = TimeFormat.get_day_around(-int(modif_value)) data["open_time"] = modif_value elif modif_key == 'sex': # 输入男、女,自动生成 idcard idcard = list(data["idcard"]) if modif_value == '女': v = random.choice('02468') idcard[16] = str(v) data["idcard"] = ''.join(idcard) elif modif_value == '男': v = random.choice('13579') idcard[16] = str(v) data["idcard"] = ''.join(idcard) else: data["idcard"] = modif_value elif modif_key == 'age': # 输入年龄,自动生成 idcard if modif_value.isdigit(): idcard = list(data["idcard"]) time_now = TimeFormat.getnow_day() year, month, day = time_now.split('-') y = int(year) - int(modif_value) idcard[6:14] = ''.join([str(y), month, day]) data["idcard"] = ''.join(idcard) else: data["idcard"] = modif_value elif modif_key == 'city': data["city"] = modif_value elif modif_key == 'total_fee': data["bills"][0]["total_fee"] = modif_value elif modif_key == 'web_fee': data["bills"][0]["web_fee"] = modif_value elif modif_key == 'voice_fee': data["bills"][0]["voice_fee"] = modif_value elif modif_key == 'sms_fee': data["bills"][0]["sms_fee"] = modif_value elif modif_key == 'extra_service_fee': data["bills"][0]["extra_service_fee"] = modif_value elif modif_key == 'extra_fee': data["bills"][0]["extra_fee"] = modif_value elif modif_key == 'base_fee': data["bills"][0]["base_fee"] = modif_value elif modif_key == 'sms_cnt': # 输入数字, 自动生成对应数字的短信条数 if modif_value.isdigit(): sms = data['smses'][0] data['smses'] = [sms for _ in range(int(modif_value))] else: data['smses'] = [] elif modif_key == 'sms_fees': data['smses'][0]['items'][0]['fee'] = modif_value elif modif_key == 'location': data["calls"][0]['items'][0]['location'] = modif_value elif modif_key == 'peer_number': data["calls"][0]['items'][0]['peer_number'] = modif_value elif modif_key == 'location_type': data["calls"][0]['items'][0]['location_type'] = modif_value elif modif_key == 'dial_type': # 输入 DAIL 或者 DAILED calls = data["calls"][0] call = copy.deepcopy(calls) call['items'][0]['dial_type'] = modif_value data["calls"][0] = call elif modif_key == 'duration': if modif_value.isdigit(): modif_value = int(modif_value) data["calls"][0]['items'][0]['duration'] = modif_value elif modif_key == 'fee': data["calls"][0]['items'][0]['fee'] = modif_value elif modif_key == 'time': # 输入时间段 # 早晨(5:30:00-9:00:00) # 上午(9:00:00-11:30:00) # 中午(11:30:00-13:30:00) # 下午(13:30:00-17:30:00) # 傍晚(17:30:00-19:30:00) # 晚上(19:30:00-23:30:00) # 凌晨(23:30:00-01:30:00) # 深夜(01:30:00-05:30:00) if modif_value in ('早晨', '上午', '中午', '下午', '傍晚', '晚上', '凌晨', '深夜'): sev_time = data["calls"][0]['items'][0]['time'] sev_day = sev_time.split(' ')[0] data["calls"][0]['items'][0]['time'] = get_time_step( sev_day, modif_value) else: data["calls"][0]['items'][0]['time'] = modif_value elif modif_key == 'time2': # 输入时间段 # 早晨(5:30-11:30) # 中午(11:30-13:30) # 下午(13:30-17:30) # 晚上(17:30-23:30) # 凌晨(23:30-5:30) if modif_value in ('早晨', '中午', '下午', '晚上', '凌晨'): sev_time = data["calls"][0]['items'][0]['time'] sev_day = sev_time.split(' ')[0] data["calls"][0]['items'][0]['time'] = get_time_step2( sev_day, modif_value) else: data["calls"][0]['items'][0]['time'] = modif_value elif modif_key == 'time3': # 输入时间段, 不用输入修改参数值, 直接获取 0-7点 sev_time = data["calls"][0]['items'][0]['time'] sev_day = sev_time.split(' ')[0] data["calls"][0]['items'][0]['time'] = get_time_step07(sev_day) elif modif_key == 'total_size': if modif_value.isdigit(): modif_value = int(modif_value) data["calls"][0]['total_size'] = modif_value elif modif_key == 'bill_month': # 输入修改的月份 7,1,3,6; 7代表7天,其余的都是月份 times = data["calls"][0]['items'][0]['time'] time_hmc = times.split(' ')[-1] if modif_value == '7': start_day = TimeFormat.get_day_around(-7) bill_month = '-'.join(start_day.split('-')[:2]) month_start_date, month_end_date = TimeFormat.get_FirstAndLastDay_month( bill_month) e_time = start_day + ' ' + time_hmc e_time_num = int(TimeFormat.string_toTimestamp_13(e_time)) n_hms = TimeFormat.getnow().split(' ')[-1] n_time_num = int( TimeFormat.string_toTimestamp_13(start_day + ' ' + n_hms)) if e_time_num <= n_time_num: e_time = TimeFormat.get_day_around(1, start_day) + ' ' + time_hmc data["calls"][0]['bill_month'] = bill_month data["calls"][0]['items'][0]['time'] = e_time data["smses"][0]['bill_month'] = bill_month data["smses"][0]['items'][0]['time'] = e_time.replace(' ', '-') data["bills"][0]['bill_month'] = bill_month data["bills"][0]['bill_start_date'] = month_start_date data["bills"][0]['bill_end_date'] = month_end_date elif modif_value in ('1', '3', '6'): month_day = TimeFormat.get_month_day_ago(int(modif_value)) year, month, day = month_day.split('-') bill_month = year + '-' + month month_start_date, month_end_date = TimeFormat.get_FirstAndLastDay_month( bill_month) data["calls"][0]['bill_month'] = bill_month e_time = month_day + ' ' + time_hmc e_time_num = int(TimeFormat.string_toTimestamp_13(e_time)) n_hms = TimeFormat.getnow().split(' ')[-1] n_time_num = int( TimeFormat.string_toTimestamp_13(month_day + ' ' + n_hms)) if e_time_num <= n_time_num: e_time = TimeFormat.get_day_around(1, month_day) + ' ' + time_hmc data["calls"][0]['items'][0]['time'] = e_time data["smses"][0]['bill_month'] = bill_month data["smses"][0]['items'][0]['time'] = e_time.replace(' ', '-') data["bills"][0]['bill_month'] = bill_month data["bills"][0]['bill_start_date'] = month_start_date data["bills"][0]['bill_end_date'] = month_end_date else: data["calls"][0]['bill_month'] = modif_value data["smses"][0]['bill_month'] = modif_value data["bills"][0]['bill_month'] = modif_value elif modif_key == 'calls': # 输入数字,自动生成通话条数 if modif_value.isdigit(): calls = data["calls"][0] call = copy.deepcopy(calls) data["calls"] = [call for _ in range(int(modif_value))] else: data["calls"] = []