<commit_before>//
//  TripDetailController.swift
//  CycleSaver
//
//  Created by <NAME> on 12/8/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import MapKit
import CoreData
import UIKit

class TripDetailController: UIViewController, MKMapViewDelegate {
    
    @IBOutlet weak var mapView: MKMapView!
    var trip: Trip!
    lazy var coreDataStack = (UIApplication.sharedApplication().delegate as! AppDelegate).coreDataStack
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        mapView.delegate = self
        mapView.showsUserLocation = true
        
        var fetchRequest: NSFetchRequest!
        var readings: [LocationReading];
        
        let model = coreDataStack.context.persistentStoreCoordinator!.managedObjectModel
        
        let filterForTrip: NSPredicate = NSPredicate(format: "ANY readingTrip == %@", trip)
        
        fetchRequest = model.fetchRequestTemplateForName("FetchTripCoords")
        fetchRequest = fetchRequest.copy() as! NSFetchRequest
        fetchRequest.predicate = filterForTrip
        
        do {
            if (trip.tripReadings!.count == 0) {
                print("No readings to display for trip!")
                return
            }
            
            readings = try coreDataStack.context.executeFetchRequest(fetchRequest) as! [LocationReading]
            
            print("Total trip readings: \(trip.tripReadings!.count)");
            print("Using \(readings.count) readings with accuracy > 70%")
            
            
            var coords: [CLLocationCoordinate2D] = []
            for reading in readings {
                let coord = CLLocationCoordinate2D(latitude: reading.latitude as Double!, longitude: reading.longitude as Double!)
                coords.append(coord)
            }
            
            let polyline = MKPolyline(coordinates: &coords, count: coords.count)
            mapView.addOverlay(polyline)
            
            mapView.setVisibleMapRect(polyline.boundingMapRect, edgePadding: UIEdgeInsetsMake(20, 20, 20, 20), animated: true)
        } catch let error as NSError {
            print("Could not fetch \(error), \(error.userInfo)")
        }
    }
    
    func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {<commit_msg>Print trip distance in miles<commit_after>//
//  TripDetailController.swift
//  CycleSaver
//
//  Created by <NAME> on 12/8/15.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Foundation
import MapKit
import CoreData
import UIKit

class TripDetailController: UIViewController, MKMapViewDelegate {
    
    @IBOutlet weak var mapView: MKMapView!
    var trip: Trip!
    lazy var coreDataStack = (UIApplication.sharedApplication().delegate as! AppDelegate).coreDataStack
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        mapView.delegate = self
        mapView.showsUserLocation = true
        
        var fetchRequest: NSFetchRequest!
        var readings: [LocationReading];
        
        let model = coreDataStack.context.persistentStoreCoordinator!.managedObjectModel
        
        let filterForTrip: NSPredicate = NSPredicate(format: "ANY readingTrip == %@", trip)
        
        fetchRequest = model.fetchRequestTemplateForName("FetchTripCoords")
        fetchRequest = fetchRequest.copy() as! NSFetchRequest
        fetchRequest.predicate = filterForTrip
        
        do {
            if (trip.tripReadings!.count == 0) {
                print("No readings to display for trip!")
                return
            }
            
            readings = try coreDataStack.context.executeFetchRequest(fetchRequest) as! [LocationReading]
            
            print("Using \(readings.count) readings with accuracy within 100 meters")
            print("Total trip readings: \(trip.tripReadings!.count)");
            print("Trip distance: \(trip.distance as! Double / 1609.344) miles")
            
            
            var coords: [CLLocationCoordinate2D] = []
            for reading in readings {
                let coord = CLLocationCoordinate2D(latitude: reading.latitude as Double!, longitude: reading.longitude as Double!)
                coords.append(coord)
            }
            
            let polyline = MKPolyline(coordinates: &coords, count: coords.count)
            mapView.addOverlay(polyline)
            
            mapView.setVisibleMapRect(polyline.boundingMapRect, edgePadding: UIEdgeInsetsMake(20, 20, 20, 20), animated: true)
        } catch let error as NSError {
            print("Could not fetch \(error), \(error.userInfo)")
        }
    }
    
    func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
{'fraction_non_alphanumeric': 0.08768267223382047, 'fraction_numerical': 0.010855949895615866, 'mean_word_length': 2.237162162162162, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, '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': '6980164', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1271, 'n_words': 311}