/
copy_to_django.sql
39 lines (37 loc) · 1.23 KB
/
copy_to_django.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
-- Copy data from energyweb 0.3 to a Django-initialized database of
-- energyweb 0.4.
-- NOTE: This has not been tested with the latest version. Use with
-- care.
INSERT INTO graph_sensorgroup
(name, color)
SELECT name, color
FROM sensor_groups ORDER BY id ASC;
INSERT INTO graph_sensor
(name, ip, sensor_group_id, three_phase, factor, port)
SELECT name, ip, sensor_group_id, three_phase, factor, port
FROM sensors ORDER BY id ASC;
-- TODO:
-- Check that the script that generates power averages comes up with
-- the same answers as those in power_averages?
INSERT INTO graph_poweraverage
(first_reading_time, last_reading_time, trunc_reading_time, sensor_id,
num_points, watts, average_type)
SELECT rdngtime_first, rdngtime_last, rdngtime_trunc, sensor_id,
num_pts, watts, avg_type
FROM power_averages;
INSERT INTO graph_sensorreading
(sensor_id, reading_time, rindex,
awatthr, bwatthr, cwatthr,
avarhr, bvarhr, cvarhr,
avahr, bvahr, cvahr,
airms, birms, cirms,
avrms, bvrms, cvrms,
tempc, freq)
SELECT sensor_id, rdngtime, rindex,
awatthr, bwatthr, cwatthr,
avarhr, bvarhr, cvarhr,
avahr, bvahr, cvahr,
airms, birms, cirms,
avrms, bvrms, cvrms,
tempc, freq
FROM sensor_readings;