本文整理汇总了Python中models.Game.selectOneJoin方法的典型用法代码示例。如果您正苦于以下问题:Python Game.selectOneJoin方法的具体用法?Python Game.selectOneJoin怎么用?Python Game.selectOneJoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Game
的用法示例。
在下文中一共展示了Game.selectOneJoin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import selectOneJoin [as 别名]
def get(self):
errors = []
user = users.get_current_user()
if not user:
logging.error('Post when not logged in!')
self.abort(500)
email = user.email()
try:
country_code = self.request.headers["X-AppEngine-Country"]
except KeyError:
country_code = '?'
logging.info(email)
if not isMedidata(email):
self.redirect('/medidataonly')
return
game = Game()
player = game.selectOneJoin("j.id, j.fullname, m.registered", "`email` = {}", [email])
if player is None:
self.redirect('/needprofilepicture')
elif player[2] == 1:
self.redirect('/')
else:
where = "`jive_profile_id` = {}"
where_inter = [player[0]]
game.update(config.MEDIFACES_PLAYER_TBL, {"registered": 1}, where, where_inter)
# spoofing in users data
base64string = base64.encodestring('{0}:{1}'.format(config.jive_username,config.jive_password))[:-1]
name = player[1]
content = "<body><p>" + name + " just signed up in <a href='https://medifaces-demo-1.appspot.com/' class='jive-link-community-small'>Medifaces</a></p><p></p><p><em>Posted by <a href='https://mdsol.jiveon.com/docs/DOC-14722'>ExpressBot</a></em></p></body>"
data = json.dumps({"visibility": "place", "parent": config.jive_placeUrl + "/"+ str(config.jive_medifaces_space), "type":"update", "content":{ "type":"text/html", "text":content}})
result = urlfetch.fetch(method=urlfetch.POST, url=config.jive_contentUrl, deadline=15, headers={"X-Jive-Run-As": "email " + email, 'Authorization': 'Basic ' + base64string, "Content-Type": "application/json"}, payload=data).content
# spoofing in users data
base64string = base64.encodestring('{0}:{1}'.format(config.jive_username,config.jive_password))[:-1]
# curl -v -u [email protected]:[email protected] -k --header "Content-Type: application/json" -d '{"visibility":"place", "parent":"https://mdsol-sandbox.jiveon.com/api/core/v3/places/41156", "type":"document", "subject":"My place document", "content":{"type":"text/html","text":"<body><p>Test of document in a place</p></body>"} }' "https://mdsol-sandbox.jiveon.com/api/core/v3/contents"
name = player[1]
content = "<body><p>" + name + " just signed up in <a href='https://medex-faces.appspot.com' class='jive-link-community-small'>Medifaces</a></p><p></p><p><em>Posted by <a href='https://mdsol.jiveon.com/docs/DOC-14722'>ExpressBot</a></em></p></body>";
data = json.dumps({"visibility": "place", "parent": config.jive_placeUrl + "/"+ str(config.jive_medifaces_space), "type":"update", "content":{ "type":"text/html", "text":content}});
result = urlfetch.fetch(method=urlfetch.POST, url=config.jive_contentUrl, deadline=15, headers={"X-Jive-Run-As": "email " + email, 'Authorization': 'Basic ' + base64string, "Content-Type": "application/json"}, payload=data).content
#Send a broadcast that we have a new player
broadcast('%s just signed up!' % email)
#Gotta flush the all_players cache
flush_all_players_cache()
self.redirect("/letsplay")
示例2: getNewCardForUser
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import selectOneJoin [as 别名]
def getNewCardForUser(self, jive_profile_id, filtr):
""" Get a new "flashcard" for the user"""
game = Game()
#all players you've already correctly identified enough times
done_players = "SELECT p_shown_id FROM " + config.MEDIFACES_REVIEW_TBL + " WHERE jive_profile_id = {} and done = TRUE"
done_players_inter = [jive_profile_id]
filtr_query = ""
# in case location and department don't show up in filtr
if filtr.get("location") is None and filtr.get("department") is None:
logging.info("WARNING: location and department not found in filtr")
filtr["location"] = "All"
filtr["department"] = "All"
filtr_query_inter = []
# add location to filtr_query if location is not "All"
if filtr.get("location") != "All":
if filtr.get("location") == "Remote":
filtr_query += " AND location like 'Remote%'" #only remote employees
elif filtr.get("location") == "Other":
filtr_query += " AND location in ('Paradigm','C3i')" #only Paradigm or C3i employees
else:
filtr_query += " AND location = {}" #only employees in specified location
filtr_query_inter.append(filtr.get("location"))
# add department to filtr_query if department is not "All"
if filtr.get("department") != "All":
filtr_query += " AND department = {}" # only employees in specified department
filtr_query_inter.append(filtr.get("department"))
logging.info(filtr_query)
done_str = ""
if done_players:
done_str = "j.id NOT IN (" + ",".join(["{}"] * len(done_players)) + ") AND"
#info of a random player not in query and not yourself and has a good avatar
player_info = game.selectOneJoin("j.fullname, j.title, j.picture_binary, j.id", "j.id NOT IN (" + done_players + ") AND j.id != {} AND m.bad_avatar='0'" + filtr_query + " ORDER BY RAND()", done_players_inter + [jive_profile_id] + filtr_query_inter)
if player_info is None:
raise NoPlayersLeft("No players you haven't seen yet in this category.")
return player_info
示例3: getNewTurnForUser
# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import selectOneJoin [as 别名]
def getNewTurnForUser(self, jive_profile_id, filtr):
"""
Get a new new turn object for the user. It's always the logged in user.
We use ancestor queries to tie all turn attempts to the user so that we
can make their turn attempts strongly consistent.
"""
# 1. Find a user that never played before by this user
game = Game()
query = "SELECT p_shown_email_id FROM " + config.MEDIFACES_GAME_TURN_TBL + " where jive_profile_id = {} AND game_state != 'N'"
query_inter = [jive_profile_id]
logging.info(query)
filtr_query = ""
filtr_query_inter = []
# in case location and department don't show up in filtr
if filtr.get("location") is None and filtr.get("department") is None:
logging.info("WARNING: location and department not found in filtr")
# add location to filtr_query if location is not "All"
if filtr.get("location") != "All":
if filtr.get("location") == "Remote":
filtr_query += " AND location like 'Remote%'" #only remote employees
elif filtr.get("location") == "Other":
filtr_query += " AND location in ('Paradigm','C3i')" #only Paradigm or C3i employees
else:
filtr_query += " AND location = {}" #only employees in specified location
filtr_query_inter.append(filtr.get("location"))
# add department to filtr_query if department is not "All"
if filtr.get("department") != "All":
filtr_query += " AND department = {}" # only employees in specified department
filtr_query_inter.append(filtr.get("department"))
# select one random player you haven't seen before, not including yourself, and return the [id, fullname, title, picture_binary, gender]
player = game.selectOneJoin("j.id, j.fullname, j.title, j.picture_binary, m.gender", "j.id NOT IN (" + query + ") AND j.id != {} AND m.bad_avatar='0'" + filtr_query + " ORDER BY RAND()", query_inter + [jive_profile_id] + filtr_query_inter)
# if there are no players you haven't seen at least once, find one you haven't answered correctly yet
if player is None:
query += " AND game_state != 'L'"
player = game.selectOneJoin("j.id, j.fullname, j.title, j.picture_binary, m.gender", "j.id NOT IN (" + query + ") AND j.id != {} AND m.bad_avatar='0'" + filtr_query + " ORDER BY RAND()", query_inter + [jive_profile_id] + filtr_query_inter)
# no players with these filters
if player is None:
raise NoPlayersLeft("No players you haven't seen yet in this category.")
gender = player[4]
where = ""
where_inter = []
if gender != 0:
where = " AND gender = {}"
where_inter.append(gender)
# pick up 4 other players to add in the game.
other_players = game.selectJoin("j.id, j.fullname, j.title", "j.id NOT IN ({},{})"+where+filtr_query+" ORDER BY RAND() LIMIT 4", [str(player[0]), jive_profile_id] + where_inter + filtr_query_inter)
# if there aren't 4 other players with matching gender + filtr, try getting more people using only gender
if len(other_players) < 4:
player_ids = [player[0], jive_profile_id] + [row[0] for row in other_players]
other_players += game.selectJoin("j.id, j.fullname, j.title", "j.id NOT IN (" + ",".join(["{}"] * len(player_ids)) + ")"+where+" ORDER BY RAND()", player_ids + where_inter, limit=4-len(other_players))
# finally, just choose people regardless of their category
if len(other_players) < 4:
player_ids = [player[0], jive_profile_id] + [row[0] for row in other_players]
other_players += game.selectAll(config.JIVE_PROFILE_TBL, "id, fullname, title", "`id` NOT IN (" + ",".join(["{}"] * len(player_ids)) + ")" + " ORDER BY RAND() LIMIT " + str(4-len(other_players)), player_ids)
logging.info(player)
logging.info(other_players)
picked_players = [player[:3]] + list(other_players)
random.shuffle(picked_players)
values = {
'jive_profile_id': jive_profile_id,
'game_state' : 'N',
'p_shown_email_id' : str(player[0]),
}
logging.info(picked_players)
for i in range(len(picked_players)):
values['p%s_email_id' % (i+1)] = picked_players[i][0]
#logging.info(values)
new_game_turn_id = game.insert(config.MEDIFACES_GAME_TURN_TBL, values)
logging.info(new_game_turn_id)
turn_data = {}
turn_data["id"] = new_game_turn_id
turn_data["image_url"] = player[3].encode('base64').replace('\n', '')
turn_data["players"] = [ {"id": row[0], "name": row[1], "title": row[2]} for row in picked_players]
logging.info(turn_data)
return turn_data