HTML result recap¶
html
– The interface¶
Interface for the html renderer The relevant parts are imported into html/__init__.py
-
libvhc.html.communication.
HTML_RECAP
= '{{recipe}}_recap_{}.html'¶ Template name for the html recap files
-
exception
libvhc.html.communication.
HtmlRecipeError
[source]¶ The html render for the recipe has not been initialised
-
libvhc.html.communication.
get_listener
(name)[source]¶ Return the queue listener
Parameters: - name : string
name of the logger
Returns: libvhc.html.queue.SetupQueueListener
can be used once in a
with
Raises: - KeyError
if the
name
listener is not found
-
libvhc.html.communication.
get_queue
(name)[source]¶ Returns the queue saved under the
name
.If it does not exist, create it first
Parameters: - path : string
path of the two above files
Returns:
-
libvhc.html.communication.
html_context
(name)[source]¶ Yield the listener and the queue associated with
name
from within awith
statementParameters: - name : string
name of the listener and the queue
Yields: - queue-like instance
SetupQueueListener
-
libvhc.html.communication.
clear_html
(name)[source]¶ Remove the queue and the listener
Parameters: - name : string
name of the queue and logger
-
libvhc.html.communication.
init_renderer
(recipe, fplane_file, use_process=True)[source]¶ Initialize the renderer for the HTML file and the
fplane.FPlane
Parameters: - recipe : string
name of the recipe
- fplane_file : string
name of the file describing the focal plane.
- use_process : bool, optional
run the listener in a process or in a thread
-
libvhc.html.communication.
_mkmessage
(vcheck, message)[source]¶ Prepend the string from
vcheck
to themessage
Parameters: - vcheck : instance of
VCheck
store the recipe name and the check currently executing
- message : string
message of the test
Returns: - string
- vcheck : instance of
-
libvhc.html.communication.
add_fplane_test
(vcheck, message, success)[source]¶ Append a new
TestResults
to the focal plane testsThe name of the recipe and driver are prepended to the message.
Parameters: - vcheck : instance of
VCheck
store the recipe name and the check currently executing
- message : string
message of the test
- success : string or bool
success status of the test; must be one of the accepted values of
TestResults
Raises: - HtmlRecipeError
if the
recipe
renderer has not been initialized
- vcheck : instance of
-
libvhc.html.communication.
add_ifu_test
(vcheck, ifuslot, message, success)[source]¶ Append a new
TestResults
to the ifu testsThe name of the recipe and driver are prepended to the message.
Parameters: - vcheck : instance of
VCheck
store the recipe name and the check currently executing
- ifuslot : string
id of the ifu slot, if the IFU does not exists, add the message to the global messages marking it as a failure. Use a non existing
ifuslot
(e.g.None
) to add it to the orphaned tests- message : string
message of the test
- success : string or bool
success status of the test; must be one of the accepted values of
TestResults
Raises: - HtmlRecipeError
if the
recipe
renderer has not been initialized
- vcheck : instance of
-
libvhc.html.communication.
add_ntests
(vcheck, new_tests)[source]¶ Add
new_tests
to the number of testsParameters: - vcheck : instance of
VCheck
store the recipe name and the check currently executing
- new_tests : int
number on tests to add
Raises: - HtmlRecipeError
if the
recipe
renderer has not been initialized
- vcheck : instance of
-
libvhc.html.communication.
render_html
(recipe, fnames, path, xmin=-450, ymin=-550, xscale=1, yscale=1, open_html=False)[source]¶ Render the html and save it into
outpath
.The name of the output html is
recipe_recap.html
. If it already exists, a counter is added:recipe_recap_n.html
Parameters: - recipe : string
name of the recipe
- fnames :
libvhc.utils.FileNameRotator
object containing the file names. It expects the html file on
fnames.html_recap
, the log file onfnames.logfile
and the result file onfnames.result_file
. The html recap file name is expected to contain a placeholder{recipe}
- path : string
path given to vhc
- xmin, ymin : float
minimum
x
andy
coordinate to rescale the ifu positions- scale : float
divide the
x
andy
by this value after subtracting the minima. Seefplane.IFU.rescale()
for further details- open_html : bool
open the new html in the default browser
html.fplane
– Focal plane containers¶
There should be no need to use the following classes directly.
Create, deal with, render and save the html result file
-
class
libvhc.html.fplane.
TestResults
(message, status)[source]¶ Bases:
object
Simple container for the test result
Parameters: - message : string
string describing the test or the message
- status : string or bool
whether the test was successful. Accepts
'success'
,'fail'
,True
orFalse
. Any thing else is interpreted as failure
Attributes: message
: stringmessage or test description
css_status
: stringstring of the status
bool_status
: boolbool of the status
-
message
¶ message or test description
-
css_status
¶ string of the status
-
bool_status
¶ bool of the status
-
class
libvhc.html.fplane.
IFU
(*args)[source]¶ Bases:
pyhetdex.het.fplane.IFU
Contain the information for the IFU from the focal plane file and the list of tests for the ifu
Parameters: - ifuslot : string
id of the ifu
- x, y : float
x and y position of the ifu in the focal plane
- specid : int
id of the spectrograph where the ifu is plugged into
- specslot : int
id of the spectrograph slot where the spectrograph is plugged into
- ifuid : string
id of the virus ifu bundle
- ifurot : float
rotation of the IFU in its seat in the IHMP
- platescl : float
focal plane plate scale at the position in the IHMP
Attributes: - ifuid, x, y, xid, yspecid : as before
- xid, yid : string or int
x (column) and y (row) id of the ifu in the ifu head mounting plate (IHMP), generated from the ifuslot
- ifuslot : string
id of the IHMP seat address
success
: stringglobal success state. Must be one of:
tests
: list ofTestResults
Returns the test, with the failures first
-
tests
¶ Returns the test, with the failures first
-
success
¶ global success state. Must be one of:
['success', 'fail', 'failsome', 'miss', 'successmiss', 'failmiss', 'failsomemiss']
Set to ‘unknown’ when none of the above is set
-
rescale
(self, xmin, ymin, xscale, yscale)[source]¶ Rescale the
x
andy
position of the IFU:(x - xmin) / xscale (y - ymin) / yscale
Parameters: - xmin, ymin : float
minimum
x
andy
coordinate- xscale, yscale : float
divide the
x
andy
by these values after subtracting the minima
-
add_test
(self, message, success)[source]¶ Append a new
TestResults
Parameters: - message : string
message of the test
- success : string or bool
success status of the test; must be one of the accepted values of
TestResults
-
class
libvhc.html.fplane.
FPlane
(recipe, fplane_file)[source]¶ Bases:
pyhetdex.het.fplane.FPlane
Focal plane.
Contains the dictionary of
IFU
instance, with the ifu id as key, the list of test common to the focal plane and provide the tools to process the ifus before rendering the html.The focal plane is expected to be like:
# IFUSLOT X_FP Y_FP SPECID SPECSLOT IFUID IFUROT PLATESC 013 -450.0 150.0 00 000 000 0.0 1.0 014 -450.0 50.0 00 000 000 0.0 1.0
Parameters: - recipe : string
name of the current recipe
- fplane_file : string
name of the file containing the ids and position of the IFUs
- conf :
confp.ConfigParser
instance configuration option
Attributes: - difus
- ids
ifus
list of
IFU
instancestests
List of
TestResults
: tests run for whole focal planetests_orphan
List of
TestResults
: orphaned tests with failures first.- recipe : string
name of the recipe
- ntests : int
number of tests expected per IFU. It’s used in
postprocess_ifus()
to determine whether all expected tests are presenttemplate
: jinja templateJinja template
- rendered : string
rendered jinja template
-
tests
¶ List of
TestResults
: tests run for whole focal plane with failures first
-
tests_orphan
¶ List of
TestResults
: orphaned tests with failures first.They should belong to one IFU, but its ID is not known.
-
ifu_rescale
(self, xmin, ymin, xscale, yscale)[source]¶ Rescale the
x
andy
position of all the ifus. SeeIFU.rescale()
for further details
-
add_test
(self, message, success)[source]¶ Append a new
TestResults
to the focal plane testsParameters: - message : string
message of the test
- success : string or bool
success status of the test; must be one of the accepted values of
TestResults
-
add_orphan_test
(self, message, success)[source]¶ Append a new
TestResults
to the orphan testsParameters: - message : string
message of the test
- success : string or bool
success status of the test; must be one of the accepted values of
TestResults
-
add_ifu_test
(self, ifuslot, message, success)[source]¶ Add to the ifu identified by
ifuid
Parameters: - ifuslot : int
id of the ifu slot, if the IFU does not exists, add the message to the global messages marking it as a failure
- message : string
message of the test
- success : string or bool
success status of the test; must be one of the accepted values of
TestResults
-
add_ntests
(self, new_tests)[source]¶ Add
new_tests
to the number of testsParameters: - new_tests : int
number on tests to add
-
postprocess_ifus
(self)[source]¶ Post process the ifu, to check if all the expected checks are present and set the
IFU.success
correspondingly
-
_load_fplane
(self, fname, empty_specid, empty_ifuid, exclude_ifuslot, skip_empty)[source]¶ Load the focal plane file and creates the
IFU
instancesParameters: - fname : string
name of the focal plane file
- empty_specid, empty_ifuid, exclude_ifuslot, skip_empty :
see
FPlane
-
add_ifu
(self, fpars)[source]¶ Parse a fplane
line
and add the IFU to the internal dictionary.Make sure that the ifuid, specid are a three digit string. Override this method if the
ifu
class constructor is not as the one ofIFU
.Parameters: - line : string
line of the fplane file
-
by_id
(self, id_, idtype)[source]¶ Returns the ifu with
id_
Parameters: - id_ : string
id of the spectrograph
- idtype : str
type of the id; must be one of ‘ifuid’, ‘ifuslot’, ‘specid’
Returns: IFU
instance
Raises: - NoIFUError
if there is no IFU identified by the input ID
- UnknownIDTypeError
if the ID type is not known
-
by_ifuid
(self, ifuid)[source]¶ Returns the ifu with
ifuid
Parameters: - ifuid : string
id of the ifu
Returns: IFU
instance
Raises: - NoIFUError
if there is no IFU identified by the input ID
-
by_ifuslot
(self, ifuslot)[source]¶ Returns the ifu with
ifuslot
Parameters: - ifuslot : string
id of the ihmp slot
Returns: IFU
instance
Raises: - NoIFUError
if there is no IFU identified by the input ID
-
by_slotpos
(self, x, y)[source]¶ Returns the ifu in ifu slot position x, y
Parameters: - x : int
x position in the IHMP (1 to 10)
- y : int
y position in the IHMP (1 to 9)
Returns: IFU
instance
Raises: - NoIFUError
if there is no IFU for the input positions
-
by_specid
(self, specid)[source]¶ Returns the ifu with
specid
Parameters: - specid : int or string
id of the spectrograph; the value is cast to an integer
Returns: IFU
instance
Raises: - NoIFUError
if there is no IFU identified by the input ID
- TypeError
if the input is not an int or a string that can be cast to an int
-
ifuids
¶ list of IFUIDs (strings)
-
ifuslots
¶ list of IFUSLOTs (strings)
-
specids
¶ list of SPECIDs (integers)
-
template
¶ Jinja template
-
libvhc.html.fplane.
_log_to_list
(lines)[source]¶ Loop through the lines and collect all log lines into a list collecting multi-lines into one entry.
Empty lines are ignored and new lines are stripped.
Warning
adapt the regex pattern if the log format is changed in
libvhc.loggers.set_logger()
Parameters: - lines : iterable
lines to parser
Returns: - logs : list
list of log messages
html.queue
– The queue listener process¶
There should be no need to use the following classes directly.
Implement a queue based communication system for the html render
The QueueListener creates and store internally an instance of
FPlane
. Each element put into the queue is
interpreted as a list of three elements:
- the name of the method or of a property of the
FPlane
instance: this must be present; - the list of args of the method (optional): if absent or None, interpreted as an empty list; if the first element is a property, the first element of this list is assigned to the property;
- the dictionary of kwargs the method (optional): if absent or None, interpreted as an empty dictionary; if the first element is a property, this is ignored.
The only exception is the sentinel
, defaulting to None
, that is passed
along without any manipulation.
Example:
-
class
libvhc.html.queue.
HTMLQueue
(*args, **kwargs)[source]¶ Bases:
pyhetdex.tools.queue.QueueContext
Queue used in the HTML interface to communicate from the processes to
FPlane
objectAttributes: - sentinel
if the object put into the queue is
sentinel
no check is done
-
put
(self, obj, block=True, timeout=None)[source]¶ Check that obj comply with the specifications in
libvhc.html.queue
and, if it does, put obj into the queue.Parameters: - obj :
object to insert into the queue
- block : bool, optional
if
True
, block until a free slot in the queue is available or, if set, timeout seconds pass; ifFalse
raise aqueue.Full
error if there are no free slots- timeout : number, optional
number of seconds to wait if block if
True
before raising aqueue.Full
error; ignored if block isFalse
Raises: - VHCQueueItemError
if the obj is not of the correct type or shape
-
class
libvhc.html.queue.
QueueListener
(queue_, fplane_class, recipe, fplane_file)[source]¶ Bases:
pyhetdex.tools.queue.QueueListener
This class implements an internal threaded listener which watches for LogRecords being added to a queue, removes them and passes them to a list of handlers for processing.
Parameters: - queue_ : queue-like instance
queue to use to transmit the information
- fplane_class :
FPlane
class class declaration that will be instantiated by the lister
- recipe : string
name of the recipe
- fplane_file : string
name of the file describing the focal plane.
-
class
libvhc.html.queue.
SetupQueueListener
(queue_, fplane_class, recipe, fplane_file, use_process=True)[source]¶ Bases:
pyhetdex.tools.queue.SetupQueueListener
Start the
QueueListener
, in a separate process if required.Adapted from logging cookbook.
The
SetupQueueListener
instance can be used as a context manager for awith
statement. Upon exiting the statement, the process andQueueListener
are stopped. If an exception happens, it will be logged as critical before stopping: in order to avoid possible errors with missing formatter keywords, the handler formatters are temporarily substituted with “%(level)s %(message)s”.Parameters: - queue_ : queue-like instance
queue to use to transmit the information
- fplane_class :
FPlane
class class declaration that will be instantiated by the listener
- recipe : string
name of the recipe
- fplane_file : string
name of the file describing the focal plane.
- use_process : bool, optional
if
True
start the listener in a separate process
Attributes: - queue : as above
- stop_event :
multiprocessing.Event
instance event used to signal to stop the listener
- lp : :class multiprocessing.Process instance
process running the listener, if
use_process
isTrue
- listener :
QueueListener
instance