From e5f7529ed89cc7dfa9c8285e116ce417935823f4 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 17 Oct 2019 22:04:05 +0100 Subject: [PATCH] update github notebook --- .../csharp/Samples/Repo Statistics.ipynb | 318 +++++++++++++++--- 1 file changed, 274 insertions(+), 44 deletions(-) diff --git a/NotebookExamples/csharp/Samples/Repo Statistics.ipynb b/NotebookExamples/csharp/Samples/Repo Statistics.ipynb index 59d9dcfb7..a1e2034de 100644 --- a/NotebookExamples/csharp/Samples/Repo Statistics.ipynb +++ b/NotebookExamples/csharp/Samples/Repo Statistics.ipynb @@ -9,13 +9,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "Attempting to install package Octokit, version 0.32.0.........................................................done!" + "Installing package Octokit, version 0.32.0.done!" ] }, "metadata": {}, @@ -33,7 +33,7 @@ { "data": { "text/html": [ - "Attempting to install package NodaTime, version 2.4.6...............done!" + "Installing package NodaTime, version 2.4.6.done!" ] }, "metadata": {}, @@ -58,9 +58,34 @@ "using XPlot.Plotly;" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## setup\n", + "Creating GitHub public api client" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [], + "source": [ + "var options = new ApiOptions();\n", + "var gitHubClient = new GitHubClient(new ProductHeaderValue(\"notebook\"));" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create check points for today, start of current month and start of current year" + ] + }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 72, "metadata": {}, "outputs": [], "source": [ @@ -70,18 +95,18 @@ ] }, { - "cell_type": "code", - "execution_count": 3, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "var options = new ApiOptions();\n", - "var gitHubClient = new GitHubClient(new ProductHeaderValue(\"notebook\"));" + "Querying Github for\n", + "* issues crate this month\n", + "* issued closed this month\n", + "* all issues for this year" ] }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 73, "metadata": {}, "outputs": [], "source": [ @@ -102,9 +127,16 @@ " };" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Pulling data via GitHub api" + ] + }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 74, "metadata": {}, "outputs": [], "source": [ @@ -113,37 +145,69 @@ "var thisYearIssues = await gitHubClient.Issue.GetAllForRepository(\"dotnet\", \"try\", thisYearIssuesRequest);" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Grouping open and closed issues by month" + ] + }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 75, "metadata": {}, "outputs": [], "source": [ - "var openSoFar = createdThisMonth.OrderBy(i => i.CreatedAt).Where(i => i.State.StringValue == \"open\");\n", - "var openByMonth = openSoFar.GroupBy(i => new { i.CreatedAt.Year, i.CreatedAt.Month})\n", - " .Select(g => new {Date = g.Key, Count = g.Count()});\n", - "var closedSoFar = thisYearIssues.OrderBy(i => i.CreatedAt).Where(i => i.State.StringValue == \"closed\");\n", - "var closedByMonth = closedSoFar.GroupBy(i => new { i.ClosedAt.Value.Year, i.ClosedAt.Value.Month})\n", - " .Select(g => new {Date = g.Key, Count = g.Count()});" + "var openSoFar = createdThisMonth.OrderBy(i => i.CreatedAt).Where(i => i.State.StringValue == \"open\").ToArray();\n", + "var openByMonthOfCreation = openSoFar.GroupBy(i => new { i.CreatedAt.Year, i.CreatedAt.Month})\n", + " .Select(g => new {Date = g.Key, Count = g.Count()}).ToArray();\n", + "\n", + "var closedSoFar = thisYearIssues.OrderBy(i => i.CreatedAt).Where(i => i.State.StringValue == \"closed\").ToArray();\n", + "var closedByMonthOfClosure = closedSoFar.GroupBy(i => new { i.ClosedAt.Value.Year, i.ClosedAt.Value.Month})\n", + " .Select(g => new {Date = g.Key, Count = g.Count()}).ToArray();\n", + "var totalOpenIssues = thisYearIssues.Count();\n", + "var openCountByMonth = closedSoFar.GroupBy(i => new { i.CreatedAt.Year, i.CreatedAt.Month})\n", + " .Select(g => {\n", + " var count = g.Count(); \n", + " var dataPoint = new {Date = g.Key, Count = totalOpenIssues};\n", + " totalOpenIssues -= count;\n", + " return dataPoint;\n", + " }).ToArray();" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Showing issues open this month grouped by day" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 76, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var idleByMonth = openSoFar.Where( i => i.Comments == 0).GroupBy(i => new DateTime( i.CreatedAt.Year, i.CreatedAt.Month, 1))\n", + " .Select(g => new {Date = g.Key, Count = g.Count()}).ToArray();\n", + "var activeByMonth = openSoFar.Where( i => i.Comments > 0).GroupBy(i => new DateTime( i.CreatedAt.Year, i.CreatedAt.Month, 1))\n", + " .Select(g => new {Date = g.Key, Count = g.Count()}).ToArray();\n", + "\n", + "var idleSeries = new Graph.Scatter\n", + "{\n", + " name = \"Idle\",\n", + " y = idleByMonth.Select(g => g.Count ).ToArray(),\n", + " x = idleByMonth.Select(g => g.Date ).ToArray()\n", + "};\n", + "\n", + "var activeSeries = new Graph.Scatter\n", + "{\n", + " name = \"Active\",\n", + " y = activeByMonth.Select(g => g.Count ).ToArray(),\n", + " x = activeByMonth.Select(g => g.Date ).ToArray()\n", + "};\n", + "\n", + "\n", + "var chart = Chart.Plot(new[] {idleSeries, activeSeries});\n", + "chart.WithTitle(\"Idle and eactive open issue report\");\n", + "display(chart);" + ] + }, + { + "cell_type": "code", + "execution_count": 80, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "var forkCreateByMonth = forks.GroupBy(f => new DateTime(f.CreatedAt.Year, f.CreatedAt.Month, f.CreatedAt.Day) ).Select(g => new {Date = g.Key, Count = g.Count()}).OrderBy(g => g.Date).ToArray();\n", + "var forkLastUpdateByMonth = forks.GroupBy(f => new DateTime(f.UpdatedAt.Year, f.UpdatedAt.Month, f.UpdatedAt.Day) ).Select(g => new {Date = g.Key, Count = g.Count()}).OrderBy(g => g.Date).ToArray();\n", + "\n", + "var total = 0;\n", + "var forkCountByMonth = forkCreateByMonth.OrderBy(g => g.Date).Select(g => new {g.Date, Count = total += g.Count}).ToArray();\n", + "\n", + "var forkCreationSeries = new Graph.Scatter\n", + "{\n", + " name = \"created by month\",\n", + " y = forkCreateByMonth.Select(g => g.Count ).ToArray(),\n", + " x = forkCreateByMonth.Select(g => g.Date ).ToArray()\n", + "};\n", + "\n", + "var forkTotalSeries = new Graph.Scatter\n", + "{\n", + " name = \"running total\",\n", + " y = forkCountByMonth.Select(g => g.Count ).ToArray(),\n", + " x = forkCountByMonth.Select(g => g.Date ).ToArray()\n", + "};\n", + "\n", + "var forkUpdateSeries = new Graph.Scatter\n", + "{\n", + " name = \"last update by month\",\n", + " y = forkLastUpdateByMonth.Select(g => g.Count ).ToArray(),\n", + " x = forkLastUpdateByMonth.Select(g => g.Date ).ToArray()\n", + "};\n", + "\n", + "\n", + "\n", + "var chart = Chart.Plot(new[] {forkCreationSeries,forkTotalSeries,forkUpdateSeries});\n", + "chart.WithTitle(\"Fork activity\");\n", "display(chart);" ] } @@ -310,7 +540,7 @@ "mimetype": "text/x-csharp", "name": "C#", "pygments_lexer": "csharp", - "version": "7.3" + "version": "8.0" } }, "nbformat": 4,