create irradiance composite graph

This commit is contained in:
Eric Hulburd
2016-03-11 17:38:03 -06:00
parent 2dd9389694
commit 782f5cbf91
32 changed files with 824 additions and 379 deletions

View File

@@ -1,85 +0,0 @@
"use strict";
import moment from 'moment-timezone';
import House from './../../../../client/models/house.js';
describe('house#setMonthState', ()=>{
var data_until = 1456589922, // Sat, 27 Feb 2016 16:18:42 +0000
house = new House({
id: 1,
name: 'Johnson',
data_from: data_until - 3600 * 24 * 365 * 3,
data_until: data_until,
timezone: 'America/New_York'
});
it('is updated properly on init', ()=>{
var current_month_moment = moment.tz({year: 2016, month: 1, day: 1}, 'America/New_York'),
energy_min = moment.tz({year: 2016, month: 0, day: 1}, 'America/New_York').unix(),
energy_max = data_until,
power_min = data_until - 3600 * 24 * 4,
power_max = data_until;
expect(house.state.month).toEqual('Feb');
expect(house.state.year).toEqual(2016);
expect(house.state.current_month_moment.unix()).toEqual(current_month_moment.unix());
expect(house.state.energy_range).toEqual([energy_min, energy_max]);
expect(house.state.power_range).toEqual([power_min, power_max]);
});
it('is not updated when passed no params', ()=>{
var current_month_moment = moment.tz({year: 2016, month: 1, day: 1}, 'America/New_York'),
energy_min = moment.tz({year: 2016, month: 0, day: 1}, 'America/New_York').unix(),
energy_max = data_until,
power_min = data_until - 3600 * 24 * 4,
power_max = data_until;
house.setMonthState({});
expect(house.state.month).toEqual('Feb');
expect(house.state.year).toEqual(2016);
expect(house.state.current_month_moment.unix()).toEqual(current_month_moment.unix());
expect(house.state.energy_range).toEqual([energy_min, energy_max]);
expect(house.state.power_range).toEqual([power_min, power_max]);
});
it('is updated properly when passed power params', ()=>{
var current_month_moment = moment.tz({year: 2015, month: 2, day: 1}, 'America/New_York'),
energy_min = moment.tz({year: 2015, month: 0, day: 1}, 'America/New_York').unix(),
energy_max = moment.tz({year: 2015, month: 0, day: 1}, 'America/New_York').endOf('year').unix(),
power_max = current_month_moment.clone().endOf('month').subtract(3, 'days').unix(),
power_min = current_month_moment.clone().endOf('month').subtract(6, 'days').unix()
house.setMonthState({
month: 'Mar',
year: 2015,
power_range: [ power_min, power_max ]
});
expect(house.state.month).toEqual('Mar');
expect(house.state.year).toEqual(2015);
expect(house.state.current_month_moment.unix()).toEqual(current_month_moment.unix());
expect(house.state.energy_range).toEqual([energy_min, energy_max]);
expect(house.state.power_range).toEqual([power_min, power_max]);
});
it('is updated properly when passed energy params', ()=>{
var current_month_moment = moment.tz({year: 2014, month: 9, day: 1}, 'America/New_York'),
energy_min = moment.tz({year: 2014, month: 0, day: 1}, 'America/New_York').unix(),
energy_max = moment.tz({year: 2014, month: 0, day: 1}, 'America/New_York').endOf('year').unix(),
power_max = moment.tz({year: 2014, month: 9, day: 1}, 'America/New_York').endOf('month').unix(),
power_min = power_max - 3600 * 24 * 4;
house.setMonthState({
month: 'Oct',
year: 2014
});
expect(house.state.month).toEqual('Oct');
expect(house.state.year).toEqual(2014);
expect(house.state.current_month_moment.unix()).toEqual(current_month_moment.unix());
expect(house.state.energy_range).toEqual([energy_min, energy_max]);
expect(house.state.power_range).toEqual([power_min, power_max]);
});
});

View File

@@ -0,0 +1,65 @@
import Loki from 'lokijs/src/lokijs';
import Databasable from './../../../client/lib/databasable';
class DbClass {
constructor(){
Object.assign(this, Databasable);
}
get lokijs_options(){
return {
adapter: null
};
}
doSomethingWithCollection(){
var db_class = this;
return db_class.collection('yadadb', 'yada_collection')
.then((collection)=>{
db_class.collection = collection;
})
.then(()=>{
db_class.worked = db_class.collection instanceof Loki.Collection;
});
}
}
var db_class;
describe('Databasable', ()=>{
beforeEach(()=>{
db_class = new DbClass();
});
describe('Databasable#accessDb', ()=>{
it('should initiate a new database', (done)=>{
db_class.accessDb('yadadb')
.then(()=>{
expect(db_class.db instanceof Loki).toEqual(true);
done();
});
});
});
describe('Databasable#collection', ()=>{
it('should initiate a new database & collection', (done)=>{
db_class.collection('yadadb', 'yada_collection')
.then((collection)=>{
expect(db_class.db instanceof Loki).toEqual(true);
expect(collection instanceof Loki.Collection).toEqual(true);
done();
});
});
it('works asynchronously', (done)=>{
db_class.doSomethingWithCollection()
.then(()=>{
expect(db_class.collection instanceof Loki.Collection).toEqual(true);
expect(db_class.worked).toEqual(true);
done();
})
});
});
});

View File

@@ -0,0 +1,76 @@
"use strict";
import moment from 'moment-timezone';
import House from './../../../client/models/house.js';
var data_until = 1456589922, // Sat, 27 Feb 2016 16:18:42 +0000
house = new House({
id: 1,
name: 'Johnson',
data_from: data_until - 3600 * 24 * 365 * 3, // 3 years before
data_until: data_until,
timezone: 'America/New_York'
});
describe('House#state', ()=>{
it('has no state after init', ()=>{
expect(house.state).toEqual({});
});
});
describe('house#verifyMonthState', ()=>{
it('verifies to data_until month and year by default', ()=>{
var params = {};
house.verifyMonthState(params);
expect(params.month).toEqual('Feb');
expect(params.year).toEqual(2016);
});
it('verifies properly when passed valid params', ()=>{
var params = {
month: 'Mar',
year: 2015
};
house.verifyMonthState(params);
expect(params.month).toEqual('Mar');
expect(params.year).toEqual(2015);
});
it('corrects for params outside of data range', ()=>{
var params = {
month: 'Mar',
year: 2006
};
house.verifyMonthState(params);
expect(params.month).toEqual('Mar');
expect(params.year).toEqual(2013);
});
});
describe('House#verifyPowerRange', ()=>{
it('defaults to last four days of data', ()=>{
var power_max = house.data.data_until,
power_min = power_max - House.MAX_POWER_RANGE,
power_range = house.verifyPowerRange([], {month: 'Feb', year: 2016});
expect(power_range).toEqual([power_min, power_max]);
});
it('otherwise verifies power range to max 4 day range', ()=>{
var power_max = moment.tz({year: 2014, month: 9, day: 1}, 'America/New_York').endOf('month').unix(),
invalid_power_min = power_max - House.MAX_POWER_RANGE - 10,
valid_power_min = power_max - House.MAX_POWER_RANGE,
power_range = house.verifyPowerRange([invalid_power_min, power_max], {
month: 'Oct',
year: 2014
});
expect(power_range).toEqual([valid_power_min, power_max]);
});
});