Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Knovigo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="kBB-2X-M2c">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="kBB-2X-M2c">
<device id="retina6_0" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand Down Expand Up @@ -2303,7 +2303,7 @@
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="EMw-UY-BOx"/>
<segue reference="uAG-Wd-VI0"/>
</inferredMetricsTieBreakers>
<resources>
<image name="arrowshape.turn.up.backward.fill" catalog="system" width="128" height="106"/>
Expand Down
71 changes: 36 additions & 35 deletions Knovigo/Controllers/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand All @@ -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)
}
}

Expand All @@ -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")
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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");
Expand Down
101 changes: 59 additions & 42 deletions Knovigo/Controllers/LocationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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]()

Expand Down Expand Up @@ -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/<id>")!
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..<hours.count{
let percent = hours[time]
if (percent == 0){
continue
}
else{
popularity.append(BarChartDataEntry(x: Double(time) + 0.5, y: Double(percent)))
}
}
self.allDays[String(key)] = popularity
}
// Add the latlngs to the heatmap layer.
self.heatMapLayer.weightedData = list;
group.leave()
}
*/
//TODO: hard coding data for chart
let set = BarChartDataSet(entries: [
BarChartDataEntry(x: 0, y: 3),
BarChartDataEntry(x: 10, y: 5),
BarChartDataEntry(x: 20, y: 10),
BarChartDataEntry(x: 30, y: 20),
BarChartDataEntry(x: 40, y: 40),
BarChartDataEntry(x: 50, y: 60),
BarChartDataEntry(x: 60, y: 40),
BarChartDataEntry(x: 70, y: 20),
BarChartDataEntry(x: 80, y: 10),
BarChartDataEntry(x: 90, y: 5),
BarChartDataEntry(x: 100, y: 3),
])

//for formatting purpose
set.drawValuesEnabled = set.isHighlightEnabled
task.resume()
group.wait()
let set = BarChartDataSet(entries: self.allDays["monday"])
set.highlightEnabled = false
set.colors = [UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)]
set.highlightColor = UIColor(red: 68/255, green: 150/255, blue: 176/255, alpha: 1)
set.highlightLineDashLengths = [CGFloat(3)]

//store data in an array
let data = BarChartData(dataSet: set)
data.setDrawValues(true);
data.setDrawValues(false);
data.accessibilityEntryLabelPrefix = "bar chart"
data.accessibilityEntryLabelSuffix = "bar chart"

//for formatting purpose
data.barWidth = 6
data.barWidth = 1

//assign data to barChart
barChart.data = data

barChart.xAxis.drawAxisLineEnabled = false
barChart.xAxis.drawGridLinesEnabled = false
barChart.xAxis.drawLabelsEnabled = false
barChart.xAxis.drawLabelsEnabled = true
barChart.leftAxis.drawLabelsEnabled = false
barChart.leftAxis.drawAxisLineEnabled = false
barChart.rightAxis.drawAxisLineEnabled = false
barChart.rightAxis.drawLabelsEnabled = true
barChart.leftAxis.axisMinimum = 0
barChart.leftAxis.axisMaximum = 100
barChart.rightAxis.axisMinimum = 0
barChart.rightAxis.axisMaximum = 100
barChart.legend.enabled = false
barChart.notifyDataSetChanged()
barChart.drawValueAboveBarEnabled = true;
barChart.doubleTapToZoomEnabled = false;
barChart.xAxis.labelPosition = XAxis.LabelPosition.bottom
barChart.xAxis.granularityEnabled = true
barChart.xAxis.granularity = 1
barChart.xAxis.setLabelCount(set.count, force: true)
}

// func dropDownInit(){
Expand Down
Loading