123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- # encoding: utf-8
- import sys
- import io
- from common.logging import Logging
- COUNTRY_REVERSE = {"安道尔共和国": "AD",
- "阿拉伯联合酋长国": "AE",
- "阿富汗": "AF",
- "安提瓜和巴布达": "AG",
- "安圭拉岛": "AI",
- "阿尔巴尼亚": "AL",
- "亚美尼亚": "AM",
- "安哥拉": "AO",
- "阿根廷": "AR",
- "奥地利": "AT",
- "澳大利亚": "AU",
- "阿塞拜疆": "AZ",
- "巴巴多斯": "BB",
- "孟加拉国": "BD",
- "比利时": "BE",
- "布基纳法索": "BF",
- "保加利亚": "BG",
- "巴林": "BH",
- "布隆迪": "BI",
- "贝宁": "BJ",
- "巴勒斯坦": "BL",
- "百慕大群岛": "BM",
- "文莱": "BN",
- "玻利维亚": "BO",
- "巴西": "BR",
- "巴哈马": "BS",
- "博茨瓦纳": "BW",
- "白俄罗斯": "BY",
- "伯利兹": "BZ",
- "加拿大": "CA",
- "中非共和国": "CF",
- "刚果": "CG",
- "瑞士": "CH",
- "库克群岛": "CK",
- "智利": "CL",
- "喀麦隆": "CM",
- "中国": "CN",
- "哥伦比亚": "CO",
- "哥斯达黎加": "CR",
- "古巴": "CU",
- "塞浦路斯": "CY",
- "捷克": "CZ",
- "德国": "DE",
- "吉布提": "DJ",
- "丹麦": "DK",
- "多米尼加共和国": "DO",
- "阿尔及利亚": "DZ",
- "厄瓜多尔": "EC",
- "爱沙尼亚": "EE",
- "埃及": "EG",
- "西班牙": "ES",
- "埃塞俄比亚": "ET",
- "芬兰": "FI",
- "斐济": "FJ",
- "法国": "FR",
- "加蓬": "GA",
- "英国": "GB",
- "格林纳达": "GD",
- "格鲁吉亚": "GE",
- "法属圭亚那": "GF",
- "加纳": "GH",
- "直布罗陀": "GI",
- "冈比亚": "GM",
- "几内亚": "GN",
- "希腊": "GR",
- "危地马拉": "GT",
- "关岛": "GU",
- "圭亚那": "GY",
- "香港特别行政区": "HK",
- "洪都拉斯": "HN",
- "海地": "HT",
- "匈牙利": "HU",
- "印度尼西亚": "ID",
- "爱尔兰": "IE",
- "以色列": "IL",
- "印度": "IN",
- "伊拉克": "IQ",
- "伊朗": "IR",
- "冰岛": "IS",
- "意大利": "IT",
- "牙买加": "JM",
- "约旦": "JO",
- "日本": "JP",
- "肯尼亚": "KE",
- "吉尔吉斯坦": "KG",
- "柬埔寨": "KH",
- "朝鲜": "KP",
- "韩国": "KR",
- "科特迪瓦共和国": "KT",
- "科威特": "KW",
- "哈萨克斯坦": "KZ",
- "老挝": "LA",
- "黎巴嫩": "LB",
- "圣卢西亚": "LC",
- "列支敦士登": "LI",
- "斯里兰卡": "LK",
- "利比里亚": "LR",
- "莱索托": "LS",
- "立陶宛": "LT",
- "卢森堡": "LU",
- "拉脱维亚": "LV",
- "利比亚": "LY",
- "摩洛哥": "MA",
- "摩纳哥": "MC",
- "摩尔多瓦": "MD",
- "马达加斯加": "MG",
- "马里": "ML",
- "缅甸": "MM",
- "蒙古": "MN",
- "澳门": "MO",
- "蒙特塞拉特岛": "MS",
- "马耳他": "MT",
- "毛里求斯": "MU",
- "马尔代夫": "MV",
- "马拉维": "MW",
- "墨西哥": "MX",
- "马来西亚": "MY",
- "莫桑比克": "MZ",
- "纳米比亚": "NA",
- "尼日尔": "NE",
- "尼日利亚": "NG",
- "尼加拉瓜": "NI",
- "荷兰": "NL",
- "挪威": "NO",
- "尼泊尔": "NP",
- "瑙鲁": "NR",
- "新西兰": "NZ",
- "阿曼": "OM",
- "巴拿马": "PA",
- "秘鲁": "PE",
- "巴布亚新几内亚": "PG",
- "菲律宾": "PH",
- "巴基斯坦": "PK",
- "波兰": "PL",
- "波多黎各": "PR",
- "葡萄牙": "PT",
- "巴拉圭": "PY",
- "卡塔尔": "QA",
- "罗马尼亚": "RO",
- "俄罗斯": "RU",
- "沙特阿拉伯": "SA",
- "所罗门群岛": "SB",
- "塞舌尔": "SC",
- "苏丹": "SD",
- "瑞典": "SE",
- "新加坡": "SG",
- "斯洛文尼亚": "SI",
- "斯洛伐克": "SK",
- "塞拉利昂": "SL",
- "圣马力诺": "SM",
- "塞内加尔": "SN",
- "索马里": "SO",
- "苏里南": "SR",
- "圣多美和普林西比": "ST",
- "萨尔瓦多": "SV",
- "叙利亚": "SY",
- "斯威士兰": "SZ",
- "乍得": "TD",
- "多哥": "TG",
- "泰国": "TH",
- "塔吉克斯坦": "TJ",
- "土库曼斯坦": "TM",
- "突尼斯": "TN",
- "汤加": "TO",
- "土耳其": "TR",
- "特立尼达和多巴哥": "TT",
- "台湾": "TW",
- "坦桑尼亚": "TZ",
- "乌克兰": "UA",
- "乌干达": "UG",
- "美国": "US",
- "乌拉圭": "UY",
- "乌兹别克斯坦": "UZ",
- "圣文森特岛": "VC",
- "委内瑞拉": "VE",
- "越南": "VN",
- "也门": "YE",
- "南斯拉夫": "YU",
- "南非": "ZA",
- "赞比亚": "ZM",
- "扎伊尔": "ZR",
- "津巴布韦": "ZW",
- }
- def shorten(floors):
- floors.sort(key=lambda x: x)
- # print floors
- shortened = []
- cur_index = 0
- while cur_index < len(floors):
- next_index = cur_index + 1
- while next_index < len(floors):
- if floors[cur_index] * 1.14 < floors[next_index]:
- break
- next_index += 1
- shortened.append(floors[next_index - 1])
- cur_index = next_index
- return shortened
- def find_match_floor(floor, floors):
- for f in floors:
- if f >= floor:
- return float(f) / 100
- def combine_floors(platform, file_path, write_to_path):
- file_handler = open(file_path, 'r')
- floor_data = file_handler.read()
- floors = floor_data.split('\n')
- floor0 = []
- floor1 = []
- floor2 = []
- floor3 = []
- for i in range(0, len(floors) / 2):
- cur_floors = floors[2 * i + 1].split(',')
- if len(cur_floors) <= 5:
- continue
- cur_floors = [int(f.strip()) for f in cur_floors]
- if cur_floors[2] not in floor0:
- floor0.append(cur_floors[2])
- if cur_floors[4] not in floor1:
- floor1.append(cur_floors[4])
- if cur_floors[6] not in floor2:
- floor2.append(cur_floors[6])
- if cur_floors[7] not in floor3:
- floor3.append(cur_floors[7])
- floor0 = shorten(floor0)
- floor1 = shorten(floor1)
- floor2 = shorten(floor2)
- floor3 = shorten(floor3)
- result_str = 'countryCode,platform,placementId,targetPrice\n'
- for i in range(0, len(floors) / 2):
- country_code = COUNTRY_REVERSE[floors[i * 2]]
- if len(floors[2 * i + 1]) == 0:
- continue
- cur_floors = floors[2 * i + 1].split(',')
- cur_floors = [int(f) for f in cur_floors]
- result_str += '%s,%s,unity_inter_I1_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[1], floor0))
- result_str += '%s,%s,unity_inter_I1_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[3], floor1))
- result_str += '%s,%s,unity_inter_I2_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[5], floor2))
- result_str += '%s,%s,unity_inter_I2_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[7], floor3))
- # result_str += '%s,%s,inter_I1_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[2], floor0) * 1.7)
- # result_str += '%s,%s,inter_I1_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[4], floor1) * 1.7)
- # result_str += '%s,%s,inter_I2_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[6], floor2) * 1.7)
- # result_str += '%s,%s,inter_I2_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[7], floor3) * 1.7)
- open(write_to_path, "w").write(result_str)
- print "文件写入完成: {}".format(write_to_path)
- def _printScriptInfo():
- print "************************************************************"
- print "* 脚本作用: 生成unity底价csv"
- print "* 参数说明:"
- print "* 游戏所在平台 (android | ios)"
- print "* 插屏价格配置文件路径"
- print "* 更新后写入的文件"
- print "* 例:"
- print "* bulldog price_script_unity inter.txt unity.csv"
- print "************************************************************"
- print ""
- def run(argv):
- print argv
- _printScriptInfo()
- if len(argv) < 4:
- Logging.error("参数个数小于3个")
- exit(0)
- platform = argv[1]
- txt_path = argv[2]
- write_to_path = argv[3]
- Logging.info("配置文件路径: {}".format(txt_path))
- Logging.info("写入文件路径: {}".format(write_to_path))
- combine_floors(platform, txt_path, write_to_path)
- if __name__ == '__main__':
- run([
- "price_script_unity.py",
- "android",
- "/Users/zhuge/Temp/20201226/test/archery_inter_20200805_20200904_summary.txt",
- "/Users/zhuge/Temp/20201226/test/unity.csv",
- ])
|