<commit_before>//
//  FirebaseAnalytics.swift
//  SmartReceipts
//
//  Created by Victor on 12/17/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import FirebaseAnalytics
import FirebaseCrash

/// Firebase implementation adopted to our custom Analytics service
class FirebaseAnalytics: AnalyticsServiceProtocol {
    
    init() {
        FIRApp.configure()
    }
    
    func record(event: Event) {
        // building a Dictionary with parameters (category and datapoints included)
        let dictionaryParameters: NSMutableDictionary = ["Category" : event.category.rawValue]
        for aDataPoint in event.dataPoints {
            dictionaryParameters.setValue(aDataPoint.toString().truncateToLength(100), forKey: aDataPoint.name.truncateToLength(40))
        }
        // cast to appropriate type:
        let parameters = dictionaryParameters as NSDictionary as? [String: NSObject] ?? [:]
        
        // Firebase tracks all crashes automatically. For iOS, exceptions will be tracked as an "error" events
        FIRAnalytics.logEvent(withName: event.name, parameters: parameters)
    }
}
<commit_msg>preventing possible initialization of Firebase for a second time.<commit_after>//
//  FirebaseAnalytics.swift
//  SmartReceipts
//
//  Created by Victor on 12/17/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import FirebaseAnalytics
import FirebaseCrash

/// Firebase implementation adopted to our custom Analytics service
class FirebaseAnalytics: AnalyticsServiceProtocol {
    
    init() {
        // Configure Firebase
        // May conflict with Google services, here is a solution:
        if FIRApp.defaultApp() == nil {
            FIRApp.configure()
        }
    }
    
    func record(event: Event) {
        // building a Dictionary with parameters (category and datapoints included)
        let dictionaryParameters: NSMutableDictionary = ["Category" : event.category.rawValue]
        for aDataPoint in event.dataPoints {
            dictionaryParameters.setValue(aDataPoint.toString().truncateToLength(100), forKey: aDataPoint.name.truncateToLength(40))
        }
        // cast to appropriate type:
        let parameters = dictionaryParameters as NSDictionary as? [String: NSObject] ?? [:]
        
        // Firebase tracks all crashes automatically. For iOS, exceptions will be tracked as an "error" events
        FIRAnalytics.logEvent(withName: event.name, parameters: parameters)
    }
}

{'fraction_non_alphanumeric': 0.08695652173913043, 'fraction_numerical': 0.012077294685990338, 'mean_word_length': 2.9696485623003195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5518489', 'n_tokens_mistral': 682, 'n_tokens_neox': 638, 'n_words': 200}