GetDownloadsByPlatform returns download counts grouped by platform
()
| 119 | |
| 120 | // GetDownloadsByPlatform returns download counts grouped by platform |
| 121 | func (c *GitHubClient) GetDownloadsByPlatform() ([]PlatformDownloads, int64, error) { |
| 122 | releases, err := c.GetReleases() |
| 123 | if err != nil { |
| 124 | return nil, 0, err |
| 125 | } |
| 126 | |
| 127 | platformCounts := make(map[string]int64) |
| 128 | var total int64 |
| 129 | |
| 130 | for _, release := range releases { |
| 131 | for _, asset := range release.Assets { |
| 132 | platform := extractPlatform(asset.Name) |
| 133 | platformCounts[platform] += asset.DownloadCount |
| 134 | total += asset.DownloadCount |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | result := make([]PlatformDownloads, 0, len(platformCounts)) |
| 139 | for platform, downloads := range platformCounts { |
| 140 | percent := float64(0) |
| 141 | if total > 0 { |
| 142 | percent = float64(downloads) / float64(total) * 100 |
| 143 | } |
| 144 | result = append(result, PlatformDownloads{ |
| 145 | Platform: platform, |
| 146 | Downloads: downloads, |
| 147 | Percent: fmt.Sprintf("%.1f%%", percent), |
| 148 | }) |
| 149 | } |
| 150 | |
| 151 | return result, total, nil |
| 152 | } |
| 153 | |
| 154 | // ReleaseDownloads represents download stats for a release |
| 155 | type ReleaseDownloads struct { |
no test coverage detected