Collecting data example
Form and Database combination is used to store the data of measurements in a Database,
"collectingdata.db". We place the data in a database through the form, then read the data from the database and plot graphs of this data and sort them into groups. Time taken from the last sample is then transformed into a decimal number of hours and used as the x-axis values for the graphs.
set pos
c
l11 , 150 , 30d
l21:= label
c
w , "Unit"d
set posc
l21 , 150 , 80d
set size
c
li21 , 65 , 22d
set pos
c
li1 , 20 , 50d
// data type li2:= line text box
c
w , ""d
l1:= label
c
w , "Select Equipment"d
set size
c
li2 , 65 , 22d
set posc
l2 , 20 , 80d
w:= widget
c
0 , "Collecting data"d
set size
c
w , 290 , 340d
base:= "collectingbase.db"
// unit li21:= line text box
c
w , ""d
set pos
c
li21 , 150 , 100d
set pos
c
l1 , 20 , 30d
l2:= label
c
w , "Data Type"d
set pos
c
li2 , 20 , 100d
t:=
names "Group 1"
"Group 2"
"Group 3"
// equipment li1:= combo box
c
w , ttd
set pos
c
li11 , 150 , 50d
l11:= label
c
w , "Select Group"d
// group li11:= combo box
c
w , td
set size
c
li11 , 70 , 22d
tt:=
names "Equipment 1"
"Equipment 2"
"Equipment 3"
Creates Select Equipment label and appropriate combo box
Set positions for label and combo box
Creates Select Group label and appropriate combo box
Set positions and size for label and combo box
Data for Select equipment and group
combo boxes Creates widget and set
his size Name of database file
we are working with
Creates Data Type label and appropriate line text box Set positions and size for
label and line text box
Creates Unit label and appropriate line text box Set positions and size for
label and line text box
www.labdeck.com
set pos
c
b , 110 , 300d
set posc
l4 , 20 , 30d
set pos
c
l5 , 20 , 80d
set posc
g1 , 20 , 140d
set sizec
g1 , 250 , 150d
set pos
c
li5 , 20 , 100d
set sizec
li5 , 80 , 22d
b:= buttonc
w , "Submit"d
//data li5:= line text box
c
g1 , ""d
l4:= label
c
g1 , "Time from last sample (hh:mm)"d
set pos
c
li4 , 20 , 50d
set sizec
li4 , 80 , 22d
l5:= label
c
g1 , "Data"d
// time li4:= line text box
c
g1 , ""d
g1:= group box
c
w , "Data"d
Creates group, name it Data and set positions and size for
group
Creates label and appropriate line text box Set positions and size for
label and line text box
Creates label Data and appropriate line text box Set positions and size for
label and line text box
Creates Submit button and set his position
query1:= "CREATE TABLE 'data table1' (id integer primary key, equipment TEXT, dgroup TEXT, "
query1+= "data_type TEXT, unit TEXT, time TEXT, data TEXT)"
database query
c
base , query1d
on event
c
b , onSubmitc d d
Creates query string that will be executed in function database query
If table exist do nothing, if it does't create table
"data table1" with appropriate columns
Execute query that we have created above, first argument is database name, second is query
Define what to do on Submit button press, b - button variable created earlier, onSubmit() - custom function defined in
following canvas
onSubmit
c d
{
}
q1 := "INSERT INTO 'data table1' (equipment, dgroup, data_type, unit, time, data) VALUES ("
q1 += "'" + widget value
c
li1 + "'" + ", '" + widget valued c
li11 + "', '" + widget valued c
li2d
q1 += "', '" + widget value
c
li21 + "', '" + widget valued c
li4 + "', '" + widget valued c
li5 + "')"d
database query
c
base , q1d
set tooltip
c
li2 , widget valuec
li2d d
set tooltip
c
li4 , widget valuec
li4d d
set tooltip
c
li5 , widget valuec
li5d d
set tooltip
c
li21 , widget valuec
li21d d
set widget value
c
li2 , ""d
set widget value
c
li4 , ""d
set widget value
c
li5 , ""d
set widget value
c
li21 , ""d
1 2 3 4 5 6 7 8 9 10 11 12
Above is function that triggers at Submit button press
q1 - query string created to save form data into the "data table1" table of database set tooltip - creates tooltip with data from last submit for each text box
set widget - deletes line text boxes values and set them to blank ("")
After submitting of values, a tooltip is created for each text box containing last submitted value for that text box.
xdata1:= timeToDec
c
time1d
gdata1:= join mat cols
c
xdata1 , data1d
data2:= database query
c
base , "SELECT data FROM 'data table1' WHERE dgroup = 'Group 2'"d
time1:= database query
c
base , "SELECT time FROM 'data table1' WHERE dgroup = 'Group 1'"d
gdata3:= join mat cols
c
xdata3 , data3d
data1:= database query
c
base , "SELECT data FROM 'data table1' WHERE dgroup = 'Group 1'"d
time2:= database query
c
base , "SELECT time FROM 'data table1' WHERE dgroup = 'Group 2'"d
xdata2:= timeToDec
c
time2d
gdata2:= join mat cols
c
xdata2 , data2d
timeToDec
c
dataVecd
{
}
rez:= vector create
c
sizec
dataVecd
, false , 0d
for
c
i:= 1 , i< sizec
dataVecd
, i+= 1d
{
}
pom:= dataVec[ ] i
h:= to number
c
splitc
pom , ":"d
[ ] 0d
n:= to number
c
splitc
pom , ":"d
[ ] 1d
[ ]
rez i = rez[ i- 1 ] + ( h 60 + n) / 60 1
2 3 4
return
c
rezd
1
2
3
data3:= database query
c
base , "SELECT data FROM 'data table1' WHERE dgroup = 'Group 3'"d
time3:= database query
c
base , "SELECT time FROM 'data table1' WHERE dgroup = 'Group 3'"d
Read data for graphs y-axis from database and store them in variablesRead data for graphs x-axis from database and store them in variables
Function that transform 'Time from last sample' value,to decimal number of
hours format
xdata3:= timeToDec
c
time3d
Transform data that we have read from database using
timeToDec() function
Join x-axis and y-axis data for graphs into the matrices
We plotted graphs that represents dependence of measurement data and time of measurement. Every group of measurements have it's own graph.