price_script_unity.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. # encoding: utf-8
  2. import sys
  3. import io
  4. from common.logging import Logging
  5. COUNTRY_REVERSE = {"安道尔共和国": "AD",
  6. "阿拉伯联合酋长国": "AE",
  7. "阿富汗": "AF",
  8. "安提瓜和巴布达": "AG",
  9. "安圭拉岛": "AI",
  10. "阿尔巴尼亚": "AL",
  11. "亚美尼亚": "AM",
  12. "安哥拉": "AO",
  13. "阿根廷": "AR",
  14. "奥地利": "AT",
  15. "澳大利亚": "AU",
  16. "阿塞拜疆": "AZ",
  17. "巴巴多斯": "BB",
  18. "孟加拉国": "BD",
  19. "比利时": "BE",
  20. "布基纳法索": "BF",
  21. "保加利亚": "BG",
  22. "巴林": "BH",
  23. "布隆迪": "BI",
  24. "贝宁": "BJ",
  25. "巴勒斯坦": "BL",
  26. "百慕大群岛": "BM",
  27. "文莱": "BN",
  28. "玻利维亚": "BO",
  29. "巴西": "BR",
  30. "巴哈马": "BS",
  31. "博茨瓦纳": "BW",
  32. "白俄罗斯": "BY",
  33. "伯利兹": "BZ",
  34. "加拿大": "CA",
  35. "中非共和国": "CF",
  36. "刚果": "CG",
  37. "瑞士": "CH",
  38. "库克群岛": "CK",
  39. "智利": "CL",
  40. "喀麦隆": "CM",
  41. "中国": "CN",
  42. "哥伦比亚": "CO",
  43. "哥斯达黎加": "CR",
  44. "古巴": "CU",
  45. "塞浦路斯": "CY",
  46. "捷克": "CZ",
  47. "德国": "DE",
  48. "吉布提": "DJ",
  49. "丹麦": "DK",
  50. "多米尼加共和国": "DO",
  51. "阿尔及利亚": "DZ",
  52. "厄瓜多尔": "EC",
  53. "爱沙尼亚": "EE",
  54. "埃及": "EG",
  55. "西班牙": "ES",
  56. "埃塞俄比亚": "ET",
  57. "芬兰": "FI",
  58. "斐济": "FJ",
  59. "法国": "FR",
  60. "加蓬": "GA",
  61. "英国": "GB",
  62. "格林纳达": "GD",
  63. "格鲁吉亚": "GE",
  64. "法属圭亚那": "GF",
  65. "加纳": "GH",
  66. "直布罗陀": "GI",
  67. "冈比亚": "GM",
  68. "几内亚": "GN",
  69. "希腊": "GR",
  70. "危地马拉": "GT",
  71. "关岛": "GU",
  72. "圭亚那": "GY",
  73. "香港特别行政区": "HK",
  74. "洪都拉斯": "HN",
  75. "海地": "HT",
  76. "匈牙利": "HU",
  77. "印度尼西亚": "ID",
  78. "爱尔兰": "IE",
  79. "以色列": "IL",
  80. "印度": "IN",
  81. "伊拉克": "IQ",
  82. "伊朗": "IR",
  83. "冰岛": "IS",
  84. "意大利": "IT",
  85. "牙买加": "JM",
  86. "约旦": "JO",
  87. "日本": "JP",
  88. "肯尼亚": "KE",
  89. "吉尔吉斯坦": "KG",
  90. "柬埔寨": "KH",
  91. "朝鲜": "KP",
  92. "韩国": "KR",
  93. "科特迪瓦共和国": "KT",
  94. "科威特": "KW",
  95. "哈萨克斯坦": "KZ",
  96. "老挝": "LA",
  97. "黎巴嫩": "LB",
  98. "圣卢西亚": "LC",
  99. "列支敦士登": "LI",
  100. "斯里兰卡": "LK",
  101. "利比里亚": "LR",
  102. "莱索托": "LS",
  103. "立陶宛": "LT",
  104. "卢森堡": "LU",
  105. "拉脱维亚": "LV",
  106. "利比亚": "LY",
  107. "摩洛哥": "MA",
  108. "摩纳哥": "MC",
  109. "摩尔多瓦": "MD",
  110. "马达加斯加": "MG",
  111. "马里": "ML",
  112. "缅甸": "MM",
  113. "蒙古": "MN",
  114. "澳门": "MO",
  115. "蒙特塞拉特岛": "MS",
  116. "马耳他": "MT",
  117. "毛里求斯": "MU",
  118. "马尔代夫": "MV",
  119. "马拉维": "MW",
  120. "墨西哥": "MX",
  121. "马来西亚": "MY",
  122. "莫桑比克": "MZ",
  123. "纳米比亚": "NA",
  124. "尼日尔": "NE",
  125. "尼日利亚": "NG",
  126. "尼加拉瓜": "NI",
  127. "荷兰": "NL",
  128. "挪威": "NO",
  129. "尼泊尔": "NP",
  130. "瑙鲁": "NR",
  131. "新西兰": "NZ",
  132. "阿曼": "OM",
  133. "巴拿马": "PA",
  134. "秘鲁": "PE",
  135. "巴布亚新几内亚": "PG",
  136. "菲律宾": "PH",
  137. "巴基斯坦": "PK",
  138. "波兰": "PL",
  139. "波多黎各": "PR",
  140. "葡萄牙": "PT",
  141. "巴拉圭": "PY",
  142. "卡塔尔": "QA",
  143. "罗马尼亚": "RO",
  144. "俄罗斯": "RU",
  145. "沙特阿拉伯": "SA",
  146. "所罗门群岛": "SB",
  147. "塞舌尔": "SC",
  148. "苏丹": "SD",
  149. "瑞典": "SE",
  150. "新加坡": "SG",
  151. "斯洛文尼亚": "SI",
  152. "斯洛伐克": "SK",
  153. "塞拉利昂": "SL",
  154. "圣马力诺": "SM",
  155. "塞内加尔": "SN",
  156. "索马里": "SO",
  157. "苏里南": "SR",
  158. "圣多美和普林西比": "ST",
  159. "萨尔瓦多": "SV",
  160. "叙利亚": "SY",
  161. "斯威士兰": "SZ",
  162. "乍得": "TD",
  163. "多哥": "TG",
  164. "泰国": "TH",
  165. "塔吉克斯坦": "TJ",
  166. "土库曼斯坦": "TM",
  167. "突尼斯": "TN",
  168. "汤加": "TO",
  169. "土耳其": "TR",
  170. "特立尼达和多巴哥": "TT",
  171. "台湾": "TW",
  172. "坦桑尼亚": "TZ",
  173. "乌克兰": "UA",
  174. "乌干达": "UG",
  175. "美国": "US",
  176. "乌拉圭": "UY",
  177. "乌兹别克斯坦": "UZ",
  178. "圣文森特岛": "VC",
  179. "委内瑞拉": "VE",
  180. "越南": "VN",
  181. "也门": "YE",
  182. "南斯拉夫": "YU",
  183. "南非": "ZA",
  184. "赞比亚": "ZM",
  185. "扎伊尔": "ZR",
  186. "津巴布韦": "ZW",
  187. }
  188. def shorten(floors):
  189. floors.sort(key=lambda x: x)
  190. # print floors
  191. shortened = []
  192. cur_index = 0
  193. while cur_index < len(floors):
  194. next_index = cur_index + 1
  195. while next_index < len(floors):
  196. if floors[cur_index] * 1.14 < floors[next_index]:
  197. break
  198. next_index += 1
  199. shortened.append(floors[next_index - 1])
  200. cur_index = next_index
  201. return shortened
  202. def find_match_floor(floor, floors):
  203. for f in floors:
  204. if f >= floor:
  205. return float(f) / 100
  206. def combine_floors(platform, file_path, write_to_path):
  207. file_handler = open(file_path, 'r')
  208. floor_data = file_handler.read()
  209. floors = floor_data.split('\n')
  210. floor0 = []
  211. floor1 = []
  212. floor2 = []
  213. floor3 = []
  214. for i in range(0, len(floors) / 2):
  215. cur_floors = floors[2 * i + 1].split(',')
  216. if len(cur_floors) <= 5:
  217. continue
  218. cur_floors = [int(f.strip()) for f in cur_floors]
  219. if cur_floors[2] not in floor0:
  220. floor0.append(cur_floors[2])
  221. if cur_floors[4] not in floor1:
  222. floor1.append(cur_floors[4])
  223. if cur_floors[6] not in floor2:
  224. floor2.append(cur_floors[6])
  225. if cur_floors[7] not in floor3:
  226. floor3.append(cur_floors[7])
  227. floor0 = shorten(floor0)
  228. floor1 = shorten(floor1)
  229. floor2 = shorten(floor2)
  230. floor3 = shorten(floor3)
  231. result_str = 'countryCode,platform,placementId,targetPrice\n'
  232. for i in range(0, len(floors) / 2):
  233. country_code = COUNTRY_REVERSE[floors[i * 2]]
  234. if len(floors[2 * i + 1]) == 0:
  235. continue
  236. cur_floors = floors[2 * i + 1].split(',')
  237. cur_floors = [int(f) for f in cur_floors]
  238. result_str += '%s,%s,unity_inter_I1_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[1], floor0))
  239. result_str += '%s,%s,unity_inter_I1_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[3], floor1))
  240. result_str += '%s,%s,unity_inter_I2_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[5], floor2))
  241. result_str += '%s,%s,unity_inter_I2_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[7], floor3))
  242. # result_str += '%s,%s,inter_I1_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[2], floor0) * 1.7)
  243. # result_str += '%s,%s,inter_I1_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[4], floor1) * 1.7)
  244. # result_str += '%s,%s,inter_I2_lv1,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[6], floor2) * 1.7)
  245. # result_str += '%s,%s,inter_I2_lv2,%.2f\n' % (country_code, platform, find_match_floor(cur_floors[7], floor3) * 1.7)
  246. open(write_to_path, "w").write(result_str)
  247. print "文件写入完成: {}".format(write_to_path)
  248. def _printScriptInfo():
  249. print "************************************************************"
  250. print "* 脚本作用: 生成unity底价csv"
  251. print "* 参数说明:"
  252. print "* 游戏所在平台 (android | ios)"
  253. print "* 插屏价格配置文件路径"
  254. print "* 更新后写入的文件"
  255. print "* 例:"
  256. print "* bulldog price_script_unity inter.txt unity.csv"
  257. print "************************************************************"
  258. print ""
  259. def run(argv):
  260. print argv
  261. _printScriptInfo()
  262. if len(argv) < 4:
  263. Logging.error("参数个数小于3个")
  264. exit(0)
  265. platform = argv[1]
  266. txt_path = argv[2]
  267. write_to_path = argv[3]
  268. Logging.info("配置文件路径: {}".format(txt_path))
  269. Logging.info("写入文件路径: {}".format(write_to_path))
  270. combine_floors(platform, txt_path, write_to_path)
  271. if __name__ == '__main__':
  272. run([
  273. "price_script_unity.py",
  274. "android",
  275. "/Users/zhuge/Temp/20201226/test/archery_inter_20200805_20200904_summary.txt",
  276. "/Users/zhuge/Temp/20201226/test/unity.csv",
  277. ])