Skip to content

Commit

Permalink
Restructured to use TrackerCertification PKs instead of OmsRun
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingface0 committed Aug 26, 2022
1 parent 473eaa5 commit 48f6c54
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 32 deletions.
9 changes: 7 additions & 2 deletions certifier/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,15 @@ def fill_numbers(self):

def prompt_feedback_plots(self):
""" """
run_numbers = self.run_numbers()
certs = [r[0] for r in self.values_list("runreconstruction")]
if not certs:
return []

return [
summary.links_prompt_feedback
for summary in SummaryInfo.objects.filter(runs=run_numbers)
for summary in SummaryInfo.objects.filter(
certifications__contained_by=certs
)
]

def pks(self):
Expand Down
4 changes: 2 additions & 2 deletions summary/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.0.6 on 2022-08-26 13:09
# Generated by Django 4.0.6 on 2022-08-26 15:59

import django.contrib.postgres.fields
from django.db import migrations, models
Expand All @@ -16,7 +16,7 @@ class Migration(migrations.Migration):
name='SummaryInfo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('runs', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), help_text='Unique summary for list of runs', size=None, unique=True)),
('certifications', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), help_text='Unique summary for list of certifications. Each element is the PK of a TrackerCertification instance', size=None, unique=True)),
('links_prompt_feedback', models.TextField(help_text='tinyurl links to plots on cmsweb.cern.ch')),
('special_comment', models.TextField(blank=True, help_text='Special comment by shifter for this summary')),
],
Expand Down
13 changes: 8 additions & 5 deletions summary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ class SummaryInfo(models.Model):
"""
Information regarding a summary/Elog.
A summary is identified by the list of runs it is composed of
A summary is identified by the list of PKs of TrackerCertification
instances it is summarizing.
ManyToManyField cannot be used, as it cannot be made unique.
"""

runs = ArrayField(
certifications = ArrayField(
base_field=models.IntegerField(null=False),
help_text="Unique summary for list of runs",
help_text="Unique summary for list of certifications. Each element is the PK of a TrackerCertification instance",
unique=True,
)
links_prompt_feedback = models.TextField(
Expand All @@ -24,8 +27,8 @@ class SummaryInfo(models.Model):

def save(self, *args, **kwargs):
# ArrayField does not seem to use a validators argument
validate_list_length(self.runs)
validate_list_length(self.certifications)
super().save(*args, **kwargs)

def __str__(self):
return f"{self.__class__.__name__} {self.runs}"
return f"{self.__class__.__name__} {self.certifications}"
10 changes: 5 additions & 5 deletions summary/templates/summary/summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h6>Generated summary</h6>
=============Sum of Quantities============
{% for sum in sums %}{{ sum }}
{% endfor %}
<div id="comment_div" style="{% if not form.special_comment %}display: none;{% else %}display: block;{% endif %}">
<div id="comment_div" style="{% if not form.special_comment.initial %}display: none;{% else %}display: block;{% endif %}">
=============Special Comments=============
<p id="specialcomment_text">{% if form.special_comment.initial %}{{ form.special_comment.initial }}{% endif %}</p><div id="formarea" style="display: none;">{{form.special_comment}}<div align="center" class="row p-1"><div class="col"><button type="button" class="btn btn-light" onclick="write_to_comment_area()"><i class="bi bi-check-lg"></i> Apply</button></div><div class="col"><button type="button" class="btn btn-light" onclick="hide_comment_area()"><i class="bi bi-x-lg"></i> Remove</button></div></div></div></div>
=============Link to the Prompt Feedback plots============
Expand All @@ -144,7 +144,7 @@ <h6>Generated summary</h6>
// all form fields without directly referencing them? dunno
'links_prompt_feedback': $('#id_links_prompt_feedback').val(),
'special_comment' : $('#id_special_comment').val(),
'runs_list': "{{runs_list}}"
'certs_list': "{{certs_list}}"
},
success: function(data) {
if(!data.success){
Expand All @@ -163,9 +163,9 @@ <h6>Generated summary</h6>

// Get text from form field, append it to HTML
function write_to_comment_area(t=$('#id_special_comment').val()) {
console.log(t)
$('#specialcomment_text').html(t);
$('#formarea').css('display', 'None');
$('#id_special_comment').val(t);// In case we want to clear it
$('#specialcomment_text').html(t);
$('#formarea').css('display', 'None');
$('#specialcomment_text').css('display', 'inline-block');
submit_form();
}
Expand Down
24 changes: 16 additions & 8 deletions summary/tests/test_summary_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def test_view_requires_shifter_rights():


def test_get_success():
"""
GETting the page should result in creation of SummaryInfo instances
"""

user = mixer.blend(User, user_privilege=User.SHIFTER)
certs = [
Expand All @@ -38,7 +41,7 @@ def test_get_success():
TrackerCertification, runreconstruction__run__run_number=299929, user=user
),
]
runs_list = [cert.runreconstruction.run.run_number for cert in certs]
certs_list = [cert.runreconstruction.pk for cert in certs]

req = RequestFactory().get(reverse("summary:summary"))

Expand All @@ -55,14 +58,17 @@ def test_get_success():


def test_post_success():
runs = [
mixer.blend(OmsRun, run_number=355555),
mixer.blend(OmsRun, run_number=299929),
"""
Successful post of summary info
"""
certs = [
mixer.blend(TrackerCertification, runreconstruction__run__run_number=355555),
mixer.blend(TrackerCertification, runreconstruction__run__run_number=299929),
]

runs_list = [run.run_number for run in runs]
certs_list = [cert.runreconstruction.pk for cert in certs]
form = SummaryExtraInfoForm(
data={"runs_list": str(runs_list), "links_prompt_feedback": "link1, link2"}
data={"certs_list": str(certs_list), "links_prompt_feedback": "link1, link2"}
)
assert form.is_valid()

Expand All @@ -77,10 +83,12 @@ def test_post_success():


def test_post_failure():

"""
Not supplying links_prompt_feedback is not allowed
"""
form = SummaryExtraInfoForm(
data={
"runs_list": str([]),
"certs_list": str([]),
}
)
assert form.is_valid() == False
Expand Down
22 changes: 12 additions & 10 deletions summary/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def get(self, request, *args, **kwargs):

summary = SummaryReport(runs)

# Get run numbers from QuerySet
runs_list = [
r[0] for r in runs.values_list("runreconstruction__run__run_number")
]
# Get TrackerCertification instances PKs from QuerySet
certs_list = [r[0] for r in runs.values_list("runreconstruction")]

try:
summary_db_instance, _ = SummaryInfo.objects.get_or_create(runs=runs_list)
summary_db_instance, _ = SummaryInfo.objects.get_or_create(
certifications=certs_list
)
form = SummaryExtraInfoForm(instance=summary_db_instance)
except ValidationError:
summary_db_instance = None
Expand All @@ -72,7 +72,7 @@ def get(self, request, *args, **kwargs):
context = {
"refs": summary.reference_runs(),
"runs": summary.runs_checked_per_type(),
"runs_list": runs_list,
"certs_list": certs_list,
"tk_maps": summary.tracker_maps_per_type(),
"certified_runs": summary.certified_runs_per_type(),
"sums": summary.sum_of_quantities_per_type(),
Expand All @@ -91,21 +91,23 @@ def post(self, request, *args, **kwargs):
# For some reason it's especially not straightforward
# to extract a list from a Querydict value
data = request.POST.copy()
runs_list = json.loads(data.pop("runs_list")[0])
certs_list = json.loads(data.pop("certs_list")[0])

try:
runs_list = [int(r) for r in runs_list]
certs_list = [int(r) for r in certs_list]
except (ValueError, TypeError) as e:
success = False
response = {"success": success, "msg": repr(e)}
return JsonResponse(response)

if len(runs_list) < 1:
if len(certs_list) < 1:
success = False
response = {"success": success, "msg": "No runs specified"}
return JsonResponse(response)

summary_instance, _ = SummaryInfo.objects.get_or_create(runs=runs_list)
summary_instance, _ = SummaryInfo.objects.get_or_create(
certifications=certs_list
)
f = self.form(data=request.POST, instance=summary_instance)
if f.is_valid():
logger.debug(f"Summary information updated for {summary_instance}")
Expand Down

0 comments on commit 48f6c54

Please sign in to comment.