当前位置: 首页>>代码示例>>Python>>正文


Python Game.selectAll方法代码示例

本文整理汇总了Python中models.Game.selectAll方法的典型用法代码示例。如果您正苦于以下问题:Python Game.selectAll方法的具体用法?Python Game.selectAll怎么用?Python Game.selectAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Game的用法示例。


在下文中一共展示了Game.selectAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import selectAll [as 别名]
    def get(self):
        user = users.get_current_user()
        game = Game()

        medex_player = game.selectOneJoin("m.bad_avatar", "`j`.`email` = {} AND m.registered = '1'", [user.email()])
        
        if medex_player is None:
            self.redirect('/register')
            return
        elif medex_player[0] != 0:
            self.redirect('/badavatar')
            return

        #Get user's info
        this_player = game.selectOne(config.JIVE_PROFILE_TBL, "fullname, title, picture_binary, id", "`email` = {}", [user.email()])
        t_player = { 'fullname': this_player[0].decode('latin-1'), 'title': this_player[1], 'picture_src': this_player[2].encode('base64').replace('\n', '')}

        departments = [row[0] for row in game.selectAll(config.JIVE_PROFILE_TBL, "department", distinct=True)]
        locations = [row[0] for row in game.selectAll(config.JIVE_PROFILE_TBL, "location", "location NOT LIKE 'Remote%' AND location NOT IN ('C3i','Paradigm')", distinct=True)]
        departments.sort()
        locations.sort()

        template_values = dict(selected='review',
                               this_player=t_player,
                               player_level=game.getLevel(user.email()), #level, name, progress
                               departments=departments,
                               locations=locations,
                               pubnub_publish_key=config.pubnub_publish_key,
                               pubnub_subscribe_key=config.pubnub_subscribe_key
        )

        #Get a flashcard
        try:
            player_info = self.getNewCardForUser(str(this_player[3]), {"department": "All", "location": "All"})
            picture_url = player_info[2].encode('base64').replace('\n', '')

            template_values.update(dict(
                picture_url = picture_url,
                player_id = player_info[3],
                answer = "{0}, {1}".format(player_info[0], player_info[1])
            ))

        except NoPlayersLeft:
            logging.info('error')
            template_values['no_players_left'] = True

        template = JINJA_ENVIRONMENT.get_template('review.html')
        self.response.write(template.render(template_values))
开发者ID:mdsol,项目名称:jive,代码行数:50,代码来源:views.py

示例2: getNewTurnForUser

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import selectAll [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
开发者ID:mdsol,项目名称:jive,代码行数:94,代码来源:views.py


注:本文中的models.Game.selectAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。