def handle(self, *args, **options):
     num_rounds = 2
     div_num = 1
     curr_div = Division(divID=str(div_num))
     curr_div.save()
     with open("entrants-3.txt") as f:
         player_num = 1
         for r in range(1, num_rounds + 1):
             curr_round = TourneyRound(division=curr_div, round_number=r)
             curr_round.save()
         for curr_line in f:
             if not curr_line.strip():
                 div_num += 1
                 player_num = 1
                 curr_div = Division(divID=str(div_num))
                 curr_div.save()
                 for r in range(1, num_rounds + 1):
                     curr_round = TourneyRound(division=curr_div, round_number=r)
                     curr_round.save()
             else:
                 comma_ind = curr_line.index(",")
                 last_name = curr_line[:comma_ind]
                 first_name = curr_line[comma_ind + 2:curr_line.index(" ", comma_ind + 2)]
                 rating_start_ind = re.search("\d", curr_line).start()
                 rating = curr_line[rating_start_ind:curr_line.index(";")]
                 curr_player = Player(number=player_num, name=first_name + " " + last_name, division=curr_div,
                                      initial_rating=rating)
                 player_num += 1
                 curr_player.save()
Example #2
0
	def handle(self, *args, **options):
			
			Player.objects.all().delete()

			allplayers = json.load(open("players.current.json"))
			
			mostminutes = ""
			highestmin = 0
			
			for player in allplayers.values():
				
				totalmin = 0
			
				for match in player["fixture_history"]["all"]:
					totalmin = totalmin + match[19]
				
				count = len(player["fixture_history"]["all"]) - 1
				nummatches = 0
				
				
				totalscorelast10 = 0
				totalminuteslast10 = 0

				while nummatches < 38 and count > 0:
					if player["fixture_history"]["all"][count][3] > 0:
						totalscorelast10 = totalscorelast10 + player["fixture_history"]["all"][count][19]
						totalminuteslast10 = totalminuteslast10 + player["fixture_history"]["all"][count][3]
						nummatches = nummatches + 1
							
					count = count - 1
					
				if(player["minutes"] > 0):
					p = Player(player_id = player["id"], team_id = player["team"], last_name = player["second_name"], first_name = player["first_name"], cost = player["now_cost"], team_name = player["team_name"], totalpoints = player["total_points"], last10total = totalscorelast10, last10minutes = totalminuteslast10, type_name = player["type_name"], totalminutes = player["minutes"])
					p.save()
Example #3
0
 def _getPlayer(self,short_id):
     try:
         print("Retrieving player with ID: {}".format(short_id.upper()))
         player = Player.objects.get(short_id=short_id.upper())
     except ObjectDoesNotExist as e:
         print("Player {} does not exist; Creating.".format(short_id.upper()))
         player = Player()
         player.short_id = short_id.upper()
         player.save()
     return player
Example #4
0
 def _update_user(self, row):
     try:
         player = Player.objects.get(short_id=row[0])
     except ObjectDoesNotExist:
         print("No player with shortID {}. Creating.".format(row[0]))
         player = Player(short_id=row[0].upper())
             
     player.first_name = row[1] 
     player.last_name = row[2]
     if row[3] != "":
         player.handle = row[3]
     player.origin = row[4] + ", " + row[5]
     player.save()
d1 = Division(divID="1")
d1.save()
d2 = Division(divID="2")
d2.save()

r1d1 = TourneyRound(division=d1, round_number=1)
r1d1.save()
r2d1 = TourneyRound(division=d1, round_number=2)
r2d1.save()
r1d2 = TourneyRound(division=d2, round_number=1)
r1d2.save()
r2d2 = TourneyRound(division=d2, round_number=2)
r2d2.save()

p1d1 = Player(number=1, name="Rafi Stern", division=d1)
p1d1.save()
p2d1 = Player(number=2, name="Amalan Igengar", division=d1)
p2d1.save()
p1d2 = Player(number=1, name="Noah Walton", division=d2)
p1d2.save()
p2d2 =  Player(number=2, name="Kevin Bolerman", division=d2)
p2d2.save()

g1r1d1=Game(board_num=1, tourney_round=r1d1, player1=p1d1, player2=p2d1)
g1r1d1.save()
g1r2d1=Game(board_num=1, tourney_round=r2d1, player1=p2d1, player2=p1d1)
g1r2d1.save()

g1r1d2=Game(board_num=1, tourney_round=r1d2, player1=p1d2, player2=p2d2)
g1r1d2.save()