Add ETo AdjustmentMethod

This commit is contained in:
Matthew Oslan
2019-06-11 19:10:32 -04:00
parent 7e2d3458fd
commit 3e0141cdac
5 changed files with 334 additions and 8 deletions

View File

@@ -0,0 +1,43 @@
import * as moment from "moment";
import { expect } from "chai";
import { GeoCoordinates } from "../../types";
import { calculateETo, EToData } from "./EToAdjustmentMethod";
const testData: TestData[] = require( "../../test/etoTest.json" );
describe( "ETo AdjustmentMethod", () => {
describe( "Should correctly calculate ETo", async () => {
for ( const locationData of testData ) {
it( "Using data from " + locationData.description, async () => {
let date = moment.unix( locationData.startTimestamp );
for ( const entry of locationData.entries ) {
const etoData: EToData = {
...entry.data,
precip: 0,
timestamp: date.unix(),
weatherProvider: "mock"
};
const calculatedETo = calculateETo( etoData, locationData.elevation, locationData.coordinates );
// Allow a small margin of error for rounding, unit conversions, and approximations.
expect( calculatedETo ).approximately( entry.eto, 0.003 );
date = date.add( 1, "days" );
}
} );
}
} );
} );
interface TestData {
description: string;
source: string;
startTimestamp: number;
elevation: number;
coordinates: GeoCoordinates;
entries: {
eto: number,
/** This is not actually full EToData - it is missing `timestamp`, `weatherProvider`, and `precip`. */
data: EToData
}[];
}