<commit_before>from zlib import crc32
from django.db import models
from django.contrib.auth.models import User
from lib.file_storage import OverwriteStorage


class Map(models.Model):
	"""Representation of a map played in Teerace"""

	name = models.CharField(max_length=50, unique=True)
	author = models.CharField(max_length=100, blank=True)

	# Just a convention. It should be 'added_at/by', though.
	created_at = models.DateTimeField(auto_now_add=True)
	created_by = models.ForeignKey(User)

	def map_filename(self, filename):
		del filename
		return 'uploads/maps/{0}_{1}.map'.format(self.name, self.crc)
	map_file = models.FileField(storage=OverwriteStorage(),
		upload_to=map_filename)
	crc = models.CharField(max_length=8)

	def save(self, *args, **kwargs):
		if self.map_file:
			self.crc = '{0:x}'.format(crc32(self.map_file.open().read()))
			self.map_file.close()
		super(Map, self).save(*args, **kwargs)


class Run(models.Model):
	"""Representation of one map finish"""

	map = models.ForeignKey(Map)
	server = models.ForeignKey('Server', related_name='runs')
	user = models.ForeignKey(User)
	nickname = models.CharField(max_length=32)
	time = models.FloatField()
	reported_at = models.DateTimeField(auto_now_add=True)
	created_at = models.DateTimeField()

	def __unicode__(self):
		return u"{0} - {1} - {2}s".format(self.map, self.user, self.time)


class Server(models.Model):
	"""
	Representation of Teeworlds server hooked up to Teerace
	
	We use maintainer account to interact with API.
	"""
<commit_msg>fixed max nick-in-game length (Rajh's fault!)<commit_after>from zlib import crc32
from django.db import models
from django.contrib.auth.models import User
from lib.file_storage import OverwriteStorage


class Map(models.Model):
	"""Representation of a map played in Teerace"""

	name = models.CharField(max_length=50, unique=True)
	author = models.CharField(max_length=100, blank=True)

	# Just a convention. It should be 'added_at/by', though.
	created_at = models.DateTimeField(auto_now_add=True)
	created_by = models.ForeignKey(User)

	def map_filename(self, filename):
		del filename
		return 'uploads/maps/{0}_{1}.map'.format(self.name, self.crc)
	map_file = models.FileField(storage=OverwriteStorage(),
		upload_to=map_filename)
	crc = models.CharField(max_length=8)

	def save(self, *args, **kwargs):
		if self.map_file:
			self.crc = '{0:x}'.format(crc32(self.map_file.open().read()))
			self.map_file.close()
		super(Map, self).save(*args, **kwargs)


class Run(models.Model):
	"""Representation of one map finish"""

	map = models.ForeignKey(Map)
	server = models.ForeignKey('Server', related_name='runs')
	user = models.ForeignKey(User)
	nickname = models.CharField(max_length=24)
	time = models.FloatField()
	reported_at = models.DateTimeField(auto_now_add=True)
	created_at = models.DateTimeField()

	def __unicode__(self):
		return u"{0} - {1} - {2}s".format(self.map, self.user, self.time)


class Server(models.Model):
	"""
	Representation of Teeworlds server hooked up to Teerace
	
	We use maintainer account to interact with API.
	"""

{'fraction_non_alphanumeric': 0.13337670787247885, 'fraction_numerical': 0.011711125569290826, 'mean_word_length': 5.40625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1036112', 'n_tokens_mistral': 1104, 'n_tokens_neox': 1040, 'n_words': 237}