Beispiel #1
0
def allteam(request,pos,order,year=4):
	teams = Team.objects.filter(current__gt=0)
	allteam_pit = []
	allteam_bat = []

	if pos == "bat" :
		league = Hitter()
		for t in teams :
			hitter=Hitter()
			bat_all = Batting.objects.filter(team=t.teamID,game__gameID__gte=year*1000)
			hitter.name = t.name
			hitter.id = t.teamID
			for bat_detail in bat_all :
				hitter.pa += bat_detail.pa
				hitter.single +=bat_detail.single
				hitter.double +=bat_detail.double
				hitter.triple +=bat_detail.triple
				hitter.hr += bat_detail.hr
				hitter.rbi += bat_detail.rbi
				hitter.r += bat_detail.run
				hitter.bb+= bat_detail.bb
				hitter.so +=bat_detail.so
				hitter.sf +=bat_detail.sf
			hitter.stat()
			allteam_bat.append(hitter)
			league.add(hitter)
		pos = "打擊"
		allteam_bat=sorted(allteam_bat,key=attrgetter(order),reverse=True)

	elif pos == "pit":
		league = Pitcher()
		for t in teams: 
			pitcher = Pitcher()
			pit_all = Pitching.objects.filter(team=t.teamID,game__gameID__gte=year*1000)
			pitcher.id = t.teamID
			pitcher.name=t.name
			for pit_detail in pit_all :
				pitcher.win+=pit_detail.win
				pitcher.lose+=pit_detail.lose
				pitcher.outs+=pit_detail.outs
				pitcher.pa+=pit_detail.pa
				pitcher.so+=pit_detail.so
				pitcher.bb+=pit_detail.bb
				pitcher.h+=pit_detail.h
				pitcher.hr+=pit_detail.hr
				pitcher.r+=pit_detail.r
				pitcher.er+=pit_detail.er
				pitcher.go+=pit_detail.go
				pitcher.fo+=pit_detail.fo

			pitcher.stat()
			allteam_pit.append(pitcher)
			league.add(pitcher)
		pos="投球"
		allteam_pit=sorted(allteam_pit,key=attrgetter(order),reverse=True)

	league.stat()
	context={'type':pos, 'teams_bat' : allteam_bat , 'teams_pit' : allteam_pit , 'league':league}
	return render(request , 'sbleague/allteam.html',context)
Beispiel #2
0
def allteam(request, porder='games_played', horder='games_played'):
    teams = Team.objects.filter(current__gt=0)
    allteam_bat = []
    allteam_pit = []
    league_bat = Hitter()
    league_pit = Pitcher()
    for t in teams:
        hitter = Hitter()
        bat_all = Batting.objects.filter(team=t.teamID)
        hitter.name = t.name
        hitter.id = t.teamID
        for bat_detail in bat_all:
            hitter.pa += bat_detail.pa
            hitter.single += bat_detail.single
            hitter.double += bat_detail.double
            hitter.triple += bat_detail.triple
            hitter.hr += bat_detail.hr
            hitter.rbi += bat_detail.rbi
            hitter.r += bat_detail.run
            hitter.bb += bat_detail.bb
            hitter.so += bat_detail.so
            hitter.sf += bat_detail.sf

        pitcher = Pitcher()
        pit_all = Pitching.objects.filter(team=t.teamID)
        pitcher.id = t.teamID
        pitcher.name = t.name
        for pit_detail in pit_all:
            pitcher.win += pit_detail.win
            pitcher.lose += pit_detail.lose
            pitcher.outs += pit_detail.outs
            pitcher.pa += pit_detail.pa
            pitcher.so += pit_detail.so
            pitcher.bb += pit_detail.bb
            pitcher.h += pit_detail.h
            pitcher.hr += pit_detail.hr
            pitcher.r += pit_detail.r
            pitcher.er += pit_detail.er
            pitcher.go += pit_detail.go
            pitcher.fo += pit_detail.fo

        hitter.stat()
        pitcher.stat()
        allteam_bat.append(hitter)
        allteam_pit.append(pitcher)
        league_bat.add(hitter)
        league_pit.add(pitcher)

    league_bat.stat()
    league_pit.stat()

    context = {
        'teams_bat': allteam_bat,
        'teams_pit': allteam_pit,
        'league_bat': league_bat,
        'league_pit': league_pit
    }
    return render(request, 'sbleague/allteam.html', context)
Beispiel #3
0
def allteam(request,porder='games_played',horder='games_played'):
	teams = Team.objects.filter(current__gt=0)
	allteam_bat = []
	allteam_pit = []
	league_bat = Hitter()
	league_pit = Pitcher()
	for t in teams :
		hitter=Hitter()
		bat_all = Batting.objects.filter(team=t.teamID)
		hitter.name = t.name
		hitter.id = t.teamID
		for bat_detail in bat_all :
			hitter.pa += bat_detail.pa
			hitter.single +=bat_detail.single
			hitter.double +=bat_detail.double
			hitter.triple +=bat_detail.triple
			hitter.hr += bat_detail.hr
			hitter.rbi += bat_detail.rbi
			hitter.r += bat_detail.run
			hitter.bb+= bat_detail.bb
			hitter.so +=bat_detail.so
			hitter.sf +=bat_detail.sf

		pitcher = Pitcher()
		pit_all = Pitching.objects.filter(team=t.teamID)
		pitcher.id = t.teamID
		pitcher.name=t.name
		for pit_detail in pit_all :
			pitcher.win+=pit_detail.win
			pitcher.lose+=pit_detail.lose
			pitcher.outs+=pit_detail.outs
			pitcher.pa+=pit_detail.pa
			pitcher.so+=pit_detail.so
			pitcher.bb+=pit_detail.bb
			pitcher.h+=pit_detail.h
			pitcher.hr+=pit_detail.hr
			pitcher.r+=pit_detail.r
			pitcher.er+=pit_detail.er
			pitcher.go+=pit_detail.go
			pitcher.fo+=pit_detail.fo

		hitter.stat()
		pitcher.stat()
		allteam_bat.append(hitter)
		allteam_pit.append(pitcher)
		league_bat.add(hitter)
		league_pit.add(pitcher)

	league_bat.stat()
	league_pit.stat()

	context={'teams_bat' : allteam_bat , 'teams_pit' : allteam_pit , 'league_bat':league_bat ,'league_pit':league_pit}
	return render(request , 'sbleague/allteam.html',context)
Beispiel #4
0
def calculate_batting_rank(players,year=4):
	
	player_map = {}
	batting_all = Batting.objects.filter(game__gameID__gte=year*1000)

	teams=Team.objects.all()
	team_gamecount=[]
	for team in teams:
		home=Game.objects.filter(home=team,gameID__gte=year*1000).count()
		away=Game.objects.filter(away=team,gameID__gte=year*1000).count()
		count=home+away
		team_gamecount.append([team,count])

	for batting in batting_all:
		id = batting.member.memberID
		if( not player_map.has_key(id) ):
			h 			= Hitter()
			h.name 		= batting.member.name
			h.memberID 	= batting.member.memberID
			h.team 		= batting.team
			h.teamID	= batting.team.teamID
			player_map[id] = h
			player_map[id].id = id

		player_map[id].pa 			+= batting.pa
		player_map[id].single 		+= batting.single
		player_map[id].double 		+= batting.double
		player_map[id].triple 		+= batting.triple
		player_map[id].hr 			+= batting.hr
		player_map[id].rbi 			+= batting.rbi
		player_map[id].r 			+= batting.run
		player_map[id].bb			+= batting.bb
		player_map[id].so 			+= batting.so
		player_map[id].sf 			+= batting.sf
		player_map[id].games_played += 1


	for player in player_map.values():
		if len(team_gamecount)!=0 :
			for team in team_gamecount:
				if team[0] == player.team:
					if team[1]*2 <= player.pa:
						player.stat()
					else:
						del player_map[player.id]
		else :
			player.stat()

	batting_list = player_map.values()

	return batting_list
Beispiel #5
0
def calculate_batting_rank(players, thr=0):

    player_map = {}
    batting_all = Batting.objects.filter(pa__gte=thr)

    teams = Team.objects.all()
    team_gamecount = []
    for team in teams:
        home = Game.objects.filter(home=team).count()
        away = Game.objects.filter(away=team).count()
        count = home + away
        team_gamecount.append([team, count])

    for batting in batting_all:
        id = batting.member.memberID
        if (not player_map.has_key(id)):
            h = Hitter()
            h.name = batting.member.name
            h.memberID = batting.member.memberID
            h.team = batting.team
            h.teamID = batting.team.teamID
            player_map[id] = h
            player_map[id].id = id

        player_map[id].pa += batting.pa
        player_map[id].single += batting.single
        player_map[id].double += batting.double
        player_map[id].triple += batting.triple
        player_map[id].hr += batting.hr
        player_map[id].rbi += batting.rbi
        player_map[id].r += batting.run
        player_map[id].bb += batting.bb
        player_map[id].so += batting.so
        player_map[id].sf += batting.sf
        player_map[id].games_played += 1

    for player in player_map.values():
        if len(team_gamecount) != 0:
            for team in team_gamecount:
                if team[0] == player.team:
                    if team[1] * 2 <= player.pa:
                        player.stat()
                    else:
                        del player_map[player.id]
        else:
            player.stat()

    batting_list = player_map.values()

    return batting_list
Beispiel #6
0
def team(request , team_id , order="hit",y=4) :
	thisteam = Team.objects.get(teamID = team_id)
	team_info = TeamStat()	#init
	team_info.name 	 = thisteam.name
	team_info.teamID = thisteam.teamID
	team_overall={}  #勝敗和那邊

	game_all = Game.objects.filter(Q(away = team_id) | Q(home = team_id)).order_by('gameID')
	game_list = []
	for game in game_all:
		year = game.gameID/1000 + 2011

		if not team_overall.has_key(year) :
			team_overall[year]=TeamStat()
			team_overall[year].year=year;
			team_overall[year].win=0;
			team_overall[year].lose=0;
			team_overall[year].tie=0;
			team_overall[year].game_played=0;
			

		g = GameStat()

		if( game.away.teamID != int(team_id) ):
			opp = game.away
		else:
			opp = game.home

		game_result = game.get_result()
		if( len(game_result) == 0 ):
			result = '和'
			team_overall[year].tie += 1
		elif( game_result[0].teamID == int(team_id) ):
			result = '勝'
			team_overall[year].win += 1
		else:
			result = '敗'
			team_overall[year].lose += 1

		team_overall[year].game_played += 1

		scores = game.get_scores()

		if game.gameID >= y*1000 and game.gameID <= (y+1)*1000: 
			
			g.gameID 	= game.gameID
			g.date 		= game.date
			g.location 	= game.location
			g.opp 		= opp
			g.scores 	= str(sum(scores[0])) + ' : ' + str(sum(scores[1]))
			g.result 	= result
			game_list.append(g)
	
	# sort by date


	game_list = sorted(game_list , key=attrgetter('date'))

	members = Member.objects.filter(team__teamID = team_id)

	members_bat= []
	members_pit= []
	team_bat = Hitter()
	team_pit = Pitcher()

	for player in members:
		#batting data
		bat = Batting.objects.filter(member__memberID = player.memberID , team = thisteam.teamID,game__gameID__gte=y*1000)
		
		if bat.exists() :
			hitter = Hitter()
			for bat_detail in bat:
				hitter.name = player.name
				hitter.id = player.memberID
				hitter.games_played += 1
				hitter.pa += bat_detail.pa
				hitter.single +=bat_detail.single
				hitter.double +=bat_detail.double
				hitter.triple +=bat_detail.triple
				hitter.hr += bat_detail.hr
				hitter.rbi += bat_detail.rbi
				hitter.r += bat_detail.run
				hitter.bb+= bat_detail.bb
				hitter.so +=bat_detail.so
				hitter.sf +=bat_detail.sf
			hitter.stat()
			members_bat.append(hitter)
			team_bat.add(hitter)
			team_bat.stat()
		members_bat=sorted(members_bat,key=attrgetter(order),reverse=True)

		#pitching data
		pit = Pitching.objects.filter(member__memberID = player.memberID , team = thisteam.teamID,game__gameID__gte=y*1000)
		if pit.exists() :
			pitcher = Pitcher()

			for pit_detail in pit:
				pitcher.name = player.name
				pitcher.games_played +=1
				pitcher.id = player.memberID
				pitcher.win+=pit_detail.win
				pitcher.lose+=pit_detail.lose
				pitcher.outs+=pit_detail.outs
				pitcher.pa+=pit_detail.pa
				pitcher.so+=pit_detail.so
				pitcher.bb+=pit_detail.bb
				pitcher.h+=pit_detail.h
				pitcher.hr+=pit_detail.hr
				pitcher.r+=pit_detail.r
				pitcher.er+=pit_detail.er
				pitcher.go+=pit_detail.go
				pitcher.fo+=pit_detail.fo

			pitcher.stat()
			members_pit.append(pitcher)
			team_pit.add(pitcher)
			team_pit.stat()

	context = {'thisteam' : thisteam, 'team_info':team_info, 'game_list': game_list, 'members_bat': members_bat ,'members_pit':members_pit, 'team_bat' : team_bat, 'team_pit' : team_pit,'team_overall':team_overall}

	return render(request , 'sbleague/team.html',context)
Beispiel #7
0
def allteam(request, pos, order):
    teams = Team.objects.filter(current__gt=0)
    allteam_pit = []
    allteam_bat = []

    if pos == "bat":
        league = Hitter()
        for t in teams:
            hitter = Hitter()
            bat_all = Batting.objects.filter(team=t.teamID)
            hitter.name = t.name
            hitter.id = t.teamID
            for bat_detail in bat_all:
                hitter.pa += bat_detail.pa
                hitter.single += bat_detail.single
                hitter.double += bat_detail.double
                hitter.triple += bat_detail.triple
                hitter.hr += bat_detail.hr
                hitter.rbi += bat_detail.rbi
                hitter.r += bat_detail.run
                hitter.bb += bat_detail.bb
                hitter.so += bat_detail.so
                hitter.sf += bat_detail.sf
            hitter.stat()
            allteam_bat.append(hitter)
            league.add(hitter)
        pos = "打擊"
        allteam_bat = sorted(allteam_bat, key=attrgetter(order), reverse=True)

    elif pos == "pit":
        league = Pitcher()
        for t in teams:
            pitcher = Pitcher()
            pit_all = Pitching.objects.filter(team=t.teamID)
            pitcher.id = t.teamID
            pitcher.name = t.name
            for pit_detail in pit_all:
                pitcher.win += pit_detail.win
                pitcher.lose += pit_detail.lose
                pitcher.outs += pit_detail.outs
                pitcher.pa += pit_detail.pa
                pitcher.so += pit_detail.so
                pitcher.bb += pit_detail.bb
                pitcher.h += pit_detail.h
                pitcher.hr += pit_detail.hr
                pitcher.r += pit_detail.r
                pitcher.er += pit_detail.er
                pitcher.go += pit_detail.go
                pitcher.fo += pit_detail.fo

            pitcher.stat()
            allteam_pit.append(pitcher)
            league.add(pitcher)
        pos = "投球"
        allteam_pit = sorted(allteam_pit, key=attrgetter(order), reverse=True)

    league.stat()
    context = {
        'type': pos,
        'teams_bat': allteam_bat,
        'teams_pit': allteam_pit,
        'league': league
    }
    return render(request, 'sbleague/allteam.html', context)
Beispiel #8
0
def team(request, team_id, order="hit"):
    thisteam = Team.objects.get(teamID=team_id)
    team_info = TeamStat()
    team_info.name = thisteam.name
    team_info.teamID = thisteam.teamID

    game_all = Game.objects.filter(Q(away=team_id) | Q(home=team_id))
    game_list = []
    for game in game_all:
        g = GameStat()

        if (game.away.teamID != int(team_id)):
            opp = game.away
        else:
            opp = game.home

        game_result = game.get_result()
        if (len(game_result) == 0):
            result = '和'
            team_info.tie += 1
        elif (game_result[0].teamID == int(team_id)):
            result = '勝'
            team_info.win += 1
        else:
            result = '敗'
            team_info.lose += 1

        team_info.game_played += 1

        scores = game.get_scores()

        g.gameID = game.gameID
        g.date = game.date
        g.location = game.location
        g.opp = opp
        g.scores = str(sum(scores[0])) + ' : ' + str(sum(scores[1]))
        g.result = result
        game_list.append(g)

    # sort by date
    game_list = sorted(game_list, key=attrgetter('date'))
    team_info.stat()

    members = Member.objects.filter(team__teamID=team_id)

    members_bat = []
    members_pit = []
    team_bat = Hitter()
    team_pit = Pitcher()

    for player in members:
        #batting data
        bat = Batting.objects.filter(member__memberID=player.memberID,
                                     team=thisteam.teamID)

        if bat.exists():
            hitter = Hitter()
            for bat_detail in bat:
                hitter.name = player.name
                hitter.id = player.memberID
                hitter.games_played += 1
                hitter.pa += bat_detail.pa
                hitter.single += bat_detail.single
                hitter.double += bat_detail.double
                hitter.triple += bat_detail.triple
                hitter.hr += bat_detail.hr
                hitter.rbi += bat_detail.rbi
                hitter.r += bat_detail.run
                hitter.bb += bat_detail.bb
                hitter.so += bat_detail.so
                hitter.sf += bat_detail.sf
            hitter.stat()
            members_bat.append(hitter)
            team_bat.add(hitter)
            team_bat.stat()
        members_bat = sorted(members_bat, key=attrgetter(order), reverse=True)

        #pitching data
        pit = Pitching.objects.filter(member__memberID=player.memberID,
                                      team=thisteam.teamID)
        if pit.exists():
            pitcher = Pitcher()

            for pit_detail in pit:
                pitcher.name = player.name
                pitcher.games_played += 1
                pitcher.id = player.memberID
                pitcher.win += pit_detail.win
                pitcher.lose += pit_detail.lose
                pitcher.outs += pit_detail.outs
                pitcher.pa += pit_detail.pa
                pitcher.so += pit_detail.so
                pitcher.bb += pit_detail.bb
                pitcher.h += pit_detail.h
                pitcher.hr += pit_detail.hr
                pitcher.r += pit_detail.r
                pitcher.er += pit_detail.er
                pitcher.go += pit_detail.go
                pitcher.fo += pit_detail.fo

            pitcher.stat()
            members_pit.append(pitcher)
            team_pit.add(pitcher)
            team_pit.stat()

    context = {
        'thisteam': thisteam,
        'team_info': team_info,
        'game_list': game_list,
        'members_bat': members_bat,
        'members_pit': members_pit,
        'team_bat': team_bat,
        'team_pit': team_pit
    }

    return render(request, 'sbleague/team.html', context)