Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate metrics #112

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chalab/templates/account/logout.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>{% trans "Logout" %}</h1>
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
{% endif %}
<button type="submit" class="btn btn-primay">{% trans 'Logout' %}</button>
<button type="submit" class="btn btn-danger">{% trans 'Logout' %}</button>
</form>


Expand Down
20 changes: 20 additions & 0 deletions wizard/migrations/0094_metricmodel_display_name.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
20 changes: 20 additions & 0 deletions wizard/migrations/0095_metricmodel_label.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
21 changes: 21 additions & 0 deletions wizard/migrations/0096_metricmodel_resource_updated.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
20 changes: 20 additions & 0 deletions wizard/migrations/0097_auto_20171211_2107.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
14 changes: 14 additions & 0 deletions wizard/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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."""
Expand Down
11 changes: 8 additions & 3 deletions wizard/templates/wizard/metric/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,11 @@ <h4>Name of the metric function:</h4>

<h4>Description:</h4>

<input name="description" id="description" type="text" class="form-control" value="
{% if metric %}{{ metric.description }}{% endif %}">
<input name="description" id="description" type="text" class="form-control" value="{% if metric %}{{ metric.description }}{% endif %}">

<h4>Label (Optional):</h4>

<input maxlength="20" name="label" id="label" type="text" class="form-control" value="{% if metric %}{{ metric.label}}{% endif %}">

<h4>Code:</h4>

Expand Down Expand Up @@ -137,6 +140,7 @@ <h4>Use a Public Metric:</h4>
success: function(data) {
$('#name').val(data.name);
$('#description').val(data.description);
$('#label').val(data.label);
CodeMirrorPython.setValue(data.code);
verif_name();
}
Expand Down Expand Up @@ -185,7 +189,8 @@ <h4>Load one of your Metrics</h4>
<label>Metric: </label>
<select name="metricPrivate" class="form-control" id="metricPrivatePicker">
{% for metric in private_metric %}
<option value="{{ metric.pk }}">{{ metric.name }} : {{ metric.description }}</option>
<option value="{{ metric.pk }}">{{ metric.display_name }}</option>
{{ metric.pk }}
{% endfor %}
</select>
</div>
Expand Down
17 changes: 13 additions & 4 deletions wizard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -586,7 +595,6 @@ def metric(request, pk):
"(static analyse)")

new_metric.save()

c.metric = new_metric
c.save()

Expand All @@ -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:
Expand All @@ -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)
Expand Down