The combos module¶
The combos are cobinations of other PyExpLabSys components in commonly used configurations. Currently the only implemented combination are:
LiveContinuousLogger
which combines aLiveSocket
with aContinuousDataSaver
and
Table of Contents
Examples¶
LiveContinuousLogger¶
This example shows the case of using the combo to log values individually, using the “now”
variety of the method (LiveContinuousLogger.log_point_now()
), which uses the time
now as the xvalue:
from time import sleep
from random import random
from math import sin
from PyExpLabSys.combos import LiveContinuousLogger
# Initialize the combo and start it
combo = LiveContinuousLogger(
name='test',
codenames=['dummy_sine_one', 'dummy_sine_two'],
continuous_data_table='dateplots_dummy',
username='dummy',
password='dummy',
time_criteria=0.1,
)
combo.start()
# Measurement loop (typically runs forever, here just for 10 sec)
for _ in range(10):
# The two sine values here emulate a value to be logged
sine_one = sin(random())
sine_two = sin(random())
combo.log_point_now('dummy_sine_one', sine_one)
combo.log_point_now('dummy_sine_two', sine_two)
sleep(1)
combo.stop()
or if it is preferred to keep track of the timestamp manually, the
LiveContinuousLogger.log_point()
method which can be used instead:
from time import sleep, time
from math import sin, pi
from PyExpLabSys.combos import LiveContinuousLogger
# Initialize the combo and start it
combo = LiveContinuousLogger(
name='test',
codenames=['dummy_sine_one', 'dummy_sine_two'],
continuous_data_table='dateplots_dummy',
username='dummy',
password='dummy',
time_criteria=0.1,
)
combo.start()
# Measurement loop (typically runs forever, here just for 10 sec)
for _ in range(10):
# The two sine values here emulate a value to be logged
now = time()
sine_one = sin(now)
sine_two = sin(now + pi)
combo.log_point('dummy_sine_one', (now, sine_one))
combo.log_point('dummy_sine_two', (now, sine_two))
sleep(1)
combo.stop()
Of course, like most of the underlying code, the combo also takes data at batches, as
shown in the following example (using LiveContinuousLogger.log_batch()
):
from time import sleep, time
from math import sin, pi
from PyExpLabSys.combos import LiveContinuousLogger
# Initialize the combo and start it
combo = LiveContinuousLogger(
name='test',
codenames=['dummy_sine_one', 'dummy_sine_two'],
continuous_data_table='dateplots_dummy',
username='dummy',
password='dummy',
time_criteria=0.1,
)
combo.start()
# Measurement loop (typically runs forever, here just for 10 sec)
for _ in range(10):
# The two sine values here emulate a value to be logged
now = time()
points = {
'dummy_sine_one': (now, sin(now)),
'dummy_sine_two': (now, sin(now + pi)),
}
combo.log_batch(points)
sleep(1)
combo.stop()
For the bacthes there is of course also a “now” variety
(LiveContinuousLogger.log_batch_now()
), which there is no example for, but the
difference is same as for the single point/value.
Autogenerated module documentation¶
This module contains socket, database saver and logger heuristic combinations

class
PyExpLabSys.combos.
LiveContinuousLogger
(name, codenames, continuous_data_table, username, password, time_criteria=None, absolute_criteria=None, relative_criteria=None, live_server_kwargs=None)[source]¶ Bases:
object
A combination of a
LiveSocket
and aContinuousDataSaver
that also does logging heuristicsFIXME explain the term log

__init__
(name, codenames, continuous_data_table, username, password, time_criteria=None, absolute_criteria=None, relative_criteria=None, live_server_kwargs=None)[source]¶ Initialize local data
Parameters:  name (str) – The name to be used in the sockets
 codenames (sequence) – A sequence of codenames. These codenames are the
measurements codenames for the
ContinuousDataSaver
and they will also be used as the codenames for theLiveSocket
.  continuous_data_table (str) – The continuous data table to log data to
 username (str) – The MySQL username
 password (str) – The password for
username
in the database  time_criteria (float or dict) – (Optional) The time after which a point will always be saved in the database. Either a single value, which will be used for all codenames or a dict of codenames to values. If supplying a dict, each codename must be present as a key.
 absolute_criteria (float or dict) – (Optional) The absolute value difference criteria. Either a single value or one for each codename, see time_criteria for details.
 relative_criteria (float or dict) – (Optional) The relative value difference criteria. Either a single value or one for each codename, see time_criteria for details.
 lives_server_kwargs (dict) – (Optinal) A dict of keyword arguments for the
LiveSocket
. See the doc string forLiveSocket.__init__()
for additional details.

start
()[source]¶ Start the underlying
LiveSocket
andContinuousDataSaver

stop
()[source]¶ Stop the underlying
LiveSocket
andContinuousDataSaver

log_point_now
(codename, value)[source]¶ Log a point now
As the time will be attached the time now.
For an explanation of what is meant by the term “log”, see the
class docstring
.Parameters:  codename (str) – The codename to log this point for
 value (float) – The value to store with the time now (
time.time()
)

log_point
(codename, point)[source]¶ Log a point
For an explanation of what is meant by the term “log”, see the
class docstring
.Parameters:  codename (str) – The codename to log this point for
 point (sequence) – A (unix_time, value) two item sequence (e.g. list or tuple), that represents a point

log_batch_now
(values)[source]¶ Log a batch of values now
For an explanation of what is meant by the term “log”, see the
class docstring
.Parameters: values (dict) – Dict of codenames to values. The values will be stored with the time now ( time.time()
)

log_batch
(points)[source]¶ Log a batch of points
For an explanation of what is meant by the term “log”, see the
class docstring
.Parameters: points (dict) – Dict of codenames to points
