-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherStation.sqlite.sql
67 lines (67 loc) · 2.05 KB
/
WeatherStation.sqlite.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS "Settings" (
"Setting" TEXT,
"Value" TEXT
);
CREATE TABLE IF NOT EXISTS "ReadingsLog" (
"DateUTC" TEXT,
"ReadingsCount" INTEGER,
"DateRetrieved" TEXT
);
CREATE TABLE IF NOT EXISTS "Readings" (
"dateutc" TEXT,
"winddir" REAL,
"windspeedmph" REAL,
"windgustmph" REAL,
"maxdailygust" REAL,
"tempf" REAL,
"hourlyrainin" REAL,
"eventrainin" REAL,
"dailyrainin" REAL,
"weeklyrainin" REAL,
"monthlyrainin" REAL,
"totalrainin" REAL,
"baromrelin" REAL,
"baromabsin" REAL,
"humidity" REAL,
"tempinf" REAL,
"humidityin" REAL,
"uv" REAL,
"solarradiation" REAL,
"feelsLike" REAL,
"dewPoint" TEXT,
"lastRain" TEXT,
"date" TEXT,
"datelocal" TEXT,
PRIMARY KEY("dateutc")
);
CREATE VIEW WeatherReport AS
select
strftime('%m/%d/%Y',datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours')) as Reading_Date,
CASE
WHEN CAST(strftime('%H', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours')) AS INTEGER) = 12
THEN strftime('%H:%M', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours')) || ' PM'
WHEN CAST(strftime('%H', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours')) AS INTEGER) > 12
THEN strftime('%H:%M', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours'), '-12 Hours') || ' PM'
WHEN CAST(strftime('%H', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours')) AS INTEGER) = 0
THEN strftime('12:%M AM', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours'))
ELSE strftime('%H:%M', datetime(ROUND(dateutc)/1000,'unixepoch','-4 Hours')) || ' AM'
END
AS Reading_Time,
CASE
WHEN tempf = 0.0
THEN '--'
ELSE
cast(round(((tempf-32)*5/9)) as int) || ' °C'
END
AS Temperature,
CASE
WHEN cast(humidity as int)=0 THEN '--'
ELSE cast(humidity as int) || ' %'
END
AS Humidity,
round((baromrelin/0.029529983071445),2) || ' hPa' as Pressure
FROM Readings ORDER BY Readings.dateutc DESC;
CREATE VIEW weatherhistory AS
select * from WeatherReport WHERE Temperature<>'--' OR humidity<>'--';
COMMIT;