GnuPlot - Multiple time series in data, plotting separate lines

1

I have a SQLite3 database which contains data similar to the following

time_index      Circuit         dateTimeRecorded                activepower
404503          GPOs            2018-05-30 00:03:50             224.57
404503          Grid            2018-05-30 00:03:50             4.34
404503          Shed            2018-05-30 00:03:50             24.86
404504          GPOs            2018-05-30 00:08:51             223.89
404504          Grid            2018-05-30 00:08:51             5.69
404504          Shed            2018-05-30 00:08:51             25.25
404505          GPOs            2018-05-30 00:13:52             247.23
404505          Grid            2018-05-30 00:13:52             3.81
404505          Shed            2018-05-30 00:13:52             24.43
404506          GPOs            2018-05-30 00:18:52             223.19
404506          Grid            2018-05-30 00:18:52             4.58
404506          Shed            2018-05-30 00:18:52             25.11
404507          GPOs            2018-05-30 00:23:52             222.57
404507          Grid            2018-05-30 00:23:52             4.01
404507          Shed            2018-05-30 00:23:52             24.86

I have managed to get a graph but all 3 circuits combine into one line. I figure I need to somehow filter and plot 3 times.

The problem is the data is vertical, not horizontal.

I considered parameterising a where clause in the SQL but could not figure out how to do that using sqlite3 command line.

I guess I could have 3 separate SQL files but I find that a bit ugly.

Progress so far is as follows...

set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
show xrange
set format x "%H:00"
#set datafile separator "   "
#set key autotitle columnhead
#
# Currently plotting all 3 sensors, working on how to plot for each sensor.
#
plot '< sqlite3 /tmp/usb_database.db ".read PlotElectricityUsage.sql"'  \
    using 3:5 \
    with lines \
    title "Electricity Usage"

pause -1 "Hit return to continue"

Where the SQL file is as follows

.header on
.separator "    "
SELECT "DATA"."time_index",
       Case   
          When EUI64 = '000D6F0005A5BE9D' then 'Grid'
          When EUI64 = '000D6F0005A5D77E' then 'GPOs'
          When EUI64 = '000D6F0005A5BCAE' then 'Shed'
          Else '????'
       End as "Circuit",
       datetime("DATA"."TimeStamp", 'unixepoch', 'localtime') as "dateTimeRecorded",
       "DATA"."activepower"
FROM "DATA" 
WHERE "DATA"."devicetype" = 15 
   AND "DATA"."voltage" > 0 
   AND "dateTimeRecorded" BETWEEN date('now', 'start of day') 
                                    AND date('now', 'start of day', '+1 day') 
   AND "dateTimeRecorded" > Datetime('2018-03-09 13:00:00')
 ORDER BY "Circuit",
      "DATA"."time_index" ASC
;

Any assistance would be greatly appreciated.

Lyall Pearce

Posted 2018-05-31T10:07:31.863

Reputation: 11

Answers

0

Use awk:

plot '< awk ''$2=="GPOs"'' /tmp/usb_database.db' u 1:5 w lp

Joce

Posted 2018-05-31T10:07:31.863

Reputation: 637