From 2b80a92ab56393be4c96ac07a1433e5774223715 Mon Sep 17 00:00:00 2001 From: Tthomas63 Date: Thu, 30 Nov 2017 22:34:55 -0800 Subject: [PATCH 1/5] Init duplicate metrics --- .../0094_metricmodel_display_name.py | 20 +++++++++++++++++++ wizard/migrations/0095_metricmodel_label.py | 20 +++++++++++++++++++ wizard/models.py | 12 +++++++++++ wizard/templates/wizard/metric/editor.html | 11 +++++++--- wizard/views.py | 13 +++++++++--- 5 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 wizard/migrations/0094_metricmodel_display_name.py create mode 100644 wizard/migrations/0095_metricmodel_label.py diff --git a/wizard/migrations/0094_metricmodel_display_name.py b/wizard/migrations/0094_metricmodel_display_name.py new file mode 100644 index 0000000..1c73efd --- /dev/null +++ b/wizard/migrations/0094_metricmodel_display_name.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-12-01 05:51 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wizard', '0093_auto_20171122_2115'), + ] + + operations = [ + migrations.AddField( + model_name='metricmodel', + name='display_name', + field=models.CharField(default='', max_length=256), + ), + ] diff --git a/wizard/migrations/0095_metricmodel_label.py b/wizard/migrations/0095_metricmodel_label.py new file mode 100644 index 0000000..6b756b4 --- /dev/null +++ b/wizard/migrations/0095_metricmodel_label.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-12-01 06:16 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wizard', '0094_metricmodel_display_name'), + ] + + operations = [ + migrations.AddField( + model_name='metricmodel', + name='label', + field=models.CharField(default='', max_length=256), + ), + ] diff --git a/wizard/models.py b/wizard/models.py index 65b83fe..e689081 100644 --- a/wizard/models.py +++ b/wizard/models.py @@ -829,6 +829,9 @@ class MetricModel(models.Model): classification = models.BooleanField(default=False, null=False) regression = models.BooleanField(default=False, null=False) + display_name = models.CharField(max_length=256, null=False, default="") + label = models.CharField(max_length=256, null=False, default="") + def __str__(self): return "<%s: \"%s\"; id=%s>" % (type(self).__name__, self.name, self.id) @@ -844,6 +847,15 @@ def delete(self): if not self.is_default and not self.is_public: super().delete() + def save(self): + print("save :D") + print(self.display_name) + if not self.label or self.label == "": + self.label = timezone.now().date() + self.display_name = "{0}: {1}-{2}".format(self.pk, self.name, self.label) + print(self.display_name) + super().save() + DEV_PHASE_DESC = """Development phase: create models and submit them or directly submit results on validation and/or test data; feed-back are provided on the validation set only.""" FINAL_PHASE_DESC = """Final phase: submissions from the previous phase are automatically cloned and used to compute the final score. The results on the test set will be revealed when the organizers make them available.""" diff --git a/wizard/templates/wizard/metric/editor.html b/wizard/templates/wizard/metric/editor.html index f7746fe..8aaa6b0 100644 --- a/wizard/templates/wizard/metric/editor.html +++ b/wizard/templates/wizard/metric/editor.html @@ -85,8 +85,11 @@

Name of the metric function:

Description:

- + + +

Label ( Optional ):

+ +

Code:

@@ -137,6 +140,7 @@

Use a Public Metric:

success: function(data) { $('#name').val(data.name); $('#description').val(data.description); + $('#label').val(data.label); CodeMirrorPython.setValue(data.code); verif_name(); } @@ -185,7 +189,8 @@

Load one of your Metrics

diff --git a/wizard/views.py b/wizard/views.py index 398bc14..17c8765 100644 --- a/wizard/views.py +++ b/wizard/views.py @@ -13,6 +13,8 @@ from django.views.generic import DetailView from django.views.generic import UpdateView +from django.utils import timezone + from bundler.models import BundleTaskModel from chalab import errors from group.models import GroupModel @@ -574,6 +576,10 @@ def metric(request, pk): new_metric.name = request.POST['name'] new_metric.description = request.POST['description'] + if len(request.POST['label']) > 20: + new_metric.label = request.POST['label'] + else: + new_metric.label = request.POST['label'][0:20] new_metric.code = request.POST['code'] # TODO Verify if the code is ok (static analyse) before validate it @@ -612,14 +618,14 @@ def metric(request, pk): public_metrics = MetricModel.objects.all().filter(is_public=True, is_ready=True) - private_metric = MetricModel.objects.all().filter(owner=request.user) + private_metric = MetricModel.objects.filter(owner=request.user) if c.metric is not None: private_metric = private_metric.exclude(id=c.metric.id) context = {'challenge': c, 'public_metrics': public_metrics, 'flow': flow.Flow(flow.MetricFlowItem, c), - 'metric': c.metric, 'private_metric': private_metric} + 'metric': c.metric, 'private_metric': private_metric, 'today': timezone.now().date()} # Load a default metric if necessary if c.metric is None: @@ -642,7 +648,8 @@ def get_metric(request, pk): data = { 'name': metric.name, 'description': metric.description, - 'code': metric.code + 'code': metric.code, + 'label': metric.label } return JsonResponse(data) From 8274c36490971d12c786bdbff4fac50a7c3bd9f7 Mon Sep 17 00:00:00 2001 From: Tthomas63 Date: Mon, 11 Dec 2017 13:13:11 -0800 Subject: [PATCH 2/5] General fixes, force date formatting --- .../0096_metricmodel_resource_updated.py | 21 +++++++++++++++++++ wizard/models.py | 13 ++++++------ wizard/templates/wizard/metric/editor.html | 2 +- wizard/views.py | 8 ++++--- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 wizard/migrations/0096_metricmodel_resource_updated.py diff --git a/wizard/migrations/0096_metricmodel_resource_updated.py b/wizard/migrations/0096_metricmodel_resource_updated.py new file mode 100644 index 0000000..cc68aca --- /dev/null +++ b/wizard/migrations/0096_metricmodel_resource_updated.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-12-11 20:26 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('wizard', '0095_metricmodel_label'), + ] + + operations = [ + migrations.AddField( + model_name='metricmodel', + name='resource_updated', + field=models.DateField(blank=True, default=django.utils.timezone.now, null=True), + ), + ] diff --git a/wizard/models.py b/wizard/models.py index e689081..ba1b50d 100644 --- a/wizard/models.py +++ b/wizard/models.py @@ -830,7 +830,8 @@ class MetricModel(models.Model): regression = models.BooleanField(default=False, null=False) display_name = models.CharField(max_length=256, null=False, default="") - label = models.CharField(max_length=256, null=False, default="") + resource_updated = models.DateField(null=True, blank=True, default=timezone.now) + label = models.CharField(max_length=20, null=False, default="") def __str__(self): return "<%s: \"%s\"; id=%s>" % (type(self).__name__, self.name, self.id) @@ -848,12 +849,12 @@ def delete(self): super().delete() def save(self): - print("save :D") - print(self.display_name) - if not self.label or self.label == "": - self.label = timezone.now().date() + if self.label == "" or not self.label: + if self.resource_updated: + self.label = self.resource_updated + else: + self.label = timezone.now() self.display_name = "{0}: {1}-{2}".format(self.pk, self.name, self.label) - print(self.display_name) super().save() diff --git a/wizard/templates/wizard/metric/editor.html b/wizard/templates/wizard/metric/editor.html index 8aaa6b0..60980c2 100644 --- a/wizard/templates/wizard/metric/editor.html +++ b/wizard/templates/wizard/metric/editor.html @@ -89,7 +89,7 @@

Description:

Label ( Optional ):

- +

Code:

diff --git a/wizard/views.py b/wizard/views.py index 17c8765..d9bde85 100644 --- a/wizard/views.py +++ b/wizard/views.py @@ -566,6 +566,7 @@ def metric(request, pk): assert k == 'public' if request.POST['button'] == 'save': + new_metric = MetricModel() # If it's here first metric or a default one, we create a new one @@ -576,10 +577,12 @@ def metric(request, pk): new_metric.name = request.POST['name'] new_metric.description = request.POST['description'] - if len(request.POST['label']) > 20: + if request.POST['label'] and request.POST['label'] != "": new_metric.label = request.POST['label'] else: - new_metric.label = request.POST['label'][0:20] + # Have to use stftime to keep the format the same between datasets and metrics. + new_metric.label = new_metric.resource_updated.strftime('%Y-%m-%d') + new_metric.code = request.POST['code'] # TODO Verify if the code is ok (static analyse) before validate it @@ -592,7 +595,6 @@ def metric(request, pk): "(static analyse)") new_metric.save() - c.metric = new_metric c.save() From 0112572314eadccde5d28d3e5aaa198ecb4d5361 Mon Sep 17 00:00:00 2001 From: Tthomas63 Date: Mon, 11 Dec 2017 13:13:52 -0800 Subject: [PATCH 3/5] Migration file --- wizard/migrations/0097_auto_20171211_2107.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 wizard/migrations/0097_auto_20171211_2107.py diff --git a/wizard/migrations/0097_auto_20171211_2107.py b/wizard/migrations/0097_auto_20171211_2107.py new file mode 100644 index 0000000..c497db0 --- /dev/null +++ b/wizard/migrations/0097_auto_20171211_2107.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10 on 2017-12-11 21:07 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('wizard', '0096_metricmodel_resource_updated'), + ] + + operations = [ + migrations.AlterField( + model_name='metricmodel', + name='label', + field=models.CharField(default='', max_length=20), + ), + ] From 8fc65e530b34924d671c0ec8ab8855baacdf7557 Mon Sep 17 00:00:00 2001 From: Tthomas63 Date: Mon, 11 Dec 2017 13:20:28 -0800 Subject: [PATCH 4/5] Fix logout button color ( Even though logout works on get instead of post ) --- chalab/templates/account/logout.html | 2 +- wizard/models.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/chalab/templates/account/logout.html b/chalab/templates/account/logout.html index bc9f9b4..6d38639 100644 --- a/chalab/templates/account/logout.html +++ b/chalab/templates/account/logout.html @@ -14,7 +14,7 @@

{% trans "Logout" %}

{% if redirect_field_value %} {% endif %} - + diff --git a/wizard/models.py b/wizard/models.py index ba1b50d..1946d5d 100644 --- a/wizard/models.py +++ b/wizard/models.py @@ -850,6 +850,7 @@ def delete(self): def save(self): if self.label == "" or not self.label: + # In case resource updated isn't set? if self.resource_updated: self.label = self.resource_updated else: From fd22ba9d6a54b28afeabef091ac87646a12e89ee Mon Sep 17 00:00:00 2001 From: Tthomas63 Date: Mon, 11 Dec 2017 13:28:23 -0800 Subject: [PATCH 5/5] Label change --- wizard/templates/wizard/metric/editor.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wizard/templates/wizard/metric/editor.html b/wizard/templates/wizard/metric/editor.html index 60980c2..35bbb7f 100644 --- a/wizard/templates/wizard/metric/editor.html +++ b/wizard/templates/wizard/metric/editor.html @@ -87,7 +87,7 @@

Description:

-

Label ( Optional ):

+

Label (Optional):