Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Presence and bill stage calculation fixes (#830)
Browse files Browse the repository at this point in the history
* Cleanup / pep8 / Remove unused methods
* Fix updating bill stage for private proposals votes
* presence includes the first day of knesset
* remove unneeded end_date check for member in presence scraping
* verify a vote is not used twice
* fix private proposal based bill automatic stage setup
  • Loading branch information
alonisser authored and OriHoch committed Jun 8, 2017
1 parent 9f04aaf commit b9c01f9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 43 deletions.
4 changes: 1 addition & 3 deletions committees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ def summary(self, order='-rank'):
'rank': '((100/%s*rating_score/(1+rating_votes+%s))+100)/2' % (
Topic.rating.range, Topic.rating.weight)
}).order_by(order)
# TODO: rinse it so this will work
return self.get_public().by_rank()


class Topic(models.Model):
Expand Down Expand Up @@ -510,7 +508,7 @@ class Meta:

@models.permalink
def get_absolute_url(self):
return ('topic-detail', [str(self.id)])
return 'topic-detail', [str(self.id)]

def __unicode__(self):
return "%s" % self.title
Expand Down
3 changes: 1 addition & 2 deletions committees/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def _build_context_data(self, cached_context, cm):
cached_context['topics'] = cm.topic_set.summary()[:5]



class MeetingDetailView(DetailView):
model = CommitteeMeeting

Expand Down Expand Up @@ -484,7 +483,7 @@ def edit_topic(request, committee_id, topic_id=None):
{
'edit_form': edit_form,
'links_formset': links_formset,
}))
}))


@login_required
Expand Down
19 changes: 14 additions & 5 deletions laws/models/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,17 @@ def update_votes(self):
if this_v.title.find('אישור'.decode('utf8')) == 0:
self.approval_vote = this_v
used_votes.append(this_v.id)
if this_v.title.find('להעביר את'.decode('utf8')) == 0:
if this_v.title.find('להעביר את'.decode('utf8')) == 0 and this_v.id not in used_votes:
self.first_vote = this_v
used_votes.append(this_v.id)

kp = KnessetProposal.objects.filter(bill=self)
if kp:
for this_v in kp[0].votes.all():
if this_v.title.find('אישור'.decode('utf8')) == 0:
if this_v.title.find('אישור'.decode('utf8')) == 0 and this_v.id not in used_votes:
self.approval_vote = this_v
used_votes.append(this_v.id)
if this_v.title.find('להעביר את'.decode('utf8')) == 0:
if this_v.title.find('להעביר את'.decode('utf8')) == 0 and this_v.id not in used_votes:
if this_v.time.date() > kp[0].date:
self.first_vote = this_v
else:
Expand All @@ -303,8 +304,16 @@ def update_votes(self):
if pps:
for pp in pps:
for this_v in pp.votes.all():
if this_v.id not in used_votes:
self.pre_votes.add(this_v)
if this_v.title.find('אישור'.decode('utf8')) == 0 and this_v.id not in used_votes:
self.approval_vote = this_v
used_votes.append(this_v.id)
if this_v.title.find('להעביר את'.decode('utf8')) == 0 and this_v.id not in used_votes:
if self.stage == BillStages.PROPOSED:
self.pre_votes.add(this_v)
elif self.stage == BillStages.PRE_APPROVED:
self.first_vote = this_v

used_votes.append(this_v.id)
self.update_stage()

def update_stage(self, force_update=False):
Expand Down
17 changes: 1 addition & 16 deletions mks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,33 +299,18 @@ def party_at(self, date):
from knesset_data_django.mks.utils import party_at
return party_at(self, date)

def TotalVotesCount(self):
return self.votes.exclude(voteaction__type='no-vote').count()

def for_votes(self):
return self.votes.filter(voteaction__type='for')

def ForVotesCount(self):
return self.for_votes().count()

def against_votes(self):
return self.votes.filter(voteaction__type='against')

def AgainstVotesCount(self):
return self.against_votes().count()

def abstain_votes(self):
return self.votes.filter(voteaction__type='abstain')

def AbstainVotesCount(self):
return self.abstain_votes().count()

def no_votes(self):
return self.votes.filter(voteaction__type='no-vote')

def NoVotesCount(self):
return self.no_votes().count()

def LowestCorrelations(self):
return Correlation.objects.filter(m1=self.id).order_by('normalized_score')[0:4]

Expand Down Expand Up @@ -366,7 +351,7 @@ def service_time(self):
def average_weekly_presence(self):
d = Knesset.objects.current_knesset().start_date
hours = WeeklyPresence.objects.filter(
date__gt=d,
date__gte=d,
member=self).values_list('hours', flat=True)
if len(hours):
return round(sum(hours) / len(hours), 1)
Expand Down
33 changes: 20 additions & 13 deletions persons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from django.contrib.auth.models import User


class Title(models.Model):
name = models.CharField(max_length=64)

Expand All @@ -26,6 +27,7 @@ class PersonAlias(models.Model):
def __unicode__(self):
return "%s -> %s" % (self.name, self.person.name)


GENDER_CHOICES = (
(u'M', _('Male')),
(u'F', _('Female')),
Expand All @@ -41,14 +43,16 @@ class Person(models.Model):
phone = models.CharField(blank=True, null=True, max_length=20)
fax = models.CharField(blank=True, null=True, max_length=20)
email = models.EmailField(blank=True, null=True)
family_status = models.CharField(blank=True, null=True,max_length=10)
family_status = models.CharField(blank=True, null=True, max_length=10)
number_of_children = models.IntegerField(blank=True, null=True)
date_of_birth = models.DateField(blank=True, null=True)
date_of_birth = models.DateField(blank=True, null=True)
place_of_birth = models.CharField(blank=True, null=True, max_length=100)
date_of_death = models.DateField(blank=True, null=True)
date_of_death = models.DateField(blank=True, null=True)
year_of_aliyah = models.IntegerField(blank=True, null=True)
place_of_residence = models.CharField(blank=True, null=True, max_length=100, help_text=_('an accurate place of residence (for example, an address'))
area_of_residence = models.CharField(blank=True, null=True, max_length=100, help_text = _('a general area of residence (for example, "the negev"'))
place_of_residence = models.CharField(blank=True, null=True, max_length=100,
help_text=_('an accurate place of residence (for example, an address'))
area_of_residence = models.CharField(blank=True, null=True, max_length=100,
help_text=_('a general area of residence (for example, "the negev"'))
place_of_residence_lat = models.CharField(blank=True, null=True, max_length=16)
place_of_residence_lon = models.CharField(blank=True, null=True, max_length=16)
residence_centrality = models.IntegerField(blank=True, null=True)
Expand Down Expand Up @@ -80,7 +84,7 @@ def number_of_meetings(self):
def number_of_committees(self):
return self.protocol_parts.values('meeting__committee').distinct().count()

def copy(self, mk = mk):
def copy(self, mk=mk):
""" copy relelvant mk's data to self """
roles = other.mk.all()
for role in roles:
Expand Down Expand Up @@ -144,7 +148,7 @@ def merge(self, other):
if val and not getattr(self, field_name):
setattr(self, field_name, val)
if self.name != other.name:
(pa,created) = PersonAlias.objects.get_or_create(name=other.name,person=self)
(pa, created) = PersonAlias.objects.get_or_create(name=other.name, person=self)
other.delete()
self.save()

Expand All @@ -170,6 +174,7 @@ def add_alias(self, alias):
def del_alias(self, alias):
PersonAlias.objects.filter(name=alias, person=self).delete()


@receiver(post_save, sender=Member)
def member_post_save(sender, **kwargs):
instance = kwargs['instance']
Expand All @@ -182,16 +187,17 @@ def member_post_save(sender, **kwargs):


class Role(models.Model):
start_date = models.DateField(null=True)
end_date = models.DateField(blank=True, null=True)
start_date = models.DateField(null=True)
end_date = models.DateField(blank=True, null=True)
text = models.CharField(blank=True, null=True, max_length=1024)
org = models.TextField(blank=True, null=True)
person = models.ForeignKey(Person, related_name='roles')

def __unicode__(self):
return _('{person} serverd as {text} in {org} from {start_date} to {end_date}').format(
person=self.person, text=self.text, org=self.org,
start_date=self.start_date, end_date=self.end_date)
person=self.person, text=self.text, org=self.org,
start_date=self.start_date, end_date=self.end_date)


class ProcessedProtocolPart(models.Model):
"""This model is used to keep track of protocol parts already searched for creating persons.
Expand All @@ -208,6 +214,7 @@ class ExternalData(models.Model):
class Meta:
abstract = True


class ExternalInfo(ExternalData):
''' a model for a text key and its value tied to a person '''
person = models.ForeignKey(Person, related_name='external_info')
Expand All @@ -217,6 +224,7 @@ class ExternalInfo(ExternalData):
def __unicode__(self):
return u"{} - {}: {}".format(self.person, self.key, self.value)


class ExternalRelation(ExternalData):
''' a relationship between two persons '''
person = models.ForeignKey(Person, related_name='external_relation')
Expand All @@ -225,5 +233,4 @@ class ExternalRelation(ExternalData):

def __unicode__(self):
return u"{} - {}: {}".format(self.person, self.relationship,
self.with_person)

self.with_person)
5 changes: 1 addition & 4 deletions simple/management/commands/syncdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,7 @@ def update_presence(self):
continue
member_presence = dict(zip([b[0] for b in presence[member.id]], [b[1] for b in presence[member.id]]))

if member.end_date:
end_timestamp = member.end_date.isocalendar()[:2]
else:
end_timestamp = todays_timestamp
end_timestamp = todays_timestamp

start_date = member.start_date or datetime.datetime.utcnow()
current_timestamp = (start_date + datetime.timedelta(7)).isocalendar()[
Expand Down

0 comments on commit b9c01f9

Please sign in to comment.