Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for Database changes #632

Merged
merged 33 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
34cf793
Merge pull request #1 from OpenEnergyDashboard/development
wadoodalam Feb 23, 2021
8f25d58
Merge pull request #2 from OpenEnergyDashboard/development
wadoodalam Feb 26, 2021
093c68c
Changes to DB regarding meters and maps
wadoodalam Mar 5, 2021
ee83764
moved to 0.6-0.7
wadoodalam Mar 5, 2021
4e1f06b
Merge branch 'development' of https://github.com/OpenEnergyDashboard/…
wadoodalam Mar 5, 2021
9a7ee05
lints check and test check error removed
wadoodalam Mar 18, 2021
bdb7e8b
Changes to meters, groups and maps.
wadoodalam Mar 19, 2021
ef39768
Maps and Meters test
wadoodalam Mar 26, 2021
406f799
meter tests
wadoodalam Mar 26, 2021
3dd2a64
Modified further tests. Chnaged the default values for maps
wadoodalam Apr 2, 2021
d1a42f2
Tests for web edited
wadoodalam Apr 15, 2021
7d7d436
Merge branch 'development' of https://github.com/OpenEnergyDashboard/…
wadoodalam Apr 23, 2021
806de16
updated
wadoodalam Apr 23, 2021
6e493e9
commented code for raw readings
wadoodalam Apr 23, 2021
27e8216
Merge pull request #6 from OpenEnergyDashboard/development
wadoodalam Apr 29, 2021
4dad94c
script fix for test data
wadoodalam Apr 29, 2021
becfc8f
Errors and issued addressed for PR
wadoodalam May 3, 2021
f66667d
fix up start/end time
huss May 4, 2021
7569515
remove previousDay/previous_day
huss May 4, 2021
dc04a7b
fix comments
huss May 4, 2021
3bc2b04
fix comments, date format, spacing
huss May 4, 2021
743097e
fix fomatting
huss May 4, 2021
afab1bf
file missed in staging
huss May 4, 2021
1e1b8a8
uniqueness of meters/groups
huss May 4, 2021
6fd30f2
put back year format
huss May 4, 2021
7991e7b
fix for no previous day
huss May 4, 2021
ac979c7
fix up for removing previous day
huss May 4, 2021
f0d5905
fix map tests
huss May 4, 2021
427ae88
fix up for previousDay removal
huss May 4, 2021
f2ac164
upgrade meter testing & route new items
huss May 4, 2021
394d590
Fix failing group test
huss May 4, 2021
cdffce7
fix group tests
huss May 5, 2021
e499dc4
remove Mac file added in PR
huss May 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/scripts/testData.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ sed -i "" -e "s/^[0-9]/313,&/" src/server/test/db/data/automatedTests/15Freq7Amp
# This will probably not be necesary once can use curl to get the files in
# CSV with meter info
cat > $postgresdir/testMeters.csv << EOF
id,name,ipaddress,enabled,displayable,meter_type,default_timezone_meter,gps,identifier
300,test4DaySin,123.45.6.0,FALSE,TRUE,mamac,,,test4DaySin
301,test4HourSin,123.45.6.0,FALSE,TRUE,mamac,,,test4HourSin
302,test23MinSin,123.45.6.0,FALSE,TRUE,mamac,,,test23MinSin
303,test15MinSin,123.45.6.0,FALSE,TRUE,mamac,,,test15MinSin
304,test23MinCos,123.45.6.0,FALSE,TRUE,mamac,,,test23MinCos
305,testSqSin,123.45.6.0,FALSE,TRUE,mamac,,,testSqSin
306,testSqCos,123.45.6.0,FALSE,TRUE,mamac,,,testSqCos
307,testAmp1Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp1Sin
308,testAmp2Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp2Sin
309,testAmp3Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp3Sin
310,testAmp4Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp4Sin
311,testAmp5Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp5Sin
312,testAmp6Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp6Sin
313,testAmp7Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp7Sin
id,name,ipaddress,enabled,displayable,meter_type,default_timezone_meter,gps,identifier,note,area,cumulative,cumulative_reset,cumulative_reset_start,cumulative_reset_end,reading_length,reading_variation,reading,start_timestamp,end_timestamp
300,test4DaySin,123.45.6.0,FALSE,TRUE,mamac,,,test4DaySin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
301,test4HourSin,123.45.6.0,FALSE,TRUE,mamac,,,test4HourSin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
302,test23MinSin,123.45.6.0,FALSE,TRUE,mamac,,,test23MinSin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
303,test15MinSin,123.45.6.0,FALSE,TRUE,mamac,,,test15MinSin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
304,test23MinCos,123.45.6.0,FALSE,TRUE,mamac,,,test23MinCos,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
305,testSqSin,123.45.6.0,FALSE,TRUE,mamac,,,testSqSin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
306,testSqCos,123.45.6.0,FALSE,TRUE,mamac,,,testSqCos,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
307,testAmp1Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp1Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
308,testAmp2Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp2Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
309,testAmp3Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp3Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
310,testAmp4Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp4Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
311,testAmp5Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp5Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
312,testAmp6Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp6Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
313,testAmp7Sin,123.45.6.0,FALSE,TRUE,mamac,,,testAmp7Sin,notesTest,25.0,FALSE,TRUE,00:00:00,00:00:00,,,20.0,,0001-01-01 : 00:00:00
EOF
# Put meters into OED
docker-compose exec database psql -U oed -c "copy meters from 'testMeters.csv' CSV HEADER"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

ALTER TABLE groups
ADD COLUMN IF NOT EXISTS displayable BOOLEAN,
ADD COLUMN IF NOT EXISTS gps POINT DEFAULT NULL,
ADD COLUMN IF NOT EXISTS note TEXT,
ADD COLUMN IF NOT EXISTS area REAL DEFAULT NULL;

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

ALTER TABLE maps
ADD COLUMN IF NOT EXISTS north_angle REAL DEFAULT 0.0,
ADD COLUMN IF NOT EXISTS max_circle_size_fraction REAL DEFAULT 0.15;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

ALTER TABLE meters
ADD COLUMN IF NOT EXISTS note TEXT,
ADD COLUMN IF NOT EXISTS area REAL DEFAULT NULL,
ADD COLUMN IF NOT EXISTS cumulative BOOLEAN DEFAULT false,
ADD COLUMN IF NOT EXISTS cumulative_reset BOOLEAN DEFAULT false,
ADD COLUMN IF NOT EXISTS cumulative_reset_start TIME DEFAULT '00:00:00',
ADD COLUMN IF NOT EXISTS cumulative_reset_end TIME DEFAULT '23:59:59.999999',
ADD COLUMN IF NOT EXISTS reading_length TIME DEFAULT '00:00:00',
ADD COLUMN IF NOT EXISTS reading_variation TIME DEFAULT '23:59:59.999999',
ADD COLUMN IF NOT EXISTS reading REAL DEFAULT 0.0,
ADD COLUMN IF NOT EXISTS start_timestamp TIMESTAMP DEFAULT '0001-01-01 00:00:00',
ADD COLUMN IF NOT EXISTS end_timestamp TIMESTAMP DEFAULT '0001-01-01 00:00:00'
;

12 changes: 10 additions & 2 deletions src/server/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ class Group {
/**
* @param id should be undefined when creating a new group
* @param name group's name
* @param displayable The group is available for display
* @param gps Location in format of GIS coordinates, default null
* @param note Note about the group
* @param area Area of the group, default null
*/
constructor(id, name) {
constructor(id, name, displayable, gps, note, area) {
this.id = id;
this.name = name;
this.displayable = displayable;
this.gps = gps;
this.note = note;
this.area = area;
}

/**
Expand Down Expand Up @@ -48,7 +56,7 @@ class Group {
* @returns {Group}
*/
static mapRow(row) {
return new Group(row.id, row.name);
return new Group(row.id, row.name, row.displayable, row.gps, row.note, row.area);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/server/models/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class Map {
* @param origin {Point} coordinates of (0,0) on map
* @param opposite {Point} coordinates of opposite corner from origin
* @param mapSource data URL of image of the map
* @param northAngle stores angle between map orientation and true north, default 0.0
* @param maxCircleSizeFraction Stores the fraction of horizontal map, default 0.15
*/
constructor(id, name, displayable, note, filename, modifiedDate, origin, opposite, mapSource) {
constructor(id, name, displayable, note, filename, modifiedDate, origin, opposite, mapSource, northAngle, maxCircleSizeFraction) {
this.id = id;
this.name = name;
this.displayable = displayable;
Expand All @@ -28,6 +30,8 @@ class Map {
this.origin = origin;
this.opposite = opposite;
this.mapSource = mapSource;
this.northAngle = northAngle;
this.maxCircleSizeFraction = maxCircleSizeFraction;
}

/**
Expand Down Expand Up @@ -73,7 +77,8 @@ class Map {
* @returns {Map}
*/
static mapRow(row) {
return new Map(row.id, row.name, row.displayable, row.note, row.filename, row.modified_date, row.origin, row.opposite, row.map_source);
return new Map(row.id, row.name, row.displayable, row.note, row.filename,
row.modified_date, row.origin, row.opposite, row.map_source, row.north_angle, row.max_circle_size_fraction);
}

/**
Expand Down
30 changes: 28 additions & 2 deletions src/server/models/Meter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@ class Meter {
* @param gps location in format of GIS coordinates
* @param meterTimezone Default timezone for meter
* @param identifier Another way to identify a meter
* @param note Note about the meter
* @param area Area of the meter default null
* @param cumulative Identifies if meter readings that are stored are the sum of usage or the particular reading, default false
* @param cumulativeReset True if cumulative values can reset back to zero., default false
* @param cumulativeResetStart The earliest time of day that a reset can occur, default '00:00:00'
* @param cumulativeResetEnd The latest time of day that a reset can occur, default '23:59:59.999999'
* @param readingLength Specifies the time range on every reading in the CSV file, default '00:00:00'
* @param readingVariation +/- time allowed on length to consider within allowed length, default '23:59:59.999999'
* @param reading The value of reading, default 0.0
* @param startTimestamp Start timestamp of last reading input for this meter, default '01-01-01 00:00:00'
* @param endTimestamp End timestamp of last reading input for this meter, '01-01-01 00:00:00'
*/
constructor(id, name, ipAddress, enabled, displayable, type, meterTimezone, gps = undefined, identifier = name) {
constructor(id, name, ipAddress, enabled, displayable, type, meterTimezone, gps = undefined, identifier = name, note, area,
cumulative, cumulativeReset, cumulativeResetStart, cumulativeResetEnd, readingLength, readingVariation, reading,
startTimestamp, endTimestamp) {
this.id = id;
this.name = name;
this.ipAddress = ipAddress;
Expand All @@ -29,6 +42,17 @@ class Meter {
this.gps = gps;
this.meterTimezone = meterTimezone;
this.identifier = identifier;
this.note = note;
this.area = area;
this.cumulative = cumulative;
this.cumulativeReset = cumulativeReset;
this.cumulativeResetStart = cumulativeResetStart;
this.cumulativeResetEnd = cumulativeResetEnd;
this.readingLength = readingLength;
this.readingVariation = readingVariation;
this.reading = reading;
this.startTimestamp = startTimestamp;
this.endTimestamp = endTimestamp;
}

/**
Expand Down Expand Up @@ -78,7 +102,9 @@ class Meter {
*/
static mapRow(row) {
return new Meter(row.id, row.name, row.ipaddress, row.enabled, row.displayable, row.meter_type,
row.default_timezone_meter, row.gps, row.identifier);
row.default_timezone_meter, row.gps, row.identifier, row.note, row.area, row.cumulative, row.cumulative_reset,
row.cumulative_reset_start, row.cumulative_reset_end, row.reading_length, row.reading_variation,
row.reading, row.start_timestamp, row.end_timestamp);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/server/routes/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function formatMapForResponse(map) {
modifiedDate: map.modifiedDate,
origin: map.origin,
opposite: map.opposite,
mapSource: map.mapSource
mapSource: map.mapSource,
northAngle: map.northAngle,
maxCircleSizeFraction: map.maxCircleSizeFraction
};
return formattedMap;
}
Expand Down
24 changes: 23 additions & 1 deletion src/server/routes/meters.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,37 @@ function formatMeterForResponse(meter, loggedInAsAdmin) {
meterType: null,
timeZone: null,
gps: meter.gps,
identifier: meter.identifier
identifier: meter.identifier,
area: meter.area,
note: null,
cumulative: null,
cumulativeReset : null,
cumulativeResetStart : null,
cumulativeResetEnd : null,
readingLength : null,
readingVariation : null,
reading : null,
startTimestamp : null,
endTimestamp : null
};

// Only logged in Admins can see IP addresses, types, timezones, and internal names
// and lots of other items now.
if (loggedInAsAdmin) {
formattedMeter.ipAddress = meter.ipAddress;
formattedMeter.meterType = meter.type;
formattedMeter.timeZone = meter.meterTimezone;
formattedMeter.name = meter.name;
formattedMeter.note = meter.note;
formattedMeter.cumulative = meter.cumulative;
formattedMeter.cumulativeReset = meter.cumulativeReset;
formattedMeter.cumulativeResetStart = meter.cumulativeResetStart;
formattedMeter.cumulativeResetEnd = meter.cumulativeResetEnd;
formattedMeter.readingLength = meter.readingLength;
formattedMeter.readingVariation = meter.readingVariation;
formattedMeter.reading = meter.reading;
formattedMeter.startTimestamp = meter.startTimestamp;
formattedMeter.endTimestamp = meter.endTimestamp;
}

// TODO: remove this line when usages of meter.name are replaced with meter.identifer
Expand Down
6 changes: 5 additions & 1 deletion src/server/sql/group/create_groups_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

CREATE TABLE IF NOT EXISTS groups (
id SERIAL PRIMARY KEY NOT NULL,
name VARCHAR(50) UNIQUE NOT NULL CHECK (char_length(name) >= 1)
name VARCHAR(50) UNIQUE NOT NULL CHECK (char_length(name) >= 1),
displayable BOOLEAN,
gps POINT DEFAULT NULL,
note TEXT,
area REAL DEFAULT NULL
);

/*
Expand Down
2 changes: 1 addition & 1 deletion src/server/sql/group/get_all_groups.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
SELECT id, name FROM groups;
SELECT id, name, displayable, gps, note, area FROM groups;
2 changes: 1 addition & 1 deletion src/server/sql/group/get_group_by_id.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
SELECT id, name FROM groups WHERE id=${id};
SELECT id, name, displayable, gps, note, area FROM groups WHERE id=${id};
2 changes: 1 addition & 1 deletion src/server/sql/group/get_group_by_name.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
SELECT id, name FROM groups WHERE name=${name};
SELECT id, name, displayable, gps, note, area FROM groups WHERE name=${name};
4 changes: 3 additions & 1 deletion src/server/sql/group/insert_new_group.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
INSERT INTO groups (name) VALUES (${name}) RETURNING id;
INSERT INTO groups (name, displayable, gps, note, area)
VALUES (${name}, ${displayable}, ${gps}, ${note}, ${area})
RETURNING id;
6 changes: 4 additions & 2 deletions src/server/sql/map/create_maps_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ CREATE TABLE IF NOT EXISTS maps (
id SERIAL PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
displayable boolean NOT NULL,
note VARCHAR(500),
note TEXT,
filename VARCHAR(200) NOT NULL,
modified_date TIMESTAMP NOT NULL,
origin POINT DEFAULT NULL,
opposite POINT DEFAULT NULL,
map_source TEXT NOT NULL
map_source TEXT NOT NULL,
north_angle REAL DEFAULT 0.0,
max_circle_size_fraction REAL DEFAULT 0.15
);
2 changes: 1 addition & 1 deletion src/server/sql/map/get_map_by_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

SELECT id, name, displayable, note, filename, modified_date, origin, opposite, map_source FROM maps
SELECT id, name, displayable, note, filename, modified_date, origin, opposite, map_source, north_angle, max_circle_size_fraction FROM maps
WHERE id=${id};
2 changes: 1 addition & 1 deletion src/server/sql/map/get_map_by_name.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

SELECT id, name, displayable, note, filename, modified_date, origin, opposite, map_source FROM maps
SELECT id, name, displayable, note, filename, modified_date, origin, opposite, map_source, north_angle, max_circle_size_fraction FROM maps
WHERE name=${name};
4 changes: 2 additions & 2 deletions src/server/sql/map/insert_new_map.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

INSERT INTO maps(name, displayable, note, filename, modified_date, origin, opposite, map_source)
VALUES (${name}, ${displayable}, ${note}, ${filename}, ${modifiedDate}, ${origin}, ${opposite}, ${mapSource})
INSERT INTO maps(name, displayable, note, filename, modified_date, origin, opposite, map_source, north_angle, max_circle_size_fraction)
VALUES (${name}, ${displayable}, ${note}, ${filename}, ${modifiedDate}, ${origin}, ${opposite}, ${mapSource}, ${northAngle}, ${maxCircleSizeFraction})
RETURNING id;
4 changes: 3 additions & 1 deletion src/server/sql/map/update_map.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ UPDATE maps
modified_date = ${modifiedDate},
origin = ${origin},
opposite = ${opposite},
map_source = ${mapSource}
map_source = ${mapSource},
north_angle = ${northAngle},
max_circle_size_fraction = ${maxCircleSizeFraction}
WHERE id = ${id};
56 changes: 39 additions & 17 deletions src/server/sql/meter/create_meters_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,45 @@
/*
Creates a table of meters containing
primary key (generally set by DB,
the name of a meter used for getting data and currently shown to user,
IP address for meter data,
enabled true if the meter should get data,
displayable true if meter visible to non-admin users,
the meter type,
the time zone for this meter (if null then use site value),
gps location of this meter,
identifier is name that will be shown to user in future
name: The name of a meter used for getting data and currently shown to user,
IP addresF: for meter data,
enabled: True if the meter should get data,
displayable: True if meter visible to non-admin users,
meter_type: The meter type,
timezone: The time zone for this meter (if null then use site value),
gps: Location of this meter,
identifier: Is name that will be shown to user in future
note: Notes about the meter
area: Area covered by the meter
cumulative: True if cumulative values can reset back to zero
cumulative_reset: True if pipline is to be reset
cumulative_reset_start: The earliest time of day that a reset can occur
cumulative_reset_end: The latest time of day that a reset can occur
reading_length: Specify the time range on every reading
reading_variation: +/- time allowed on length to consider within allowed length
reading: The last reading input for the meter
start_timestamp: Start timestamp of last reading input for this meter
end_timestamp: End timestamp of last reading for this meter
*/
CREATE TABLE IF NOT EXISTS meters (
wadoodalam marked this conversation as resolved.
Show resolved Hide resolved
id SERIAL PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
ipAddress VARCHAR(20),
enabled BOOLEAN NOT NULL,
displayable BOOLEAN NOT NULL,
meter_type meter_type NOT NULL,
default_timezone_meter TEXT DEFAULT NULL,
gps POINT DEFAULT NULL,
identifier TEXT
id SERIAL PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
ipAddress VARCHAR(20),
enabled BOOLEAN NOT NULL,
displayable BOOLEAN NOT NULL,
meter_type meter_type NOT NULL,
default_timezone_meter TEXT DEFAULT NULL,
gps POINT DEFAULT NULL,
identifier TEXT UNIQUE NOT NULL,
note TEXT,
area REAL DEFAULT NULL,
cumulative BOOLEAN DEFAULT false,
cumulative_reset BOOLEAN DEFAULT false,
cumulative_reset_start TIME DEFAULT '00:00:00',
cumulative_reset_end TIME DEFAULT '23:59:59.999999',
reading_length TIME DEFAULT '00:00:00',
reading_variation TIME DEFAULT '23:59:59.999999',
reading REAL DEFAULT 0.0,
start_timestamp TIMESTAMP DEFAULT '0001-01-01 00:00:00',
end_timestamp TIMESTAMP DEFAULT '0001-01-01 00:00:00'
);
7 changes: 5 additions & 2 deletions src/server/sql/meter/get_meter_by_id.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

SELECT id, name, ipaddress, enabled, displayable, meter_type, default_timezone_meter, gps, identifier FROM meters
WHERE id=${id};
SELECT id, name, ipaddress, enabled, displayable, meter_type, default_timezone_meter, gps, identifier,
note, area, cumulative, cumulative_reset, cumulative_reset_start, cumulative_reset_end,
reading_length, reading_variation, reading, start_timestamp, end_timestamp
FROM meters
WHERE id=${id};
Loading