rewrite.lib.utils.db package¶
Submodules¶
rewrite.lib.utils.db.CountRecordAdapter module¶
-
class
rewrite.lib.utils.db.CountRecordAdapter.CountRecordAdapter(*args, **kwargs)[source]¶ Bases:
mongoengine.document.EmbeddedDocumentAdapter class to store Counts in MongoDB
Parameters: - (Bool) (valid) – validity of the record.
- (int) (counts_trigger) – Counts in channel X
- (int) – trigger counts recieved
- (Real) (counts_time) – the time of the record
-
counters_time¶ Counts in the time register of the DAQ card. Basically a timestamp
-
counts_ch0¶ Counts in channel 0
-
counts_ch1¶ Counts in channel 1
-
counts_ch2¶ Counts in channel 2
-
counts_ch3¶ Counts in channel 3
-
counts_trigger¶ Trigger counts
-
createCount()[source]¶ Creates a CountRecord from the current object
Returns: CountRecord from the current CountRecordAdapter
-
static
get(rec)[source]¶ Creates a CountRecordAdapter from a CountRecord
Parameters: rec – CountRecord to convert
-
valid¶ Set to true if the underlying record is valid
rewrite.lib.utils.db.DataRecordAdapter module¶
-
class
rewrite.lib.utils.db.DataRecordAdapter.DataRecordAdapter(*args, **kwargs)[source]¶ Bases:
mongoengine.document.EmbeddedDocumentAdapter class for the data record. Basically just a string wrapper.
-
createData()[source]¶ Converts the current object to a DataRecord
Returns: DataRecord from the current DataRecordAdapter
-
static
get(rec)[source]¶ Create a DataRecordAdapter from a DataRecord
Parameters: rec – DataRecord to convert
-
msg¶ A unicode string field.
-
rewrite.lib.utils.db.PressureRecordAdapter module¶
-
class
rewrite.lib.utils.db.PressureRecordAdapter.PressureRecordAdapter(*args, **kwargs)[source]¶ Bases:
mongoengine.document.EmbeddedDocumentAdapter class for the pressure record.
Parameters: - (Bool) (valid) – Validity of the record. Set to True, if the message starts with ‘BA’
- (Real) (pressure) – Floating point value of in the pressure record
- (PressureType) (pressure_type) – Either mBar or plain data
-
createPressure()[source]¶ Converts the current object to a PressureRecord
Returns: PressureRecord from the current PressureRecordAdapter
-
static
get(rec)[source]¶ Create a PressureRecordAdapter from a PressureRecord
Parameters: rec – PressureRecord to convert
-
pressure¶ Fixed-point decimal number field. Stores the value as a float by default unless force_string is used. If using floats, beware of Decimal to float conversion (potential precision loss)
-
pressure_type¶ A unicode string field.
-
valid¶ Boolean field type.
rewrite.lib.utils.db.RecordAdapter module¶
-
class
rewrite.lib.utils.db.RecordAdapter.RecordAdapter(**kwargs)[source]¶ Bases:
mongoengine.document.DocumentThis is an adapter class which helps to save and load a record in MongoDB.
Parameters: - _id – Object ID given by MongoDB. Explicitly declared to be able to load from dict.
- packageNumber – A sequential number of all packages send by a DAQ server
- RecType – Type of the record
- timestamp – Unixtimestamp
- payload_cnt – Count Payload
- payload_dat – Data Payload
- payload_tme – Temperature Payload
- payload_prs – Pressure Payload
Sadly the payload for each type of payload needs to be in a separate field, as we need an EmbeddedDocumentField of a certain type.
-
exception
DoesNotExist¶ Bases:
mongoengine.errors.DoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
mongoengine.errors.MultipleObjectsReturned
-
createRecord()[source]¶ Creates a Record with the current data.
Returns: Record with the current data
-
static
get(rec)[source]¶ Construct a RecordAdapter from a Record
Parameters: rec – a record that will be converted to a RecordAdapter Returns: a newly constructed RecordAdapter
-
static
getChoice(i)[source]¶ Translate RecordType aka int to string.
Parameters: i – RecordType to be converted.
-
id¶ A field wrapper around MongoDB’s ObjectIds.
-
objects¶ The default QuerySet Manager.
Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a
Documentclass as its first argument, and aQuerySetas its second argument.The method function should return a
QuerySet, probably the same one that was passed in, but modified in some way.
-
packageNumber¶ 32-bit integer field.
-
payload_cnt¶ An embedded document field - with a declared document_type. Only valid values are subclasses of
EmbeddedDocument.
-
payload_dat¶ An embedded document field - with a declared document_type. Only valid values are subclasses of
EmbeddedDocument.
-
payload_prs¶ An embedded document field - with a declared document_type. Only valid values are subclasses of
EmbeddedDocument.
-
payload_tem¶ An embedded document field - with a declared document_type. Only valid values are subclasses of
EmbeddedDocument.
-
timestamp¶ Datetime field.
Uses the python-dateutil library if available alternatively use time.strptime to parse the dates. Note: python-dateutil’s parser is fully featured and when installed you can utilise it to convert varying types of date formats into valid python datetime objects.
Note: To default the field to the current datetime, use: DateTimeField(default=datetime.utcnow)
- Note: Microseconds are rounded to the nearest millisecond.
- Pre UTC microsecond support is effectively broken.
Use
ComplexDateTimeFieldif you need accurate microsecond support.
-
type¶ only valid choices here are: CONTROL, DATA, TEMPERATURE, PRESSURE, COUNTER
Type: String
rewrite.lib.utils.db.TemperatureRecordAdapter module¶
-
class
rewrite.lib.utils.db.TemperatureRecordAdapter.TemperatureRecordAdapter(*args, **kwargs)[source]¶ Bases:
mongoengine.document.EmbeddedDocumentAdapter class for the temperature record.
Parameters: - (Bool) (valid) – Validity of the record. Set to True, if the message starts with ‘TH’
- (Real) (temperature) – The temperature of the record.
-
createTemperature()[source]¶ Converts the current object to a TemperatureRecord
Returns: TemperatureRecord from the current TemperatureRecordAdapter
-
static
get(rec)[source]¶ Create a TemperatureRecordAdapter from a TemperatureRecord
Parameters: rec – TemperatureRecord to convert
-
temperature¶ Fixed-point decimal number field. Stores the value as a float by default unless force_string is used. If using floats, beware of Decimal to float conversion (potential precision loss)
-
valid¶ Boolean field type.