private void ApplyStatsToDbItems(List <PlayerHeldItem> items, StatFetch type) { var records = GetRecordsForItems(items); Dictionary <string, List <DBSTatRow> > statMap = _databaseItemStatDao.GetStats(records, type); foreach (PlayerHeldItem phi in items) { List <DBSTatRow> stats = new List <DBSTatRow>(); if (statMap.ContainsKey(phi.BaseRecord)) { stats.AddRange(Filter(statMap[phi.BaseRecord])); } var statsWithText = Filter(stats.Where(m => !string.IsNullOrEmpty(m.TextValue))); List <DBSTatRow> statsWithNumerics = stats.Where(m => string.IsNullOrEmpty(m.TextValue)) .GroupBy(r => r.Stat) .Select(g => new DBSTatRow { Record = g.FirstOrDefault()?.Record, TextValue = g.FirstOrDefault()?.TextValue, Stat = g.FirstOrDefault()?.Stat, Value = g.Sum(v => v.Value) }) .ToList(); statsWithNumerics.AddRange(statsWithText); phi.Tags = new HashSet <DBSTatRow>(statsWithNumerics); } Logger.Debug($"Applied stats to {items.Count()} items"); }
public Dictionary <string, List <DBSTatRow> > GetStats(ISession session, StatFetch fetchMode) { return(ThreadExecuter.Execute( () => repo.GetStats(session, fetchMode) )); }
public Dictionary <long, List <DBSTatRow> > GetStats(List <long> records, StatFetch fetchMode) { return(ThreadExecuter.Execute( () => repo.GetStats(records, fetchMode) )); }
public Dictionary <String, List <DBSTatRow> > GetStats(IEnumerable <string> records, StatFetch fetchMode) { using (var session = SessionCreator.OpenSession()) { return(GetStats(session, records, fetchMode)); } }
public Dictionary <String, List <DBSTatRow> > GetStats(ISession session, StatFetch fetchMode) { return(GetStats(session, new List <string>(), fetchMode)); }
private Dictionary <string, List <DBSTatRow> > GetStats(ISession session, IEnumerable <string> records, StatFetch fetchMode) { Dictionary <string, List <DBSTatRow> > statMap = new Dictionary <string, List <DBSTatRow> >(); Logger.Debug($"Fetching all stats for {records.Count()} items, fetchMode={fetchMode}"); string sql = string.Join(" ", new[] { $@"select db.{DatabaseItemTable.Record} as Record, s.stat as Stat, s.val1 as Value, s.textvalue as TextValue FROM {DatabaseItemTable.Table} db, databaseitemstat_v2 s where s.id_databaseitem = db.{DatabaseItemTable.Id}", "AND (val1 > 0 or stat in ( :whitelist ))", //"AND (val1 > 0 or NOT stat IN ( :blacklist ))", fetchMode == StatFetch.PlayerItems ? $"AND baserecord IN (SELECT record FROM playeritemrecord)" : "", fetchMode == StatFetch.BuddyItems ? $"AND {DatabaseItemTable.Record} IN (SELECT {BuddyItemRecordTable.Record} FROM {BuddyItemRecordTable.Table})" : "", fetchMode == StatFetch.RecipeItems ? $"AND baserecord in (SELECT {RecipeItemTable.Record} FROM {RecipeItemTable.Table})" : "", fetchMode == StatFetch.Skills ? $"AND db.{DatabaseItemTable.Id} IN (SELECT map.{SkillMappingTable.Item} FROM {SkillMappingTable.Table} map)" : "", // Redundant? Either doesn't cover enough, or completely redundant "AND NOT stat IN ( :blacklist )", records.Any() ? $"AND db.{DatabaseItemTable.Record} IN ( :filter )" : "" } ); IQuery query = session.CreateSQLQuery(sql) .SetParameterList("whitelist", SpecialStats) .SetParameterList("blacklist", SpecialIgnores) .SetResultTransformer(Transformers.AliasToBean <DBSTatRow>()); Logger.Debug(sql); if (records.Count() > 0) { query.SetParameterList("filter", records); //logger.Debug($":filter={String.Join(",", records)}"); } statMap[string.Empty] = new List <DBSTatRow>(); foreach (DBSTatRow row in query.List <DBSTatRow>()) { if (!statMap.ContainsKey(row.Record)) { statMap[row.Record] = new List <DBSTatRow>(); } statMap[row.Record].Add(row); } Logger.Debug($"Fetching stat for {statMap.Count} records"); #if DEBUG // If you have run into this exception, you've messed up. // This is a safety catch to detect issues with applying stats too broadly. if (statMap.Count > 10000) { throw new InvalidOperationException("Stat fetch has been done with too many items, severe performance penalties."); } #endif return(statMap); }
public Dictionary <long, List <DBSTatRow> > GetStats(List <long> records, StatFetch fetchMode) { using (var session = SessionCreator.OpenSession()) { var statMap = new Dictionary <long, List <DBSTatRow> >(); if (fetchMode != StatFetch.Skills) { throw new ArgumentException(nameof(fetchMode)); } Logger.Debug($"Fetching all stats for {records.Count} items, fetchMode={fetchMode}"); string sql = string.Join(" ", new[] { $"select db.{DatabaseItemTable.Id} as Id, db.{DatabaseItemTable.Record} as Record, s.{DatabaseItemStatTable.Stat} as Stat, s.{DatabaseItemStatTable.Value} as Value, s.{DatabaseItemStatTable.TextValue} as TextValue from {DatabaseItemTable.Table} db, {DatabaseItemStatTable.Table} s", $"where s.{DatabaseItemStatTable.Item} = db.{DatabaseItemTable.Id}", $"AND ({DatabaseItemStatTable.Value} > 0 or {DatabaseItemStatTable.Stat} in ( :whitelist ))", //$"AND db.{DatabaseItemTable.Id} IN (SELECT map.{SkillMappingTable.Item} FROM {SkillMappingTable.Table} map)", $"AND NOT {DatabaseItemStatTable.Stat} IN ( :blacklist )", records.Any() ? $"AND db.{DatabaseItemTable.Id} IN ( :filter )" : "" } ); IQuery query = session.CreateSQLQuery(sql) .SetParameterList("whitelist", SpecialStats) .SetParameterList("blacklist", SpecialIgnores) .SetResultTransformer(Transformers.AliasToBean <DBSTatRow>()); Logger.Debug(sql); if (records.Count > 0) { query.SetParameterList("filter", records); } foreach (DBSTatRow row in query.List <DBSTatRow>()) { if (!statMap.ContainsKey(row.Id)) { statMap[row.Id] = new List <DBSTatRow>(); } statMap[row.Id].Add(row); } Logger.Debug($"Fetching stat for {statMap.Count} records"); #if DEBUG // If you have run into this exception, you've messed up. // This is a safety catch to detect issues with applying stats too broadly. if (statMap.Count > 10000) { throw new InvalidOperationException( "Stat fetch has been done with too many items, severe performance penalties."); } #endif return(statMap); } }
public Dictionary <string, List <DBStatRow> > GetStats(IEnumerable <string> records, StatFetch fetchMode) { return(ThreadExecuter.Execute( () => repo.GetStats(records, fetchMode) )); }