<commit_before>//
//  InfluenceTrackerService.swift
//  RoverNotifications
//
//  Created by <NAME> on 2018-03-11.
//  Copyright © 2018 Rover Labs Inc. All rights reserved.
//

import UIKit

class InfluenceTrackerService: InfluenceTracker {
    let influenceTime: Int
    let eventQueue: EventQueue?
    let notificationCenter: NotificationCenter
    let userDefaults: UserDefaults
    
    var didBecomeActiveObserver: NSObjectProtocol?
    
    init(influenceTime: Int, eventQueue: EventQueue?, notificationCenter: NotificationCenter, userDefaults: UserDefaults) {
        self.influenceTime = influenceTime
        self.eventQueue = eventQueue
        self.notificationCenter = notificationCenter
        self.userDefaults = userDefaults
    }
    
    func startMonitoring() {
        #if swift(>=4.2)
        didBecomeActiveObserver = notificationCenter.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: nil) { _ in
            self.trackInfluencedOpen()
        }
        #else
        didBecomeActiveObserver = notificationCenter.addObserver(forName: .UIApplicationDidBecomeActive, object: nil, queue: nil) { _ in
            self.trackInfluencedOpen()
        }
        #endif
    }
    
    func stopMonitoring() {
        guard let didBecomeActiveObserver = didBecomeActiveObserver else {
            return
        }
        
        notificationCenter.removeObserver(didBecomeActiveObserver)
    }
    
    func trackInfluencedOpen() {
        guard let data = userDefaults.value(forKey: "io.rover.lastReceivedNotification") as? Data else {
            return
        }
        <commit_msg>Remove observer reference in InfluenceTracker<commit_after>//
//  InfluenceTrackerService.swift
//  RoverNotifications
//
//  Created by <NAME> on 2018-03-11.
//  Copyright © 2018 Rover Labs Inc. All rights reserved.
//

import UIKit

class InfluenceTrackerService: InfluenceTracker {
    let influenceTime: Int
    let eventQueue: EventQueue?
    let notificationCenter: NotificationCenter
    let userDefaults: UserDefaults
    
    var didBecomeActiveObserver: NSObjectProtocol?
    
    init(influenceTime: Int, eventQueue: EventQueue?, notificationCenter: NotificationCenter, userDefaults: UserDefaults) {
        self.influenceTime = influenceTime
        self.eventQueue = eventQueue
        self.notificationCenter = notificationCenter
        self.userDefaults = userDefaults
    }
    
    func startMonitoring() {
        #if swift(>=4.2)
        didBecomeActiveObserver = notificationCenter.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: nil) { [weak self] _ in
            self?.trackInfluencedOpen()
        }
        #else
        didBecomeActiveObserver = notificationCenter.addObserver(forName: .UIApplicationDidBecomeActive, object: nil, queue: nil) { [weak self] _ in
            self?.trackInfluencedOpen()
        }
        #endif
    }
    
    func stopMonitoring() {
        guard let didBecomeActiveObserver = didBecomeActiveObserver else {
            return
        }
        
        notificationCenter.removeObserver(didBecomeActiveObserver)
    }
    
    func trackInfluencedOpen() {
        guard let data = userDefaults.value(forKey: "io.rover.lastReceivedNotification") as? Data else {
            return
        }
        
{'fraction_non_alphanumeric': 0.07507507507507508, 'fraction_numerical': 0.008408408408408409, 'mean_word_length': 2.7809307604994324, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6650179', 'n_tokens_mistral': 936, 'n_tokens_neox': 882, 'n_words': 202}