public void EvaluateTour(int headToHeadTourId) { var headToHeadTour = _context.HeadToHeadTours.Include(t => t.Matches).Single(t => t.HeadToHeadTourId == headToHeadTourId); var tourId = headToHeadTour.ParentTourId; var headToHeadMatches = headToHeadTour.Matches; //////////////////////////////////////////////////////////////////////////////////////////////// var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithPredictionsWithExperts() }; var tours = _context.GetLastTournamentTours(fetchStrategies); var tour = tours.Single(t => t.TourId == tourId); if (!tour.IsClosed) { throw new InvalidOperationException("Tour must be closed."); } var matches = tour.Matches; var predictionSumByExpert = GetExpertTourSums(matches); //////////////////////////////////////////////////////////////////////////////////////////////// foreach (var match in headToHeadMatches) { match.HomeGoals = (byte)predictionSumByExpert[match.HomeExpertId]; match.AwayGoals = (byte)predictionSumByExpert[match.AwayExpertId]; } _context.SaveChanges(); }
public IReadOnlyList <string> GenerateMeanPredictions(int tourId) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithPredictions() }; var tour = _context.GetTours(fetchStrategies).AsNoTracking().Single(t => t.TourId == tourId); var matches = tour.Matches; var scores = new List <string>(); foreach (var match in matches) { var homeSum = 0; var awaySum = 0; var matchNumber = matches.Count; foreach (var prediction in match.Predictions) { homeSum += PredictionEvaluator.GetHomeGoals(prediction.Value); awaySum += PredictionEvaluator.GetAwayGoals(prediction.Value); } var homeMean = homeSum / matchNumber; var awayMean = awaySum / matchNumber; scores.Add(homeMean + ":" + awayMean); } return(scores); }
public TileFetchDispatcher(ITileCache <Feature> tileCache, IFetchStrategy fetchStrategy = null, Func <TileInfo, object, Feature> fetchToFeature = null, Func <TileInfo, object> fetchGetTile = null) { _tileCache = tileCache; _fetchStrategy = fetchStrategy ?? new MinimalFetchStrategy(); _fetchToFeature = fetchToFeature ?? ToFeature; _fetchGetTile = fetchGetTile; }
public List <FootballScoreViewModel> GeneratePredictionlist(int tourId, int expertId, bool editable = false, string emptyDisplay = "-") { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithPredictionsWithExperts() }; var tour = _context.Tours .Include(t => t.Matches.Select(m => m.Predictions.Select(p => p.Expert))).Single(t => t.TourId == tourId); var mpList = tour.Matches.Select(m => new { //match-prediction list Match = m, Prediction = m.Predictions.SingleOrDefault(p => p.ExpertId == expertId) }) .ToList(); emptyDisplay = editable ? string.Empty : emptyDisplay; return(mpList .Select(mp => new FootballScoreViewModel(mp.Prediction == null ? emptyDisplay : mp.Prediction.Value, editable)) .ToList()); }
public IReadOnlyList <Tuple <string, int?> > GenerateMeanPredictionsAndWinners(int tourId) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithPredictions() }; var tour = _context.GetTours(fetchStrategies).AsNoTracking().Single(t => t.TourId == tourId); var matches = tour.Matches; var scoresAndWinners = new List <Tuple <string, int?> >(); foreach (var match in matches) { var predictionValues = match.Predictions.Select(p => p.Value); var winners = match.Predictions.Select(p => p.PlayoffWinner); var meanScore = CalculateMeanScore(predictionValues); var meanWinner = CalculateMeanPlayoffWinner(winners); if (PredictionEvaluator.GetDifference(meanScore) != 0) { meanWinner = null; } else if (meanWinner == null) { meanWinner = 1; } scoresAndWinners.Add(new Tuple <string, int?>(meanScore, meanWinner)); } return(scoresAndWinners); }
protected override IQueryable <T> GetAllQuery(IFetchStrategy <T> fetchStrategy) { var query = BaseQuery(fetchStrategy); SetTraceInfo("GetAll", query); return(query); }
public override IEnumerable <T> GetAll(IQueryOptions <T> queryOptions, IFetchStrategy <T> fetchStrategy) { return(_queryManager.ExecuteGetAll( () => GetAllQuery(queryOptions, fetchStrategy).ToList(), null, queryOptions )); }
protected override T GetQuery(TKey key, IFetchStrategy <T> fetchStrategy) { var keyBsonType = ((RepresentationSerializationOptions)BsonClassMap.LookupClassMap(typeof(T)).IdMemberMap.SerializationOptions).Representation; return(IsValidKey(key) ? BaseCollection().FindOneById(BsonTypeMapper.MapToBsonValue(key, keyBsonType)) : default(T)); }
protected override T GetQuery(TKey key, IFetchStrategy <T> fetchStrategy) { T result; _items.TryGetValue(key, out result); return(result); }
protected override IQueryable <GeoInformation> BaseQuery(IFetchStrategy <GeoInformation> fetchStrategy = null) { if (!AllItems.Any()) { LoadItems(FileNames); } return(AllItems.AsQueryable <GeoInformation>()); }
//add custom includes public Tour LoadTour(int?tourId) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithPredictionsWithExperts() }; return(_context.GetTours(fetchStrategies).Single(t => t.TourId == tourId)); }
protected IQueryable <TEntity> GetQuery(IFetchStrategy <TEntity> fetchStrategy) { if (fetchStrategy == null) { return(EntitySet); } return(fetchStrategy.IncludedNavigationPaths.Aggregate(this.All(), (current, path) => path(current))); }
public List <Tour> GetLastTournamentSchedule() { var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithHomeTeam(), new FetchToursWithMatchesWithAwayTeam() }; return(_context.GetLastTournamentTours(fetchStrategies).ToList()); }
public IReadOnlyCollection <Match> GenerateMatchlist(int tournamentId, int tourId) { var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithHomeTeam(), new FetchToursWithMatchesWithAwayTeam() }; return(_context.GetLastTournamentTours(fetchStrategies).TourById(tourId).Matches.ToList()); }
public IReadOnlyCollection <Match> GetTourSchedule(int tourId) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithHomeTeam(), new FetchMatchesWithAwayTeam() }; return(_context.GetTours(fetchStrategies).TourById(tourId).Matches); }
protected override T GetQuery(TKey key, IFetchStrategy <T> fetchStrategy) { try { return(typeof(TKey) == typeof(string) ? Session.Load <T>(key as string) : base.GetQuery(key, fetchStrategy)); } catch (ArgumentException) { return(null); } }
public TileFetcher(ITileSource tileSource, MemoryCache<Feature> memoryCache, int maxAttempts = DefaultMaxAttempts, int maxThreads = DefaultMaxThreads, IFetchStrategy strategy = null) { if (tileSource == null) throw new ArgumentException("TileProvider can not be null"); if (memoryCache == null) throw new ArgumentException("MemoryCache can not be null"); _tileSource = tileSource; _memoryCache = memoryCache; _maxAttempts = maxAttempts; _maxThreads = maxThreads; _strategy = strategy ?? new FetchStrategy(); }
public IList <FootballScoreViewModel> GenerateScorelist(int tourId, bool editable = false) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithHomeTeam(), new FetchMatchesWithAwayTeam() }; var matches = _context.GetTours(fetchStrategies).TourById(tourId).Matches; return(matches.GetScores().ToViewModels(editable).ToList()); }
private IQueryable <T> GetQuery <T>(IFetchStrategy <T> fetchStrategy) where T : class { var query = context.Set <T>().AsQueryable(); if (fetchStrategy == null) { return(query); } return(fetchStrategy.IncludePaths.Aggregate(query, (current, includePath) => current.Include(includePath))); }
protected override IQueryable <T> BaseQuery(IFetchStrategy <T> fetchStrategy = null) { var query = DbSet.AsQueryable(); if (fetchStrategy != null && fetchStrategy.NoTracking) { query = query.AsNoTracking(); } return(fetchStrategy == null ? query : fetchStrategy.IncludePaths.Aggregate(query, (current, path) => current.Include(path))); }
protected virtual Specification <T> Instanciate(Expression <Func <T, bool> > predicate, IFetchStrategy <DbSet <T> > strategy = null) { var specification = new Specification <T>(predicate); if (strategy != null) { specification.FetchStrategy = strategy; } return(specification); }
public TileFetchDispatcher( ITileCache <Feature> tileCache, ITileSchema tileSchema, Func <TileInfo, Feature> fetchTileAsFeature, IFetchStrategy fetchStrategy = null) { _tileCache = tileCache; _tileSchema = tileSchema; _fetchTileAsFeature = fetchTileAsFeature; _fetchStrategy = fetchStrategy ?? new MinimalFetchStrategy(); _fetchMachine = new FetchMachine(this); }
//optimization! looks ugly // "0" for all tours public List <ExpertDto> GenerateExpertsInfo(int tourNumber = 0) { var results = new List <ExpertDto>(); if (tourNumber == 0) { var experts = _context.Experts.ToList(); experts.ForEach(e => results.Add(new ExpertDto(e.Nickname, e.Sum, e.Scores, e.Differences, e.Outcomes))); return(results); } var fetchStrategies = new IFetchStrategy <Tournament>[] { new FetchToursWithMatchesWithPredictionsWithExperts() }; var tours = _context.GetLastTournamentTours(fetchStrategies); var matches = tours.Single(t => t.TourNumber == tourNumber) .Matches; var predictions = matches .SelectMany(m => m.Predictions) .GroupBy(p => p.Expert) .ToList(); foreach (var epGroup in predictions) { var info = new ExpertDto { Nickname = epGroup.Key.Nickname }; foreach (var prediction in epGroup) { info.Sum += prediction.Sum; if (prediction.Score) { info.Scores++; } else if (prediction.Difference) { info.Differences++; } else if (prediction.Outcome) { info.Outcomes++; } } results.Add(info); } return(results.OrderByDescending(expert => expert.Sum).ToList()); }
protected override IQueryable <T> BaseQuery(IFetchStrategy <T> fetchStrategy = null) { if (fetchStrategy != null && fetchStrategy is MongoDbFetchStrategy <T> && ((MongoDbFetchStrategy <T>)fetchStrategy).AllowDiskUse) { return(BaseCollection().AsQueryable(new AggregateOptions { AllowDiskUse = true })); } else { return(BaseCollection().AsQueryable()); } }
// we override the implementation of LinqBaseRepository because this is built in protected override T GetQuery(TKey key, IFetchStrategy <T> fetchStrategy) { var item = Client.GetDocument(key.ToString()); if (item == null) { return(null); } // this always returns an object, so check to see if the PK is null, if so then return null GetPrimaryKey(item, out TKey id); return(id == null ? null : item); }
public TileLayer(ITileSource source = null, int minTiles = 200, int maxTiles = 300, int maxRetries = TileFetcher.DefaultMaxAttempts, int maxThreads = TileFetcher.DefaultMaxThreads, IFetchStrategy fetchStrategy = null, IRenderGetStrategy renderFetchStrategy = null, int minExtraTiles = -1, int maxExtraTiles = -1) { _memoryCache = new MemoryCache<Feature>(minTiles, maxTiles); Style = new VectorStyle { Outline = { Color = Color.FromArgb(0, 0, 0, 0) } }; // initialize with transparent outline _maxRetries = maxRetries; _maxThreads = maxThreads; _fetchStrategy = fetchStrategy ?? new FetchStrategy(); _renderFetchStrategy = renderFetchStrategy ?? new RenderGetStrategy(); _minExtraTiles = minExtraTiles; _maxExtraTiles = maxExtraTiles; SetTileSource(source); }
protected IFetchStrategy <T> InstanciateFetchStrategy(IFetchStrategy <T> strategy) { var thisPaths = FetchStrategy != null ? FetchStrategy.IncludePaths : new List <string>(); var paramPaths = strategy != null ? strategy.IncludePaths : new List <string>(); var includePaths = thisPaths.Union(paramPaths); var newStrategy = new GenericFetchStrategy <T>(); foreach (var includePath in includePaths) { newStrategy.Include(includePath); } return(newStrategy); }
public TileLayer(ITileSource source = null, int minTiles = 200, int maxTiles = 300, int maxRetries = TileFetcher.DefaultMaxAttempts, int maxThreads = TileFetcher.DefaultMaxThreads, IFetchStrategy fetchStrategy = null, IRenderGetStrategy renderFetchStrategy = null, int minExtraTiles = -1, int maxExtraTiles = -1) { _memoryCache = new MemoryCache <Feature>(minTiles, maxTiles); Style = new VectorStyle { Outline = { Color = Color.FromArgb(0, 0, 0, 0) } }; // initialize with transparent outline _maxRetries = maxRetries; _maxThreads = maxThreads; _fetchStrategy = fetchStrategy ?? new FetchStrategy(); _renderFetchStrategy = renderFetchStrategy ?? new RenderGetStrategy(); _minExtraTiles = minExtraTiles; _maxExtraTiles = maxExtraTiles; SetTileSource(source); }
protected override T GetQuery(TKey key, IFetchStrategy <T> fetchStrategy) { var keyBsonType = ((StringSerializer)BsonClassMap.LookupClassMap(typeof(T)).IdMemberMap.GetSerializer()).Representation; var keyMemberName = BsonClassMap.LookupClassMap(typeof(T)).IdMemberMap.MemberName; if (IsValidKey(key)) { var keyBsonValue = BsonTypeMapper.MapToBsonValue(key, keyBsonType); var filter = Builders <T> .Filter.Eq(keyMemberName, keyBsonValue); return(BaseCollection().Find(filter).FirstOrDefault()); } else { return(default(T)); } }
public TileFetcher(ITileSource tileSource, MemoryCache <Feature> memoryCache, int maxAttempts = DefaultMaxAttempts, int maxThreads = DefaultMaxThreads, IFetchStrategy strategy = null) { if (tileSource == null) { throw new ArgumentException("TileProvider can not be null"); } if (memoryCache == null) { throw new ArgumentException("MemoryCache can not be null"); } _tileSource = tileSource; _memoryCache = memoryCache; _maxAttempts = maxAttempts; _maxThreads = maxThreads; _strategy = strategy ?? new FetchStrategy(); }
public IReadOnlyList <int?> GenerateMeanPlayoffWinners(int tourId) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithPredictions() }; var tour = _context.GetTours(fetchStrategies).AsNoTracking().Single(t => t.TourId == tourId); var matches = tour.Matches; var winners = new List <int?>(); foreach (var match in matches) { var predictionValues = match.Predictions.Select(p => p.PlayoffWinner); winners.Add(CalculateMeanPlayoffWinner(predictionValues)); } return(winners); }
public IReadOnlyList <string> GenerateMeanPredictions(int tourId) { var fetchStrategies = new IFetchStrategy <Tour>[] { new FetchMatchesWithPredictions() }; var tour = _context.GetTours(fetchStrategies).AsNoTracking().Single(t => t.TourId == tourId); var matches = tour.Matches; var scores = new List <string>(); foreach (var match in matches) { var predictionValues = match.Predictions.Select(p => p.Value); scores.Add(CalculateMeanScore(predictionValues)); } return(scores); }