<commit_before>//
//  TTMapViewController.swift
//  TrolleyTracker
//
//  Created by <NAME> on 6/16/15.
//  Copyright (c) 2015 Code For Greenville. All rights reserved.
//

import UIKit
import MapKit

extension TTTrolley: MKAnnotation {
    
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
    }
    
    var title: String! {
        // TODO: Return Trolley Name
        return "Trolley"
    }
    
    var subTitle: String! {
        return "The One"
    }
}

extension TTTrolleyStop: MKAnnotation {
    
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
    }
    
    var title: String! {
        // TODO: Return Trolley Name
        return "Trolley"
    }
    
    var subTitle: String! {
        return "The One"
    }
}

// TODO: Add tracking button that toggles MKUserTrackingMode like native maps

class TTMapViewController: UIViewController, MKMapViewDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "Trolly Tracker"
        
        view.backgroundColor = UIColor.whiteColor()
        let detailViewController: TTDetailViewController = TTDetailViewController();
        self.view.addSubview(detailView)
        view.addSubview(mapView)
        
      self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Settings", comment: "Settings"), style: .Plain, target: self, action:"showSettings")
        self.addChildViewController(detailViewController)
        view.addSubview(detailViewController.view)
        detailViewController.didMoveToParentViewController(self)
        
        let views = ["detailView": detailView, "mapView": mapView]
        
        NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[detailView]|", options: nil, metrics: nil, views: views))
        NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[mapView]|", options: nil, metrics: nil, views: views))
        
        NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[mapView][detailView(==mapView)]|", options: nil, metrics: nil, views: views))
    }
    
    func loadStops() {
        // TODO: Get Stops
        let stops: [TTTrolleyStop] = []
        
        // Plot each stop as an annotation on the MapView
        stops.map {
            trolleyStop -> () in
            
            self.mapView.addAnnotation(trolleyStop)
        }
    }
    
    func loadTrolleys() {
        // TODO: Get Trolleys
        let trolleys: [TTTrolley] = []
        
        // Plot each Trolley as an annotation on the MapView
        trolleys.map {
            trolleyStop -> () in
            
            self.mapView.addAnnotation(trolleyStop)
        }
    }
    
    func updateTrolleys() {
        // TODO: Get Trolley Updates
        
        // Get Trolley Annotations
        let trolleyFilter: ((AnyObject) -> (Bool)) = { (annotation) -> Bool in
            return self.isKindOfClass(TTTrolley.self)
        }
        
        if let trolleyAnnotations = mapView.annotations.filter(trolleyFilter) as? [TTTrolley] {
            
            // TODO: Move Trolley annotations to current locations
            trolleyAnnotations.map {
                trolleyAnnotation -> () in
                
                let annotationView = self.mapView.viewForAnnotation(trolleyAnnotation)
                
                let mapPoint = MKMapPointForCoordinate(trolleyAnnotation.coordinate)
                let zoomFactor = self.mapView.visibleMapRect.size.width / Double(self.mapView.bounds.width)
                let point = CGPoint(x: mapPoint.x/zoomFactor, y: mapPoint.y/zoomFactor)
                
                annotationView.center = point
            }
            
        }

    }
    
    //==========================================================================
    // mark: MKMapViewDelegate
    //==========================================================================
    
    let trolleyAnnotationReuseIdentifier = "TrolleyAnnotation"
    let stopAnnotationReuseIdentifier = "StopAnnotation"
    
    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
        
        // Handle Trolleys
        if let trolleyAnnotation = annotation as? TTTrolley {
            let annotationView = MKAnnotationView(annotation: trolleyAnnotation, reuseIdentifier: trolleyAnnotationReuseIdentifier)
            
            return annotationView
        }
        
        // Handle Stops
        if let stopAnnotation = annotation as? TTTrolleyStop {
            let annotationView = MKAnnotationView(annotation: stopAnnotation, reuseIdentifier: trolleyAnnotationReuseIdentifier)
            
            return annotationView
        }
        
        return nil
    }
    
    func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
        // TODO: Adjust DetailViewController information to show the current selected object (trolley or stop)
    }
    
    //==========================================================================
    // mark: Views
    //==========================================================================
    
    lazy var mapView: MKMapView = {
        let mapView = MKMapView()
        mapView.setTranslatesAutoresizingMaskIntoConstraints(false)
        
        mapView.mapType = MKMapType.Standard
        
        mapView.showsUserLocation = true
        
        mapView.delegate = self
        
        return mapView
    }()
    
    lazy var detailView: UIView = {
        let detailView = UIView()
        detailView.setTranslatesAutoresizingMaskIntoConstraints(false)
        return detailView
    }()
  
  //==========================================================================
  // mark: Actions
  //==========================================================================
  
  func showSettings() {
    var settingsViewController = TTSettingsViewController()
    
    self.navigationController?.pushViewController(settingsViewController, animated: true)
  }
}<commit_msg>Added some logic to center on users's location<commit_after>//
//  TTMapViewController.swift
//  TrolleyTracker
//
//  Created by <NAME> on 6/16/15.
//  Copyright (c) 2015 Code For Greenville. All rights reserved.
//

import UIKit
import MapKit

extension TTTrolley: MKAnnotation {
    
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
    }
    
    var title: String! {
        // TODO: Return Trolley Name
        return "Trolley"
    }
    
    var subTitle: String! {
        return "The One"
    }
}

extension TTTrolleyStop: MKAnnotation {
    
    var coordinate: CLLocationCoordinate2D {
        return CLLocationCoordinate2D(latitude: 0.0, longitude: 0.0)
    }
    
    var title: String! {
        // TODO: Return Trolley Name
        return "Trolley"
    }
    
    var subTitle: String! {
        return "The One"
    }
}

// TODO: Add tracking button that toggles MKUserTrackingMode like native maps

class TTMapViewController: UIViewController, MKMapViewDelegate {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        title = "Trolly Tracker"
        
        view.backgroundColor = UIColor.whiteColor()
        let detailViewController: TTDetailViewController = TTDetailViewController();
        self.view.addSubview(detailView)
        view.addSubview(mapView)
        
      self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("Settings", comment: "Settings"), style: .Plain, target: self, action:"showSettings")
        self.addChildViewController(detailViewController)
        view.addSubview(detailViewController.view)
        detailViewController.didMoveToParentViewController(self)
        
        let views = ["detailView": detailView, "mapView": mapView]
        
        NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[detailView]|", options: nil, metrics: nil, views: views))
        NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[mapView]|", options: nil, metrics: nil, views: views))
        
        NSLayoutConstraint.activateConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[mapView][detailView(==mapView)]|", options: nil, metrics: nil, views: views))
    }
    
    func loadStops() {
        // TODO: Get Stops
        let stops: [TTTrolleyStop] = []
        
        // Plot each stop as an annotation on the MapView
        stops.map {
            trolleyStop -> () in
            
            self.mapView.addAnnotation(trolleyStop)
        }
    }
    
    func loadTrolleys() {
        // TODO: Get Trolleys
        let trolleys: [TTTrolley] = []
        
        // Plot each Trolley as an annotation on the MapView
        trolleys.map {
            trolleyStop -> () in
            
            self.mapView.addAnnotation(trolleyStop)
        }
    }
    
    func updateTrolleys() {
        // TODO: Get Trolley Updates
        
        // Get Trolley Annotations
        let trolleyFilter: ((AnyObject) -> (Bool)) = { (annotation) -> Bool in
            return self.isKindOfClass(TTTrolley.self)
        }
        
        if let trolleyAnnotations = mapView.annotations.filter(trolleyFilter) as? [TTTrolley] {
            
            // TODO: Move Trolley annotations to current locations
            trolleyAnnotations.map {
                trolleyAnnotation -> () in
                
                let annotationView = self.mapView.viewForAnnotation(trolleyAnnotation)
                
                let mapPoint = MKMapPointForCoordinate(trolleyAnnotation.coordinate)
                let zoomFactor = self.mapView.visibleMapRect.size.width / Double(self.mapView.bounds.width)
                let point = CGPoint(x: mapPoint.x/zoomFactor, y: mapPoint.y/zoomFactor)
                
                annotationView.center = point
            }
            
        }

    }
    
    //==========================================================================
    // mark: MKMapViewDelegate
    //==========================================================================
    
    let trolleyAnnotationReuseIdentifier = "TrolleyAnnotation"
    let stopAnnotationReuseIdentifier = "StopAnnotation"
    
    func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
        
        // Handle Trolleys
        if let trolleyAnnotation = annotation as? TTTrolley {
            let annotationView = MKAnnotationView(annotation: trolleyAnnotation, reuseIdentifier: trolleyAnnotationReuseIdentifier)
            
            return annotationView
        }
        
        // Handle Stops
        if let stopAnnotation = annotation as? TTTrolleyStop {
            let annotationView = MKAnnotationView(annotation: stopAnnotation, reuseIdentifier: trolleyAnnotationReuseIdentifier)
            
            return annotationView
        }
        
        return nil
    }
    
    func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
        // TODO: Adjust DetailViewController information to show the current selected object (trolley or stop)
    }
    
    func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) {
        let region = MKCoordinateRegionMake(userLocation.coordinate, MKCoordinateSpanMake(0.01, 0.01))
        mapView.setRegion(region, animated: true)
    }
    
    //==========================================================================
    // mark: Views
    //==========================================================================
    
    lazy var mapView: MKMapView = {
        let mapView = MKMapView()
        mapView.setTranslatesAutoresizingMaskIntoConstraints(false)
        
        mapView.mapType = MKMapType.Standard
        
        mapView.showsUserLocation = true
        mapView.zoomEnabled = true
        mapView.scrollEnabled = true
        
        mapView.delegate = self
        
        return mapView
    }()
    
    lazy var detailView: UIView = {
        let detailView = UIView()
        detailView.setTranslatesAutoresizingMaskIntoConstraints(false)
        return detailView
    }()
  
  //==========================================================================
  // mark: Actions
  //==========================================================================
  
  func showSettings() {
    var settingsViewController = TTSettingsViewController()
    
    self.navigationController?.pushViewController(settingsViewController, animated: true)
  }
}
{'fraction_non_alphanumeric': 0.14609984399375975, 'fraction_numerical': 0.00374414976599064, 'mean_word_length': 2.4539331896551726, 'pattern_counts': {'":': 4, '<': 5, '<?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': '1069718', 'n_tokens_mistral': 3469, 'n_tokens_neox': 3259, 'n_words': 709}