public List <CurrentEmpireRanking> GetRankings(string jsonRankingData) { var res = new List <CurrentEmpireRanking>(); var allTokens = JsonConvert.DeserializeObject(jsonRankingData) as Newtonsoft.Json.Linq.JArray; if (allTokens != null) { var ranksArray = allTokens.First(); foreach (var rankRow in ranksArray) { var rank = new CurrentEmpireRanking(); foreach (Newtonsoft.Json.Linq.JProperty rankRowProperty in rankRow) { var name = rankRowProperty.Name; switch (name) { case "1": rank.PlayerName = rankRowProperty.Value.ToString(); break; case "2": rank.Rank = ParseInt(rankRowProperty.Value.ToString()); break; case "3": rank.Score = ParseInt(rankRowProperty.Value.ToString()); break; case "4": rank.AlianceName = rankRowProperty.Value.ToString(); break; case "5": rank.CitiesNo = ParseInt(rankRowProperty.Value.ToString()); break; default: break; } } rank.UpdateDT = DateTime.Now; res.Add(rank); } } return(res); }
public List <CurrentEmpireRanking> GetUnitsKills(string jsonRankingData) { var res = new List <CurrentEmpireRanking>(); var allTokens = JsonConvert.DeserializeObject(jsonRankingData) as Newtonsoft.Json.Linq.JObject; if (allTokens != null) { var ranksArray = allTokens.First.First; foreach (var rankRow in ranksArray) { var rank = new CurrentEmpireRanking(); foreach (Newtonsoft.Json.Linq.JProperty rankRowProperty in rankRow) { var name = rankRowProperty.Name; rank.Continent = 56; //zawsze.. bo to ranking globalny switch (name) { case "1": rank.PlayerName = rankRowProperty.Value.ToString(); break; case "2": rank.UnitsKillsRank = ParseInt(rankRowProperty.Value.ToString()); break; case "3": rank.AlianceName = rankRowProperty.Value.ToString(); break; case "4": rank.UnitsKills = ParseLong(rankRowProperty.Value.ToString()); break; default: break; } } rank.UpdateDT = DateTime.Now; res.Add(rank); } } return(res); }
public void UpdateEmpire(DBCurrentEmpireRanking dbRank, CurrentEmpireRanking currentRank) { if (dbRank.Score.HasValue) //sojusze tylko dla ogólnej punktacji są { dbRank.AlianceName = currentRank.AlianceName; } dbRank.UpdateDT = DateTime.Now; if (currentRank.Rank.HasValue) { if (dbRank.Id.HasValue) { dbRank.RankLastChange = dbRank.Rank - currentRank.Rank; } dbRank.Rank = currentRank.Rank; } if (currentRank.Score.HasValue) { if (dbRank.Id.HasValue) { dbRank.ScoreLastChange = currentRank.Score - dbRank.Score; } dbRank.Score = currentRank.Score; } if (currentRank.CitiesNo.HasValue) { if (dbRank.Id.HasValue) { dbRank.CitiesNoLastChange = currentRank.CitiesNo - dbRank.CitiesNo; } dbRank.CitiesNo = currentRank.CitiesNo; } if (currentRank.UnitsKills.HasValue) { dbRank.UnitsKills = currentRank.UnitsKills; } if (currentRank.UnitsKillsRank.HasValue) { dbRank.UnitsKillsRank = currentRank.UnitsKillsRank; } if (currentRank.Caverns.HasValue) { dbRank.Caverns = currentRank.Caverns; } if (currentRank.CavernsRank.HasValue) { dbRank.CavernsRank = currentRank.CavernsRank; } if (currentRank.DefReputation.HasValue) { dbRank.DefReputation = currentRank.DefReputation; } if (currentRank.DefReputationRank.HasValue) { dbRank.DefReputationRank = currentRank.DefReputationRank; } if (currentRank.OffReputation.HasValue) { dbRank.OffReputation = currentRank.OffReputation; } if (currentRank.OffReputationRank.HasValue) { dbRank.OffReputationRank = currentRank.OffReputationRank; } if (currentRank.Score.HasValue) { //historia głównego rankingu var histRank = new DBRankingsEmpireScore(); histRank.AlianceName = dbRank.AlianceName; histRank.CitiesNo = dbRank.CitiesNo.Value; histRank.Continent = dbRank.Continent; histRank.CreateDT = dbRank.UpdateDT; histRank.PlayerName = dbRank.PlayerName; histRank.Rank = dbRank.Rank.Value; histRank.Score = dbRank.Score.Value; Session.SaveOrUpdate(histRank); /* * var last3Rows = Session.QueryOver<DBRankingsEmpireScore>() * .Where(x => x.PlayerName == dbRank.PlayerName && x.Continent == dbRank.Continent) * .OrderBy(x => x.CreateDT).Desc * .Take(3) * .List(); */ //odczytuję historię ostanich 3 pomiarów do obliczenia średniej z przyrostów var last3Rows = m_ScoreHistCache .Where(x => x.PlayerName == dbRank.PlayerName && x.Continent == dbRank.Continent) .OrderByDescending(x => x.CreateDT) .ToList(); if (last3Rows.Count > 0) { dbRank.ScoreDiffAvg = (last3Rows.Max(x => x.Score) - last3Rows.Min(x => x.Score)) / last3Rows.Count; } else { dbRank.ScoreDiffAvg = 0; } } if (currentRank.UnitsKills.HasValue) { //historia ubitych jednostek var histKills = new DBUnitsKillsHistory(); histKills.PlayerName = dbRank.PlayerName; histKills.Rank = dbRank.UnitsKillsRank.Value; histKills.Score = dbRank.UnitsKills.Value; histKills.CreateDT = dbRank.UpdateDT; Session.SaveOrUpdate(histKills); //odczytuję historię ostanich 3 pomiarów do obliczenia średniego przyrostu var last3Rows = m_KilsHistCache .Where(x => x.PlayerName == dbRank.PlayerName) .OrderByDescending(x => x.CreateDT) .ToList(); if (last3Rows.Count > 0) { dbRank.UnitsKillsDiffAvg = (last3Rows.Max(x => x.Score) - last3Rows.Min(x => x.Score)) / last3Rows.Count; } else { dbRank.UnitsKillsDiffAvg = 0; } } if (currentRank.DefReputation.HasValue) { //historia chwały w obronie var hist = new DBDefReputationHistory(); hist.PlayerName = dbRank.PlayerName; hist.Rank = dbRank.DefReputationRank.Value; hist.Score = dbRank.DefReputation.Value; hist.CreateDT = dbRank.UpdateDT; Session.SaveOrUpdate(hist); //odczytuję historię ostanich 3 pomiarów do obliczenia średniego przyrostu var last3Rows = m_DefHistCache .Where(x => x.PlayerName == dbRank.PlayerName) .OrderByDescending(x => x.CreateDT) .ToList(); if (last3Rows.Count > 0) { dbRank.DefReputationDiffAvg = (last3Rows.Max(x => x.Score) - last3Rows.Min(x => x.Score)) / last3Rows.Count; } else { dbRank.DefReputationDiffAvg = 0; } } if (currentRank.OffReputation.HasValue) { //historia chwały w ataku var hist = new DBOffReputationHistory(); hist.PlayerName = dbRank.PlayerName; hist.Rank = dbRank.OffReputationRank.Value; hist.Score = dbRank.OffReputation.Value; hist.CreateDT = dbRank.UpdateDT; Session.SaveOrUpdate(hist); //odczytuję historię ostanich 3 pomiarów do obliczenia średniego przyrostu var last3Rows = m_OffHistCache .Where(x => x.PlayerName == dbRank.PlayerName) .OrderByDescending(x => x.CreateDT) .ToList(); if (last3Rows.Count > 0) { dbRank.OffReputationDiffAvg = (last3Rows.Max(x => x.Score) - last3Rows.Min(x => x.Score)) / last3Rows.Count; } else { dbRank.OffReputationDiffAvg = 0; } } if (currentRank.Caverns.HasValue) { //historia lochów var histCav = new DBCavernsHistory(); histCav.PlayerName = dbRank.PlayerName; histCav.Rank = dbRank.CavernsRank.Value; histCav.Score = dbRank.Caverns.Value; histCav.CreateDT = dbRank.UpdateDT; Session.SaveOrUpdate(histCav); } //tutaj bo wyżej jeszcze średnią wyliczam... Session.SaveOrUpdate(dbRank); }