diff --git a/Knovigo/Base.lproj/Main.storyboard b/Knovigo/Base.lproj/Main.storyboard index 56af6b8..6221225 100644 --- a/Knovigo/Base.lproj/Main.storyboard +++ b/Knovigo/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -2303,7 +2303,7 @@ - + diff --git a/Knovigo/Controllers/HomeViewController.swift b/Knovigo/Controllers/HomeViewController.swift index c6f6785..52ee74a 100644 --- a/Knovigo/Controllers/HomeViewController.swift +++ b/Knovigo/Controllers/HomeViewController.swift @@ -33,7 +33,7 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ locationManager = CLLocationManager() locationManager.requestWhenInUseAuthorization() - + // set map @UCLA let camera = GMSCameraPosition.camera(withLatitude: mapLocation.coordinates.latitude, longitude: mapLocation.coordinates.longitude, zoom: 14.5) mapView.camera = camera @@ -57,15 +57,15 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ locationManager.startUpdatingLocation() var currentLoc: CLLocation! if(CLLocationManager.authorizationStatus() == .authorizedWhenInUse || - CLLocationManager.authorizationStatus() == .authorizedAlways) { + CLLocationManager.authorizationStatus() == .authorizedAlways) { locationManager.startUpdatingLocation() currentLoc = locationManager.location } if (currentLoc == nil) { locationManager.requestWhenInUseAuthorization() locationManager.startUpdatingLocation() -// self.dismiss(animated: false, completion: nil) -// alertLocationAccessNeeded(); + // self.dismiss(animated: false, completion: nil) + // alertLocationAccessNeeded(); currentLoc = CLLocation(latitude: 34.0700, longitude: -118.4398) } @@ -77,29 +77,29 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ //sets the data for the heatmap loadHeatmap(); - + } func alertLocationAccessNeeded(controller:UIViewController) { let settingsAppURL = URL(string: UIApplication.openSettingsURLString)! - - let alert = UIAlertController( - title: "Need Location Access", - message: "Location access is required for including the landmark pins. Please allow access and refresh the application for best use!", + + let alert = UIAlertController( + title: "Need Location Access", + message: "Location access is required for including the landmark pins. Please allow access and refresh the application for best use!", preferredStyle: UIAlertController.Style.alert - ) - + ) + alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil)) alert.addAction(UIAlertAction(title: "Allow Location Access", - style: .cancel, - handler: {(alert) -> Void in + style: .cancel, + handler: {(alert) -> Void in UIApplication.shared.open(settingsAppURL, - options: [:], - completionHandler: nil) - })) - + options: [:], + completionHandler: nil) + })) + DispatchQueue.main.async{ - self.present(alert, animated: true, completion: nil) + self.present(alert, animated: true, completion: nil) } } @@ -108,12 +108,12 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ let task2 = URLSession.shared.dataTask(with: url2!) {(data, response, error) in guard let data = data else { return } guard let json = try? JSONSerialization.jsonObject(with: data, options: []) else { - print("Serialization went wrong") - return + print("Serialization went wrong") + return } guard let object2 = json as? [[String: Any]] else { - print("Could not read the JSON.") - return + print("Could not read the JSON.") + return } for item in object2 { var locImage = UIImage(named: "tongva.jpg") @@ -125,15 +125,15 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ } } - let hour = Calendar.current.component(.hour, from: Date())*100 - let weekday = Calendar.current.component(.weekday, from: Date()) - var validHour = false - var openHour = -1 - var closeHour = -1 - var openString = "" - var closeString = "" - let arr = item["businessHours"] as! [[String: Any]] - let times = arr.first + let hour = Calendar.current.component(.hour, from: Date())*100 + let weekday = Calendar.current.component(.weekday, from: Date()) + var validHour = false + var openHour = -1 + var closeHour = -1 + var openString = "" + var closeString = "" + let arr = item["businessHours"] as! [[String: Any]] + let times = arr.first switch(weekday) { case 1: openString = "sunday_open" @@ -175,7 +175,7 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ validHour = true } - let loc = location(name: item["name"] as! String, coordinates: CLLocationCoordinate2D(latitude: 34.0700, longitude: -118.4398), address: item["address"] as! String, image: locImage!, wideImage: locWideImage!, distance: Double(round(1000*(item["distance"] as! Double))/1000), isOpen: validHour, label: "temp", pinLabel: item["agg_density"] as! Double, sliderMask: item["agg_mask"] as! Double, sliderDistance: item["agg_social"] as! Double, sliderDensity: item["agg_density"] as! Double) + let loc = location(name: item["name"] as! String, coordinates: CLLocationCoordinate2D(latitude: 34.0700, longitude: -118.4398), address: item["address"] as! String, image: locImage!, wideImage: locWideImage!, distance: Double(round(1000*(item["distance"] as! Double))/1000), isOpen: validHour, label: "temp", pinLabel: item["agg_density"] as! Double, sliderMask: item["agg_mask"] as! Double, sliderDistance: item["agg_social"] as! Double, sliderDensity: item["agg_density"] as! Double, id: item["place_id"] as! String) self.markCoords.append(loc) } DispatchQueue.main.async { @@ -189,6 +189,7 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ func setMarker(markerGeoCoords: [location], tempCoords: [location]){ var marker: GMSMarker for i in markerGeoCoords { + var place_id = i.id var coords = i.coordinates var description = i.label for loc in markerCoords { @@ -204,9 +205,9 @@ class HomeViewController: UIViewController, GMSMapViewDelegate{ //styling the marker marker.map = self.mapView marker.accessibilityLabel = i.name - marker.userData = data(image: i.image, imageWide: i.wideImage, distance: i.distance, isOpen: i.isOpen, label: description, pin: i.pinLabel, sMask: i.sliderMask, sDistance: i.sliderDistance, sDensity: i.sliderDensity); - - if (i.pinLabel <= 0.20) { + marker.userData = data(image: i.image, imageWide: i.wideImage, distance: i.distance, isOpen: i.isOpen, label: description, pin: i.pinLabel, sMask: i.sliderMask, sDistance: i.sliderDistance, sDensity: i.sliderDensity, id : place_id); + + if (i.pinLabel <= 0.20) { marker.icon = UIImage(named: "pin-dark-green"); } else if (i.pinLabel <= 0.40) { marker.icon = UIImage(named: "pin-light-green"); diff --git a/Knovigo/Controllers/LocationViewController.swift b/Knovigo/Controllers/LocationViewController.swift index 3339702..392276e 100644 --- a/Knovigo/Controllers/LocationViewController.swift +++ b/Knovigo/Controllers/LocationViewController.swift @@ -15,7 +15,6 @@ class LocationViewController: UIViewController, ChartViewDelegate, UIPickerViewD override func viewDidLoad() { super.viewDidLoad() // barChart.delegate = self; - charInit() //dropDownInit() setSliderInvert(slider: estiDensity); setSlider(slider: estiDistancing); @@ -37,6 +36,7 @@ class LocationViewController: UIViewController, ChartViewDelegate, UIPickerViewD locTitle.text = locMarker.title locAddress.text = locMarker.snippet let data = locMarker.userData as? data + charInit(place_data: data!) if (!(data?.isOpen ?? false)) { locIsClosed.text = "Closed" locIsClosed.textColor = UIColor.red @@ -76,7 +76,18 @@ class LocationViewController: UIViewController, ChartViewDelegate, UIPickerViewD title.textAlignment = .center return title - + } + + func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + let set = BarChartDataSet(entries: self.allDays[pickerData[row].lowercased()]) + set.highlightEnabled = false + set.colors = [UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)] + let data = BarChartData(dataSet: set) + data.setDrawValues(false); + data.accessibilityEntryLabelPrefix = "bar chart" + data.accessibilityEntryLabelSuffix = "bar chart" + data.barWidth = 1 + barChart.data = data } var pickerData: [String] = [String]() @@ -115,79 +126,85 @@ class LocationViewController: UIViewController, ChartViewDelegate, UIPickerViewD let dropDown = DropDown() var locMarker = GMSMarker(); - - func charInit(){ + var allDays : [String: [BarChartDataEntry]] = [:] + func charInit(place_data : data){ + let group = DispatchGroup() + group.enter() //popular times --> monday --> array of 24 indexed 0-23 - /* - let url = URL(string: "http://52.33.183.202:8000/places/place/")! + var popularity : [BarChartDataEntry] = [] + let url = URL(string: "http://13.52.104.196:8000/places/place/" + place_data.id)! let task = URLSession.shared.dataTask(with: url) {(data, response, error) in guard let data = data else { return } guard let json = try? JSONSerialization.jsonObject(with: data, options: []) else { print("Serialization went wrong") return } - guard let object = json as? [[String: Any]] else { + guard let object = json as? [String: Any] else { print("Could not read the JSON.") return } - - for item in object { - let lat = item["lat"] as! CLLocationDegrees - let lng = item["lng"] as! CLLocationDegrees - let int = item["intensity"] as! Float - let coords = GMUWeightedLatLng( - coordinate: CLLocationCoordinate2DMake(lat, lng), - intensity: int - ) - list.append(coords) + guard let times = object["popularTimes"] as? [[String: Any]] else{ + print("Could not retrieve popular times") + return + } + if (times.count == 0){ + return + } + var days = times[0] + days.removeValue(forKey:"place") + for (key, value) in days{ + popularity = [] + let hours = value as! [Int] + for time in 0..