-
-
Save psipaylo/0ddb7b6427403cf87c0aeac5a1c0f1ba to your computer and use it in GitHub Desktop.
Firebase OS Version breakdown
This file contains 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
// How to: | |
// 1. Go in the Firebase Analytics Dashboard | |
// 2. Filter iOS or Android Platform only | |
// 3. Scroll down to the "What is your audience like?" widget, select the `Devices` tab | |
// 4. Export the CSV data (top right corner, there's a "Download CSV" button) | |
// 5. Open the file and select the OS breakdown raw data | |
// 6. Replace the sample data in this script with your data | |
// 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 | |
""" | |
let lines = data.split { $0.isNewline } | |
var OSDictionary: [String: Int] = [:] | |
for line in lines { | |
let OSVersion: String = String(line.split(separator: ".").first!).lowercased() | |
let numberOfUsers = Int(line.split(separator: ",").last!)! | |
OSDictionary[OSVersion, default: 0] += numberOfUsers | |
} | |
let totalUsers: Int = OSDictionary.values.reduce(into: 0, { $0 += $1 }) | |
for (OSVersion, numberOfUsers) in OSDictionary { | |
let percent = String(format: "%.2f", Double(numberOfUsers) / Double(totalUsers) * Double(100)) | |
print("\(OSVersion): \(percent)%") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
сделал UP скрипта