コード例 #1
0
ファイル: views.py プロジェクト: ParkerPo/ntusbleague
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)
コード例 #2
0
ファイル: allteam.py プロジェクト: phoenix104104/ntusbleague
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)
コード例 #3
0
ファイル: allteam.py プロジェクト: phoenix104104/ntusbleague
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)
コード例 #4
0
ファイル: views.py プロジェクト: ParkerPo/ntusbleague
def people(request , member_id) :

	player = Member.objects.get(memberID = member_id)

	# --- batting
	game_all 	= Batting.objects.filter(member__memberID = member_id).order_by("game")
	hitting_list = []
	hitting_sum  = Hitter()
	
	if game_all.exists() :
		for game_detail in game_all:
			hitter 			= Hitter()
			hitter.pa 		= game_detail.pa
			hitter.single 	= game_detail.single
			hitter.double 	= game_detail.double
			hitter.triple 	= game_detail.triple
			hitter.hr 		= game_detail.hr
			hitter.rbi 		= game_detail.rbi
			hitter.r 		= game_detail.run
			hitter.bb		= game_detail.bb
			hitter.so 		= game_detail.so
			hitter.sf 		= game_detail.sf

			hitter.games_played = 1
			hitter.stat()
			hitting_sum.add(hitter)
			hitting_sum.stat()

			# accumulated statistic
			hitter.avg_s	= hitting_sum.avg_s
			hitter.slg_s	= hitting_sum.slg_s
			hitter.obp_s	= hitting_sum.obp_s
			hitter.ops_s	= hitting_sum.ops_s
			
			# game information
			game 			= game_detail.game
			hitter.date 	= str(game.date)
			hitter.gameID 	= str(game.gameID)

			# opponent team
			if( game_detail.team == game.home ):
				opp = game.away	
			else:
				opp = game.home

			hitter.opp 		= str(opp)
			hitter.oppID 	= str(opp.teamID)

			hitting_list.append(hitter)

	# --- pitching
	game_all  	  = Pitching.objects.filter(member__memberID = member_id).order_by("game")
	pitching_list = []
	pitching_sum  = Pitcher()
	
	if game_all.exists() :
		for game_detail in game_all:
			pitcher 		= Pitcher()
			pitcher.win 	= game_detail.win
			pitcher.lose 	= game_detail.lose
			pitcher.outs 	= game_detail.outs
			pitcher.pa 		= game_detail.pa
			pitcher.so 		= game_detail.so
			pitcher.bb 		= game_detail.bb
			pitcher.h		= game_detail.h
			pitcher.hr		= game_detail.hr
			pitcher.r 		= game_detail.r
			pitcher.er 		= game_detail.er
			pitcher.go 		= game_detail.go
			pitcher.fo 		= game_detail.fo

			pitcher.games_played = 1
			pitcher.stat()
			pitching_sum.add(pitcher)
			pitching_sum.stat()

			# accumulated statistic
			pitcher.bb_inning_s 	= pitching_sum.bb_inning_s
			pitcher.era_s 	= pitching_sum.era_s
			pitcher.whip_s 	= pitching_sum.whip_s
			
			# game information
			game 			= game_detail.game
			pitcher.date 	= str(game.date)
			pitcher.gameID 	= str(game.gameID)

			# opponent team
			if( game_detail.team == game.home ):
				opp = game.away	
			else:
				opp = game.home

			pitcher.opp 	= str(opp)
			pitcher.oppID 	= str(opp.teamID)

			pitching_list.append(pitcher)


	context = {'thispeople' : player, 'name': player.name, 'hitting_list': hitting_list, 'hitting_sum': hitting_sum, 'pitching_list': pitching_list, 'pitching_sum': pitching_sum, }

	return render(request, 'sbleague/people.html', context)
コード例 #5
0
ファイル: views.py プロジェクト: ParkerPo/ntusbleague
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)
コード例 #6
0
def people(request, member_id):

    player = Member.objects.get(memberID=member_id)

    # --- batting
    game_all = Batting.objects.filter(
        member__memberID=member_id).order_by("game")
    hitting_list = []
    hitting_sum = Hitter()

    if game_all.exists():
        for game_detail in game_all:
            hitter = Hitter()
            hitter.pa = game_detail.pa
            hitter.single = game_detail.single
            hitter.double = game_detail.double
            hitter.triple = game_detail.triple
            hitter.hr = game_detail.hr
            hitter.rbi = game_detail.rbi
            hitter.r = game_detail.run
            hitter.bb = game_detail.bb
            hitter.so = game_detail.so
            hitter.sf = game_detail.sf

            hitter.games_played = 1
            hitter.stat()
            hitting_sum.add(hitter)
            hitting_sum.stat()

            # accumulated statistic
            hitter.avg_s = hitting_sum.avg_s
            hitter.slg_s = hitting_sum.slg_s
            hitter.obp_s = hitting_sum.obp_s
            hitter.ops_s = hitting_sum.ops_s

            # game information
            game = game_detail.game
            hitter.date = str(game.date)
            hitter.gameID = str(game.gameID)

            # opponent team
            if (game_detail.team == game.home):
                opp = game.away
            else:
                opp = game.home

            hitter.opp = str(opp)
            hitter.oppID = str(opp.teamID)

            hitting_list.append(hitter)

    # --- pitching
    game_all = Pitching.objects.filter(
        member__memberID=member_id).order_by("game")
    pitching_list = []
    pitching_sum = Pitcher()

    if game_all.exists():
        for game_detail in game_all:
            pitcher = Pitcher()
            pitcher.win = game_detail.win
            pitcher.lose = game_detail.lose
            pitcher.outs = game_detail.outs
            pitcher.pa = game_detail.pa
            pitcher.so = game_detail.so
            pitcher.bb = game_detail.bb
            pitcher.h = game_detail.h
            pitcher.hr = game_detail.hr
            pitcher.r = game_detail.r
            pitcher.er = game_detail.er
            pitcher.go = game_detail.go
            pitcher.fo = game_detail.fo

            pitcher.games_played = 1
            pitcher.stat()
            pitching_sum.add(pitcher)
            pitching_sum.stat()

            # accumulated statistic
            pitcher.bb_inning_s = pitching_sum.bb_inning_s
            pitcher.era_s = pitching_sum.era_s
            pitcher.whip_s = pitching_sum.whip_s

            # game information
            game = game_detail.game
            pitcher.date = str(game.date)
            pitcher.gameID = str(game.gameID)

            # opponent team
            if (game_detail.team == game.home):
                opp = game.away
            else:
                opp = game.home

            pitcher.opp = str(opp)
            pitcher.oppID = str(opp.teamID)

            pitching_list.append(pitcher)

    context = {
        'thispeople': player,
        'name': player.name,
        'hitting_list': hitting_list,
        'hitting_sum': hitting_sum,
        'pitching_list': pitching_list,
        'pitching_sum': pitching_sum,
    }

    return render(request, 'sbleague/people.html', context)
コード例 #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)
コード例 #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)