<commit_before>from django import forms
from django.db import models, transaction
from django.db.models import Count
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist

from pybb.models import *

from datetime import date, datetime
import re


class Field(models.Model):
	id = models.AutoField(primary_key=True)
	name = models.TextField()
	layout_link = models.TextField()
	address = models.TextField()
	driving_link = models.TextField()
	note = models.TextField()
	class Meta:
		db_table = u'field'
		ordering = ['name']

	def __unicode__(self):
		return self.name


class FieldNames(models.Model):
	id = models.AutoField(primary_key=True)
	name = models.TextField()
	field = models.ForeignKey('leagues.Field')
	class Meta:
		db_table = u'field_names'
		verbose_name_plural = 'field names'
		ordering = ['field__name', 'name']

	def __unicode__(self):
		return '%s %s' % (self.field.name, self.name)


class League(models.Model):
	LEAGUE_STATE_CHOICES = (
		('archived',	'Archived'),
		('planning',	'Planning'),
		('active',		'Active'),
	)

	LEAGUE_GENDER_CHOICES = (
		('coed',			'Normal co-ed gender matched'),
		('50/50',			'50/50 league'),
		('hat',				'Hat tourney'),
		('hat_free',		'Hat tourney (no pay, just add to registration list)'),
		('hat_nocap',		'Hat tourney (no captains)'),
		('bonanza_free',	'Clinics and pickup (no pay)'),
		('competitive',		'Competitive league'),
		('showcase',		'Showcase league'),
		('party',			'No group-limits party night'),
		('open',			'Open, no gender match'),
		('women',			'Women only'),
	)

	id = models.AutoField(primary_key=True)
	night = models.CharField(max_length=96, help_text='lower case, no special characters, e.g. "sunday", "tuesday and thursday", "end of season tournament"')
	season = models.CharField(max_length=96, help_text='lower case, no special characters, e.g. "late fall", "winter"')
	year = models.IntegerField(help_text='four digit year, e.g. 2013')
	gender = models.CharField(max_length=96, choices=LEAGUE_GENDER_CHOICES)
	gender_note = models.TextField(help_text='gender or other notes for league, e.g. 50/50 league, showcase league notes')
	baggage = models.IntegerField(help_text='max baggage group size')
	times = models.TextField(help_text='start to end time, e.g. 6:00-8:00pm')
	reg_start_date = models.DateField(help_text='date that registration process is open (not currently automated)')
	waitlist_start_date = models.DateField(help_text='date that waitlist is started (regardless of number of registrations)')
	freeze_group_date = models.DateField(help_text='date of last day to form groups')
	league_start_date = models.DateField(help_text='date of first game')
	league_end_date = models.DateField(help_text='date of last game')
	paypal_cost = models.IntegerField()
	check_cost = models.IntegerField()
	max_players = models.IntegerField(help_text='max players for league, extra registrations will be placed on waitlist')
	state = models.CharField(max_length=96, choices=LEAGUE_STATE_CHOICES, help_text='''
		Archived - not visible to anyone<br/>
		Planning - only visibil to junta<br/>
		Active - visible to everyone''')
	field = models.ManyToManyField(Field, db_table='field_league', help_text='''Select the fields these games will be played at, use
		the green "+" icon if we're playing at a new field.''')
	details = models.TextField(help_text='details page text, use HTML')
	league_email = models.CharField(max_length=192, blank=True, help_text='email address for entire season')
	league_captains_email = models.CharField(max_length=192, blank=True, help_text='email address for league captains')
	division_email = models.CharField(max_length=192, blank=True, help_text='email address for just this league')
	mail_check_address = models.TextField(help_text='treasurer mailing address')

	class Meta:
		db_table = u'league'

	def get_fields(self):
		return self.fieldleague_set.all()

	def get_field_names(self):
		return FieldNames.objects.filter(field__fieldleague__league=self, game__league=self).distinct().order_by('field__name', 'name')

	def get_league_registrations_for_user(self, user):
		return self.registrations_set.filter(user=user)

	def get_registrations(self):
		return Registrations.objects.filter(league=self).order_by('registered')

	def get_teams(self):
		return self.team_set.all()

	def get_completed_registrations(self):
		registrations = Registrations.objects.filter(league=self).order_by('registered')
		return [r for r in registrations if not r.waitlist and not r.refunded and r.is_complete()]

	def get_waitlisted_registrations(self):
		registrations = Registrations.objects.filter(league=self).order_by('registered')
		return [r for r in registrations if r.waitlist and not r.refunded and r.is_complete()]

	def get_games(self):
		return self.game_set.all().order_by('field_name__field__name', 'field_name__name')

	def get_user_games(self, user):
		return Game.objects.filter(league=self, gameteams__team__teammember__user=user).order_by('date')

	def get_num_game_events(self):
		# need to use multiply by weekly events count
		diff = self.league_end_date - self.league_start_date
		return (diff.days / 7) + 1

	def get_league_captains(self):
		return User.objects.filter(teammember__team__league=self, teammember__captain=1)<commit_msg>[feature] added num_games_per_week support for league<commit_after>from django import forms
from django.db import models, transaction
from django.db.models import Count
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist

from pybb.models import *

from datetime import date, datetime
import re


class Field(models.Model):
	id = models.AutoField(primary_key=True)
	name = models.TextField()
	layout_link = models.TextField()
	address = models.TextField()
	driving_link = models.TextField()
	note = models.TextField()
	class Meta:
		db_table = u'field'
		ordering = ['name']

	def __unicode__(self):
		return self.name


class FieldNames(models.Model):
	id = models.AutoField(primary_key=True)
	name = models.TextField()
	field = models.ForeignKey('leagues.Field')
	class Meta:
		db_table = u'field_names'
		verbose_name_plural = 'field names'
		ordering = ['field__name', 'name']

	def __unicode__(self):
		return '%s %s' % (self.field.name, self.name)


class League(models.Model):
	LEAGUE_STATE_CHOICES = (
		('archived',	'Archived'),
		('planning',	'Planning'),
		('active',		'Active'),
	)

	LEAGUE_GENDER_CHOICES = (
		('coed',			'Normal co-ed gender matched'),
		('50/50',			'50/50 league'),
		('hat',				'Hat tourney'),
		('hat_free',		'Hat tourney (no pay, just add to registration list)'),
		('hat_nocap',		'Hat tourney (no captains)'),
		('bonanza_free',	'Clinics and pickup (no pay)'),
		('competitive',		'Competitive league'),
		('showcase',		'Showcase league'),
		('party',			'No group-limits party night'),
		('open',			'Open, no gender match'),
		('women',			'Women only'),
	)

	id = models.AutoField(primary_key=True)
	night = models.CharField(max_length=96, help_text='lower case, no special characters, e.g. "sunday", "tuesday and thursday", "end of season tournament"')
	season = models.CharField(max_length=96, help_text='lower case, no special characters, e.g. "late fall", "winter"')
	year = models.IntegerField(help_text='four digit year, e.g. 2013')
	gender = models.CharField(max_length=96, choices=LEAGUE_GENDER_CHOICES)
	gender_note = models.TextField(help_text='gender or other notes for league, e.g. 50/50 league, showcase league notes')
	baggage = models.IntegerField(help_text='max baggage group size')
	times = models.TextField(help_text='start to end time, e.g. 6:00-8:00pm')
	num_games_per_week = models.IntegerField(default=1, help_text='number of games per week, used to calculate number of games for a league')
	reg_start_date = models.DateField(help_text='date that registration process is open (not currently automated)')
	waitlist_start_date = models.DateField(help_text='date that waitlist is started (regardless of number of registrations)')
	freeze_group_date = models.DateField(help_text='date of last day to form groups')
	league_start_date = models.DateField(help_text='date of first game')
	league_end_date = models.DateField(help_text='date of last game')
	paypal_cost = models.IntegerField()
	check_cost = models.IntegerField()
	max_players = models.IntegerField(help_text='max players for league, extra registrations will be placed on waitlist')
	state = models.CharField(max_length=96, choices=LEAGUE_STATE_CHOICES, help_text='''
		Archived - not visible to anyone<br/>
		Planning - only visibil to junta<br/>
		Active - visible to everyone''')
	field = models.ManyToManyField(Field, db_table='field_league', help_text='''Select the fields these games will be played at, use
		the green "+" icon if we're playing at a new field.''')
	details = models.TextField(help_text='details page text, use HTML')
	league_email = models.CharField(max_length=192, blank=True, help_text='email address for entire season')
	league_captains_email = models.CharField(max_length=192, blank=True, help_text='email address for league captains')
	division_email = models.CharField(max_length=192, blank=True, help_text='email address for just this league')
	mail_check_address = models.TextField(help_text='treasurer mailing address')

	class Meta:
		db_table = u'league'

	def get_fields(self):
		return self.fieldleague_set.all()

	def get_field_names(self):
		return FieldNames.objects.filter(field__fieldleague__league=self, game__league=self).distinct().order_by('field__name', 'name')

	def get_league_registrations_for_user(self, user):
		return self.registrations_set.filter(user=user)

	def get_registrations(self):
		return Registrations.objects.filter(league=self).order_by('registered')

	def get_teams(self):
		return self.team_set.all()

	def get_completed_registrations(self):
		registrations = Registrations.objects.filter(league=self).order_by('registered')
		return [r for r in registrations if not r.waitlist and not r.refunded and r.is_complete()]

	def get_waitlisted_registrations(self):
		registrations = Registrations.objects.filter(league=self).order_by('registered')
		return [r for r in registrations if r.waitlist and not r.refunded and r.is_complete()]

	def get_games(self):
		return self.game_set.all().order_by('field_name__field__name', 'field_name__name')

	def get_user_games(self, user):
		return Game.objects.filter(league=self, gameteams__team__teammember__user=user).order_by('date')

	def get_num_game_events(self):
		diff = self.league_end_date - self.league_start_date
		num_weeks = (diff.days / 7) + 1

		if self.num_games_per_week > 1:
			num_games = num_weeks * self.num_games_per_week
		else:
			num_games = num_weeks

		return num_games

	def get_league_captains(self):
		return User.objects.filter(teammember__team__league=self, teammember__captain=1)
{'fraction_non_alphanumeric': 0.11935632183908046, 'fraction_numerical': 0.007908045977011495, 'mean_word_length': 5.848866498740554, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '785377', 'n_tokens_mistral': 3832, 'n_tokens_neox': 3531, 'n_words': 883}