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


Python Framework.norun方法代码示例

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


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

示例1: run

# 需要导入模块: from framework import Framework [as 别名]
# 或者: from framework.Framework import norun [as 别名]
  def run(self):

    try:
      tournament = Tournament()
      tournament.status = Tournament.STATUS_CHOICES[0][0]
      tournament.save()

      logging.debug('Scheduler.run: tournament = ' + str(tournament))

      bots = Bot.objects.filter(is_deleted=0)
      start_time = time()
      for white in bots:

        try:
          white_participant = Participant.objects.get(tournament__id=tournament.id, bot__id=white.id)
        except ObjectDoesNotExist:
          white_participant = Participant(tournament=tournament, bot=white)

        logging.debug('Scheduler.run: white = ' + str(white))

        for black in bots:
          if not white == black:
            logging.debug(white.name + ' v. ' + black.name)

            try:
              black_participant = Participant.objects.get(tournament__id=tournament.id, bot__id=black.id)
            except ObjectDoesNotExist:
              black_participant = Participant(tournament=tournament, bot=black)

            logging.debug('Scheduler.run: black = ' + str(black))

            game = Game(tournament=tournament, white=white, black=black)

            logging.debug('Scheduler.run: game = ' + str(game))

            commandLine = 'framework --white="' + white.name + '" --black="' + black.name + '" --times="600000,0,0" --moves=", " --expansions=""'
            commandLine = commandLine.encode('ascii')
            framework = Framework(shlex.split(commandLine))
            results = framework.norun() 

            logging.debug('Scheduler.run: results = ' + str(results))

            white_participant.wins += results['white']['wins']
            white_participant.losses += results['white']['loses']
            white_participant.draws += results['white']['draws']
            white_participant.number_of_moves += results['white']['number_of_moves']
            white_participant.time += results['white']['time']
            white_participant.errors += results['white']['errors']
            white_participant.save()

            black_participant.wins += results['black']['wins']
            black_participant.losses += results['black']['loses']
            black_participant.draws += results['black']['draws']
            black_participant.number_of_moves += results['black']['number_of_moves']
            black_participant.time += results['black']['time']
            black_participant.errors += results['black']['errors']
            black_participant.save()

            game.duration = results['white']['time'] + results['black']['time']
            game.duration = results['white']['time'] + results['black']['time']
            game.number_of_moves = results['white']['number_of_moves'] + results['black']['number_of_moves']

            if results['white']['wins'] == 1:
              game.winner = game.WINNER_CHOICES[0][0]
            elif results['black']['wins'] == 1: 
              game.winner = game.WINNER_CHOICES[1][0]
            else: 
              game.winner = game.WINNER_CHOICES[2][0]

            result_json = json.dumps({ 
              'white': white.name,
              'black': black.name,
              'times': results['args']['times'],
              'moves': results['args']['moves'],
              'expansions': results['args']['expansions'],
              'date_played': datetime.utcnow().isoformat(),
              'duration': game.duration,
              'winner': game.winner,
              'play_by_play': results['play_by_play']
              }, indent=2)

            game.result_file.save('result.json', ContentFile(result_json))

            game.save()

      end_time = time()

      tournament.duration = round((end_time - start_time) * 100)
      tournament.status = Tournament.STATUS_CHOICES[2][0]
      tournament.save()
    except:
      print "Unexpected error:", sys.exc_info()
开发者ID:tylerxprice,项目名称:hive-framework,代码行数:94,代码来源:scheduler.py


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