<commit_before>//
//  AnalyticsManager.swift
//  Naterade
//
//  Created by <NAME> on 4/28/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import AmplitudeFramework


class AnalyticsManager {

    // MARK: - Helpers

    private static var amplitudeAPIKey: String? {
        if let settingsPath = NSBundle.mainBundle().pathForResource("RemoteSettings", ofType: "plist"),
            settings = NSDictionary(contentsOfFile: settingsPath)
        {
            return settings["AmplitudeAPIKey"] as? String
        }

        return nil
    }

    private static func logEvent(name: String, withProperties properties: [NSObject: AnyObject]? = nil) {
        guard amplitudeAPIKey != nil else {
            return
        }

        Amplitude.instance().logEvent(name, withEventProperties: properties)
    }

    // MARK: - UIApplicationDelegate

    static func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) {

        if let APIKey = amplitudeAPIKey {
            Amplitude.instance().initializeApiKey(APIKey)
        }
    }

    // MARK: - Screens

    static func didDisplayBolusScreen() {
        logEvent("Bolus Screen")
    }

    static func didDisplaySettingsScreen() {
        logEvent("Settings Screen")
    }

    static func didDisplayStatusScreen() {
        logEvent("Status Screen")
    }

    // MARK: - Config Events

    static func didChangeRileyLinkConnectionState() {
        logEvent("RileyLink Connection")
    }

    static func transmitterTimeDidDrift(drift: NSTimeInterval) {
        logEvent("Transmitter time change", withProperties: ["value" : drift])
    }

    static func didChangeBasalRateSchedule() {
        logEvent("Basal rate change")
    }

    static func didChangeCarbRatioSchedule() {
        logEvent("Carb ratio change")
    }

    static func didChangeInsulinActionDuration() {
        logEvent("Insulin action duration change")
    }

    static func didChangeInsulinSensitivitySchedule() {
        logEvent("Insulin sensitivity change")
    }

    static func didChangeGlucoseTargetRangeSchedule() {
        logEvent("Glucose target range change")
    }

    static func didChangeMaximumBasalRate() {
        logEvent("Maximum basal rate change")
    }

    static func didChangeMaximumBolus() {
        logEvent("Maximum bolus change")
    }

    // MARK: - Loop Events

    static func didAddCarbsFromWatch(carbs: Double) {
        logEvent("Carb entry created", withProperties: ["source" : "Watch", "value": carbs])
    }

    static func didRetryBolus() {
        logEvent("Bolus Retry")
    }

    static func didSetBolusFromWatch(units: Double) {
        logEvent("Bolus set", withProperties: ["source" : "Watch", "value": units])
    }

    static func loopDidSucceed() {
        logEvent("Loop success")
    }

    static func loopDidError() {
        logEvent("Loop error")
    }
}<commit_msg>Track loop events as "out of session"<commit_after>//
//  AnalyticsManager.swift
//  Naterade
//
//  Created by <NAME> on 4/28/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import AmplitudeFramework


class AnalyticsManager {

    // MARK: - Helpers

    private static var amplitudeAPIKey: String? {
        if let settingsPath = NSBundle.mainBundle().pathForResource("RemoteSettings", ofType: "plist"),
            settings = NSDictionary(contentsOfFile: settingsPath)
        {
            return settings["AmplitudeAPIKey"] as? String
        }

        return nil
    }

    private static func logEvent(name: String, withProperties properties: [NSObject: AnyObject]? = nil, outOfSession: Bool = false) {
        guard amplitudeAPIKey != nil else {
            return
        }

        Amplitude.instance().logEvent(name, withEventProperties: properties, outOfSession: outOfSession)
    }

    // MARK: - UIApplicationDelegate

    static func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) {

        if let APIKey = amplitudeAPIKey {
            Amplitude.instance().initializeApiKey(APIKey)
        }
    }

    // MARK: - Screens

    static func didDisplayBolusScreen() {
        logEvent("Bolus Screen")
    }

    static func didDisplaySettingsScreen() {
        logEvent("Settings Screen")
    }

    static func didDisplayStatusScreen() {
        logEvent("Status Screen")
    }

    // MARK: - Config Events

    static func didChangeRileyLinkConnectionState() {
        logEvent("RileyLink Connection")
    }

    static func transmitterTimeDidDrift(drift: NSTimeInterval) {
        logEvent("Transmitter time change", withProperties: ["value" : drift])
    }

    static func didChangeBasalRateSchedule() {
        logEvent("Basal rate change")
    }

    static func didChangeCarbRatioSchedule() {
        logEvent("Carb ratio change")
    }

    static func didChangeInsulinActionDuration() {
        logEvent("Insulin action duration change")
    }

    static func didChangeInsulinSensitivitySchedule() {
        logEvent("Insulin sensitivity change")
    }

    static func didChangeGlucoseTargetRangeSchedule() {
        logEvent("Glucose target range change")
    }

    static func didChangeMaximumBasalRate() {
        logEvent("Maximum basal rate change")
    }

    static func didChangeMaximumBolus() {
        logEvent("Maximum bolus change")
    }

    // MARK: - Loop Events

    static func didAddCarbsFromWatch(carbs: Double) {
        logEvent("Carb entry created", withProperties: ["source" : "Watch", "value": carbs], outOfSession: true)
    }

    static func didRetryBolus() {
        logEvent("Bolus Retry", outOfSession: true)
    }

    static func didSetBolusFromWatch(units: Double) {
        logEvent("Bolus set", withProperties: ["source" : "Watch", "value": units], outOfSession: true)
    }

    static func loopDidSucceed() {
        logEvent("Loop success", outOfSession: true)
    }

    static func loopDidError() {
        logEvent("Loop error", outOfSession: true)
    }
}
{'fraction_non_alphanumeric': 0.10016501650165016, 'fraction_numerical': 0.0029702970297029703, 'mean_word_length': 2.82397476340694, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7045441', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1637, 'n_words': 415}