本文整理汇总了Python中db.Database.getLocation方法的典型用法代码示例。如果您正苦于以下问题:Python Database.getLocation方法的具体用法?Python Database.getLocation怎么用?Python Database.getLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.getLocation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_new_vote
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import getLocation [as 别名]
def post_new_vote(study_id):
def incVotes(obj):
# Keep obj updates for consistency
if obj.get("votes"):
obj["votes"] += 1
Database.locations.update({"_id": obj["_id"]}, {"$inc": {"votes": 1}})
Database.incQSVoteCount(study_id, str(obj.get("_id")))
leftObj = Database.getLocation(request.form["left"])
rightObj = Database.getLocation(request.form["right"])
if leftObj is None or rightObj is None:
return jsonifyResponse({"error": "Locations don't exist!"})
map(incVotes, [leftObj, rightObj])
newVoteObj = {
"study_id": request.form["study_id"],
"left": request.form["left"],
"right": request.form["right"],
"choice": request.form["choice"],
"timestamp": datetime.now(),
}
# If there is no userObj, create one now
if not session.get("userObj"):
# Generate a random ID to associate votes with this user if one does not already exist
session["voterID"] = session["voterID"] if session.get("voterID") else str(uuid4().hex)
session["userObj"] = Database.createUserObj(session["voterID"])
if session["userObj"].get("email"):
newVoteObj["voter_email"] = session["userObj"]["email"]
if session.get("voterID"):
newVoteObj["voter_uniqueid"] = session["voterID"]
# Insert vote into DB
Database.votes.insert(newVoteObj)
# Increment votes in DB
Database.users.update({"_id": session["userObj"]["_id"]}, {"$inc": {"num_votes": 1}})
# And in cookied object
session["userObj"]["num_votes"] = session["userObj"]["num_votes"] + 1 if session["userObj"].get("num_votes") else 1
# Did the user unlock anything?
unlockedStudies = Gamification.unlockNew(session["userObj"])
if len(unlockedStudies) > 0:
Database.users.update(
{"_id": session["userObj"]["_id"]},
{
"$pushAll": {"unlocked_studies": unlockedStudies},
"$set": {"last_unlocked_at": session["userObj"]["num_votes"]},
},
)
# Get user obj from database and update cookied object
session["userObj"] = Database.getUserById(session["userObj"]["_id"])
session.modified = True
response = {"success": True}
# Finally, if the user requested an update to their gamification status, send it
if request.form.get("gamification_status"):
response["gamificationStatus"] = Gamification.getUnlockStatus(session["userObj"])
return jsonifyResponse(response)
示例2: get_bottom_n_place
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import getLocation [as 别名]
def get_bottom_n_place(study_id, place_id, n):
qss = list(Database.qs.find({'study_id': study_id, 'place_id': place_id}).sort('trueskill.score', direction=1).limit(n))
for qs in qss:
#place = Database.getPlace(qs['place_id'])
#qs['place_name'] = place['place_name']
location = Database.getLocation(qs['location_id'])['loc']
qs['location'] = location
return jsonifyResponse(qss)
示例3: curate_location
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import getLocation [as 别名]
def curate_location():
# Insert the new study into Mongo
location = Database.getLocation(id)
# Return the ID for the client to rendezvous at /study/populate/<id>
return jsonifyResponse({
'latitude': str(location.loc[0]),
'longitude': str(location.loc[1]),
'heading': str(location.heading),
'pitch': str(location.pitch)
})
示例4: get_location
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import getLocation [as 别名]
def get_location(location_id):
locationCursor = Database.getLocation(location_id)
lat = locationCursor["loc"][0]
lng = locationCursor["loc"][1]
return (
"<img src='http://maps.googleapis.com/maps/api/streetview?size=404x296&location="
+ lat
+ ","
+ lng
+ "&sensor=false'/>"
)
示例5: get_study_pairing
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import getLocation [as 别名]
def get_study_pairing(study_id):
# get location 1
QS1 = Database.randomQS(study_id, fewestVotes=True)
if QS1 is None:
return jsonifyResponse({"error": "Could not get location 1 from QS collection."})
# get location 2
if not QS1.has_key("q"): # location 1 has no q score
QS2 = Database.randomQS(study_id, exclude=QS1.get("location_id"))
else:
# get 25 locations with q scores
obj = {
"study_id": study_id,
"location_id": {"$ne": QS1.get("location_id")},
"num_votes": {"$lte": 30},
"q": {"$exists": True},
}
f = 25
count = Database.qs.find(obj).count() - 1
s = randint(0, max(0, count - f))
QSCursor = Database.qs.find(obj).skip(s).limit(f)
# pick location with closest score
dist = lambda QS: abs(QS.get("q") - QS1["q"])
try:
QS2 = min(QSCursor, key=dist)
except ValueError: # db query yields zero results
QS2 = Database.randomQS(study_id, exclude=QS1.get("location_id"))
if QS2 is None:
return jsonifyResponse({"error": "Could not get location 2 from QS collection."})
# convert to location objects
location1 = Database.getLocation(QS1.get("location_id"))
location2 = Database.getLocation(QS2.get("location_id"))
locationsToDisplay = [location1, location2]
if location1 is None or location2 is None:
return jsonifyResponse({"error": "Locations could not be retrieved from location collection!"})
return jsonifyResponse({"locs": map(objifyPlace, locationsToDisplay)})