123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using NPOI.HSSF.UserModel;
- using StackExchange.Redis;
- using CSharpUtil;
- using Newtonsoft.Json.Linq;
- //using System.Diagnostics;
- namespace DataTransfer.tongji
- {
- class DataToExcelText
- {
- public static void excelText(string memKey, int retain, int zoneid, float day)
- {
- //获取redis种的数据
- var mem = Redis.Ins.GetDatabase(0);
- HashEntry[] ctxList = mem.HashGetAll(memKey);
- int length = ctxList.Length;
- if (length <= 0)
- {
- return;
- }
- Dictionary<string, string> levelDic = new Dictionary<string, string>();
- Dictionary<string, string> taskDic = new Dictionary<string, string>();
- Dictionary<string, string> gateDic = new Dictionary<string, string>();
- foreach (var item in ctxList)
- {
- string[] sList = item.ToString().Split(':');
- string type = sList[0];
- string num = sList[1];
- string[] ctx = type.Split('-');
- string name = ctx[0];
- //string id = ctx[1];
- if (name == "level")
- {
- levelDic[type] = num;
- }
- else if (name == "task")
- {
- taskDic[type] = num;
- }
- else if (name == "gateId")
- {
- gateDic[type] = num;
- }
- }
- Dictionary<string, string> dic = levelDic.Union(taskDic).ToDictionary(k => k.Key, v => v.Value);
- Dictionary<string, string> newdic = dic.Union(gateDic).ToDictionary(k => k.Key, v => v.Value);
- HSSFWorkbook workbook = new HSSFWorkbook();
- //创建工作表
- var sheet = workbook.CreateSheet("信息表");
- var row = sheet.CreateRow(0);
- //创建单元格
- var cellid = row.CreateCell(0);
- cellid.SetCellValue("指标类型");
- var cellname = row.CreateCell(1);
- cellname.SetCellValue("指标id");
- var cellpwd = row.CreateCell(2);
- cellpwd.SetCellValue("指标累计值");
- int x = 1;
- foreach (KeyValuePair<string, string> kv in newdic)
- {
- string[] sList = kv.Key.Split('-');
- string name = sList[0];
- string id = sList[1];
- int num = int.Parse(kv.Value);
- var rowi = sheet.CreateRow(x);
- var cname = rowi.CreateCell(0);
- cname.SetCellValue(name);
- var cid = rowi.CreateCell(1);
- cid.SetCellValue(id);
- var cnum = rowi.CreateCell(2);
- cnum.SetCellValue(num);
- x += 1;
- }
- string txtName = "流失玩家指标累计信息表_" + "zone" + zoneid + "_" + retain + "lose_" + day;
- FileStream file = new FileStream(@"F:\excel\" + txtName + ".xls", FileMode.CreateNew, FileAccess.Write);
- workbook.Write(file);
- file.Dispose();
- }
- /// <summary>
- /// 指标累计值数据转为execl表
- /// </summary>
- public static void TargetStatistics()
- {
- var mem = Redis.Ins.GetDatabase(0);
- int zoneid = 1;
- HashEntry[] ctxList = mem.HashGetAll(MemKey_Statistics.TargetStatistics(zoneid));
- int length = ctxList.Length;
- if (length <= 0)
- {
- return;
- }
- Dictionary<string, Dictionary<string, int>> dic = new Dictionary<string, Dictionary<string, int>>();
- foreach (var item in ctxList)
- {
- string[] sList = item.ToString().Split(':');
- string type = sList[0];
- int num = int.Parse(sList[1]);
- string[] cLict = type.Split('-');
- string nType = cLict[0];
- if (dic.ContainsKey(nType))
- {
- dic[type].Add(type, num);
- }
- else
- {
- Dictionary<string, int> itemDic = new Dictionary<string, int>();
- itemDic.Add(type, num);
- dic[type] = itemDic;
- }
- }
- HSSFWorkbook workbook = new HSSFWorkbook();
- //创建工作表
- var sheet = workbook.CreateSheet("指标统计表");
- var row = sheet.CreateRow(0);
- //创建单元格
- var cellid = row.CreateCell(0);
- cellid.SetCellValue("指标描述信息");
- var cellname = row.CreateCell(1);
- cellname.SetCellValue("指标类型");
- var cellpwd = row.CreateCell(2);
- cellpwd.SetCellValue("指标累计值");
- int x = 1;
- foreach (KeyValuePair<string, Dictionary<string,int>> kv in dic)
- {
- Dictionary<string, int> dict = kv.Value;
- foreach (KeyValuePair<string,int>kt in dict)
- {
- string type = kt.Key;
- int num = kt.Value;
- string desc = TargetDesc(type);
- var rowi = sheet.CreateRow(x);
- var cdesc = rowi.CreateCell(0);
- cdesc.SetCellValue(desc);
- var cType = rowi.CreateCell(1);
- cType.SetCellValue(type);
- var cnum = rowi.CreateCell(2);
- cnum.SetCellValue(num);
- x += 1;
- }
- }
- string txtName = "指标累计信息表_" + "zone" + zoneid;
- FileStream file = new FileStream(@"F:\excel\" + txtName + ".xls", FileMode.CreateNew, FileAccess.Write);
- workbook.Write(file);
- file.Dispose();
- }
- public static string TargetDesc(string type)
- {
- string[] sList = type.Split('-');
- var mem = Redis.Ins.GetDatabase(0);
- string desc = "";
- switch (sList[0])
- {
- case "registerUserNum":
- desc = "注册人数累计";
- break;
- case "comNewGuideUserNum":
- desc = "完成新手引导人数累计";
- break;
- case "unlockbuidId":
- string ctx = mem.HashGet(MemKey_Game.Build(),sList[1]);
- JObject ctxDic = JObject.Parse(ctx);
- string s = ctxDic["name"].ToString();
- desc = "累计解锁建筑-" + s+"的人数";
- break;
- case "mainTaskId_ComUserNum"://主线任务id--完成人数
- desc = "完成主线任务id-" + sList[1] + "的人数";
- break;
- case "shopTaskId_ComUserNum":
- desc = "完成悬赏任务id-" + sList[1] + "的人数";
- break;
- case "shopTaskId_BuyUserNum":
- desc = "购买悬赏任务id-" + sList[1] + "的人数";
- break;
- case "collegeTaskId_ComUserNum":
- desc = "完成学院任务id-" + sList[1] + "的人数";
- break;
- case "collegeCouseId_UnlockUserNum":
- desc = "解锁学院课程id-" + sList[1] + "的人数";
- break;
- case "dailyTaskId_ComUserNum":
- desc = "完成日常任务id-" + sList[1] + "的人数";
- break;
- case "storyGateId_ComUserNum":
- desc = "完成剧情关卡id-" + sList[1] + "的人数";
- break;
- case "storyGateId_BattleNum":
- desc = "剧情关卡id-" + sList[1] + "的挑战次数/通关次数";
- break;
- case "HuanLingShiGateId_ComUserNum":
- desc = "完成副本唤灵师关卡id-" + sList[1] + "的人数";
- break;
- case "HuanLingShiGateId_BattleNum":
- desc = "完成副本唤灵师关卡id-" + sList[1] + "的挑战次数/通关次数";
- break;
- case "WeaponGateId_ComUserNum":
- desc = "完成副本武器关卡id-" + sList[1] + "的人数";
- break;
- case "WeaponGateId_BattleNum":
- desc = "完成副本武器关卡id-" + sList[1] + "的挑战次数/通关次数";
- break;
- case "YanLingGateId_ComUserNum":
- desc = "完成副本言灵关卡id-" + sList[1] + "的人数";
- break;
- case "YanLingGateId_BattleNum":
- desc = "完成副本言灵关卡id-" + sList[1] + "的挑战次数/通关次数";
- break;
- case "userlevel":
- desc = "玩家等级为-" + sList[1] + "的人数";
- break;
- case "newUserLotteryDraw_one":
- desc = "新手池抽卡单次抽奖的访问频率";
- break;
- case "newUserLotteryDraw_ten":
- desc = "新手池抽卡十连抽的访问频率";
- break;
- case "yanLingLotteryDraw_one":
- desc = "言灵活动祈愿奖池单次抽奖的访问频率";
- break;
- case "yanLingLotteryDraw_ten":
- desc = "言灵活动祈愿奖池十连抽的访问频率";
- break;
- case "weaponLotteryDraw_one":
- desc = "武器活动祈愿奖池单次抽奖的访问频率";
- break;
- case "weaponLotteryDraw_ten":
- desc = "武器活动祈愿奖池十连抽的访问频率";
- break;
- case "commonLotteryDraw_one":
- desc = "常驻祈愿奖池单次抽奖的访问频率";
- break;
- case "commonLotteryDraw_ten":
- desc = "常驻祈愿奖池十连抽的访问频率";
- break;
- case "HuanLingShiLevel_UserNum":
- desc = "唤灵师"+sList[1]+"等级为"+sList[2]+"的人数";
- break;
- case "HuanLingShiId_UserNum":
- desc = "拥有唤灵师"+ sList[1]+"的人数";
- break;
- case "YanLingId_UserNum":
- desc = "拥有言灵" + sList[1] + "的人数";
- break;
- case "YanLingIdLevel_UserNum":
- desc = "言灵" + sList[1] + "等级为" + sList[2] + "的人数";
- break;
- case "WeaponId_UserNum":
- desc = "拥有武器" + sList[1] + "的人数";
- break;
- case "WeaponIdLevel_UserNum":
- desc = "武器" + sList[1] + "等级为" + sList[2] + "的人数";
- break;
-
- }
- return desc;
- }
- }
- public class User
- {
- /// <summary>
- /// 索引
- /// </summary>
- public int Id { get; set; }
- public string Name { get; set; }
- public string pwd { get; set; }
- public string type { get; set; }
- }
- }
|