private ApprenticeshipApplicationMetrics GetApprenticeshipApplicationMetrics()
        {
            var averageApplicationCountPerApprenticeship = _apprenticeshipMetricsRepository.GetAverageApplicationCountPerApprenticeship();
            var apprenticeshipApplicationMetrics         = new ApprenticeshipApplicationMetrics
            {
                ApprenticeshipsWithApplicationsCount = averageApplicationCountPerApprenticeship["apprenticeshipsWithApplicationsCount"].AsInt32,
                TotalApplicationsCount = averageApplicationCountPerApprenticeship["count"].AsInt32,
                AverageApplicationsPerApprenticeship = averageApplicationCountPerApprenticeship["average"].AsDouble
            };

            var applicationCountPerApprenticeship = _apprenticeshipMetricsRepository.GetApplicationCountPerApprenticeship();

            foreach (var applicationCount in applicationCountPerApprenticeship)
            {
                var vacancyId = applicationCount["_id"]["VacancyId"].AsInt32;
                var title     = applicationCount["_id"]["Title"].AsString;
                var count     = applicationCount["count"].AsInt32;

                var apprenticeshipMetrics = new ApprenticeshipMetrics
                {
                    Id               = vacancyId,
                    Title            = title,
                    ApplicationCount = count
                };

                apprenticeshipApplicationMetrics.ApprenticeshipMetrics[vacancyId] = apprenticeshipMetrics;
            }
            return(apprenticeshipApplicationMetrics);
        }
        private static void WriteApprenticeshipApplicationMetricsCsv(ApprenticeshipApplicationMetrics userApplicationMetrics, DateTime fileDateTime)
        {
            var fileName   = string.Format("ApprenticeshipApplicationMetrics_{0}.csv", fileDateTime.ToString("s").Replace(":", "-"));
            var textWriter = new StreamWriter(fileName);
            var csv        = new CsvWriter(textWriter);

            csv.WriteRecords(userApplicationMetrics.ApprenticeshipMetrics.Values);
            textWriter.Flush();
            textWriter.Close();
        }