<commit_before>//
//  Analytics.swift
//  Analytical
//
//  Created by <NAME> on 18/07/16.
//  Copyright © 2016 Unified Sense. All rights reserved.
//

import UIKit

///
/// Serves as a bounce wrapper for Analytics providers
///
open class Analytics : Analytical {
    fileprivate static let DeviceKey = "AnalyticsDeviceKey"
    
    fileprivate var userDefaults = UserDefaults.standard
    
    open var providers : [Analytical] = []
    
    open var deviceId : String {
        if let id = userDefaults.string(forKey: Analytics.DeviceKey) {
            return id
        }
        
        if let id = UIDevice.current.identifierForVendor?.uuidString {
            userDefaults.set(id, forKey: Analytics.DeviceKey)
            
            return id
        }
        
        let id = Analytics.randomId()
        
        userDefaults.set(id, forKey: Analytics.DeviceKey)
        
        return id
    }
    
    public init () {
    }
    
    //
    // MARK: Public Methods
    //
    
    /*!
     If one of your providers requires launch options and application reference, this method must be called,
     or parameteres must manually be provided.
     
     - parameter application:   UIApplication instance
     - parameter launchOptions: launch options
     */
    open func setup(_ application: UIApplication?, launchOptions: [AnyHashable: Any]?) {
        var properties : Properties = [:]
        
        if let launchOptions = launchOptions {
            properties = [Property.Launch.options.rawValue : launchOptions as AnyObject]
        }
        
        setup(with: properties)
    }
    
    open func provider<T : Analytical>(_ type: T.Type) -> T? {
        return providers.filter { return ($0 is T) }.first as? T
    }
    
    //<commit_msg>Update Analytics.swift<commit_after>//
//  Analytics.swift
//  Analytical
//
//  Created by <NAME> on 18/07/16.
//  Copyright © 2016 Unified Sense. All rights reserved.
//

import UIKit

///
/// Serves as a bounce wrapper for Analytics providers
///
open class Analytics : Analytical {
    fileprivate static let DeviceKey = "AnalyticsDeviceKey"
    
    fileprivate var userDefaults = UserDefaults.standard
    
    open var providers : [Analytical] = []
    
    open var deviceId : String {
        if let id = userDefaults.string(forKey: Analytics.DeviceKey) {
            return id
        }
        
        if let id = UIDevice.current.identifierForVendor?.uuidString {
            userDefaults.set(id, forKey: Analytics.DeviceKey)
            
            return id
        }
        
        let id = Analytics.randomId()
        
        userDefaults.set(id, forKey: Analytics.DeviceKey)
        
        return id
    }
    
    public init () {
    }
    
    //
    // MARK: Public Methods
    //
    
    /*!
     If one of your providers requires launch options and application reference, this method must be called,
     or parameteres must manually be provided.
     
     - parameter application:   UIApplication instance
     - parameter launchOptions: launch options
     */
    open func setup(_ application: UIApplication?, launchOptions: [UIApplicationLaunchOptionsKey: Any]?) {
        var properties : Properties = [:]
        
        if let application = application {
            properties[Property.Launch.application.rawValue] = application
        }
        
        if let launchOptions = launchOptions {
            properties[Property.Launch.options.rawValue] = launchOptions
        }
        
        setup(with: properties)
    }
    
    open func provider<T : Analytical>(_ type: T.Type) -> T? {
        return providers.filter { return ($0 is T) }.first as? T
    }
    
    //
{'fraction_non_alphanumeric': 0.08762886597938144, 'fraction_numerical': 0.005968529571351058, 'mean_word_length': 1.910023677979479, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '4138005', 'n_tokens_mistral': 1028, 'n_tokens_neox': 969, 'n_words': 292}