From 5e51dad445d663abfb523cd209c07d74844da9c5 Mon Sep 17 00:00:00 2001 From: Marcel Wege Date: Thu, 22 Jun 2017 16:56:35 +0200 Subject: [PATCH 1/2] GitHubContributors --- .../Controllers/GitHubContributorController.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/OurUmbraco/Community/Controllers/GitHubContributorController.cs b/OurUmbraco/Community/Controllers/GitHubContributorController.cs index 14a23969..df480119 100644 --- a/OurUmbraco/Community/Controllers/GitHubContributorController.cs +++ b/OurUmbraco/Community/Controllers/GitHubContributorController.cs @@ -67,18 +67,12 @@ namespace OurUmbraco.Community.Controllers // filter to only include items from the last year var filteredRange = DateTime.UtcNow.AddYears(-1).Subtract(new DateTime(1970, 1, 1)).TotalSeconds; + var contribWeeks = contrib.Weeks.Where(x => x.W >= filteredRange); foreach (var contrib in gitHubContributors) { - int add = 0, del = 0, total = 0; - foreach (var wk in contrib.Weeks.Where(x => x.W >= filteredRange)) - { - add += wk.A; - del += wk.D; - total += wk.C; - } - contrib.Total = total; - contrib.TotalAdditions = add; - contrib.TotalDeletions = del; + contrib.Total = contrib.w; + contrib.TotalAdditions = contribWeeks.Sum(x=>x.A); + contrib.TotalDeletions = contribWeeks.Sum(x=>x.D); } var filteredContributors = gitHubContributors From 40a6aaa1a8fb46e51fd09cc91b2938232cc36868 Mon Sep 17 00:00:00 2001 From: Marcel Wege Date: Thu, 22 Jun 2017 17:29:57 +0200 Subject: [PATCH 2/2] foreach to Linq.SUM --- .../Community/Controllers/GitHubContributorController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OurUmbraco/Community/Controllers/GitHubContributorController.cs b/OurUmbraco/Community/Controllers/GitHubContributorController.cs index df480119..3abf80a0 100644 --- a/OurUmbraco/Community/Controllers/GitHubContributorController.cs +++ b/OurUmbraco/Community/Controllers/GitHubContributorController.cs @@ -67,12 +67,13 @@ namespace OurUmbraco.Community.Controllers // filter to only include items from the last year var filteredRange = DateTime.UtcNow.AddYears(-1).Subtract(new DateTime(1970, 1, 1)).TotalSeconds; - var contribWeeks = contrib.Weeks.Where(x => x.W >= filteredRange); + foreach (var contrib in gitHubContributors) { - contrib.Total = contrib.w; + var contribWeeks = contrib.Weeks.Where(x => x.W >= filteredRange).ToList(); contrib.TotalAdditions = contribWeeks.Sum(x=>x.A); contrib.TotalDeletions = contribWeeks.Sum(x=>x.D); + contrib.Total = contrib.TotalAdditions + contrib.TotalDeletions; } var filteredContributors = gitHubContributors