protected override async Task FinalizeJob(ScheduledJob job) { foreach (var indicator in _indicators) { var indicatorResults = await GetIntermediateResults(job.JobId, indicator.IndicatorId); var calculator = _calculatorFactory.Create(indicator); indicatorResults = calculator.Combine(indicatorResults); await _globalIndicatorService.Save(new GlobalIndicator { SectorId = 0, IndicatorId = indicator.IndicatorId, Values = indicatorResults, StartDate = indicatorResults.Last().Date, EndDate = indicatorResults.First().Date, CalculatedSuccessful = true, CompanyCount = Total, LastCalculated = DateTime.UtcNow }); await ClearIntermediateResults(job.JobId, indicator.IndicatorId); } }
public void Start() { var log = new Logger(); try { var indicators = _indicatorService.GetGlobalIndicators(); var findRequest = new FindCompaniesForJobRequest() { JobId = Guid.NewGuid().ToString(), MaxRecordCount = 10, SectorId = 0 }; var companies = _companyService.FindCompaniesForJob(findRequest); var sectorResult = new GlobalIndicatorResults(0); while (companies != null && companies.Any()) { foreach (var company in companies) { foreach (var indicator in indicators) { var result = CalculateIndicators(company, indicator); sectorResult.Add(result, indicator, company.Ticker); } log.Info($"Processed {company.Ticker}"); } _companyService.CompleteJob(new CompleteJobRequest { JobId = findRequest.JobId, Tickers = companies.Select(c => c.Ticker).ToList() }); companies = null; // _companyService.FindCompaniesForJob(findRequest); } var indicatorResults = sectorResult.IndicatorResults.Select(i => i.Value).ToList(); if (indicatorResults.Any()) { var tickers = indicatorResults.First().Select(r => r.Ticker).ToList(); foreach (var indicatorResult in indicatorResults) { var calculator = _processorFactory.Create(indicatorResult.Indicator); var result = calculator.Merge(indicatorResult); _globalIndicatorService.Save(new GlobalIndicator { SectorId = 0, //sector.SectorId, IndicatorId = indicatorResult.Indicator.IndicatorId, Values = result, StartDate = result.Last().Date, EndDate = result.First().Date, CalculatedSuccessful = true, CompanyCount = tickers.Count, LastCalculated = DateTime.UtcNow }).GetAwaiter().GetResult(); } } } catch (Exception ex) { log.Error("FindCompaniesForJob", ex); } }