Skip to content

Commit

Permalink
Merge pull request #285 from Ilhasoft/staging
Browse files Browse the repository at this point in the history
Order by repository
  • Loading branch information
VictorMeneghini committed Sep 12, 2019
2 parents 015bed8 + da621e4 commit eeb1f8d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
31 changes: 31 additions & 0 deletions bothub/common/migrations/0032_repository_total_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 2.1.5 on 2019-08-14 19:45

from django.db import migrations, models

from bothub.common.models import RepositoryUpdate
from bothub.common.models import Repository


def updateRepository(apps, schema_editor):
for update in RepositoryUpdate.objects.all().filter(
trained_at__isnull=False
):
repository = Repository.objects.get(uuid=update.repository.uuid)
repository.total_updates += 1
repository.save()


class Migration(migrations.Migration):

dependencies = [
('common', '0031_auto_20190502_1732'),
]

operations = [
migrations.AddField(
model_name='repository',
name='total_updates',
field=models.IntegerField(default=0, verbose_name='total updates'),
),
migrations.RunPython(updateRepository),
]
11 changes: 10 additions & 1 deletion bothub/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def order_by_relevance(self):
return self \
.annotate(votes_summ=models.Sum('votes__vote')) \
.annotate(examples_sum=models.Sum('updates__added')) \
.order_by('-votes_summ', '-examples_sum', '-created_at')
.order_by('-total_updates', '-examples_sum', '-created_at')

def supported_language(self, language):
valid_examples = RepositoryExample.objects.filter(
Expand Down Expand Up @@ -175,6 +175,13 @@ class Meta:
_('created at'),
auto_now_add=True)

total_updates = models.IntegerField(
_('total updates'),
default=0,
blank=False,
null=False
)

objects = RepositoryManager()

nlp_train_url = '{}train/'.format(settings.BOTHUB_NLP_BASE_URL)
Expand Down Expand Up @@ -631,6 +638,8 @@ def save_training(self, bot_data):

self.trained_at = timezone.now()
self.bot_data = base64.b64encode(bot_data).decode('utf8')
self.repository.total_updates += 1
self.repository.save()
self.save(
update_fields=[
'trained_at',
Expand Down
1 change: 1 addition & 0 deletions bothub/common/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ def test_last_trained_update(self):
self.assertEqual(
update_1,
self.repository.last_trained_update())
self.assertEqual(self.repository.total_updates, 1)

def test_available_languages(self):
available_languages = self.repository.available_languages
Expand Down

0 comments on commit eeb1f8d

Please sign in to comment.