Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nothingface0 committed Aug 26, 2022
2 parents cc7d769 + 14849db commit d3dc5b0
Show file tree
Hide file tree
Showing 27 changed files with 775 additions and 221 deletions.
21 changes: 19 additions & 2 deletions certifier/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from shiftleader.exceptions import CannotAssumeRunTypeException
from listruns.utilities.luminosity import convert_luminosity_to_pb
from oms.models import OmsFill
from summary.models import SummaryInfo

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -314,6 +315,19 @@ def fill_numbers(self):
.values("fill_number")
]

def prompt_feedback_plots(self):
""" """
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(
certifications__contained_by=certs
)
]

def pks(self):
"""
:return: sorted list of primary keys
Expand Down Expand Up @@ -573,7 +587,9 @@ def compare_with_run_registry(self):
run_registry_entries = runregistry.get_datasets(
filter={
"run_number": {"or": run_numbers},
"dataset_name": {"notlike": "%online%"},
"dataset_name": {
"and": [{"notlike": "%online%"}, {"notlike": "%commissioning%"}]
},
}
)

Expand Down Expand Up @@ -642,11 +658,12 @@ def group_run_numbers_by_fill_number(self):
.order_by("-fill_number")
.distinct()
)

fill_run_group = []
for fill in fills:
fill_run_group.append(
{
"fill_number": fill.fill_number,
"fill": fill,
"run_number": [
run["run_number"]
for run in fill.oms_runs.order_by("-run_number").values(
Expand Down
2 changes: 1 addition & 1 deletion dqmhelper/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
messages.ERROR: "danger",
}
# Version to display in order to keep track of changes
CERTHELPER_VERSION = "1.9.1"
CERTHELPER_VERSION = "1.10.0"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down
30 changes: 23 additions & 7 deletions dqmhelper/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
from .settings import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'database',
if os.environ.get("GITHUB_WORKFLOW"):
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "github_actions",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "127.0.0.1",
"PORT": "5432",
}
}
else:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "postgres-local",
"USER": "postgres",
"PASSWORD": "postgres",
"PORT": "5432"
# 'HOST': 'localhost'
}
}
}

DYNAMIC_PREFERENCES = {
'ENABLE_CACHE': False,
"ENABLE_CACHE": False,
}

EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
12 changes: 12 additions & 0 deletions listruns/static/listruns/css/list_table.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,15 @@ th:after {
font-weight: bold;
color: grey;
}
.inline-tooltip{
place-content: stretch flex-start;
-moz-box-align: center;
align-items: center;
flex-wrap: nowrap;
-moz-box-pack: start;
display: flex;
}

.i-tooltip{
display:inline;
}
1 change: 1 addition & 0 deletions openshift-start-up-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

python manage.py collectstatic --noinput
python manage.py migrate --run-syncdb
python manage.py clear_scripts_running_status

daphne -b 0.0.0.0 -p 8080 dqmhelper.asgi:application
1 change: 1 addition & 0 deletions remotescripts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def formfield_for_foreignkey(self, db_field, request, **kwargs):
class RemoteScriptConfigurationAdmin(admin.ModelAdmin):
list_display = ("title", "num_pos_args", "num_kw_args", "num_output_files")
actions = [execute]
exclude = ["is_running"]

def num_pos_args(self, obj):
return obj.positional_arguments.count()
Expand Down
25 changes: 25 additions & 0 deletions remotescripts/management/commands/clear_scripts_running_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand, CommandError
from remotescripts.models import ScriptConfigurationBase


class Command(BaseCommand):
help = (
"Clears the running status of all remotescripts. To be used on server restart"
)

def handle(self, *args, **options):
scripts = ScriptConfigurationBase.objects.all()
count = 0
for script in scripts:
if script.is_running:
script.is_running = False
script.save()
count += 1
if count:
self.stdout.write(
self.style.SUCCESS("Cleared 'running' status of %s scripts" % count)
)
else:
self.stdout.write(
self.style.SUCCESS("No scripts with status 'running' were found")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.0.6 on 2022-08-23 10:55

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('remotescripts', '0007_scriptconfigurationbase_is_running'),
]

operations = [
migrations.AlterModelOptions(
name='scriptconfigurationbase',
options={'ordering': ['id']},
),
]
39 changes: 23 additions & 16 deletions remotescripts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,36 @@ def save(self, *args, **kwargs):

def before_execution(self):
self.is_running = True
logger.debug(f"Marking script {self} as running")
self.save()

def after_execution(self):
logger.debug(f"Marking script {self} as not running")
self.is_running = False
self.save()

@abstractclassmethod
def execute(self, *args, **kwargs):
def execute_core(self, *args, **kwargs):
"""
Abstract class method to be overriden by subclasses.
Executes the script specified by this instance.
"""

def execute(self, *args, **kwargs):
"""
Main script execution.
Meant to be run in a thread.
"""
pass
if self.is_running:
logger.warning("{self} is already running!")
return

self.before_execution()
try:
self.execute_core(*args, **kwargs)
except Exception as e:
logger.error(e)
self.after_execution()

@abstractclassmethod
def get_output(self, *args, **kwargs):
Expand All @@ -121,31 +137,29 @@ def get_output(self, *args, **kwargs):
"""
pass

class Meta:
ordering = ["id"]


class BashScriptConfiguration(ScriptConfigurationBase):
"""
Model for local bash script configuration
"""

def execute(self, *args, **kwargs):
def execute_core(self, *args, **kwargs):
"""
The idea here is to save the script in a temp file,
then pass it to bash via subprocess.
Not tested a lot, but the main idea works.
"""
if self.is_running:
logger.warning("{self} is already running!")
return

cmd_to_execute = self._form_command(*args, **kwargs)
self.before_execution()
with tempfile.NamedTemporaryFile() as fp:
fp.write(cmd_to_execute.encode())
with subprocess.Popen(["bash", fp.name], stdout=subprocess.PIPE) as process:
output, error = process.communicate()
logger.info(output)
self.after_execution()

def __str__(self) -> str:
return f"{self.title} (Local)"
Expand Down Expand Up @@ -216,16 +230,10 @@ def _line_buffered(f):
for line in f:
yield line

def execute(self, *args, **kwargs) -> int:
def execute_core(self, *args, **kwargs) -> int:
"""
Method that executes the remote script.
"""
if self.is_running:
logger.warning("{self} is already running!")
return

self.before_execution()
self._configure_callbacks(kwargs)

self.on_script_start()
Expand Down Expand Up @@ -321,7 +329,6 @@ def execute(self, *args, **kwargs) -> int:
self.on_new_output_file(f_db.id, localpath)
ftp.close()
ssh.close()
self.after_execution()
return exit_status

def __str__(self) -> str:
Expand Down
26 changes: 19 additions & 7 deletions shiftleader/templates/shiftleader/day-by-day.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ <h3>Day by day notes: {{ day.name|title }}, {{ day.date|yyyymmdd_to_ddmmyyyy }}<
<p>
<ul>
<li>Fills <strong>{{ day.collisions.express.fill_numbers|join:"," }}</strong>
<ul>
<li>
<strong>[insert here]</strong> colliding bunches, peak lumi <strong>[insert here]</strong> x 10³⁴ cm²/s
</li>
</ul>
<!-- <ul>
<li>
<strong>[insert here]</strong> colliding bunches, peak lumi <strong>[insert here]</strong> x 10³⁴ cm²/s
</li>
</ul> -->
</li>
<li>Number of runs certified:
<ul>
Expand All @@ -35,8 +35,20 @@ <h3>Day by day notes: {{ day.name|title }}, {{ day.date|yyyymmdd_to_ddmmyyyy }}<
</li>
</ul>

Daily Shifter Summaries: <strong>link1</strong>, <strong>link2</strong>
Prompt Feedback plots: <strong>link1</strong>
<p>
Daily Shifter Summaries: <strong>link1</strong>, <strong>link2</strong>
</p>
<p>
Prompt Feedback plots:
<ul>
{% for link in day.runs.prompt_feedback_plots %}
<li><strong>{{ link }}</strong></li>
{%endfor%}
</ul>



</p>
</p>
</div>
{% endfor %}
39 changes: 16 additions & 23 deletions shiftleader/templates/shiftleader/lhc_fill_table.html
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
{% if queryset.run_numbers %}
<div style="max-width: 700px;">
<h4>{{ caption }}</h4>
<table class="table table-hover">
<thead>
<div style="max-width: 700px;">
<h4>{{ caption }}</h4>
<table class="table table-striped">
<thead>
<tr>
<th class="col-sm-3">Fill Number</th>
{% comment %}
<th>Ini Lumi (1033 cm2/s)</th>
<th>End Lumi (1033 cm2/s)</th>
<th>N Bunches</th>
<th>N Colliding Bunches</th>
<th>Peak PU</th>
{% endcomment %}
<th class="col-sm-9">Certified Runs</th>
<th class="col-sm-3" scope="col">Fill Number</th>
<th class="col-sm-9" scope="col">Certified Runs</th>
</tr>
</thead>
<tbody>
</thead>
<tbody>
{% for fill in queryset.fills %}
<tr>
<td class="col-sm-3">{{ fill.fill_number}}</td>
<td class="col-sm-9">{{ fill.run_number|join:", " }}</td>
</tr>
<tr>
<td scope="row" class="col-sm-3">{{ fill.fill.fill_number}}</td>
<td class="col-sm-9">{{ fill.run_number|join:", " }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</tbody>
</table>
</div>
{% endif %}
Loading

0 comments on commit d3dc5b0

Please sign in to comment.