def saveSnapshot(conn, data, servicename=None, configname=None, comment=None,approval=False): """ save a snapshot (masar event) with data. The data format is a tuple array like [('pv name', 'string value', 'double value', 'long value', 'dbr type', 'isConnected', 'secondsPastEpoch', 'nanoSeconds', 'timeStampTag', 'alarmSeverity', 'alarmStatus', 'alarmMessage', 'is_array', 'array_value')] Return service_event_id, masar_data_id[]. >>> import sqlite3 >>> from pymasar.service.service import (saveService, retrieveServices) >>> from pymasar.service.serviceconfig import (saveServiceConfig, retrieveServiceConfigs) >>> from pymasar.db.masarsqlite import (SQL) >>> conn = sqlite3.connect(":memory:") >>> cur = conn.cursor() >>> result = cur.executescript(SQL) >>> saveService(conn, 'masar1', desc='non-empty description') 1 >>> saveService(conn, 'masar2', desc='non-empty description') 2 >>> saveServiceConfig(conn, 'masar1', 'orbit C01', 'BPM horizontal readout for storage ring') 1 >>> saveServiceConfig(conn, 'masar1', 'orbit C02', 'BPM horizontal readout for storage ring') 2 >>> saveServiceConfig(conn, 'masar2', 'orbit C01', 'BPM horizontal readout for storage ring') 3 >>> saveServiceConfig(conn, 'masar2', 'orbit C02', 'BPM horizontal readout for storage ring') 4 >>> result = retrieveServiceConfigs(conn, servicename='masar1', configname='orbit C01') >>> data = [('SR:C01-BI:G02A<BPM:L1>Pos-X','12.2', 12.2, 12, 6, 1, 435686768234, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G02A<BPM:L2>Pos-X', '12.2', 12.2, 12, 6, 1, 435686768234, 3452345098734, 0, 0, 0, "", 1, [1.2,2.3, 3.4, 4.5]), ... ('SR:C01-BI:G04A<BPM:M1>Pos-X', '12.2', 12.2, 12, 6, 1, 435686768234, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G04B<BPM:M1>Pos-X', '12.2', 12.2, 12, 6, 1, 435686768234, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G06B<BPM:H1>Pos-X', '12.2', 12.2, 12, 6, 1, 435686768234, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G06B<BPM:H2>Pos-X', '12.2', 12.2, 12, 6, 1, 435686768234, 3452345098734, 0, 0, 0, "", 0, [])] >>> saveSnapshot(conn, data, servicename='masar1', configname='orbit C01', comment='a service event') (1, [1, 2, 3, 4, 5, 6]) >>> data = [('SR:C01-BI:G02A<BPM:L1>Pos-X','12.2', 12.2, 12, 6, 1, 564562342566, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G02A<BPM:L2>Pos-X', '12.2', 12.2, 12, 6, 1, 564562342566, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G04A<BPM:M1>Pos-X', '12.2', 12.2, 12, 6, 1, 564562342566, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G04B<BPM:M1>Pos-X', '12.2', 12.2, 12, 6, 1, 564562342566, 3452345098734, 0, 0, 0, "", 0, []), ... ('SR:C01-BI:G06B<BPM:H1>Pos-X', '12.2', 12.2, 12, 6, 1, 564562342566, 3452345098734, 0, 0, 0, "", 1, [1.2,2.3, 3.4, 4.5]), ... ('SR:C01-BI:G06B<BPM:H2>Pos-X', '12.2', 12.2, 12, 6, 1, 564562342566, 3452345098734, 0, 0, 0, "", 0, [])] >>> saveSnapshot(conn, data, servicename='masar1', configname='orbit C01', comment='a service event') (2, [7, 8, 9, 10, 11, 12]) >>> conn.close() """ checkConnection(conn) eventid = saveServiceEvent(conn, servicename, configname, comment=comment, approval=approval) masarid = None try: masarid = __saveMasarData(conn, eventid, data) except sqlite3.Error, e: print ('Error %s' %e.args[0]) raise
def dummyServiceEventNoData(): for k, v in sorted(event4conf.items()): eid = saveServiceEvent(conn, __servicename, k) updateServiceEvent(conn, eid, comment=v[0], approval=True, username="******")