Git Product home page Git Product logo

nba_database's Introduction

Project Name:

NBA_dataset

Purpose:

Combines NBA players data since 1950, to make NBA player database, using it to check and analysis.

Data set:

https://www.kaggle.com/drgilermo/nba-players-stats#Seasons_Stats.csv

Data model:

alt text

Package Dependencies:

All the package are in the requirements.txt, you can use

(venv) $ pip install -r requirements.txt

in your virtual environment.

nba_database's People

Contributors

chenyipeng1 avatar

Watchers

James Cloos avatar

Forkers

arwhyte

nba_database's Issues

Bad logic prevents processing of team/season info unless len(team) == len(season)

From an internal comment ("One problem, team and season can only be one to one here. Sucks") it's clear you recognize that the logic you imposed on these methods is problematic. Perhaps in the new year we can sit down and work out a better way to add/update players that includes adding/updating their team and season stats in full.

class PlayerCreateView(generic.View)

def post(self, request):
		form = PlayerForm(request.POST)
		# ensure that team and season must have same length
		if form.is_valid():
			player = form.save(commit=False)
			player.save()
			if len(form.cleaned_data['team']) == len(form.cleaned_data['season']):
				for i in range(len(form.cleaned_data['team'])):
					SeasonPlayer.objects.create(
						player_id=player.player_id,
						team_id=form.cleaned_data['team'][i].team_id,
						season_id=form.cleaned_data['season'][i].season_id
					)
			return redirect(player) # shortcut to object's get_absolute_url()
			# return HttpResponseRedirect(player.get_absolute_url())
		return render(request, 'nba_stats/player_new.html', {'form': form})

class PlayerUpdateView()

def form_valid(self, form):
		player = form.save(commit=False)
		player.save()
		if form.is_valid():

			# Current team_id values linked to player
			old_team_ids = list(SeasonPlayer.objects\
							.values_list('team_id', flat=True)\
							.filter(player_id = player.player_id))


			# Current season_id values linked to player
			old_season_ids = list(SeasonPlayer.objects\
							.values_list('season_id', flat=True)\
							.filter(player_id = player.player_id))


			# New team list
			new_teams = form.cleaned_data['team']
			# New season list
			new_seasons = form.cleaned_data['season']

			# New ids
			new_team_ids = []
			new_season_ids = []


			if len(new_teams) == len(new_seasons):
				# Insert new unmatched entries
				for i in range(len(new_teams)):
					new_team_id = new_teams[i].team_id
					new_season_id = new_seasons[i].season_id
					new_team_ids.append(new_team_id)
					new_season_ids.append(new_season_id)


					try:
						if old_team_ids.index(new_team_id) == old_season_ids.index(new_season_id):
							print("num 1", old_team_ids.index(new_team_id),old_season_ids.index(new_season_id))
							# matched
							continue
						else:
							print("num 2", old_team_ids.index(new_team_id),old_season_ids.index(new_season_id))
							SeasonPlayer.objects\
								.create(player_id=player.player_id, season_id=new_season_id, team_id=new_team_id)
					except:
						print("num 3", player.player_id, new_season_id, new_team_id)
						SeasonPlayer.objects\
							.create(player_id=player.player_id, season_id=new_season_id, team_id=new_team_id)					
				# Delete new unmatched entries
				for i in range(len(old_team_ids)):
					try:
						if new_season_ids.index(old_season_ids[i]) == new_team_ids.index(old_team_ids[i]):
							print("num 4", new_season_ids.index(old_season_ids[i]), new_team_ids.index(old_team_ids[i]))
							continue
						else:
							print("num 5", new_season_ids.index(old_season_ids[i]), new_team_ids.index(old_team_ids[i]))
							# SeasonPlayer.objects\
							# 	.filter(player_id=player.player_id, season_id=new_season_id, team_id=new_team_id) \
							# 	.delete()
					except:
						print("num 6", player.player_id, new_season_id, new_team_id)
						SeasonPlayer.objects\
							.filter(player_id=player.player_id, season_id=old_season_ids[i], team_id=old_team_ids[i]) \
							.delete()

				# One problem, team and season can only be one to one here. Sucks.

		return HttpResponseRedirect(player.get_absolute_url())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.