static AccountSummary Convert(Account account, AccountRating rating) { AccountSummary summary = new AccountSummary { AccountGuid = account.Guid, Username = account.Username, Created = account.Created }; if (rating != null) { summary.BuyerRating = rating.BuyerRating; summary.BuyerRatingCount = rating.BuyerRatingCount; summary.LastModified = DateTime.SpecifyKind(rating.LastModified, DateTimeKind.Utc); summary.Rating = rating.Rating; summary.RatingCount = rating.RatingCount; summary.SellerRating = rating.SellerRating; summary.SellerRatingCount = rating.SellerRatingCount; summary.TotalSellTrades = rating.TotalSellTrades; summary.TotalBuyTrades = rating.TotalBuyTrades; summary.TotalTrades = rating.TotalTrades; } return(summary); }
static AccountRating CalculateRating(Guid accountGuid) { using (DatabaseContext context = new DatabaseContext()) { AccountRating rating = new AccountRating { AccountGuid = accountGuid }; var relatedReviews = (from r in context.TradeReviews where r.SellerGuid == accountGuid || r.BuyerGuid == accountGuid select r).ToList(); //get sellerRating var sellerReviews = (from r in relatedReviews where r.SellerGuid == accountGuid && r.BuyerRating > 0 select r).ToList(); rating.SellerRating = sellerReviews.Count == 0 ? 0 : Convert.ToDecimal(sellerReviews.Average(t => t.BuyerRating)); rating.SellerRatingCount = sellerReviews.Count; var buyerReviews = (from r in relatedReviews where r.BuyerGuid == accountGuid && r.SellerRating > 0 select r).ToList(); rating.BuyerRating = buyerReviews.Count == 0 ? 0 : Convert.ToDecimal(buyerReviews.Average(t => t.SellerRating)); rating.BuyerRatingCount = buyerReviews.Count; var totalSellerScore = sellerReviews.Sum(t => t.BuyerRating); var totalBuyerScore = buyerReviews.Sum(t => t.SellerRating); var totalCount = sellerReviews.Count + buyerReviews.Count; rating.Rating = totalCount == 0 ? 0 : (totalSellerScore + totalBuyerScore) / totalCount; rating.RatingCount = totalCount; rating.LastModified = relatedReviews.Max(t => t.LastModified); var totalBuyTrades = (from t in context.Trades where t.BuyerGuid == accountGuid select t).Count(); var totalSellTrades = (from t in context.Trades where t.SellerGuid == accountGuid select t).Count(); rating.TotalSellTrades = totalSellTrades; rating.TotalBuyTrades = totalBuyTrades; rating.TotalTrades = totalSellTrades + totalBuyTrades; return(rating); } }
public void SaveToDB() { lock (dbLock) { DateTime start = DateTime.Now; using (var db = new ZkDataContext()) { HashSet <int> processedPlayers = new HashSet <int>(); int deleted = 0; int added = 0; foreach (var accountRating in db.AccountRatings.Where(x => x.RatingCategory == category)) { if (!playerRatings.ContainsKey(accountRating.AccountID)) { deleted++; db.AccountRatings.DeleteOnSubmit(accountRating); continue; } processedPlayers.Add(accountRating.AccountID); if (Math.Abs(playerRatings[accountRating.AccountID].LadderElo - accountRating.LadderElo ?? 9999) > 0.5 || Math.Abs(playerRatings[accountRating.AccountID].RealElo - accountRating.RealElo) > 0.5 || accountRating.IsRanked != (playerRatings[accountRating.AccountID].Rank < int.MaxValue)) { accountRating.UpdateFromRatingSystem(playerRatings[accountRating.AccountID]); } } foreach (int player in playerRatings.Keys) { if (!processedPlayers.Contains(player)) { var accountRating = new AccountRating(player, category); accountRating.UpdateFromRatingSystem(playerRatings[player]); db.AccountRatings.InsertOnSubmit(accountRating); added++; } } db.SaveChanges(); Trace.TraceInformation("WHR " + category + " Ratings saved to DB in " + DateTime.Now.Subtract(start).TotalSeconds + " seconds, " + added + " entries added, " + deleted + " entries removed, " + (GC.GetTotalMemory(false) / (1 << 20)) + "MiB total memory allocated"); } } }
public void SaveToDB(IEnumerable <int> players) { lock (dbLock) { using (var db = new ZkDataContext()) { foreach (int player in players) { var accountRating = db.AccountRatings.Where(x => x.RatingCategory == category && (x.AccountID) == player).FirstOrDefault(); if (accountRating == null) { accountRating = new AccountRating(player, category); accountRating.UpdateFromRatingSystem(playerRatings[player]); db.AccountRatings.InsertOnSubmit(accountRating); } else { accountRating.UpdateFromRatingSystem(playerRatings[player]); } } db.SaveChanges(); } } }
public UserPost GetUserPost([Parent] AccountRating rating, IResolverContext ctx) { return(_ovidDb.UserPosts.Where(m => m.PostId == rating.PostId).SingleOrDefault()); }