When I first started storing data for this website, the software I used was wview (http://wviewweather.com) a pretty good and flexible solution for collecting the data from my Davis Station Vantage Vue.
I've recently moved a lot of my monitoring software to a Mac Mini Server and although wview will work on Mac OSX, I came across Lightsoft Weather Center (LWC) which is a native Mac OSX product and works very well.
As I already had almost a year of data in wview, I needed to migrate this data to bring my LWC historical stats up to date.
This document was written for LWC V2.00, Build 2112 and wview 5.17.2 .
The LWC Data
The LWC Software has a data importer but it only imports from the Davis Station Weather Display software files - wview stores data in sqlite databases in it's own format.
The LWC Data files which are outlined in the LWC documentation have some nice, clean documentation at the top of each monthly generated file.
So each LWC Data File, one for each month, will look like the this one below (from the start of November). The files are named Month_LWC_Data.lw2 (eg 11_LWC_Data.lw2 - months lke Febuary will be 2_LWC_Data.lw2).
LWC data file ***If you modify this file, be sure to delete the relevent .hrs file***.
t and V are not optional, all other fields are.
t is the day, hour and minute (2 digits each), T is outside temperature, Ti is internal temperature, T1 to T8 is auxiliary temperatures, D is dew point, Pr is barometric pressure, W is wind speed,
Wd is wind direction, Wc is wind chill, Wg is wind gust, Ph is hourly precipitation, P is total precipitation,
H is outside humidity, Hi is internal humidity, H1 to H8 are auxiliary humidity sensors, S is solar,
Sm1 to Sm4 is soil moisture, Lw1 to Lw4 is leaf wetness, St1 to St4 is soil temperature,
Lt1 to Lt4 is leaf temperature, U is UV, C is current conditions (delimited by double quotes), V is validation.
2290 t:021410 T:20.00 Ti:24.33 D:10.12 Pr:1017.2333 W:6.44 Wd:274 Wc:20.00 Wg:9.66 Ph:0.00 P:0.00 H:53 Hi:58 S:0 U:0.0 Lw4:0.0 C:"Light Clouds" V:4
2 t:021412 T:19.89 Ti:24.33 D:10.02 Pr:1017.2333 W:6.44 Wd:272 Wc:19.89 Wg:14.48 Ph:0.00 P:0.00 H:53 Hi:58 S:0 U:0.0 Lw4:0.0 C:"Light Clouds" V:4
4 t:021414 T:19.83 Ti:24.39 D:10.25 Pr:1017.3010 W:6.44 Wd:270 Wc:19.83 Wg:14.48 Ph:0.00 P:0.00 H:54 Hi:58 S:0 U:0.0 Lw4:0.0 C:"Light Clouds" V:4
10 t:021420 T:19.78 Ti:24.44 D:10.20 Pr:1017.3010 W:4.83 Wd:272 Wc:19.78 Wg:14.48 Ph:0.00 P:0.00 H:54 Hi:58 S:0 U:0.0 Lw4:0.0 C:"Light Clouds" V:4
13 t:021423 T:19.89 Ti:24.44 D:10.30 Pr:1017.3010 W:4.83 Wd:249 Wc:19.89 Wg:14.48 Ph:0.00 P:0.00 H:54 Hi:58 S:0 U:0.0 Lw4:0.0 C:"Light Clouds" V:4
and so on .....
A couple of things of note:
- The comments at the top are not required if you are creating the files yourself (maybe a bit obvious)
- The number before each row is not required
- The VERS:3 is critical
- The P (Precipitation) is a daily cumulative value rather than the value for the time period being shown.
The wview data that is most useful for our requirements here is the 'archive' table stored in the file
wview-archive.sdb . In my Linux installation is was located with all of the other database files in
The structure of the archive table is as follows:
dateTime INTEGER NOT NULL UNIQUE PRIMARY KEY,
usUnits INTEGER NOT NULL,
interval INTEGER NOT NULL,
The main columns we need is the dateTime column (seconds since unixepoch - 01/01/1970) and the relevant sensor columns.
The data in the archive table are in US Imperial units so we also need to do some imperial to metric conversion.
So mapping between wview and LWC we need the following data:
Conversion from wview to LWC
||UnixEpoch (t is ddHH24mi)
||Outside Temp (F -> C)
||Inside Temp (F -> C)
||Dew Point (F -> C)
||Barometric Pressure (US inches - inHg -> Hpa)
||Pr=barometer x 33.8639
||Wind Speed (mph -> kmh)
||Wind Direction (degrees)
||Wd = windDir
||Wind Chill (F -> C)
||Wc = (windchill-32)/1.8
||Wind Gust (mph -> kmh)
||Rain per hour (in/h --> mm/h)
||total rain (in in period -> mm total for day)
||P=sum(rain for the day)*25.4
||Inside Humidity (Percentage)
So the challenge was to write some SQL code to extract the data, converting it to metric and calculate the cumulative rain total.
The Extraction Code
After a bit of trial and error and the belief I could do it all in SQL (SQLite is very much 'Oracle-like' in coding and some functionality) I came up with the following:
select 't:'||strftime('%d%H%M',datetime(aa.ddateTime,'unixepoch','localtime','-1 hour'))||
(select strftime('%Y%m%d',datetime(a.dateTime,'unixepoch','localtime','-1 hour')) dday,
round(barometer * 33.8639,4) barometer,
from archive a
where strftime('%Y%m',datetime(a.dateTime,'unixepoch','localtime','-1 hour')) = '201010'
(select strftime('%Y%m%d',datetime(b.dateTime,'unixepoch','localtime','-1 hour')) dday,
from archive b
where strftime('%Y%m',datetime(b.dateTime,'unixepoch','localtime','-1 hour')) = '201010'
where bb.dday = aa.dday
and strftime('%Y%m',datetime(aa.ddateTime,'unixepoch','localtime')) = '201010'
and bb.ddateTime <= aa.ddateTime
group by aa.ddateTime
Some little things about the query:
- It is for the month of October 2010 (hence the 201010 in the where clauses)
- This example caters for daylight savings time. To run it in non-DST see the full example below :- essentially remove the -3600 secs bit and the '-1 hour' in the date conversion.
- The second 'inline view' does the cumulative calculation for the rain and we join it back to the raw data query
- Although not strictly required in each inline view , the date where clauses does improve the performance.
So running this query generates the data for the month - it could take 5-10 minutes depending on your host machine.
All we have to do is now bring it all together, create the first line heading and generate our files.
- Create a file like this one ( LWC_Dump.sql - which is for March 2010.)
- Edit it for the month you require.
- Login to the wview archive database
- Run the script
- Do it again for each month you require
[root@redhead archive]# sqlite3 wview-archive.sdb
SQLite version 3.3.3
Enter ".help" for instructions
sqlite> .read lwc_dump.sql
Get the Data into LWC
There is lots of good information on how to do this in the LWC Manual as well as help available from the LWC forums. The LWC Data files are stored in 'your home folder' -> Library -> LWCData -> Location1 (probably) -> Year (eg 2010).
The steps you need to do are:
- Move the monthly generated files to your LWC machine (somewhere like your home or Downloads directory)
- Make sure LWC is not running
- Backup you data directory just in case everything goes wrong
- Delete the files like *.lw2.hrs if you are overwriting (or have edited) a specific month. These will be re-generated when LWC is restarted.
- Copy the Monthly Files generated from your wview database to the appropriate Year folder in the LWC data directory
- Startup LWC
If there is a problem with any file, LWC will let you know and give you the option to Quit or Re-initialise the file (Quit and clean it up would be a good option :-) ).
I had quite a few stumbling blocks on the way, so if you hit any yourself, let me know and I might be able to help out.