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
38 changes: 28 additions & 10 deletions Cal-Hacks-TBD/Cal-Hacks-TBD/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="i1K-gj-o2c">
<rect key="frame" x="68" y="539" width="210" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Continue to Map Page for Now"/>
<connections>
<segue destination="3h1-n7-Cyk" kind="show" identifier="mapscreensegue" id="Z69-EN-MgI"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Username" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="h8e-9u-8wV">
<rect key="frame" x="139" y="127" width="79" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand Down Expand Up @@ -93,14 +85,16 @@
<connections>
<outlet property="firstBox" destination="PEP-wQ-Vvf" id="CCW-wf-DbH"/>
<outlet property="secondBox" destination="ZYQ-cX-gJg" id="5CF-b9-Nhd"/>
<outlet property="signUpBox" destination="EGX-U1-Sqy" id="24n-yT-NBH"/>
<segue destination="diG-zi-HYZ" kind="show" identifier="createContract" id="LAL-j6-ozX"/>
<segue destination="3h1-n7-Cyk" kind="show" identifier="mapscreensegue" id="1iT-G4-co4"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1948" y="55.322338830584712"/>
</scene>
<!--Map View Controller-->
<!--Item-->
<scene sceneID="PeV-wZ-jsx">
<objects>
<viewController id="3h1-n7-Cyk" customClass="MapViewController" customModule="Cal_Hacks_TBD" customModuleProvider="target" sceneMemberID="viewController">
Expand All @@ -110,6 +104,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="Nlh-Be-eMw"/>
</view>
<tabBarItem key="tabBarItem" title="Item" id="usF-FS-aLj"/>
<connections>
<outlet property="mapView" destination="QIN-1X-Vmf" id="eB4-3t-JLW"/>
</connections>
Expand All @@ -118,6 +113,24 @@
</objects>
<point key="canvasLocation" x="2706.4000000000001" y="54.422788605697157"/>
</scene>
<!--Tab Bar Controller-->
<scene sceneID="H01-QJ-eJt">
<objects>
<tabBarController id="B25-uf-jTB" sceneMemberID="viewController">
<tabBar key="tabBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="fBz-iV-tqV">
<rect key="frame" x="0.0" y="0.0" width="375" height="49"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tabBar>
<connections>
<segue destination="3h1-n7-Cyk" kind="relationship" relationship="viewControllers" id="z37-xQ-3lb"/>
<segue destination="diG-zi-HYZ" kind="relationship" relationship="viewControllers" id="rs5-1T-6wM"/>
</connections>
</tabBarController>
<placeholder placeholderIdentifier="IBFirstResponder" id="R4T-Up-AzF" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="167" y="968"/>
</scene>
<!--Sign Up-->
<scene sceneID="hVF-Hd-k6n">
<objects>
Expand Down Expand Up @@ -197,7 +210,7 @@
</objects>
<point key="canvasLocation" x="2453.5999999999999" y="775.86206896551732"/>
</scene>
<!--Login Controller-->
<!--Item-->
<scene sceneID="T8f-Hd-9yJ">
<objects>
<viewController id="diG-zi-HYZ" customClass="LoginController" customModule="Cal_Hacks_TBD" customModuleProvider="target" sceneMemberID="viewController">
Expand Down Expand Up @@ -264,6 +277,7 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<viewLayoutGuide key="safeArea" id="cIt-8d-BGC"/>
</view>
<tabBarItem key="tabBarItem" title="Item" id="Kpc-3s-h9T"/>
<connections>
<outlet property="descriptionOfQuery" destination="Cu4-Xg-vQh" id="MoR-Dj-kd9"/>
<outlet property="destination" destination="G0j-yG-XO8" id="6cJ-OH-xaf"/>
Expand Down Expand Up @@ -318,4 +332,8 @@
<point key="canvasLocation" x="1008.8" y="55.322338830584712"/>
</scene>
</scenes>
<inferredMetricsTieBreakers>
<segue reference="LAL-j6-ozX"/>
<segue reference="1iT-G4-co4"/>
</inferredMetricsTieBreakers>
</document>
20 changes: 10 additions & 10 deletions Cal-Hacks-TBD/Cal-Hacks-TBD/LoginController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,24 @@ class LoginController: UIViewController, UITextFieldDelegate {
request.httpMethod = HTTPMethod.post.rawValue
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
print("HERE")
//if !destination.endEditing(false){
// print("EXITING HERE")
// return
// }
//let quick = "(" + (placeNames[finalDest]?.coordinate.latitude.description)!
// let temp = quick
// + "," + (placeNames[finalDest]?.coordinate.longitude.description)!
//let final = temp + ")"
if !destination.endEditing(false){
print("EXITING HERE")
return
}
let quick = "(" + (placeNames[finalDest]?.coordinate.latitude.description)!
let temp = quick
+ "," + (placeNames[finalDest]?.coordinate.longitude.description)!
let final = temp + ")"

let myCoords = (locationManager.location?.coordinate)!
let quickone = "(" + myCoords.latitude.description
let tempone = quickone
+ "," + myCoords.latitude.description
+ "," + myCoords.longitude.description
let sourcefinal = tempone + ")"
print("XXXXXX")
print(sourcefinal)
print("XXXXXX")
let parameters = ["destination":"(20,10)", "price": price.text,"userid":userid,"source":sourcefinal,"description":descriptionOfQuery.text!] as! Dictionary<String, Any>
let parameters = ["destination":final, "price": price.text!,"userid":"random","source":sourcefinal,"description":descriptionOfQuery.text!] as! Dictionary<String, String>


do {
Expand Down
32 changes: 21 additions & 11 deletions Cal-Hacks-TBD/Cal-Hacks-TBD/MapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class MapViewController: UIViewController {
let cameraUpdate = GMSCameraUpdate.fit(mapBounds)
print(cameraUpdate)
mapView.moveCamera(cameraUpdate)
locationManager.startUpdatingLocation()
locationManager.startUpdatingLocation()
makeGetRequest()
}
func scheduledTimerWithTimeInterval(){
// Scheduling timer to Call the function "updateCounting" with the interval of 1 seconds
Expand Down Expand Up @@ -135,10 +136,9 @@ class MapViewController: UIViewController {
let myCoords = (locationManager.location?.coordinate)!
let quickone = "(" + myCoords.latitude.description
let tempone = quickone
+ "," + myCoords.latitude.description
+ "," + myCoords.longitude.description
let sourcefinal = tempone + ")"
print(sourcefinal)
let parameters = ["location":"temp", "radius": "5"] as Dictionary<String, String>
let parameters = ["location":sourcefinal, "radius": "5"] as Dictionary<String, String>


do {
Expand All @@ -149,28 +149,38 @@ class MapViewController: UIViewController {
}
print("EVEN GETTING HERE")
Alamofire.request(request).responseJSON { (response) in
var temp = response.value!
print(temp)
self.renderData(responseData: response.description)
let temp = response.value! as? [Any]
print("SHE WORKING ME")
self.renderData(responseData: temp!)

}
}

func renderData(responseData: String){
func renderData(responseData: [Any]){
// do some parsing to get the individual coordinates
// assuming we create some list:
// we're basically going to iterate through list and add them all to a path
let path = GMSMutablePath()
// latitude: 37.8716,longitude: -122.2727
let names = [(37.9716,-122.2727), (37.6716,-122.2727), (37.7716,-122.2727)]
for name in names {
path.add(CLLocationCoordinate2D(latitude: CLLocationDegrees(name.0), longitude: CLLocationDegrees(name.1)))
for name in responseData {
let myCurrent = name as? Dictionary<String,Any>
let start_location = myCurrent!["startLocation"] as? [Double]
let end_location = myCurrent!["endlocation"] as? [Double]
let contract_id = myCurrent!["_id"]
let validity = myCurrent!["valid"]
let price = myCurrent!["price"]
let position = CLLocationCoordinate2D(latitude: CLLocationDegrees(start_location![0]), longitude: CLLocationDegrees(start_location![1]))
let marker = GMSMarker(position: position)
marker.title = "Random"
marker.map = mapView
path.add(CLLocationCoordinate2D(latitude: CLLocationDegrees(start_location![0]), longitude: CLLocationDegrees(start_location![1])))
}
if locationManager.location != nil{
path.add((locationManager.location?.coordinate)!)
mapView?.isMyLocationEnabled = true
}
//Update your mapView with path
print("HERE")
let mapBounds = GMSCoordinateBounds(path: path)
let cameraUpdate = GMSCameraUpdate.fit(mapBounds)
mapView.moveCamera(cameraUpdate)
Expand Down
5 changes: 5 additions & 0 deletions Cal-Hacks-TBD/Cal-Hacks-TBD/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Alamofire
import GooglePlaces
class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var signUpBox: UIButton!
@IBOutlet weak var firstBox: UITextField!
var locationManager = CLLocationManager()
var userid = ""
Expand Down Expand Up @@ -79,6 +80,10 @@ class ViewController: UIViewController, UITextFieldDelegate {
vc.userid = userid
vc.logIn = logIn
}
if let vc = segue.destination as? SignUp
{
signUpBox.isHidden = true
}
}

override func didReceiveMemoryWarning() {
Expand Down
113 changes: 113 additions & 0 deletions MongoDB_backend/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

from pymongo import MongoClient, GEO2D
from bson.objectid import ObjectId

client = MongoClient()

db = client.pretty

contracts = db.contract
users = db.users

contracts.create_index([("startLocation", GEO2D)])
contracts.create_index([("endLocation", GEO2D)])

def createContract(ownerID, sLat, sLong, eLat, eLon, price, title, description):
contract = {
"ownerID" : ownerID,
"acceptID" : -1,
"startLocation" :[sLat, sLong],
"endLocation" : [eLat, eLon],
"price" : price,
"title" : title,
"description" : description,
"valid" : True,
"active" : False,
}

result = contracts.insert(contract);
return str(result);

def createUser(name, password, userID, rating):
found = users.find({"username" :userID}).count()
if found:
return -1

user = {
"name" : name,
"password" : password,
"username" : userID,
"rating" : rating
}
result = users.insert(user)
print str(result);

return str(result);


def acceptContract(userID, contractID):
objID = ObjectId(contractID)
found = contracts.find( {"$and" :[{"_id" : objID}, {"valid": True}]}).count()

if found > 0:
contracts.update({"_id": objID}, { "$set" : {"valid": False, "active": True, "acceptID": userID } })
return True
else:
return False

def completeContract(contractID):
objID = ObjectId(contractID)
found = contracts.find( {"$and" : [{"_id" : objID}, {"active": True}]} ).count()

if found > 0:
contracts.update( {"_id" : objID}, { "$set" : {"active" : False}})
return True
else:
return False




def validLogin(username, password):
found = users.find_one({"$and" :[{"username" : username, "password": password}] })

if found :
return str(found.get('_id'))
else:
return -1


def getContractSpatial(lat, lon, radius) :
query = contracts.find( {"$and" :[{"valid": True},{"startLocation": {"$within": {"$center": [[lat, lon], radius]}}} ]})

return query



def getContract(contractID):
contract = contracts.find_one({"_id": ObjectId(contractID)})

for data in contract:
toReturn = [data.get("owner"), data.get("startLocation"), data.get("endLocation"), data.get("price")]

return toReturn

def getUser(blockID):
contract = contracts.find({"_id": ObjectId(blockID)})

for data in contract:
toReturn = [data.get("name"), data.get("password"), data.get("screenName"), data.get("rating")]

return toReturn



#createContract("5bdde74ab7ae36d406d6ea65" , 20, 20, 60, 40, 100)
#createUser("Theo", "pass", "theoluan", 0)
#acceptContract("5bdde74ab7ae36d406d6ea65", "5bdde93fb7ae36d449895550")
#print validLogin("theoluan", "not")
#getContract("Theo")