<commit_before>//
//  RouteDetailViewController.swift
//  TCAT
//
//  Created by <NAME> on 2/11/17.
//  Copyright © 2017 cuappdev. All rights reserved.
//

import UIKit
import GoogleMaps
import CoreLocation
import MapKit
import SwiftyJSON
import NotificationBannerSwift

struct RouteDetailCellSize {
    static let smallHeight: CGFloat = 60
    static let largeHeight: CGFloat = 80
    static let regularWidth: CGFloat = 120
    static let indentedWidth: CGFloat = 140
}

class RouteDetailViewController: UIViewController, GMSMapViewDelegate, CLLocationManagerDelegate, UIGestureRecognizerDelegate, UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate {
    
    var detailView = UIView()
    var detailTableView: UITableView!
    var summaryView = UIView()
    var locationManager = CLLocationManager()
    
    var mapView: GMSMapView!
    var routePaths: [Path] = []
    var currentLocation: CLLocationCoordinate2D?
    var bounds = GMSCoordinateBounds()
    
    var networkTimer: Timer? = nil
    /// Number of seconds to wait before auto-refreshing network call
    var refreshRate: Double = 10.0
    var buses = [GMSMarker]()
    var banner: StatusBarNotificationBanner? = nil
    
    var route: Route!
    var directions: [Direction] = []
    
    let main = UIScreen.main.bounds
    let summaryViewHeight: CGFloat = 80
    var largeDetailHeight: CGFloat = 80
    var mediumDetailHeight: CGFloat = UIScreen.main.bounds.height / 2
    var smallDetailHeight: CGFloat = UIScreen.main.bounds.height - 80
    
    var contentOffset: CGFloat = 0
    
    let markerRadius: CGFloat = 8
    let mapPadding: CGFloat = 40
    
    /** Initalize RouteDetailViewController. Be sure to send a valid route, otherwise
     * dummy data will be used. The directions parameter have logical assumptions,
     * such as ArriveDirection always comes after DepartDirection. */
    init (route: Route? = nil) {
        super.init(nibName: nil, bundle: nil)
        if route == nil {
            let json = try! JSON(data: Data(contentsOf: Bundle.main.url(forResource: "testNew", withExtension: "json")!))
            initializeRoute(route: try! Route(json: json))
        } else {
            initializeRoute(route: route!)
        }
    }
    
    /** Construct Directions based on Route and parse Waypoint / Path data */
    func initializeRoute(route: Route) {
        
        self.route = route
        self.directions = route.directions
        
        // Plot the paths of all directions
        for (arrayIndex, direction) in directions.enumerated() {
            
            var waypoints: [Waypoint] = []
            
            for (pathIndex, point) in direction.path.enumerated() {
                
                var type: WaypointType = .none
                
                if arrayIndex == 0 {
                    type = .origin
                }
                
                else if arrayIndex == directions.count - 1 {
                    type = .destination
                }
                
                else if pathIndex == 0 || pathIndex == direction.path.count - 1 {
                    type = .origin
                }
                
                let waypoint = Waypoint(lat: point.latitude, long: point.longitude, wpType: type)
                waypoints.append(waypoint)
                
            }
            
            let pathType: PathType = direction.type == .walk ? .walking : .driving
            let path = Path(waypoints: waypoints, pathType: pathType, color: .tcatBlueColor)
            routePaths.append(path)
            
            // Temporary walk calculator
            if direction.type == .walk && direction.path.isEmpty {
                calculateWalkingDirections(direction) { (path) in
                    waypoints = path.enumerated().flatMap { (pathIndex, coord) -> Waypoint in
                        var type: WaypointType = .none
                        if arrayIndex == 0 && pathIndex == 0 {
                            type = .origin
                        }
                        else if arrayIndex == self.directions.count - 1 && pathIndex == path.count - 1 {
                            type = .destination
                        }
                        return Waypoint(lat: coord.latitude, long: coord.longitude, wpType: type)
                    }
                    self.routePaths.append(Path(waypoints: waypoints, pathType: .walking, color: .tcatBlueColor))
                    self.drawMapRoute(); self.centerMap(topHalfCentered: true)
                }
            }
            
        }
        
    }<commit_msg>finalize route model and parsing, resolve merge conflicts<commit_after>//
//  RouteDetailViewController.swift
//  TCAT
//
//  Created by <NAME> on 2/11/17.
//  Copyright © 2017 cuappdev. All rights reserved.
//

import UIKit
import GoogleMaps
import CoreLocation
import MapKit
import SwiftyJSON
import NotificationBannerSwift

struct RouteDetailCellSize {
    static let smallHeight: CGFloat = 60
    static let largeHeight: CGFloat = 80
    static let regularWidth: CGFloat = 120
    static let indentedWidth: CGFloat = 140
}

class RouteDetailViewController: UIViewController, GMSMapViewDelegate, CLLocationManagerDelegate, UIGestureRecognizerDelegate, UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate {
    
    var detailView = UIView()
    var detailTableView: UITableView!
    var summaryView = UIView()
    var locationManager = CLLocationManager()
    
    var mapView: GMSMapView!
    var routePaths: [Path] = []
    var currentLocation: CLLocationCoordinate2D?
    var bounds = GMSCoordinateBounds()
    
    var networkTimer: Timer? = nil
    /// Number of seconds to wait before auto-refreshing network call
    var refreshRate: Double = 10.0
    var buses = [GMSMarker]()
    var banner: StatusBarNotificationBanner? = nil
    
    var route: Route!
    var directions: [Direction] = []
    
    let main = UIScreen.main.bounds
    let summaryViewHeight: CGFloat = 80
    var largeDetailHeight: CGFloat = 80
    var mediumDetailHeight: CGFloat = UIScreen.main.bounds.height / 2
    var smallDetailHeight: CGFloat = UIScreen.main.bounds.height - 80
    
    var contentOffset: CGFloat = 0
    
    let markerRadius: CGFloat = 8
    let mapPadding: CGFloat = 40
    
    /** Initalize RouteDetailViewController. Be sure to send a valid route, otherwise
     * dummy data will be used. The directions parameter have logical assumptions,
     * such as ArriveDirection always comes after DepartDirection. */
    init (route: Route? = nil) {
        super.init(nibName: nil, bundle: nil)
        if route == nil {
            let json = try! JSON(data: Data(contentsOf: Bundle.main.url(forResource: "testNew", withExtension: "json")!))
            initializeRoute(route: try! Route(json: json))
        } else {
            initializeRoute(route: route!)
        }
    }
    
    /** Construct Directions based on Route and parse Waypoint / Path data */
    func initializeRoute(route: Route) {
        
        self.route = route
        self.directions = route.directions
        
        // Plot the paths of all directions
        for (arrayIndex, direction) in directions.enumerated() {
            
            var waypoints: [Waypoint] = []
            
            for (pathIndex, point) in direction.path.enumerated() {
                
                var type: WaypointType = .none
                
                if direction.type == .depart {
                    
                    if arrayIndex == 0 {
                        type = .origin
                    }
                        
                    else if arrayIndex == directions.count - 1 {
                        type = .destination
                    }
                        
                    else if pathIndex == 0 || pathIndex == direction.path.count - 1 {
                        type = .origin
                    }

                }
                
                else if direction.type == .walk {
                    
                    if arrayIndex == 0 && pathIndex == 0 {
                        type = .origin
                    }
                        
                    else if arrayIndex == self.directions.count - 1 && pathIndex == direction.path.count - 1 {
                        type = .destination
                    }
                    
                }
                
                let waypoint = Waypoint(lat: point.latitude, long: point.longitude, wpType: type)
                waypoints.append(waypoint)
                
            }
            
            let pathType: PathType = direction.type == .walk ? .walking : .driving
            let path = Path(waypoints: waypoints, pathType: pathType, color: .tcatBlueColor)
            routePaths.append(path)
            
        }
        
    }
{'fraction_non_alphanumeric': 0.07910178289325209, 'fraction_numerical': 0.009478672985781991, 'mean_word_length': 1.699664940603107, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '5900921', 'n_tokens_mistral': 2406, 'n_tokens_neox': 2234, 'n_words': 656}