Skip to content

Instantly share code, notes, and snippets.

@psipaylo
Forked from zntfdr/firebase-iOS-breakdown.swift
Last active January 5, 2024 10:59
Show Gist options
  • Save psipaylo/0ddb7b6427403cf87c0aeac5a1c0f1ba to your computer and use it in GitHub Desktop.
Save psipaylo/0ddb7b6427403cf87c0aeac5a1c0f1ba to your computer and use it in GitHub Desktop.
Firebase OS Version breakdown
// 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)%")
}
@larryonoff
Copy link

larryonoff commented Jan 5, 2024

сделал UP скрипта

// 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 usersByMajorVersion = data
  .split(whereSeparator: \.isNewline)
  .reduce(into: [String: Int]()) { result, line in
    let majorVersion: String = String(line.split(separator: ".").first!).lowercased()
    let usersCount = Int(line.split(separator: " ").last!)!
    result[majorVersion, default: 0] += usersCount
  }

let totalUsersCount: Int = usersByMajorVersion.values.reduce(into: Int(0), +=)

let usersPercentageByMajorVersion = usersByMajorVersion
  .reduce(into: [String: Double]()) { result, versionPair in
    result[versionPair.key] = Double(versionPair.value) / Double(totalUsersCount) * Double(100)
  }
  .sorted { lhs, rhs in lhs.value > rhs.value }

let result = usersPercentageByMajorVersion.reduce(into: "") { result, versionPair in
  let percents = String(format: "%.2f%%", versionPair.value)
  result += "\(versionPair.key): \(percents)\n"
}

print("users percentage by major OS version\n\(result)")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment