TargetStatistics.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using NPOI.HSSF.UserModel;
  7. using StackExchange.Redis;
  8. using Newtonsoft.Json.Linq;
  9. using System.IO;
  10. using CSharpUtil;
  11. namespace StatisticsTransfer.tongji
  12. {
  13. class TargetStatistics
  14. {
  15. /// <summary>
  16. /// 指标累计值数据转为execl表
  17. /// </summary>
  18. public static void TargetValToExecl()
  19. {
  20. var mem = Redis.Ins.GetDatabase(0);
  21. int zoneid = 1;
  22. HashEntry[] ctxList = mem.HashGetAll(MemKey_Statistics.TargetStatistics(zoneid));
  23. int length = ctxList.Length;
  24. if (length <= 0)
  25. {
  26. return;
  27. }
  28. Dictionary<string, Dictionary<string, int>> dic = new Dictionary<string, Dictionary<string, int>>();
  29. foreach (var item in ctxList)
  30. {
  31. string[] sList = item.ToString().Split(':');
  32. string type = sList[0];
  33. int num = int.Parse(sList[1]);
  34. string[] clist = type.Split('-');
  35. string nType = targetType(clist[0]);
  36. //Console.WriteLine("nType-----.." + nType);
  37. if (dic.ContainsKey(nType))
  38. {
  39. //Console.WriteLine("type-----..." + type);
  40. dic[nType].Add(type, num);
  41. }
  42. else
  43. {
  44. Dictionary<string, int> itemDic = new Dictionary<string, int>();
  45. itemDic.Add(type, num);
  46. dic[nType] = itemDic;
  47. //Console.WriteLine("type-----..." + type);
  48. }
  49. }
  50. HSSFWorkbook workbook = new HSSFWorkbook();
  51. foreach (KeyValuePair<string, Dictionary<string, int>> kv in dic)
  52. {
  53. Dictionary<string, int> dict = kv.Value;
  54. Console.WriteLine("kv--key-----........" + kv.Key);
  55. string tableName = "指标统计表_" + kv.Key;
  56. //创建工作表
  57. var sheet = workbook.CreateSheet(tableName);
  58. var row = sheet.CreateRow(0);
  59. //创建单元格
  60. var cellid = row.CreateCell(0);
  61. cellid.SetCellValue("指标描述信息");
  62. var cellname = row.CreateCell(1);
  63. cellname.SetCellValue("指标类型");
  64. var cellpwd = row.CreateCell(2);
  65. cellpwd.SetCellValue("指标累计值");
  66. int x = 1;
  67. foreach (KeyValuePair<string, int> kt in dict)
  68. {
  69. string type = kt.Key;
  70. int num = kt.Value;
  71. string desc = TargetDesc(type);
  72. //Console.WriteLine("ktttt--type-----........" + type);
  73. //Console.WriteLine("ktttt--name-----........" + desc);
  74. var rowi = sheet.CreateRow(x);
  75. var cdesc = rowi.CreateCell(0);
  76. cdesc.SetCellValue(desc);
  77. var cType = rowi.CreateCell(1);
  78. cType.SetCellValue(type);
  79. var cnum = rowi.CreateCell(2);
  80. cnum.SetCellValue(num);
  81. x += 1;
  82. }
  83. }
  84. TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
  85. float curday = MathF.Floor((long)ts.TotalSeconds / 24 / 60 / 60);
  86. string txtName = "指标累计信息表_" + "zone" + zoneid + "-day-" + curday;
  87. FileStream file = new FileStream(@"F:\excel\" + txtName + ".xls", FileMode.CreateNew, FileAccess.Write);
  88. workbook.Write(file);
  89. file.Dispose();
  90. Console.WriteLine("指标累计execl完成........");
  91. }
  92. public static string TargetDesc(string type)
  93. {
  94. string[] sList = type.Split('-');
  95. var mem = Redis.Ins.GetDatabase(0);
  96. string desc = "";
  97. switch (sList[0])
  98. {
  99. case "registerUserNum":
  100. desc = "注册人数累计";
  101. break;
  102. case "comNewGuideUserNum":
  103. desc = "完成新手引导人数累计";
  104. break;
  105. case "unlockbuidId":
  106. string ctx = mem.HashGet(MemKey_Game.Build(), sList[1]);
  107. JObject ctxDic = JObject.Parse(ctx);
  108. string s = ctxDic["name"].ToString();
  109. desc = "累计解锁建筑-" + s + "的人数";
  110. break;
  111. case "mainTaskId_ComUserNum"://主线任务id--完成人数
  112. desc = "完成主线任务id-" + sList[1] + "的人数";
  113. break;
  114. case "shopTaskId_ComUserNum":
  115. desc = "完成悬赏任务id-" + sList[1] + "的人数";
  116. break;
  117. case "shopTaskId_BuyUserNum":
  118. desc = "购买悬赏任务id-" + sList[1] + "的人数";
  119. break;
  120. case "collegeTaskId_ComUserNum":
  121. desc = "完成学院任务id-" + sList[1] + "的人数";
  122. break;
  123. case "collegeCouseId_UnlockUserNum":
  124. desc = "解锁学院课程id-" + sList[1] + "的人数";
  125. break;
  126. case "dailyTaskId_ComUserNum":
  127. desc = "完成日常任务id-" + sList[1] + "的人数";
  128. break;
  129. case "storyGateId_ComUserNum":
  130. desc = "完成剧情关卡id-" + sList[1] + "的人数";
  131. break;
  132. case "storyGateId_BattleNum":
  133. desc = "剧情关卡id-" + sList[1] + "的挑战次数/通关次数";
  134. break;
  135. case "HuanLingShiGateId_ComUserNum":
  136. desc = "完成副本唤灵师关卡id-" + sList[1] + "的人数";
  137. break;
  138. case "HuanLingShiGateId_BattleNum":
  139. desc = "完成副本唤灵师关卡id-" + sList[1] + "的挑战次数/通关次数";
  140. break;
  141. case "WeaponGateId_ComUserNum":
  142. desc = "完成副本武器关卡id-" + sList[1] + "的人数";
  143. break;
  144. case "WeaponGateId_BattleNum":
  145. desc = "完成副本武器关卡id-" + sList[1] + "的挑战次数/通关次数";
  146. break;
  147. case "YanLingGateId_ComUserNum":
  148. desc = "完成副本言灵关卡id-" + sList[1] + "的人数";
  149. break;
  150. case "YanLingGateId_BattleNum":
  151. desc = "完成副本言灵关卡id-" + sList[1] + "的挑战次数/通关次数";
  152. break;
  153. case "userlevel":
  154. desc = "玩家等级为" + sList[1] + "的人数";
  155. break;
  156. case "newUserLotteryDraw_one":
  157. desc = "新手池抽卡单次抽奖的访问频率";
  158. break;
  159. case "newUserLotteryDraw_ten":
  160. desc = "新手池抽卡十连抽的访问频率";
  161. break;
  162. case "yanLingLotteryDraw_one":
  163. desc = "言灵活动祈愿奖池单次抽奖的访问频率";
  164. break;
  165. case "yanLingLotteryDraw_ten":
  166. desc = "言灵活动祈愿奖池十连抽的访问频率";
  167. break;
  168. case "weaponLotteryDraw_one":
  169. desc = "武器活动祈愿奖池单次抽奖的访问频率";
  170. break;
  171. case "weaponLotteryDraw_ten":
  172. desc = "武器活动祈愿奖池十连抽的访问频率";
  173. break;
  174. case "commonLotteryDraw_one":
  175. desc = "常驻祈愿奖池单次抽奖的访问频率";
  176. break;
  177. case "commonLotteryDraw_ten":
  178. desc = "常驻祈愿奖池十连抽的访问频率";
  179. break;
  180. case "HuanLingShiLevel_UserNum":
  181. desc = "唤灵师" + sList[1] + "等级为" + sList[2] + "的人数";
  182. break;
  183. case "HuanLingShiId_UserNum":
  184. desc = "拥有唤灵师" + sList[1] + "的人数";
  185. break;
  186. case "YanLingId_UserNum":
  187. desc = "拥有言灵" + sList[1] + "的人数";
  188. break;
  189. case "YanLingIdLevel_UserNum":
  190. desc = "言灵" + sList[1] + "等级为" + sList[2] + "的人数";
  191. break;
  192. case "WeaponId_UserNum":
  193. desc = "拥有武器" + sList[1] + "的人数";
  194. break;
  195. case "WeaponIdLevel_UserNum":
  196. desc = "武器" + sList[1] + "等级为" + sList[2] + "的人数";
  197. break;
  198. }
  199. return desc;
  200. }
  201. public static string targetType(string t)
  202. {
  203. string type = "";
  204. switch (t)
  205. {
  206. case "registerUserNum":
  207. type = "registerUserNum";
  208. break;
  209. case "comNewGuideUserNum":
  210. type = "comNewGuideUserNum";
  211. break;
  212. case "unlockbuidId":
  213. type = "unlockbuidId";
  214. break;
  215. case "mainTaskId_ComUserNum"://主线任务id--完成人数
  216. type = "mainTask";
  217. break;
  218. case "shopTaskId_ComUserNum":
  219. type = "shopTask";
  220. break;
  221. case "shopTaskId_BuyUserNum":
  222. type = "shopTask";
  223. break;
  224. case "collegeTaskId_ComUserNum":
  225. type = "collegeTask";
  226. break;
  227. case "collegeCouseId_UnlockUserNum":
  228. type = "collegeTask";
  229. break;
  230. case "dailyTaskId_ComUserNum":
  231. type = "dailyTask";
  232. break;
  233. case "storyGateId_ComUserNum":
  234. type = "storyGate";
  235. break;
  236. case "storyGateId_BattleNum":
  237. type = "storyGate";
  238. break;
  239. case "HuanLingShiGateId_ComUserNum":
  240. type = "HuanLingShiGate";
  241. break;
  242. case "HuanLingShiGateId_BattleNum":
  243. type = "HuanLingShiGate";
  244. break;
  245. case "WeaponGateId_ComUserNum":
  246. type = "WeaponGate";
  247. break;
  248. case "WeaponGateId_BattleNum":
  249. type = "WeaponGate";
  250. break;
  251. case "YanLingGateId_ComUserNum":
  252. type = "YanLingGate";
  253. break;
  254. case "YanLingGateId_BattleNum":
  255. type = "YanLingGate";
  256. break;
  257. case "userlevel":
  258. type = "userlevel";
  259. break;
  260. case "newUserLotteryDraw_one":
  261. type = "LotteryDraw";
  262. break;
  263. case "newUserLotteryDraw_ten":
  264. type = "LotteryDraw";
  265. break;
  266. case "yanLingLotteryDraw_one":
  267. type = "LotteryDraw";
  268. break;
  269. case "yanLingLotteryDraw_ten":
  270. type = "LotteryDraw";
  271. break;
  272. case "weaponLotteryDraw_one":
  273. type = "LotteryDraw";
  274. break;
  275. case "weaponLotteryDraw_ten":
  276. type = "LotteryDraw";
  277. break;
  278. case "commonLotteryDraw_one":
  279. type = "LotteryDraw";
  280. break;
  281. case "commonLotteryDraw_ten":
  282. type = "LotteryDraw";
  283. break;
  284. case "HuanLingShiLevel_UserNum":
  285. type = "HuanLingShi";
  286. break;
  287. case "HuanLingShiId_UserNum":
  288. type = "HuanLingShi";
  289. break;
  290. case "YanLingId_UserNum":
  291. type = "YanLing";
  292. break;
  293. case "YanLingIdLevel_UserNum":
  294. type = "YanLing";
  295. break;
  296. case "WeaponId_UserNum":
  297. type = "Weapon";
  298. break;
  299. case "WeaponIdLevel_UserNum":
  300. type = "Weapon";
  301. break;
  302. }
  303. return type;
  304. }
  305. }
  306. }