""" # sessioncontrol.py This script updates the number of sessions currently active by deleting expired sessions (those that did not include a log out) and counting those that are active. Besides being able to tell who is online at any given time and from where, this will allow us to limit the number of sessions per user """ # Determine whether this process is enabled: enabled = dblib.sqlitedatumquery( pilib.dirs.dbs.system, 'select sessioncontrolenabled from \'systemstatus\'') while enabled: #print('enabled') polltime = dblib.sqlitedatumquery( pilib.dirs.dbs.session, 'select updatefrequency from \'settings\'') # Go through sessions and delete expired ones sessions = pilib.dirs.dbs.session.read_table('sessions') arrayquery = [] for session in sessions: sessionstart = datalib.timestringtoseconds(session['timecreated']) sessionlength = session['sessionlength'] if time.time() - sessionstart > sessionlength: arrayquery.append('delete from sessions where sessionid=\'' +
def get_mode(self): from pilib import dirs from iiutilities.dblib import sqlitedatumquery self.mode = sqlitedatumquery(dirs.dbs.control, 'select mode from channels where name=\'' + channel.name + '\'')
def get_setpoint_value(self): from pilib import dirs from iiutilities.dblib import sqlitedatumquery self.setpointvalue = sqlitedatumquery(dirs.dbs.control, 'select setpointvalue from channels where name=\'' + channel.name + '\'')
""" # sessioncontrol.py This script updates the number of sessions currently active by deleting expired sessions (those that did not include a log out) and counting those that are active. Besides being able to tell who is online at any given time and from where, this will allow us to limit the number of sessions per user """ # Determine whether this process is enabled: enabled = dblib.sqlitedatumquery(pilib.dirs.dbs.system, 'select sessioncontrolenabled from \'systemstatus\'') while enabled: #print('enabled') polltime = dblib.sqlitedatumquery(pilib.dirs.dbs.session, 'select updatefrequency from \'settings\'') # Go through sessions and delete expired ones sessions = pilib.dirs.dbs.session.read_table('sessions') arrayquery = [] for session in sessions: sessionstart = datalib.timestringtoseconds(session['timecreated']) sessionlength = session['sessionlength'] if time.time() - sessionstart > sessionlength: arrayquery.append('delete from sessions where sessionid=\'' + session['sessionid'] + '\'') # Delete offensive sessions
def updateowfsdevices(busdevices, myProxy=None, debug=False): from cupid import pilib from iiutilities import dblib from iiutilities import datalib from iiutilities import utility # get defaults defaults = pilib.dirs.dbs.control.read_table('defaults') default_dict = {} for default_item in defaults: default_dict[default_item['valuename']] = default_item['value'] # get current entries previnputs = pilib.dirs.dbs.control.read_table('inputs') # Make list of IDs for easy indexing previnputids = [] for input in previnputs: previnputids.append(input['id']) # Iterate over devices. Determine if values exist for polltime, frequency. # If so, update the device. If not, use defaults. # Then determine whether we should update value or not (Read temperature) for index, device in enumerate(busdevices): # print(device.__dict__) if device.sensorid in previnputids: try: newpollfreq = float(previnputs[previnputids.index( device.sensorid)]['pollfreq']) except ValueError: device.pollfreq = float(default_dict['inputpollfreq']) else: if newpollfreq >= 0: device.pollfreq = float(previnputs[previnputids.index( device.sensorid)]['pollfreq']) else: device.pollfreq = float(default_dict['inputpollfreq']) device.ontime = previnputs[previnputids.index( device.sensorid)]['ontime'] device.offtime = previnputs[previnputids.index( device.sensorid)]['offtime'] device.polltime = previnputs[previnputids.index( device.sensorid)]['polltime'] device.value = previnputs[previnputids.index( device.sensorid)]['value'] device.log_options = previnputs[previnputids.index( device.sensorid)]['log_options'] else: device.pollfreq = float(default_dict['inputpollfreq']) device.ontime = '' device.offtime = '' device.polltime = '' device.value = '' """ We're going to set a name because calling things by their ids is getting a bit ridiculous, but we can't have empty name fields if we rely on them being there. They need to be unique, so we'll name them by type and increment them Not really sure why this is conditional? """ if device.type in ['DS18B20', 'DS1825']: # Get name if one exists name = dblib.sqlitedatumquery( pilib.dirs.dbs.control, 'select name from ioinfo where id=\'' + device.sensorid + '\'') # If doesn't exist, check to see if proposed name exists. If it doesn't, add it. # If it does, keep trying. if name == '': for rangeindex in range(100): # check to see if name exists name = device.type + '-' + str(int(index + 1)) # print(name) foundid = dblib.sqlitedatumquery( pilib.dirs.dbs.control, 'select id from ioinfo where name=\'' + name + '\'') # print('foundid' + foundid) if foundid: pass else: dblib.sqlitequery( pilib.dirs.dbs.control, dblib.makesqliteinsert( 'ioinfo', valuelist=[device.sensorid, name], valuenames=['id', 'name'])) break device.name = name device.time_since_last = datalib.timestringtoseconds( datalib.gettimestring()) - datalib.timestringtoseconds( device.polltime, defaulttozero=True) # Is it time to read temperature? if device.time_since_last > device.pollfreq: utility.log( pilib.dirs.logs.io, 'reading temperature [' + device.name + '][' + device.id + ']', 9, pilib.loglevels.io) device.readprop('temperature', myProxy) device.polltime = datalib.gettimestring() device.value = device.temperature.decode('utf-8') else: utility.log( pilib.dirs.logs.io, 'not time to poll', 9, pilib.loglevels.io, ) # print('not time to poll') device.unit = 'F' # We update the device and send them back for other purposes. busdevices[index] = device return busdevices
def updateowfsdevices(busdevices, myProxy=None, debug=False): from cupid import pilib from iiutilities import dblib from iiutilities import datalib from iiutilities import utility # get defaults defaults = pilib.dirs.dbs.control.read_table('defaults') default_dict={} for default_item in defaults: default_dict[default_item['valuename']] = default_item['value'] # get current entries previnputs = pilib.dirs.dbs.control.read_table('inputs') # Make list of IDs for easy indexing previnputids = [] for input in previnputs: previnputids.append(input['id']) # Iterate over devices. Determine if values exist for polltime, frequency. # If so, update the device. If not, use defaults. # Then determine whether we should update value or not (Read temperature) for index, device in enumerate(busdevices): # print(device.__dict__) if device.sensorid in previnputids: try: newpollfreq = float(previnputs[previnputids.index(device.sensorid)]['pollfreq']) except ValueError: device.pollfreq = float(default_dict['inputpollfreq']) else: if newpollfreq >= 0: device.pollfreq = float(previnputs[previnputids.index(device.sensorid)]['pollfreq']) else: device.pollfreq = float(default_dict['inputpollfreq']) device.ontime = previnputs[previnputids.index(device.sensorid)]['ontime'] device.offtime = previnputs[previnputids.index(device.sensorid)]['offtime'] device.polltime = previnputs[previnputids.index(device.sensorid)]['polltime'] device.value = previnputs[previnputids.index(device.sensorid)]['value'] device.log_options = previnputs[previnputids.index(device.sensorid)]['log_options'] else: device.pollfreq = float(default_dict['inputpollfreq']) device.ontime = '' device.offtime = '' device.polltime = '' device.value = '' """ We're going to set a name because calling things by their ids is getting a bit ridiculous, but we can't have empty name fields if we rely on them being there. They need to be unique, so we'll name them by type and increment them Not really sure why this is conditional? """ if device.type in ['DS18B20', 'DS1825']: # Get name if one exists name = dblib.sqlitedatumquery(pilib.dirs.dbs.control, 'select name from ioinfo where id=\'' + device.sensorid + '\'') # If doesn't exist, check to see if proposed name exists. If it doesn't, add it. # If it does, keep trying. if name == '': for rangeindex in range(100): # check to see if name exists name = device.type + '-' + str(int(index + 1)) # print(name) foundid = dblib.sqlitedatumquery(pilib.dirs.dbs.control, 'select id from ioinfo where name=\'' + name + '\'') # print('foundid' + foundid) if foundid: pass else: dblib.sqlitequery(pilib.dirs.dbs.control, dblib.makesqliteinsert('ioinfo', valuelist=[device.sensorid, name], valuenames=['id', 'name'])) break device.name = name device.time_since_last = datalib.timestringtoseconds(datalib.gettimestring()) - datalib.timestringtoseconds(device.polltime, defaulttozero=True) # Is it time to read temperature? if device.time_since_last > device.pollfreq: utility.log(pilib.dirs.logs.io, 'reading temperature [' + device.name + '][' + device.id + ']' , 9, pilib.loglevels.io) device.readprop('temperature', myProxy) device.polltime = datalib.gettimestring() device.value = device.temperature.decode('utf-8') else: utility.log(pilib.dirs.logs.io, 'not time to poll', 9, pilib.loglevels.io, ) # print('not time to poll') device.unit = 'F' # We update the device and send them back for other purposes. busdevices[index] = device return busdevices