<commit_before>//
//  SurveyViewController.swift
//  Pods
//
//  Created by <NAME> on 9/22/15.
//
//

import Foundation
import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}

fileprivate func >= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l >= r
  default:
    return !(lhs < rhs)
  }
}


class SurveyViewController: UIViewController, NPSScoreViewControllerDelegate, CommentsViewControllerDelegate, RateAppViewControllerDelegate, NegativeFeedbackCompleteViewControllerDelegate {
    
    var blurEffect: UIBlurEffect?
    var blurEffectView: UIVisualEffectView?
    
    //Phils variables
    var npsScoreVC: NPSScoreViewController?
    var commentsVC: CommentsViewController?
    var rateAppVC: RateAppViewController?
    var negativeFeedbackVC: NegativeFeedbackCompleteViewController?
    
    var state: SurveyViewControllerState // keep track of what screen is showing for analytics
    
    required init?(coder aDecoder: NSCoder) {
        self.state = .ratingScreen
        super.init(coder: aDecoder)
    }
    
    override init(nibName nibNameOrNil: String!, bundle: Bundle!) {
        self.state = .ratingScreen
        super.init(nibName: nibNameOrNil, bundle: bundle)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //only apply the blur if the user hasn't disabled transparency effects
        if !UIAccessibilityIsReduceTransparencyEnabled() {
            showBlurredWindowImage()
        } else {
            self.view.backgroundColor = .black
        }
        
        Brilliant.sharedInstance().completedSurvey?.triggerTimestamp = Date()
        
        self.npsScoreVC = NPSScoreViewController(nibName: "NPSScoreViewController", bundle: Brilliant.xibBundle())
        self.npsScoreVC?.delegate = self
        self.addFullScreenSubViewController(npsScoreVC!)
    }
    
    lazy var blurredBackgroundImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.translatesAutoresizingMaskIntoConstraints = false
        imageView.contentMode = .scaleAspectFill
        imageView.addSubview(self.blurVisualEffectView)
        return imageView
    }()
    let blurVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
    
    fileprivate func showBlurredWindowImage() {
        guard let keyWindow = UIApplication.shared.keyWindow else { return }
        
        if let windowImage = getWindowImage() {
            blurredBackgroundImageView.backgroundColor = .red
            view.addSubview(blurredBackgroundImageView)
            blurredBackgroundImageView.image = windowImage
            blurredBackgroundImageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
            blurredBackgroundImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
            blurredBackgroundImageView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
            blurredBackgroundImageView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
            
            blurVisualEffectView.frame = keyWindow.frame
        } else {
            self.view.backgroundColor = .black
        }
    }
    
    override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
        guard let keyWindow = UIApplication.shared.keyWindow else { return }
        blurVisualEffectView.frame = CGRect(x: 0, y: 0, width: keyWindow.frame.height, height: keyWindow.frame.width)
    }
    
    override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
        
    }<commit_msg>better image rotation/scaling<commit_after>//
//  SurveyViewController.swift
//  Pods
//
//  Created by <NAME> on 9/22/15.
//
//

import Foundation
import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l < r
  case (nil, _?):
    return true
  default:
    return false
  }
}

fileprivate func >= <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?):
    return l >= r
  default:
    return !(lhs < rhs)
  }
}


class SurveyViewController: UIViewController, NPSScoreViewControllerDelegate, CommentsViewControllerDelegate, RateAppViewControllerDelegate, NegativeFeedbackCompleteViewControllerDelegate {
    
    var blurEffect: UIBlurEffect?
    var blurEffectView: UIVisualEffectView?
    
    //Phils variables
    var npsScoreVC: NPSScoreViewController?
    var commentsVC: CommentsViewController?
    var rateAppVC: RateAppViewController?
    var negativeFeedbackVC: NegativeFeedbackCompleteViewController?
    
    var state: SurveyViewControllerState // keep track of what screen is showing for analytics
    
    required init?(coder aDecoder: NSCoder) {
        self.state = .ratingScreen
        super.init(coder: aDecoder)
    }
    
    override init(nibName nibNameOrNil: String!, bundle: Bundle!) {
        self.state = .ratingScreen
        super.init(nibName: nibNameOrNil, bundle: bundle)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //only apply the blur if the user hasn't disabled transparency effects
        if !UIAccessibilityIsReduceTransparencyEnabled() {
            showBlurredWindowImage()
        } else {
            self.view.backgroundColor = .black
        }
        
        Brilliant.sharedInstance().completedSurvey?.triggerTimestamp = Date()
        
        self.npsScoreVC = NPSScoreViewController(nibName: "NPSScoreViewController", bundle: Brilliant.xibBundle())
        self.npsScoreVC?.delegate = self
        self.addFullScreenSubViewController(npsScoreVC!)
    }
    
    lazy var blurredBackgroundImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.translatesAutoresizingMaskIntoConstraints = false
        imageView.addSubview(self.blurVisualEffectView)
        return imageView
    }()
    let blurVisualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .dark))
    
    fileprivate func showBlurredWindowImage() {
        guard let keyWindow = UIApplication.shared.keyWindow else { return }
        
        if let windowImage = getWindowImage() {
            blurredBackgroundImageView.backgroundColor = .red
            view.addSubview(blurredBackgroundImageView)
            blurredBackgroundImageView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
            blurredBackgroundImageView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
            blurredBackgroundImageView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
            blurredBackgroundImageView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
            blurredBackgroundImageView.image = windowImage
            
            blurVisualEffectView.frame = keyWindow.frame
        } else {
            self.view.backgroundColor = .black
        }
    }
    
    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        guard let keyWindow = UIApplication.shared.keyWindow else { return }
        let orientation = UIDevice.current.orientation
        if orientation == .portrait || orientation == .portraitUpsideDown {
            blurVisualEffectView.frame = CGRect(x: 0, y: 0, width: keyWindow.frame.height, height: keyWindow.frame.width)
        } else {
            blurVisualEffectView.frame = CGRect(x: 0, y: 0, width: keyWindow.frame.height, height: keyWindow.frame.height)
        }
    }
{'fraction_non_alphanumeric': 0.08485083301046106, 'fraction_numerical': 0.002066382539067545, 'mean_word_length': 2.946992864424057, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '4996211', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2086, 'n_words': 475}