Skip to content

Instantly share code, notes, and snippets.

@steipete
Forked from zntfdr/firebase-iOS-breakdown.swift
Created June 16, 2020 10:18
Show Gist options
  • Save steipete/a82cd22631e0704a51442b477bc6a625 to your computer and use it in GitHub Desktop.
Save steipete/a82cd22631e0704a51442b477bc6a625 to your computer and use it in GitHub Desktop.
Firebase iOS Version breakdown
// How to:
// 1. Go in the Firebase Analytics Dashboard
// 2. Filter iOS Platform only
// 3. Scroll down, select `Device` under the "What is your audience like?" widget
// 4. Export the CSV data (top right of the corner, there's a `...` menu with Download CSV option)
// 5. Open the file and select the iOS breakdown raw data
// 6. Replace your data with the sample data in this script
// 7. Run the script in a Xcode Playground
// 8. See the terminal output
import Foundation
var data = """
ios 13.1.3,38215
iOS 13.1.3,14333
ios 13.2.3,12667
iOS 13.2.3,9568
ios 12.4.1,8392
ios 13.2.2,6816
ios 13.1.2,6652
ios 13.2,5439
ios 12.4.2,4008
ios 12.4.3,3715
iOS 12.4.1,3111
ios 12.3.1,3021
iOS 13.1.2,2514
iOS 12.4.3,2455
ios 12.4,2119
ios 13.0,1500
ios 12.2,1225
iOS 12.3.1,1197
ios 13.1.1,1060
ios 11.4.1,965
iOS 12.4,771
ios 12.1.4,753
ios 13.1,585
iOS 13.0,559
iOS 13.2,559
iOS 13.2.2,530
iOS 12.4.2,480
ios 12.1.2,435
iOS 12.2,425
iOS 13.1.1,422
iOS 11.4.1,395
ios 13.3,340
ios 12.1,333
ios 11.4,287
iOS 12.1.4,266
ios 12.3.2,230
iOS 13.1,219
ios 12.0.1,208
ios 10.3.3,206
ios 11.3.1,200
ios 11.2.6,178
iOS 12.1.2,168
ios 10.3.4,157
ios 12.0,154
iOS 13.3,132
iOS 12.1,125
ios 11.2.1,120
ios 11.3,117
iOS 11.4,112
ios 12.3,109
ios 11.1.2,107
ios 10.2.1,103
ios 10.3.2,86
iOS 12.0.1,85
ios 11.2.5,82
iOS 11.3.1,71
iOS 10.3.3,70
ios 11.0.3,70
ios 12.1.1,69
iOS 12.0,67
ios 12.1.3,67
iOS 11.2.6,65
iOS 12.3.2,60
ios 10.1.1,48
ios 11.2,48
iOS 10.3.4,46
ios 10.2,43
iOS 11.2.1,42
iOS 11.3,42
iOS 12.3,42
ios 11.0,42
ios 11.0.2,36
ios 11.1,36
ios 11.1.1,34
ios 11.2.2,34
iOS 12.1.1,32
iOS 10.2.1,31
iOS 11.2.5,30
iOS 10.3.2,29
iOS 11.0.3,29
iOS 12.1.3,26
iOS 11.1.2,24
ios 10.3.1,24
ios 11.0.1,24
iOS 11.2,22
iOS 11.1.1,18
iOS 11.2.2,17
iOS 10.1.1,16
iOS 11.0,16
iOS 10.2,15
ios 10.0.2,15
iOS 11.1,14
iOS 11.0.2,13
iOS 10.3.1,10
ios 10.1,10
iOS 11.0.1,9
iOS 10.0.2,7
ios 10.0.1,5
ios 10.3,4
iOS 10.1,3
iOS 10.0.1,2
iOS 10.3,2
ios 10.0,2
iOS 10.0.3,1
iOS 9.3.5,1
"""
let lines = data.split { $0.isNewline }
var iOSDictionary: [String: Int] = [:]
for line in lines {
let iOSVersion: String = String(line.split(separator: ".").first!)
let numberOfUsers = Int(line.split(separator: ",").last!)!
iOSDictionary[iOSVersion, default: 0] += numberOfUsers
}
let totalUsers: Int = iOSDictionary.values.reduce(into: 0, { $0 += $1 })
print("total users: \(totalUsers)")
for (iOSVersion, numberOfUsers) in iOSDictionary.sorted(by: >) {
let percent = String(format: "%.2f", Double(numberOfUsers) / Double(totalUsers) * Double(100))
print("\(iOSVersion): \(percent)%")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment