public async Task <ProcessedPlayerCollection> process() { try { var currEvent = await(new EventFinder(_client).GetCurrentEvent()); // Get all the footballer data required var footballers = await getFootballers(); var players = footballers.Keys; var explains = await getLiveExplains(players); var provider = new ProcessedPlayerProviderV3(currEvent.id); var playerCollection = new ProcessedPlayerCollection(); foreach (var id in players) { var footballer = footballers[id]; List <FootballerScoreDetailElement> gwExplains = new List <FootballerScoreDetailElement>(); explains.TryGetValue(id, out gwExplains); var liveData = await _client.getLiveData(currEvent.id); var processor = new SinglePlayerProcessorV3(provider, currEvent.id, footballer, gwExplains, liveData); var player = await processor.process(); playerCollection.players.Add(id, player); } await provider.writeFullPlayers(playerCollection); await provider.writeApiPlayers(playerCollection); return(playerCollection); } catch (Exception ex) { _log.Error(ex); } return(await Task.FromResult((ProcessedPlayerCollection)null)); }
public async Task Init() { _bootstrap = await _client.getBootstrapStatic(); _live = await _client.getLiveData(_gameweek); _fixtures = await _client.GetFixtures(_gameweek); }
public async Task Process() { var bs = await _client.getBootstrapStatic(); var currEvent = bs.events.FirstOrDefault(ev => ev.is_current); var gw = currEvent.id; var currentLive = await _client.getLiveData(gw); var previousTimeline = await ReadPreviousTimeline(gw); var newTimeline = new GameweekTimeline(previousTimeline, currentLive.elements.Select(el => new TimelineLiveElement(el)).ToList()); // Find and log differences between previous timeline and current live var diffs = FindAllPlayerDifferences(previousTimeline, currentLive); var timestamp = DateTime.Now; var prediction = new List <TimelineLiveElement>(); var predictor = new TimelinePredictor(gw, _client); await predictor.Init(); foreach (var element in bs.elements) { var liveElementBase = currentLive.elements.FirstOrDefault(e => e.id == element.id); var liveElement = liveElementBase != null ? new TimelineLiveElement(liveElementBase) : new TimelineLiveElement() { id = element.id }; prediction.Add(await predictor.Predict(liveElement)); } newTimeline.prediction = prediction; var predictionDiff = FindAllPlayerPredictionDifferences(previousTimeline != null ? previousTimeline.prediction : new List <TimelineLiveElement>(), newTimeline.prediction); Console.WriteLine($"Diffs: {diffs.Count}"); Console.WriteLine($"PredictionDiffs: {predictionDiff.Count}"); if (diffs.Count > 0 || predictionDiff.Count > 0) { newTimeline.timeline.Add(new GameweekTimelineEntry() { timestamp = timestamp, diff = diffs, predictionDiff = predictionDiff }); await WriteTimeline(gw, newTimeline); } }
private async Task <List <Fixture> > getTodaysFixtures(Event ev) { Live liveData = await _client.getLiveData(ev.id); if (liveData == null) { return(new List <Fixture>()); } List <Fixture> retFixtures = new List <Fixture>(); foreach (var fixture in liveData.fixtures) { DateTime now = DateTime.Now; DateTime kickoff = Date.fromApiString(fixture.kickoff_time); if (kickoff.Month == now.Month && kickoff.Day == now.Day) { retFixtures.Add(fixture); } } return(retFixtures); }