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 12, 2022
2 parents 6d3077a + 43ff0cc commit cc7d769
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 44 deletions.
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.0"
CERTHELPER_VERSION = "1.9.1"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down
175 changes: 132 additions & 43 deletions shiftleader/utilities/shiftleader_report_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from shiftleader.templatetags.shiftleaderfilters import join_good_runs
from listruns.utilities.luminosity import format_integrated_luminosity
from odf.opendocument import OpenDocumentPresentation
from odf.element import Element
from odf.style import (
Style,
MasterPage,
Expand Down Expand Up @@ -146,7 +147,7 @@ def _configure_styles(self):
ParagraphProperties(textalign="center", verticalalign="middle")
)
self.titlestyle_content.addElement(
TextProperties(fontsize="44pt", fontfamily="sans", color="#00b0f0")
TextProperties(fontsize="28pt", fontfamily="sans", color="#00b0f0")
)
self.titlestyle_content.addElement(
GraphicProperties(fill="none", stroke="none", overflowbehavior="clip")
Expand Down Expand Up @@ -227,6 +228,11 @@ def _configure_styles(self):
border="0.03pt solid #000000", writingmode="lr-tb", textalign="left"
)
)
self.style_cell.addElement(
TextProperties(
fontsize="13pt", fontsizeasian="13pt", fontsizecomplex="13pt"
)
)
self.doc.automaticstyles.addElement(self.style_cell)

# Header Cell style
Expand Down Expand Up @@ -346,15 +352,41 @@ def _configure_styles(self):
)
self.doc.automaticstyles.addElement(self.style_span_pagenumber)

# Good runs style
self.style_span_good = Style(name="spgood", family="text")
self.style_span_good.addElement(
TextProperties(
color="#008000",
fontweight="bold",
fontweightasian="bold",
fontweightcomplex="bold",
)
)
self.doc.automaticstyles.addElement(self.style_span_good)

# Bad runs style
self.style_span_bad = Style(name="spbad", family="text")
self.style_span_bad.addElement(
TextProperties(
color="#ff0000",
fontweight="bold",
fontweightasian="bold",
fontweightcomplex="bold",
)
)
self.doc.automaticstyles.addElement(self.style_span_bad)

def _generate_list(self, list_items: list, identation_level: int = 1) -> List:
stylename = f"L1-{identation_level}"
l = List(stylename=stylename)
for item in list_items:
li = ListItem()

if isinstance(item, list):
if isinstance(item, list): # Recursion
item = self._generate_list(item, identation_level + 1)
li.addElement(item)
elif isinstance(item, Element):
li.addElement(item)
else:
li.addElement(P(text=item))

Expand All @@ -364,6 +396,15 @@ def _generate_list(self, list_items: list, identation_level: int = 1) -> List:
def _generate_filename(self) -> str:
return f"shiftleader_report_{self.date_from}_{self.date_to}.odp"

@staticmethod
def _format_list_to_str(l: list, comma=False) -> str:
if not isinstance(l, list):
raise ValueError(f"Invalid argument {l}, list expected")
s = str(l).replace("[", "").replace("]", "")
if not comma:
s = s.replace(",", "")
return s

def _add_page_title(self):
"""
Add title page to presentation
Expand Down Expand Up @@ -394,14 +435,10 @@ def _add_page_title(self):
c_frame.addElement(c_text)
c_text.addElement(P(text=f"SL: {self.name_shift_leader}"))
c_text.addElement(
P(
text=f"""Shifters: {str(self.names_shifters).replace('[', '').replace(']', '').replace("'", '')}"""
)
P(text=f"""Shifters: {self._format_list_to_str(self.names_shifters)}""")
)
c_text.addElement(
P(
text=f"""On-call: {str(self.names_oncall).replace('[', '').replace(']', '').replace("'", '')}"""
)
P(text=f"""On-call: {self._format_list_to_str(self.names_oncall)}""")
)
page.addElement(c_frame)

Expand Down Expand Up @@ -439,7 +476,7 @@ def _add_page_list_lhc_fills(self):
page = self._create_content_page(title=f"List of LHC Fills - {table_name}")

WIDTH_FRAME = 648
WIDTH_COL = 300
WIDTH_COL = 70
HEIGHT_FRAME = 105
HEIGHT_ROW = 50

Expand All @@ -461,11 +498,18 @@ def _add_page_list_lhc_fills(self):
tr = TableRow(
defaultcellstylename=self.style_cell_header, stylename=style_row
)

col_names = ["Fill", "Run"]

# Two columns
for i, col_name in enumerate(["Fill Number", "Certified Runs"]):
for i, col_name in enumerate(col_names):
style_column = Style(name=f"co{i}", family="table-column")
# Last column is given the rest of the total frame width,
# this was the only way to set a width for the first column
style_column.addElement(
TableColumnProperties(columnwidth=f"{WIDTH_COL}pt")
TableColumnProperties(
columnwidth=f"{WIDTH_COL if i < len(col_names)-1 else WIDTH_FRAME-i*WIDTH_COL}pt"
)
)
self.doc.automaticstyles.addElement(style_column)

Expand All @@ -491,7 +535,14 @@ def _add_page_list_lhc_fills(self):
tc = TableCell()
tr.addElement(tc)
p = P()
p.addElement(Span(text=v, stylename=self.style_span))
p.addElement(
Span(
text=self._format_list_to_str(v, comma=True)
if isinstance(v, list)
else v,
stylename=self.style_span,
)
)
tc.addElement(p)

table_frame.addElement(table)
Expand All @@ -501,6 +552,36 @@ def _add_page_day_by_day(self):
"""
Day-by-day certification report
"""

def _generate_flag_changed_good_run_list_element(runs) -> Element:
"""
Nested helper function for formatting good runs for changed flags runs
"""
p = P()
sp0 = Span(
text=f"Number of changed flags from Express to Prompt={runs.total_number()}"
)
p.addElement(sp0)
if runs.total_number() > 0:
sp1 = Span(text=" (")
sp2 = Span(
text=self._format_list_to_str(runs.good().run_numbers()),
stylename=self.style_span_good,
)
spbl = Span(text=" ")
sp3 = Span(
text=self._format_list_to_str(runs.bad().run_numbers()),
stylename=self.style_span_bad,
)
sp4 = Span(text=")")
p.addElement(sp1)
p.addElement(sp2)
p.addElement(spbl)
p.addElement(sp3)
p.addElement(sp4)

return p

for day in self.slreport.day_by_day():
page = self._create_content_page(
title=f"Day by day notes: {day.name()}, {day.date()}"
Expand All @@ -509,7 +590,7 @@ def _add_page_day_by_day(self):
tb = TextBox()
list1 = self._generate_list(
list_items=[
f"Fills {str(day.collisions().express().fill_numbers())}",
f"Fills {self._format_list_to_str(day.collisions().express().fill_numbers(), comma=True)}",
[
"[insert here] colliding bunches, peak lumi [insert here] x 10³³ cm²/s",
],
Expand All @@ -519,12 +600,7 @@ def _add_page_day_by_day(self):
f"Cosmics: {day.cosmics().express().total_number()} in Stream-Express, {day.cosmics().prompt().total_number()} in Prompt-Reco",
],
f"Total number of BAD runs = {day.bad().total_number()} ({format_integrated_luminosity(day.bad().integrated_luminosity())})",
[
f"Number of changed flags from Express to Prompt={day.flag_changed().total_number()}"
+ f" ({day.flag_changed().good().run_numbers()})" # TODO, format as green?
if day.flag_changed().total_number() > 0
else ""
],
[_generate_flag_changed_good_run_list_element(day.flag_changed())],
"Conditions update:",
"Issues reported in the Elog and feedback to Online:",
"On calls:",
Expand All @@ -541,6 +617,7 @@ def _add_page_weekly_certification(self):
"""
Weekly certification page
"""

page = self._create_content_page(title=f"Weekly certification")
frame = self._create_full_page_content_frame(self.style_frame_list)
tb = TextBox()
Expand Down Expand Up @@ -582,6 +659,38 @@ def _add_page_summary(self):
)
# TODO: add content

def _generate_daily_good_bad_run_list_element(self, day_queryset) -> Element:
p = P()
sps = Span(text=f"{day_queryset.name()}: ")
p.addElement(sps)

if len(day_queryset.good().run_numbers()) > 0:
sp0 = Span(text="Good: ")
sp1 = Span(
text=self._format_list_to_str(
[run_number for run_number in day_queryset.good().run_numbers()]
),
stylename=self.style_span_good,
)
p.addElement(sp0)
p.addElement(sp1)
if len(day_queryset.bad().run_numbers()) > 0:
spbl = Span(text=" ")
p.addElement(spbl)

if len(day_queryset.bad().run_numbers()) > 0:
sp2 = Span(text=f"Bad: ")
sp3 = Span(
text=self._format_list_to_str(
[run_number for run_number in day_queryset.bad().run_numbers()]
),
stylename=self.style_span_bad,
)
p.addElement(sp2)
p.addElement(sp3)

return p

def _add_page_list_express(self):
page = self._create_content_page(title="List of runs certified StreamExpress")
frame = self._create_full_page_content_frame(self.style_frame_list)
Expand All @@ -590,22 +699,12 @@ def _add_page_list_express(self):
list_items=[
"Collisions",
[
f"{day.name()}: Good: {[run_number for run_number in day.good().run_numbers()]}, "
+ (
f"Bad: {[run_number for run_number in day.bad().run_numbers()]}"
if len(day.bad().run_numbers()) > 0
else ""
)
self._generate_daily_good_bad_run_list_element(day)
for day in self.slreport.collisions().express().day_by_day()
],
"Cosmics",
[
f"{day.name()}: Good: {[run_number for run_number in day.good().run_numbers()]}, "
+ (
f"Bad: {[run_number for run_number in day.bad().run_numbers()]}"
if len(day.bad().run_numbers()) > 0
else ""
)
self._generate_daily_good_bad_run_list_element(day)
for day in self.slreport.cosmics().express().day_by_day()
],
]
Expand All @@ -622,22 +721,12 @@ def _add_page_list_prompt(self):
list_items=[
"Collisions",
[
f"{day.name()}: Good: {[run_number for run_number in day.good().run_numbers()]}, "
+ (
f"Bad: {[run_number for run_number in day.bad().run_numbers()]}"
if len(day.bad().run_numbers()) > 0
else ""
)
self._generate_daily_good_bad_run_list_element(day)
for day in self.slreport.collisions().prompt().day_by_day()
],
"Cosmics",
[
f"{day.name()}: Good: {[run_number for run_number in day.good().run_numbers()]}, "
+ (
f"Bad: {[run_number for run_number in day.bad().run_numbers()]}"
if len(day.bad().run_numbers()) > 0
else ""
)
self._generate_daily_good_bad_run_list_element(day)
for day in self.slreport.cosmics().prompt().day_by_day()
],
]
Expand Down

0 comments on commit cc7d769

Please sign in to comment.