started fixing datalogger to match db structure of tag server
This commit is contained in:
@@ -109,23 +109,29 @@ CREATE TABLE IF NOT EXISTS tag_classes(
|
||||
description TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tags(
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
class INTEGER,
|
||||
tag TEXT,
|
||||
data_type TEXT,
|
||||
change_threshold REAL,
|
||||
guarantee_sec INTEGER,
|
||||
map_function TEXT
|
||||
CREATE TABLE IF NOT EXISTS tags (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT,
|
||||
class TEXT,
|
||||
tag TEXT,
|
||||
description TEXT,
|
||||
data_type TEXT,
|
||||
change_threshold REAL,
|
||||
guarantee_sec INTEGER,
|
||||
map_function TEXT,
|
||||
units TEXT,
|
||||
minExpected REAL,
|
||||
maxExpected REAL,
|
||||
map
|
||||
dateAdded TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
deleted INTEGER DEFAULT 0
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS tag_vals(
|
||||
CREATE TABLE IF NOT EXISTS tag_vals (
|
||||
id INTEGER PRIMARY KEY,
|
||||
dtime TIMESTAMP,
|
||||
name TEXT,
|
||||
val TEXT
|
||||
tagID INTEGER,
|
||||
val REAL,
|
||||
dtime TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS well_config(
|
||||
@@ -152,5 +158,14 @@ CREATE TABLE IF NOT EXISTS alarms(
|
||||
name TEXT,
|
||||
class INTEGER,
|
||||
tag TEXT,
|
||||
cond TEXT
|
||||
condition TEXT
|
||||
);
|
||||
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (1, 'stroke', 'Stroke Information');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (2, 'history', 'Historical Data');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (3, 'gaugeoff', 'Gauge Off Data');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (4, 'welltest', 'Well Test Data');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (5, 'custom', 'Custom tags');
|
||||
|
||||
INSERT INTO alarm_classes(id, alarm_class, description) VALUES (1, 'analog', 'Analog Alarms');
|
||||
INSERT INTO alarm_classes(id, alarm_class, description) VALUES (2, 'bit', 'Bit Statuses');
|
||||
|
||||
@@ -94,7 +94,7 @@ def checkDateInDB(da):
|
||||
class Tag():
|
||||
global readTag, con
|
||||
|
||||
def __init__(self, name, tag, data_type, change_threshold, guarantee_sec, mapFn=None):
|
||||
def __init__(self, name, tag, data_type, change_threshold, guarantee_sec, db_id, mapFn=None):
|
||||
self.name = name
|
||||
self.tag = tag
|
||||
self.data_type = data_type
|
||||
@@ -104,8 +104,10 @@ class Tag():
|
||||
self.chg_threshold = change_threshold
|
||||
self.last_send_time = 0
|
||||
self.mapFn = mapFn
|
||||
self.db_id = db_id
|
||||
|
||||
def read(self, forceSend):
|
||||
time.sleep(0.01)
|
||||
if self.tag:
|
||||
v = readTag(PLC_IP_ADDRESS, self.tag)
|
||||
if v:
|
||||
@@ -131,7 +133,7 @@ class Tag():
|
||||
return False
|
||||
|
||||
def sendToDB(self):
|
||||
query = "INSERT INTO tag_vals (dtime, name, val) VALUES ({}, '{}', {})".format(time.time(), self.name, self.value)
|
||||
query = "INSERT INTO tag_vals (dtime, tagID, val) VALUES ({}, {}, {})".format(time.time(), self.db_id, self.value)
|
||||
print query
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
@@ -267,36 +269,37 @@ gaugeoff_tags = {} # Tags stored at gauge off
|
||||
welltest_tags = {} # Tags stored at well test submit
|
||||
bit_tags = {}
|
||||
safety_tags = {}
|
||||
status = Status('run_status', 'Pump.Run_Status', 'STRING', 0, 3600, mapFn=maps['statusMap'])
|
||||
status = Status('run_status', 'Pump.Run_Status', 'STRING', 0, 3600, 0, mapFn=maps['statusMap'])
|
||||
|
||||
def setupTags():
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
query = "SELECT t.name as name, c.tag_class as class, t.tag as tag, t.data_type as data_type, t.change_threshold as change_threshold, t.guarantee_sec as guarantee_sec, t.map_function as map_function FROM tags t JOIN tag_classes c ON c.id = t.class;"
|
||||
query = "SELECT t.name as name, c.tag_class as class, t.tag as tag, t.data_type as data_type, t.change_threshold as change_threshold, t.guarantee_sec as guarantee_sec, t.id as id, t.map_function as map_function FROM tags t JOIN tag_classes c ON c.id = t.class;"
|
||||
cur.execute(query)
|
||||
tags = cur.fetchall()
|
||||
# 0: name, 1: class, 2: tag, 3: data_type, 4: change_threshold, 5: guarantee_sec, 6: map_function
|
||||
# 0: name, 1: class, 2: tag, 3: data_type, 4: change_threshold, 5: guarantee_sec, 6: db id, 7: map_function
|
||||
for x in tags:
|
||||
print(x)
|
||||
if str(x[1]) == 'stroke':
|
||||
if x[6]:
|
||||
stroke_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]), mapFn=maps[str(x[6])])
|
||||
if x[7]:
|
||||
stroke_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6], mapFn=maps[str(x[7])])
|
||||
else:
|
||||
stroke_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]))
|
||||
stroke_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6])
|
||||
elif str(x[1]) == 'history':
|
||||
if x[6]:
|
||||
history_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]), mapFn=maps[str(x[6])])
|
||||
if x[7]:
|
||||
history_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6], mapFn=maps[str(x[7])])
|
||||
else:
|
||||
history_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]))
|
||||
history_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6])
|
||||
elif str(x[1]) == 'gaugeoff':
|
||||
if x[6]:
|
||||
gaugeoff_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]), mapFn=maps[str(x[6])])
|
||||
if x[7]:
|
||||
gaugeoff_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6], mapFn=maps[str(x[7])])
|
||||
else:
|
||||
gaugeoff_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]))
|
||||
gaugeoff_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6])
|
||||
elif str(x[1]) == 'welltest':
|
||||
if x[6]:
|
||||
welltest_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]), mapFn=maps[str(x[6])])
|
||||
if x[7]:
|
||||
welltest_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6], mapFn=maps[str(x[7])])
|
||||
else:
|
||||
welltest_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), str(x[4]), str(x[5]))
|
||||
welltest_tags[x[0]] = Tag(str(x[0]), str(x[2]), str(x[3]), x[4], x[5], x[6])
|
||||
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
@@ -382,6 +385,7 @@ def evalTapers():
|
||||
|
||||
|
||||
def main():
|
||||
readConfig()
|
||||
read_tapers = False
|
||||
already_gauged_off = False
|
||||
already_entered_well_test = False
|
||||
|
||||
31
tagSetup.sql
31
tagSetup.sql
@@ -1,12 +1,3 @@
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (1, 'stroke', 'Stroke Information');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (2, 'history', 'Historical Data');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (3, 'gaugeoff', 'Gauge Off Data');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (4, 'welltest', 'Well Test Data');
|
||||
INSERT INTO tag_classes (id, tag_class, description) VALUES (5, 'custom', 'Custom tags');
|
||||
|
||||
INSERT INTO alarm_classes(id, alarm_class, description) VALUES (1, 'analog', 'Analog Alarms');
|
||||
INSERT INTO alarm_classes(id, alarm_class, description) VALUES (2, 'bit', 'Bit Statuses');
|
||||
|
||||
INSERT INTO tags (name, class, tag, data_type, change_threshold, guarantee_sec, map_function) VALUES ('card_type', 1, 'Card_Past[1].Card_Type', 'STRING', 0, 3600, 'card_type_map');
|
||||
INSERT INTO tags (name, class, tag, data_type, change_threshold, guarantee_sec) VALUES ('card_id', 1, 'Card_Past[1].ID', 'DINT', 25, 3600);
|
||||
|
||||
@@ -88,14 +79,14 @@ INSERT INTO alarms (name, class, tag) VALUES ('Speed', 1, 'Safety_Speed');
|
||||
INSERT INTO alarms (name, class, tag) VALUES ('Load LoLo', 1, 'Safety_Load_LoLo');
|
||||
INSERT INTO alarms (name, class, tag) VALUES ('Inclinometer', 1, 'Safety_Inclinometer');
|
||||
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Unit Jogged', 2, 'Pump.Jog', 'Unit Jog');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Restart (Auto Mode)', 2, 'Pump.Auto_Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Pump Off (POC Mode)', 2, 'Pump.POC_Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Restart (Timer Mode)', 2, 'Pump.Timed_Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Restart (POC Mode)', 2, 'Pump.POC_Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Pump Off (Auto Mode)', 2, 'Pump.Auto_Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Peak Energy Restart', 2, 'PeakEnergy.Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Peak Energy Stop', 2, 'PeakEnergy.Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('User Initiated Start', 2, 'Pump.Start', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('User Initiated Stop', 2, 'Pump.Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, cond) VALUES ('Pump Off (Timer Mode)', 2, 'Pump.Timed_Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Unit Jogged', 2, 'Pump.Jog', 'Unit Jog');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Restart (Auto Mode)', 2, 'Pump.Auto_Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Pump Off (POC Mode)', 2, 'Pump.POC_Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Restart (Timer Mode)', 2, 'Pump.Timed_Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Restart (POC Mode)', 2, 'Pump.POC_Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Pump Off (Auto Mode)', 2, 'Pump.Auto_Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Peak Energy Restart', 2, 'PeakEnergy.Restart', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Peak Energy Stop', 2, 'PeakEnergy.Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('User Initiated Start', 2, 'Pump.Start', 'Unit Start');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('User Initiated Stop', 2, 'Pump.Stop', 'Unit Stop');
|
||||
INSERT INTO alarms (name, class, tag, condition) VALUES ('Pump Off (Timer Mode)', 2, 'Pump.Timed_Stop', 'Unit Stop');
|
||||
|
||||
Reference in New Issue
Block a user