public Analyze(string dbFile, int battleType, double userPara, bool selfDefined) { para = userPara; this.battleType = battleType; ah = new AccessHandler(dbFile); curDir = Environment.CurrentDirectory; initalFailed = true; raceData = ah.SelectToDataTable("select pokemon.hp,pokemon.attack,pokemon.defense,pokemon.specialAttack,pokemon.specialDefense,pokemon.speed,battleType" + battleType + ".ranking,battleType" + battleType + ".nature1,battleType" + battleType + ".nu1,battleType" + battleType + ".nature2,battleType" + battleType + ".nu2,battleType" + battleType + ".nature3,battleType" + battleType + ".nu3 from battleType" + battleType + " inner join [;database=" + curDir + "/Data/PokeData.mdb].pokemon on pokemon.poke_id = battleType" + battleType + ".poke_id"); rankingDetails = ah.SelectToDataTable("select * from battleType" + battleType + ""); total = 0; if (selfDefined) { SelfDefinedModelParser sdmp; try { sdmp = new SelfDefinedModelParser("Data/SelfDefinedModel.txt"); } catch { SelfDesignedMsg sdm = new SelfDesignedMsg("Sorry~ 小女子找不到您定义模型的文件...\r\n请确认文件Data/SelfDefinedModel.txt的存在~", false); sdm.ShowDialog(); return; } ArrayList selfModel = sdmp.getModelLists(); if (selfModel == null) { return; } if (selfModel.Count < rankingDetails.Rows.Count) { SelfDesignedMsg sdm = new SelfDesignedMsg("您定义的模型数据不足哦~ 请至少定义" + rankingDetails.Rows.Count + "条", false); sdm.ShowDialog(); return; } model = new double[rankingDetails.Rows.Count + 1]; model[0] = 0; for (int i = 1; i <= rankingDetails.Rows.Count; i++) { model[i] = (double)selfModel[i - 1]; total += model[i]; } } else { model = new double[rankingDetails.Rows.Count + 1]; model[0] = 0; for (int i = 1; i <= rankingDetails.Rows.Count; i++) { model[i] = Math.Pow(i, para); total += model[i]; } } initalFailed = false; }
//check new data on PGL public int checkUpdate() { newTables = new ArrayList(); fetchTasks = new ArrayList(); for (int i = 0; i < GlobalConstants.GENERATION.Count; i++) { int[] blankTable = { 1, 1, 1, 1, 1, 1 }; Fetch fetch = new Fetch(i); if (fetch.serverStatus == -1) { return(-2); } if (fetch.serverStatus == 0) { return(-1); } if (fetch.mostUpdated.Equals(GlobalConstants.MOSTRECENTFILES[i].ToString())) { int tableCount = 0; AccessHandler ah = new AccessHandler(GlobalConstants.MOSTRECENTFILES[i].ToString()); string[] rankTables = ah.showAllTables(); foreach (string rankTable in rankTables) { blankTable[rankTable[10] - '0'] = 0; tableCount++; } if (tableCount < 6) { newTables.Add(blankTable); fetchTasks.Add(fetch); if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString())) { defaultHasNew = true; } } } else { newTables.Add(blankTable); fetchTasks.Add(fetch); if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString())) { defaultHasNew = true; } } } if (fetchTasks.Count == 0) { return(0); } return(1); }
public ShowAnalysis(AccessHandler ah, string curSingleFile, string[] rankTables) { InitializeComponent(); if (GlobalConstants.dpiX == 120) { foreach (Control ct in this.Controls) { ct.Font = new System.Drawing.Font(ct.Font.FontFamily, (float)(ct.Font.Size / 1.25), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); } } label15.Text = "Top" + GlobalConstants.POPULARTHRESHOLD + label15.Text; battleType = -1; this.curSingleFile = curSingleFile; this.ah = ah; this.rankTables = rankTables; defaultpara = new double[6]; defaultpara[0] = 0; for (int i = 1; i < 6; i++) { defaultpara[i] = double.Parse(GlobalConstants.ANALYSISPARA[i - 1]); } radioButton1.Checked = true; string fileName = curSingleFile.Split('/')[2].Replace(".mdb", ""); string[] nameParts = fileName.Split('-'); label6.Text = nameParts[0] + "-" + nameParts[1] + "赛季-" + nameParts[2]; comboBox1.Items.Clear(); string generationSelected = curSingleFile.Split('/')[1]; int defaultTable = -1; for (int i = 0; i < rankTables.Length; i++) { comboBox1.Items.Add(generationSelected + "-" + GlobalConstants.TABLENAMES[rankTables[i][10] - '0']); if (GlobalConstants.DEFAULTBATTLETYPE[0] - '0' == rankTables[i][10] - '0') { defaultTable = i; } } if (defaultTable >= 0) { comboBox1.SelectedIndex = -1; comboBox1.SelectedIndex = defaultTable; } else { SelfDesignedMsg sdm = new SelfDesignedMsg("Sorry~~【对战类型】下拉菜单中没有找到您所设的默认榜单, 请手动选择其它榜单~", false); sdm.ShowDialog(); } }
public string getSeasonPokemonDetail(int battleType) { string url = "http://3ds.pokemon-gl.com/frontendApi/gbu/getSeasonPokemonDetail"; AccessHandler db = new AccessHandler(mostUpdated); db.createTablePkDetail(battleType); for (int i = 0; i < pkIdList.Count; i++) { string pkId = pkIdList[i].ToString(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = GlobalConstants.CONTENTTYPE; request.Referer = GlobalConstants.REFERER; string data = "languageId=2&seasonId=" + curSeasonId + "&battleType=" + battleType + "&timezone=EST&pokemonId=" + pkId + "&displayNumberWaza=20&displayNumberTokusei=3&displayNumberSeikaku=3&displayNumberItem=3&displayNumberLevel=10&displayNumberPokemonIn=1&displayNumberPokemonDown=1&displayNumberPokemonDownWaza=1"; request.ContentLength = Encoding.ASCII.GetByteCount(data); StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII); writer.Write(data); writer.Flush(); writer.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); bool status = JsonParser.seasonPokemonDetail(db, battleType, pkId, reader.ReadToEnd()); if (!status) { bkWorker.ReportProgress(1, "请求精灵编号" + pkId + "数据失败\r\n"); } finished++; if (finished % 10 == 0) { stopwatch.Stop(); TimeSpan timeSpan = stopwatch.Elapsed; int secondsRemain = (int)(timeSpan.TotalSeconds * (total - finished) / finished); bkWorker.ReportProgress(0, new int[] { finished *100 / total, secondsRemain }); stopwatch.Start(); } reader.Close(); } db.closeDatabase(); return(generation + " " + GlobalConstants.BATTLENAME[battleType] + "数据更新完成\r\n"); }
public static bool seasonPokemonDetail(AccessHandler db, int battleType, string pkIdStr, string jsonText) { try { JObject seasonPokemonDetail = JObject.Parse(jsonText); //check return code float pkId = float.Parse(pkIdStr.Replace("-", ".")); int ranking = Convert.ToInt32(seasonPokemonDetail["rankingPokemonInfo"]["ranking"]); if (ranking == 0) { return(true); } string[] moveName = new string[20]; int[] moveType = new int[20]; float[] moveUsage = new float[20]; string[] itemName = new string[3]; float[] itemUsage = new float[3]; string[] abilityName = new string[3]; float[] abilityUsage = new float[3]; string[] natureName = new string[3]; float[] natureUsage = new float[3]; int listSize = seasonPokemonDetail["rankingPokemonTrend"]["wazaInfo"].Count(); if (listSize > 20) { listSize = 20; } for (int i = 0; i < listSize; i++) { moveName[i] = seasonPokemonDetail["rankingPokemonTrend"]["wazaInfo"][i]["name"].ToString(); moveType[i] = Convert.ToInt32(seasonPokemonDetail["rankingPokemonTrend"]["wazaInfo"][i]["typeId"]); moveUsage[i] = (float)(Convert.ToDouble(seasonPokemonDetail["rankingPokemonTrend"]["wazaInfo"][i]["usageRate"])); } for (int i = listSize; i < 20; i++) { moveName[i] = "-"; moveType[i] = -1; moveUsage[i] = 0; } listSize = seasonPokemonDetail["rankingPokemonTrend"]["itemInfo"].Count(); if (listSize > 3) { listSize = 3; } for (int i = 0; i < listSize; i++) { itemName[i] = seasonPokemonDetail["rankingPokemonTrend"]["itemInfo"][i]["name"].ToString(); itemUsage[i] = (float)(Convert.ToDouble(seasonPokemonDetail["rankingPokemonTrend"]["itemInfo"][i]["usageRate"])); } for (int i = listSize; i < 3; i++) { itemName[i] = "-"; itemUsage[i] = 0; } listSize = seasonPokemonDetail["rankingPokemonTrend"]["tokuseiInfo"].Count(); for (int i = 0; i < listSize; i++) { abilityName[i] = seasonPokemonDetail["rankingPokemonTrend"]["tokuseiInfo"][i]["name"].ToString(); abilityUsage[i] = (float)(Convert.ToDouble(seasonPokemonDetail["rankingPokemonTrend"]["tokuseiInfo"][i]["usageRate"])); } for (int i = listSize; i < 3; i++) { abilityName[i] = "-"; abilityUsage[i] = 0; } listSize = seasonPokemonDetail["rankingPokemonTrend"]["seikakuInfo"].Count(); if (listSize > 3) { listSize = 3; } for (int i = 0; i < listSize; i++) { natureName[i] = seasonPokemonDetail["rankingPokemonTrend"]["seikakuInfo"][i]["name"].ToString(); natureUsage[i] = (float)(Convert.ToDouble(seasonPokemonDetail["rankingPokemonTrend"]["seikakuInfo"][i]["usageRate"])); } for (int i = listSize; i < 3; i++) { natureName[i] = "-"; natureUsage[i] = 0; } string sql = "insert into battleType" + battleType + " values("; sql += pkId + ","; sql += ranking + ","; for (int i = 0; i < 3; i++) { sql += "'" + abilityName[i] + "',"; sql += abilityUsage[i] + ","; } for (int i = 0; i < 3; i++) { sql += "'" + natureName[i] + "',"; sql += natureUsage[i] + ","; } for (int i = 0; i < 3; i++) { sql += "'" + itemName[i].Replace("'", "''") + "',"; sql += itemUsage[i] + ","; } for (int i = 0; i < 19; i++) { sql += "'" + moveName[i].Replace("'", "''") + "',"; sql += moveType[i] + ","; sql += moveUsage[i] + ","; } sql += "'" + moveName[19].Replace("'", "''") + "',"; sql += moveType[19] + ","; sql += moveUsage[19] + ")"; db.ExecuteSQLNonquery(sql); return(true); } catch { return(false); } }
//mega配比统计 public ArrayList megaUsageRate(AccessHandler ah) { ArrayList res = new ArrayList(); double totalMegaRate = 0; HashSet <string> megaSet = new HashSet <string>(GlobalConstants.MEGASTONES); foreach (DataRow row in rankingDetails.Rows) { double weight = model[(int)row[1]] / total; if (megaSet.Contains(row[14].ToString())) { double megaRate = weight * (double)(row[15]); string pkId = row[0].ToString() + ".1"; if (row[14].ToString().Equals("Charizardite Y") || row[14].ToString().Equals("Mewtwonite Y")) { pkId = row[0].ToString() + ".2"; } DataTable dt = ah.SelectToDataTable("select chi from pokemon where poke_id = " + pkId); if (dt.Rows.Count > 0) { res.Add(new KeyValuePair <string, double>(dt.Rows[0][0].ToString(), megaRate)); totalMegaRate += megaRate; } } if (megaSet.Contains(row[16].ToString())) { double megaRate = weight * (double)(row[17]); string pkId = row[0].ToString() + ".1"; if (row[16].ToString().Equals("Charizardite Y") || row[16].ToString().Equals("Mewtwonite Y")) { pkId = row[0].ToString() + ".2"; } DataTable dt = ah.SelectToDataTable("select chi from pokemon where poke_id = " + pkId); if (dt.Rows.Count > 0) { res.Add(new KeyValuePair <string, double>(dt.Rows[0][0].ToString(), megaRate)); totalMegaRate += megaRate; } } if (megaSet.Contains(row[18].ToString())) { double megaRate = weight * (double)(row[19]); string pkId = row[0].ToString() + ".1"; if (row[18].ToString().Equals("Charizardite Y") || row[18].ToString().Equals("Mewtwonite Y")) { pkId = row[0].ToString() + ".2"; } DataTable dt = ah.SelectToDataTable("select chi from pokemon where poke_id = " + pkId); if (dt.Rows.Count > 0) { res.Add(new KeyValuePair <string, double>(dt.Rows[0][0].ToString(), megaRate)); totalMegaRate += megaRate; } } if ((double)row[0] == 384) { for (int i = 20; i < 80; i += 3) { if ((string)row[i] == "Dragon Ascent") { double megaRate = weight * (double)(row[i + 2]); res.Add(new KeyValuePair <string, double>("烈空坐", megaRate)); totalMegaRate += megaRate; break; } } } } res.Add(new KeyValuePair <string, double>("total", totalMegaRate)); return(res); }
public UpdateData(bool autoCheck) { InitializeComponent(); if (GlobalConstants.dpiX == 120) { foreach (Control ct in this.Controls) { ct.Font = new System.Drawing.Font(ct.Font.FontFamily, (float)(ct.Font.Size / 1.25), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); } } valid = false; defaultHasNew = false; radioButton2.Enabled = false; radioButton2.Visible = false; int checkRes = checkUpdate(); bool gitValid = checkGit(); //fail to connect to PGL if (checkRes == -2) { radioButton1.Enabled = false; radioButton1.Visible = false; radioButton1.Checked = false; if (!gitValid) { if (!autoCheck) { SelfDesignedMsg sdm = new SelfDesignedMsg("Sorry~ 无法连接PGL服务器, 可能这货在维护...", false); sdm.ShowDialog(); } return; } } //no return for PGL http post else if (checkRes == -1) { radioButton1.Enabled = false; radioButton1.Visible = false; radioButton1.Checked = false; if (!gitValid) { if (!autoCheck) { SelfDesignedMsg sdm = new SelfDesignedMsg("刚刚进入新赛季,PGL服务器上暂时还找不到新的数据~", false); sdm.ShowDialog(); } return; } } //no new data else if (checkRes == 0) { if (!autoCheck) { SelfDesignedMsg sdm = new SelfDesignedMsg("您已拥有最新各项榜单啦~", false); sdm.ShowDialog(); } return; } //initialize a new thread valid = true; errorExists = false; bkWorker.WorkerReportsProgress = true; bkWorker.WorkerSupportsCancellation = true; bkWorker.DoWork += new DoWorkEventHandler(startUpdate); bkWorker.ProgressChanged += new ProgressChangedEventHandler(updateProgress); bkWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completeWork); //get user's selection for new data treeView1.CheckBoxes = true; if (checkRes > 0 && (!gitValid)) { for (int i = 0; i < fetchTasks.Count; i++) { TreeNode tn = new TreeNode(); tn.Text = ((Fetch)fetchTasks[i]).generation + "-" + ((Fetch)fetchTasks[i]).curSeasonName + "-" + ((Fetch)fetchTasks[i]).updateTime.Split('-')[0]; if (((int[])newTables[i])[0] == 1) { tn.Nodes.Add("All Matches"); } if (((int[])newTables[i])[1] == 1) { tn.Nodes.Add("Single"); } if (((int[])newTables[i])[2] == 1) { tn.Nodes.Add("Double"); } if (((int[])newTables[i])[3] == 1) { tn.Nodes.Add("Triple"); } if (((int[])newTables[i])[4] == 1) { tn.Nodes.Add("Rotation"); } if (((int[])newTables[i])[5] == 1) { tn.Nodes.Add("Special"); } treeView1.Nodes.Add(tn); } } else { gitTasks = new ArrayList(); newTables.Clear(); for (int i = 0; i < GlobalConstants.GENERATION.Count; i++) { int[] blankTable = { 1, 1, 1, 1, 1, 1 }; if (gitVersions[i].ToString().Equals("")) { int tableCount = 0; AccessHandler ah = new AccessHandler(GlobalConstants.MOSTRECENTFILES[i].ToString()); string[] rankTables = ah.showAllTables(); foreach (string rankTable in rankTables) { blankTable[rankTable[10] - '0'] = 0; tableCount++; } if (tableCount < 6) { newTables.Add(blankTable); gitTasks.Add(GlobalConstants.MOSTRECENTFILES[i].ToString()); if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString())) { defaultHasNew = true; } } } else { newTables.Add(blankTable); gitTasks.Add(gitVersions[i].ToString()); if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString())) { defaultHasNew = true; } } } if (gitTasks.Count == 0) { valid = false; if (!autoCheck) { SelfDesignedMsg sdm = new SelfDesignedMsg("您已拥有最新各项榜单啦~", false); sdm.ShowDialog(); } return; } for (int i = 0; i < gitTasks.Count; i++) { TreeNode tn = new TreeNode(); string[] nameParts = gitTasks[i].ToString().Split('/'); tn.Text = nameParts[1] + "-" + nameParts[2].Split('-')[1] + "-" + nameParts[2].Split('-')[2]; if (((int[])newTables[i])[0] == 1) { tn.Nodes.Add("All Matches"); } if (((int[])newTables[i])[1] == 1) { tn.Nodes.Add("Single"); } if (((int[])newTables[i])[2] == 1) { tn.Nodes.Add("Double"); } if (((int[])newTables[i])[3] == 1) { tn.Nodes.Add("Triple"); } if (((int[])newTables[i])[4] == 1) { tn.Nodes.Add("Rotation"); } if (((int[])newTables[i])[5] == 1) { tn.Nodes.Add("Special"); } treeView1.Nodes.Add(tn); } } }
public UpdateBySqls(string newFile) { db = new AccessHandler(newFile); }