Last active
January 15, 2016 13:58
-
-
Save altrive/7251658 to your computer and use it in GitHub Desktop.
Create chart, Github PowerShell repository created by month.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop" | |
| function Main | |
| { | |
| $list = New-Object Collections.ArrayList | |
| foreach ($year in 2010..2013) | |
| { | |
| foreach ($month in 1..12) | |
| { | |
| $date = New-Object DateTime($year, $month, 1) | |
| $filter = $date.ToString('yyyy-MM-dd') | |
| $results = Find-GitHubRepository -Filter "language:powershell+created:<=$filter&sort=stars" -Verbose | |
| Write-Host ("{0}: {1}" -f $date.ToString('yyyy/MM'), $results.total_count) | |
| $list.Add([pscustomobject] @{ | |
| Date = $date | |
| Count = $results.total_count | |
| }) | Out-Null | |
| } | |
| } | |
| #Remove 2013/12 entry | |
| #$list.RemoveAt($list.Count-1) | |
| #Show chart | |
| Show-Chart -Data $list | |
| } | |
| function Show-Chart | |
| { | |
| param ( | |
| $Data | |
| ) | |
| Add-Type -AssemblyName System.Windows.Forms | |
| Add-Type -AssemblyName System.Windows.Forms.DataVisualization | |
| $chart = New-Object System.Windows.Forms.DataVisualization.Charting.Chart | |
| $chart.Anchor = [Windows.Forms.AnchorStyles]::Bottom -bor [Windows.Forms.AnchorStyles]::Right -bor [Windows.Forms.AnchorStyles]::Top -bor [Windows.Forms.AnchorStyles]::Left | |
| $chart.AutoSize = $true | |
| $chart.Width = 500 | |
| $chart.Height = 400 | |
| $chartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea | |
| $chartArea.Name = "Default" | |
| $chart.ChartAreas.Add($chartArea) | |
| $series1 = $chart.Series.Add("Series1") | |
| $series2 = $chart.Series.Add("Series2") | |
| [int] $valLastMonth = 0 | |
| foreach ($item in $Data) | |
| { | |
| $series1.Points.AddXY($item.Date, $item.Count) > $null | |
| $diff = $item.Count - $valLastMonth | |
| $series2.Points.AddXY($item.Date, $diff) > $null | |
| $valLastMonth = $item.Count | |
| } | |
| $series1.ChartType = [Windows.Forms.DataVisualization.Charting.SeriesChartType]::Line; | |
| $series2.ChartType = [Windows.Forms.DataVisualization.Charting.SeriesChartType]::Spline; | |
| $series1.IsValueShownAsLabel = $true; | |
| $series2.IsValueShownAsLabel = $true; | |
| $chart.ChartAreas["Default"].AxisX.IsMarginVisible = $true; | |
| #$chart.ChartAreas["Default"].Area3DStyle.Enable3D = $true; | |
| # display the chart | |
| $Form = New-Object Windows.Forms.Form | |
| $Form.Text = "PowerShell Chart" | |
| $Form.Width = 600 | |
| $Form.Height = 600 | |
| $Form.controls.add($chart) | |
| $Form.Add_Shown({ $Form.Activate()}) | |
| $Form.ShowDialog() | |
| } | |
| function Find-GitHubRepository | |
| { | |
| [CmdletBinding()] | |
| param ( | |
| [string] $Filter | |
| ) | |
| $ErrorActionPreference = "Stop" | |
| $requestUrl = "https://api.github.com/search/repositories?q={0}&page=1&per_page=1" -f $Filter | |
| while ($true){ | |
| try { | |
| $results = Invoke-RestMethod -Method Get -Uri $requestUrl -UserAgent "Find-GitHubRepository-App" -Headers @{ Accept = "application/vnd.github.v3+json" } -Verbose:$false -ErrorAction Ignore | |
| break | |
| } | |
| catch { | |
| $ex = $_ | |
| sleep 10 | |
| } | |
| } | |
| return $results | |
| } | |
| . Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment