public override void PublishWebReports()
        {
            var reportName = string.Format(@"{0}\Index.html", DestinationFolder);


            var lastStatusDate = VirusTrackerItems.Select(item => item.StatusDate.ToShortDateString())
                                 .Distinct()
                                 .OrderBy(item => DateTime.Parse(item))
                                 .Last();

            var allCountries = VirusTrackerItems.Select(item => item.Country).Distinct().ToList();

            var consolidatedTrackerItems = allCountries.Select(country => new {
                Country    = country,
                StatusDate = lastStatusDate,
                Infections = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == lastStatusDate && item.Country == country).Sum(item => item.Infections),
                Deaths     = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == lastStatusDate && item.Country == country).Sum(item => item.Deaths),
                Recovery   = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == lastStatusDate && item.Country == country).Sum(item => item.Recovery)
            });

            var template = File.ReadAllText(@"Templates\LandingPage.txt");

            var countryData = consolidatedTrackerItems
                              .Where(item => item.Infections > 0)
                              .OrderByDescending(item => item.Infections)
                              .Aggregate(string.Empty, (curr, next) => curr + string.Format("<tr><td><a href='{0}-Page.html'>{0}</a></td><td>{1}</td><td>{2}</td><td>{3}</td></tr>", next.Country, next.Infections, next.Deaths, next.Recovery));

            template = template.Replace("ALLCOUNTRIESDATAGOESHERE", countryData);

            template = template.Replace("LASTUPDATEDDATE", lastStatusDate);

            File.WriteAllText(reportName, template);
        }
        public override void PublishWebReports()
        {
            ValidateInputs();


            var distinctStatesOrProvinces = VirusTrackerItems.Where(item => item.Country == Country)
                                            .Select(item => item.ProvinceOrState)
                                            .Distinct()
                                            .Where(provinceOrState => provinceOrState.Trim() != string.Empty)
                                            .ToList();

            if (!distinctStatesOrProvinces.Any())
            {
                return;
            }

            var consolidatedTrackerItems = distinctStatesOrProvinces.Select(state => new {
                Country         = Country,
                ProvinceOrState = state,
                Infections      = VirusTrackerItems.Where(item => item.Country == Country && item.ProvinceOrState == state).Last().Infections,
                Deaths          = VirusTrackerItems.Where(item => item.Country == Country && item.ProvinceOrState == state).Last().Deaths,
                Recovery        = VirusTrackerItems.Where(item => item.Country == Country && item.ProvinceOrState == state).Last().Recovery
            }).ToList();

            var reportName = string.Format(@"{0}\{1}-States.html", DestinationFolder, Country);

            var template = File.ReadAllText(@"Templates\ProvinceOrStatesLandingPage.txt");

            var countryData = consolidatedTrackerItems
                              .Where(item => item.Infections > 0)
                              .OrderByDescending(item => item.Infections)
                              .Aggregate(string.Empty, (curr, next) => curr + string.Format("<tr><td><a href='{0}-{1}-Page.html'>{1}</a></td><td>{2}</td><td>{3}</td><td>{4}</td></tr>", Country, next.ProvinceOrState, next.Infections, next.Deaths, next.Recovery));


            template = template.Replace("ALLPROVINCEORSTATEDATAGOESHERE", countryData);

            template = template.Replace("COUNTRYNAMEGOESHERE", Country);

            template = template.Replace("LASTUPDATEDDATE", VirusTrackerItems.Last().StatusDate.ToShortDateString());


            File.WriteAllText(reportName, template);
        }
        public override void PublishWebReports()
        {
            ValidateInputs();

            var distinctStatesOrProvinces = VirusTrackerItems.Where(item => item.Country == Country)
                                            .Select(item => item.ProvinceOrState)
                                            .Distinct()
                                            .Where(provinceOrState => provinceOrState.Trim() != string.Empty)
                                            .ToList();

            if (!distinctStatesOrProvinces.Any())
            {
                return;
            }

            var hasStatesOrProvinceDate = VirusTrackerItems.Select(item => item.ProvinceOrState)
                                          .Any(state => !string.IsNullOrEmpty(state.Trim()));

            Parallel.ForEach(distinctStatesOrProvinces, provinceOrState =>
            {
                var reportName = string.Format(@"{0}\{1}-{2}-Page.html", DestinationFolder, Country, provinceOrState);

                var distinctDates = VirusTrackerItems.Where(item => item.ProvinceOrState == provinceOrState)
                                    .Select(item => item.StatusDate.ToShortDateString())
                                    .Distinct()
                                    .OrderBy(item => DateTime.Parse(item))
                                    .ToList();


                var consolidatedTrackerItems = distinctDates.Select(statusDate => new {
                    Country         = Country,
                    ProvinceOrState = provinceOrState,
                    StatusDate      = statusDate,
                    Infections      = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.ProvinceOrState == provinceOrState).Sum(item => item.Infections),
                    Deaths          = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.ProvinceOrState == provinceOrState).Sum(item => item.Deaths),
                    Recovery        = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.ProvinceOrState == provinceOrState).Sum(item => item.Recovery)
                }).ToList();

                //If there are no Infections in a province or state don't produce the report
                if (consolidatedTrackerItems.Last().Infections == 0)
                {
                    return;
                }

                var template = File.ReadAllText(@"Templates\ProvinceOrStatePage.txt");

                var chartTitle = string.Format("COVID-19 Infections, Deaths & Recovery - {0}-{1}", Country, provinceOrState);

                var chartData = consolidatedTrackerItems.Aggregate("['Date', 'Infections','Deaths','Recovery']", (curr, next) => curr + "," + "['" + DateTime.Parse(next.StatusDate).ToString("MM/dd") + "'," + next.Infections + "," + next.Deaths + "," + next.Recovery + "]");

                var deathProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().Deaths / (double)consolidatedTrackerItems.Last().Infections) * 100);

                var recoveryProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().Recovery / (double)consolidatedTrackerItems.Last().Infections) * 100);

                template = template.Replace("STATENAMEGOESHERE", provinceOrState);

                template = template.Replace("COUNTRYNAMEGOESHERE", Country);

                template = template.Replace("CHARTTITLEGOESHERE", chartTitle);

                template = template.Replace("CHARTDATAGOESHERE", chartData);

                template = template.Replace("TOTALINFECTIONS", consolidatedTrackerItems.Last().Infections.ToString());

                template = template.Replace("TOTALDEATHS", consolidatedTrackerItems.Last().Deaths.ToString());

                template = template.Replace("TOTALRECOVERIES", consolidatedTrackerItems.Last().Recovery.ToString());

                template = template.Replace("DEATHPROGRESSBARWIDTH", deathProgressBarWidth.ToString());

                template = template.Replace("RECOVERYPROGRESSBARWIDTH", recoveryProgressBarWidth.ToString());

                template = template.Replace("UNDERTREATMENTPROGRESSBARWIDTH", (100 - deathProgressBarWidth).ToString());

                template = template.Replace("NONRECOVEREDPROGRESSBARWIDTH", (100 - recoveryProgressBarWidth).ToString());


                //Update or overwrite a file only if has changed
                if (!File.Exists(reportName))
                {
                    File.WriteAllText(reportName, template);
                }
                else
                {
                    var existingFileContent = File.ReadAllText(reportName);
                    if (!existingFileContent.Equals(template))
                    {
                        File.WriteAllText(reportName, template);
                    }
                }
            });
        }
예제 #4
0
        private void PublishCompareReport(string otherCountry)
        {
            var reportName = string.Format(@"{0}\{1}-{2}-Page.html", DestinationFolder, Country, otherCountry);

            var distinctDates = VirusTrackerItems
                                .Where(item => item.Country.Equals(Country))
                                .Select(item => item.StatusDate.ToShortDateString())
                                .Distinct()
                                .OrderBy(item => DateTime.Parse(item));

            var consolidatedTrackerItems = distinctDates.Select(statusDate => new {
                Country                = Country,
                StatusDate             = statusDate,
                Infections             = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country == Country).Sum(item => item.Infections),
                Deaths                 = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country == Country).Sum(item => item.Deaths),
                Recovery               = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country == Country).Sum(item => item.Recovery),
                OtherCountryInfections = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country == otherCountry).Sum(item => item.Infections),
                OtherCountryDeaths     = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country == otherCountry).Sum(item => item.Deaths),
                OtherCountryRecovery   = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country == otherCountry).Sum(item => item.Recovery)
            });

            //Create the Filesonly if the number of infections is more than zero
            if (consolidatedTrackerItems.Last().Deaths == 0)
            {
                return;
            }

            var template = File.ReadAllText(@"Templates\ComparePageTemplate.txt");

            var infectionsTitle = string.Format("COVID-19 Infections - {0} & {1}", Country, otherCountry);

            var deathsTitle = string.Format("COVID-19 Deaths - {0} & {1}", Country, otherCountry);

            var recoveryTitle = string.Format("COVID-19 Recovery - {0} & {1}", Country, otherCountry);


            var infectionsChartData = consolidatedTrackerItems.Aggregate(string.Format("['Date', '{0} Infections','{1} Infections']", Country, otherCountry), (curr, next) => curr + "," + "['" + DateTime.Parse(next.StatusDate).ToString("MM/dd") + "'," + next.Infections + "," + next.OtherCountryInfections + "]");

            var deathsChartData = consolidatedTrackerItems.Aggregate(string.Format("['Date', '{0} Deaths','{1} Deaths']", Country, otherCountry), (curr, next) => curr + "," + "['" + DateTime.Parse(next.StatusDate).ToString("MM/dd") + "'," + next.Deaths + "," + next.OtherCountryDeaths + "]");

            var recoveryChartData = consolidatedTrackerItems.Aggregate(string.Format("['Date', '{0} Recovery','{1} Recovery']", Country, otherCountry), (curr, next) => curr + "," + "['" + DateTime.Parse(next.StatusDate).ToString("MM/dd") + "'," + next.Recovery + "," + next.OtherCountryRecovery + "]");

            var infectionProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().OtherCountryInfections / (double)consolidatedTrackerItems.Last().Infections) * 100);

            var deathsProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().OtherCountryDeaths / (double)consolidatedTrackerItems.Last().Deaths) * 100);

            var recoveryProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().OtherCountryRecovery / (double)consolidatedTrackerItems.Last().Recovery) * 100);

            template = template.Replace("INFECTIONTITLEGOESHERE", infectionsTitle);

            template = template.Replace("DEATHSTITLEGOESHERE", deathsTitle);

            template = template.Replace("RECOVERYTITLEGOESHERE", recoveryTitle);

            template = template.Replace("COUNTRYNAME", Country);

            template = template.Replace("COMPARETOCOUNTRY", otherCountry);

            template = template.Replace("COUNTRYPAGE", string.Format("{0}-Page.html", Country));

            template = template.Replace("INFECTIONDATAGOESHERE", infectionsChartData);

            template = template.Replace("DEATHSDATAGOESHERE", deathsChartData);

            template = template.Replace("RECOVERYDATAGOESHERE", recoveryChartData);


            template = template.Replace("TOTALINFECTIONS", string.Format("{0} - {1}", Country, consolidatedTrackerItems.Last().Infections.ToString()));
            template = template.Replace("OTHERCOUNTRYINFECTIONS", string.Format("{0} - {1}", otherCountry, consolidatedTrackerItems.Last().OtherCountryInfections.ToString()));

            template = template.Replace("TOTALDEATHS", string.Format("{0} - {1}", Country, consolidatedTrackerItems.Last().Deaths.ToString()));
            template = template.Replace("OTHERCOUNTRYDEATHS", string.Format("{0} - {1}", otherCountry, consolidatedTrackerItems.Last().OtherCountryDeaths.ToString()));

            template = template.Replace("TOTALRECOVERIES", string.Format("{0} - {1}", Country, consolidatedTrackerItems.Last().Recovery.ToString()));
            template = template.Replace("OTHERCOUNTRYRECOVERIES", string.Format("{0} - {1}", otherCountry, consolidatedTrackerItems.Last().OtherCountryRecovery.ToString()));

            template = template.Replace("INFECTIONSPROGRESSBARWIDTH", infectionProgressBarWidth.ToString());

            template = template.Replace("DEATHSPROGRESSBARWIDTH", deathsProgressBarWidth.ToString());

            template = template.Replace("RECOVERYPROGRESSBARWIDTH", recoveryProgressBarWidth.ToString());

            //Update or overwrite a file only if has changed
            if (!File.Exists(reportName))
            {
                File.WriteAllText(reportName, template);
            }
            else
            {
                var existingFileContent = File.ReadAllText(reportName);

                if (!existingFileContent.Equals(template))
                {
                    File.WriteAllText(reportName, template);
                }
            }
        }
예제 #5
0
        public override void PublishWebReports()
        {
            ValidateInputs();

            var distinctDates = VirusTrackerItems
                                .Where(item => item.Country.Equals(Country))
                                .Select(item => item.StatusDate.ToShortDateString())
                                .Distinct()
                                .OrderBy(item => DateTime.Parse(item));

            var consolidatedTrackerItems = distinctDates.Select(statusDate => new {
                Country    = Country,
                StatusDate = statusDate,
                Infections = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country.Equals(Country)).Sum(item => item.Infections),
                Deaths     = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country.Equals(Country)).Sum(item => item.Deaths),
                Recovery   = VirusTrackerItems.Where(item => item.StatusDate.ToShortDateString() == statusDate && item.Country.Equals(Country)).Sum(item => item.Recovery)
            });

            //If there are no Deaths in a country don't produce the report
            if (consolidatedTrackerItems.Last().Deaths == 0)
            {
                return;
            }

            var template = File.ReadAllText(@"Templates\CountryPageTemplate.txt");

            var deathProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().Deaths / (double)consolidatedTrackerItems.Last().Infections) * 100);

            var recoveryProgressBarWidth = Math.Round(((double)consolidatedTrackerItems.Last().Recovery / (double)consolidatedTrackerItems.Last().Infections) * 100);

            var chartData = consolidatedTrackerItems.Aggregate("['Date', 'Infections','Deaths','Recovery']", (curr, next) => curr + "," + "['" + DateTime.Parse(next.StatusDate).ToString("MM/dd") + "'," + next.Infections + "," + next.Deaths + "," + next.Recovery + "]");

            var otherCountriesList = OtherCountries.Aggregate(new StringBuilder(), (curr, next) => curr.AppendLine(string.Format("<a class=\"dropdown-item\" href=\"{0}-Page.html\">{0}</a>", next)));

            template = template.Replace("COUNTRYNAMEGOESHERE", Country);

            template = template.Replace("CHARTTITLEGOESHERE", ChartsTitle);

            template = template.Replace("CHARTDATAGOESHERE", chartData);

            template = template.Replace("TOTALINFECTIONS", consolidatedTrackerItems.Last().Infections.ToString());

            template = template.Replace("TOTALDEATHS", consolidatedTrackerItems.Last().Deaths.ToString());

            template = template.Replace("TOTALRECOVERIES", consolidatedTrackerItems.Last().Recovery.ToString());

            template = template.Replace("OTHERCOUNTRIESLIST", otherCountriesList.ToString());

            template = template.Replace("DEATHPROGRESSBARWIDTH", deathProgressBarWidth.ToString());

            template = template.Replace("RECOVERYPROGRESSBARWIDTH", recoveryProgressBarWidth.ToString());

            template = template.Replace("UNDERTREATMENTPROGRESSBARWIDTH", (100 - deathProgressBarWidth).ToString());

            template = template.Replace("NONRECOVEREDPROGRESSBARWIDTH", (100 - recoveryProgressBarWidth).ToString());


            if (!HasProviceOrStatesData)
            {
                template = template.Replace("PROVINCEORSTATEBUTTONSTATE", "disabled");

                template = template.Replace("NOSTATESDATETOOLTIP", "title=\"States or Province Data Not Avaialable\"");

                template = template.Replace("STATESLANDINGPAGELINK", "onclick=\"alert('States or Province Data Not Avaialable')\"");
            }
            else
            {
                template = template.Replace("PROVINCEORSTATEBUTTONSTATE", string.Empty);

                template = template.Replace("NOSTATESDATETOOLTIP", string.Empty);

                template = template.Replace("STATESLANDINGPAGELINK", string.Format("href='{0}-States.html'", Country));
            }

            //Update or overwrite a file only if has changed
            if (!File.Exists(ReportName))
            {
                File.WriteAllText(ReportName, template);
            }
            else
            {
                var existingFileContent = File.ReadAllText(ReportName);

                if (!existingFileContent.Equals(template))
                {
                    File.WriteAllText(ReportName, template);
                }
            }
        }