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/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/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/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), + ), + ] diff --git a/wizard/models.py b/wizard/models.py index 65b83fe..1946d5d 100644 --- a/wizard/models.py +++ b/wizard/models.py @@ -829,6 +829,10 @@ 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="") + 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) @@ -844,6 +848,16 @@ def delete(self): if not self.is_default and not self.is_public: super().delete() + 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: + self.label = timezone.now() + self.display_name = "{0}: {1}-{2}".format(self.pk, self.name, self.label) + 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..35bbb7f 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..d9bde85 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 @@ -564,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 @@ -574,6 +577,12 @@ def metric(request, pk): new_metric.name = request.POST['name'] new_metric.description = request.POST['description'] + if request.POST['label'] and request.POST['label'] != "": + new_metric.label = request.POST['label'] + else: + # 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 @@ -586,7 +595,6 @@ def metric(request, pk): "(static analyse)") new_metric.save() - c.metric = new_metric c.save() @@ -612,14 +620,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 +650,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)