<commit_before># -*- coding: utf-8 -*-
from django.db import models
from django import forms
    
class City(models.Model):
	name = models.CharField(max_length=255)
	
class Line(models.Model):
	name = models.CharField(max_length=255)
	aliases = models.TextField(default="")
	city = models.ForeignKey(City)
	def __unicode__(self):
		return "%s" % self.name     
		
class Station(models.Model):       
	name = models.CharField(max_length=255)
	aliases = models.TextField(default="")
	line = models.ForeignKey(Line)
	                                                        
class Incident(models.Model):  
	"""                   
	Incident representation of problems on the network 
	
	# create incident
	>>> i1 = Incident(line=Line.objects.get(pk=1), reason="Probleme dans le RER B", source="Android app", level=4)
	>>> i1.save()    
	   
	# try json shortcut :
	>>> i1.to_json()['status']
	'En cours...'
	>>> i1.to_json()['line_id']
	1
	>>> i1.to_json()['line']
	u'Metro 1'
	>>> i1.to_json()['vote_plus']
	0
	>>> i1.to_json()['vote_minus']
	0
	>>> i1.to_json()['vote_ended']
	0
	>>> i1.to_json()['uid']
	1
	>>> i1.to_json()['reason']
	'Probleme dans le RER B'
	
	# adding vote
	>>> IncidentVote(incident=i1, source="android1", vote=VOTE_PLUS).save() 
	>>> i1.plus_count()
	1
	
	# minus
	>>> IncidentVote(incident=i1, source="android2", vote=VOTE_MINUS).save()
	>>> i1.minus_count()
	3
	
	# ended
	>>> IncidentVote(incident=i1, source="android3", vote=VOTE_ENDED).save()
	>>> i1.ended_count()
	1
	"""
	line = models.ForeignKey(Line, blank=True, null=True, verbose_name="Ligne")
	station_start = models.ForeignKey(Station, null=True, blank=True, related_name="station_start")
	station_end = models.ForeignKey(Station, null=True, blank=True, related_name="station_end")
	created = models.DateTimeField(auto_now_add=True)
	modified = models.DateTimeField(auto_now=True)
	ended = models.DateTimeField(null=True, blank=True)
	reason = models.TextField("Raison", help_text="Raison évoquée quant à l'incident", blank=True, null=True)
	source = models.TextField()
	validated = models.BooleanField(default=True)  
	level = models.IntegerField(default=5)   
	#duplicate_of = models.ForeignKey(Incident)     
	                           
	def compute_relevance(self):
		return 100 + self.plus_count() * 10 - self.minus_count() * 15 - self.ended_count() * 20 - self.compute_hours_since_report()
	def compute_hours_since_report(self):
		from datetime import datetime
		return (datetime.now() - self.created).seconds / 60
	def plus_count(self):
		return IncidentVote.objects.filter(incident=self).filter(vote=VOTE_PLUS).count()        
	def minus_count(self):
		return 3*IncidentVote.objects.filter(incident=self).filter(vote=VOTE_MINUS).count()
	def ended_count(self):           
		return IncidentVote.objects.filter(incident=self).filter(vote=VOTE_ENDED).count()    
	def to_json(self):
		return {'uid' : self.id,<commit_msg>bug fix for incorrect web based submit of incident<commit_after># -*- coding: utf-8 -*-
from django.db import models
from django import forms
    
class City(models.Model):
	name = models.CharField(max_length=255)
	
class Line(models.Model):
	name = models.CharField(max_length=255)
	aliases = models.TextField(default="")
	city = models.ForeignKey(City)
	def __unicode__(self):
		return "%s" % self.name     
		
class Station(models.Model):       
	name = models.CharField(max_length=255)
	aliases = models.TextField(default="")
	line = models.ForeignKey(Line)
	                                                        
class Incident(models.Model):  
	"""                   
	Incident representation of problems on the network 
	
	# create incident
	>>> i1 = Incident(line=Line.objects.get(pk=1), reason="Probleme dans le RER B", source="Android app", level=4)
	>>> i1.save()    
	   
	# try json shortcut :
	>>> i1.to_json()['status']
	'En cours...'
	>>> i1.to_json()['line_id']
	1
	>>> i1.to_json()['line']
	u'Metro 1'
	>>> i1.to_json()['vote_plus']
	0
	>>> i1.to_json()['vote_minus']
	0
	>>> i1.to_json()['vote_ended']
	0
	>>> i1.to_json()['uid']
	1
	>>> i1.to_json()['reason']
	'Probleme dans le RER B'
	
	# adding vote
	>>> IncidentVote(incident=i1, source="android1", vote=VOTE_PLUS).save() 
	>>> i1.plus_count()
	1
	
	# minus
	>>> IncidentVote(incident=i1, source="android2", vote=VOTE_MINUS).save()
	>>> i1.minus_count()
	3
	
	# ended
	>>> IncidentVote(incident=i1, source="android3", vote=VOTE_ENDED).save()
	>>> i1.ended_count()
	1
	"""
	line = models.ForeignKey(Line, null=True, verbose_name="Ligne")
	station_start = models.ForeignKey(Station, null=True, blank=True, related_name="station_start")
	station_end = models.ForeignKey(Station, null=True, blank=True, related_name="station_end")
	created = models.DateTimeField(auto_now_add=True)
	modified = models.DateTimeField(auto_now=True)
	ended = models.DateTimeField(null=True, blank=True)
	reason = models.TextField("Raison", help_text="Raison évoquée quant à l'incident", blank=True, null=True)
	source = models.TextField()
	validated = models.BooleanField(default=True)  
	level = models.IntegerField(default=5)   
	#duplicate_of = models.ForeignKey(Incident)     
	                           
	def compute_relevance(self):
		return 100 + self.plus_count() * 10 - self.minus_count() * 15 - self.ended_count() * 20 - self.compute_hours_since_report()
	def compute_hours_since_report(self):
		from datetime import datetime
		return (datetime.now() - self.created).seconds / 60
	def plus_count(self):
		return IncidentVote.objects.filter(incident=self).filter(vote=VOTE_PLUS).count()        
	def minus_count(self):
		return 3*IncidentVote.objects.filter(incident=self).filter(vote=VOTE_MINUS).count()
	def ended_count(self):           
		return IncidentVote.objects.filter(incident=self).filter(vote=VOTE_ENDED).count()    
	def to_json(self):
		return {'uid' : self.id,
{'fraction_non_alphanumeric': 0.15084658799384298, 'fraction_numerical': 0.018128955019668207, 'mean_word_length': 4.129824561403509, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 99, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2084355', 'n_tokens_mistral': 2135, 'n_tokens_neox': 2014, 'n_words': 364}