@neaps/tide-predictor 0.0.3 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.eslintrc.cjs +18 -0
  2. package/.github/workflows/test.yml +21 -0
  3. package/.prettierrc +2 -1
  4. package/README.md +21 -5
  5. package/{lib/index.es6.js → dist/commonjs/index.js} +59 -59
  6. package/dist/commonjs/package.json +1 -0
  7. package/dist/{tide-predictor.js → web/tide-predictor.js} +58 -60
  8. package/dist/web/tide-predictor.min.js +1 -0
  9. package/package.json +24 -33
  10. package/rollup.config.js +2 -2
  11. package/src/astronomy/coefficients.js +6 -6
  12. package/src/astronomy/index.js +7 -7
  13. package/src/constituents/compound-constituent.js +6 -7
  14. package/src/constituents/constituent.js +9 -10
  15. package/src/constituents/index.js +5 -5
  16. package/src/harmonics/index.js +12 -12
  17. package/src/harmonics/prediction.js +14 -14
  18. package/src/index.js +3 -3
  19. package/src/node-corrections/index.js +2 -2
  20. package/{src/__mocks__ → test/_mocks}/constituents.js +0 -0
  21. package/{src/__mocks__ → test/_mocks}/secondary-station.js +0 -0
  22. package/{src/harmonics/__mocks__ → test/_mocks}/water-levels.js +0 -0
  23. package/test/astronomy/coefficients.js +15 -0
  24. package/test/astronomy/index.js +98 -0
  25. package/test/constituents/compound-constituent.js +46 -0
  26. package/test/constituents/constituent.js +67 -0
  27. package/test/constituents/index.js +35 -0
  28. package/{src/harmonics/__tests__ → test/harmonics}/index.js +24 -22
  29. package/{src/harmonics/__tests__ → test/harmonics}/prediction.js +29 -23
  30. package/{src/__tests__ → test}/index.js +21 -20
  31. package/test/lib/close-to.js +7 -0
  32. package/test/noaa.js +110 -0
  33. package/test/node-corrections/index.js +116 -0
  34. package/.circleci/config.yml +0 -26
  35. package/.eslintrc.js +0 -21
  36. package/Gruntfile.js +0 -87
  37. package/babel.config.js +0 -9
  38. package/lib/astronomy/coefficients.js +0 -31
  39. package/lib/astronomy/constants.js +0 -10
  40. package/lib/astronomy/index.js +0 -199
  41. package/lib/constituents/compound-constituent.js +0 -67
  42. package/lib/constituents/constituent.js +0 -74
  43. package/lib/constituents/index.js +0 -140
  44. package/lib/harmonics/index.js +0 -113
  45. package/lib/harmonics/prediction.js +0 -195
  46. package/lib/index.js +0 -53
  47. package/lib/node-corrections/index.js +0 -147
  48. package/src/__tests__/noaa.js +0 -92
  49. package/src/astronomy/__tests__/coefficients.js +0 -12
  50. package/src/astronomy/__tests__/index.js +0 -96
  51. package/src/constituents/__tests__/compound-constituent.js +0 -44
  52. package/src/constituents/__tests__/constituent.js +0 -65
  53. package/src/constituents/__tests__/index.js +0 -34
  54. package/src/node-corrections/__tests__/index.js +0 -114
@@ -1,199 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports._nupp = exports._nup = exports._nu = exports._xi = exports._I = exports.JD = exports.T = exports.derivativePolynomial = exports.polynomial = exports["default"] = void 0;
7
-
8
- var _constants = require("./constants");
9
-
10
- var _coefficients = _interopRequireDefault(require("./coefficients"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- // Evaluates a polynomial at argument
15
- var polynomial = function polynomial(coefficients, argument) {
16
- var result = [];
17
- coefficients.forEach(function (coefficient, index) {
18
- result.push(coefficient * Math.pow(argument, index));
19
- });
20
- return result.reduce(function (a, b) {
21
- return a + b;
22
- });
23
- }; // Evaluates a derivative polynomial at argument
24
-
25
-
26
- exports.polynomial = polynomial;
27
-
28
- var derivativePolynomial = function derivativePolynomial(coefficients, argument) {
29
- var result = [];
30
- coefficients.forEach(function (coefficient, index) {
31
- result.push(coefficient * index * Math.pow(argument, index - 1));
32
- });
33
- return result.reduce(function (a, b) {
34
- return a + b;
35
- });
36
- }; // Meeus formula 11.1
37
-
38
-
39
- exports.derivativePolynomial = derivativePolynomial;
40
-
41
- var T = function T(t) {
42
- return (JD(t) - 2451545.0) / 36525;
43
- }; // Meeus formula 7.1
44
-
45
-
46
- exports.T = T;
47
-
48
- var JD = function JD(t) {
49
- var Y = t.getFullYear();
50
- var M = t.getMonth() + 1;
51
- var D = t.getDate() + t.getHours() / 24.0 + t.getMinutes() / (24.0 * 60.0) + t.getSeconds() / (24.0 * 60.0 * 60.0) + t.getMilliseconds() / (24.0 * 60.0 * 60.0 * 1e6);
52
-
53
- if (M <= 2) {
54
- Y = Y - 1;
55
- M = M + 12;
56
- }
57
-
58
- var A = Math.floor(Y / 100.0);
59
- var B = 2 - A + Math.floor(A / 4.0);
60
- return Math.floor(365.25 * (Y + 4716)) + Math.floor(30.6001 * (M + 1)) + D + B - 1524.5;
61
- };
62
- /**
63
- * @todo - What's with the array returned from the arccos?
64
- * @param {*} N
65
- * @param {*} i
66
- * @param {*} omega
67
- */
68
-
69
-
70
- exports.JD = JD;
71
-
72
- var _I = function _I(N, i, omega) {
73
- N = _constants.d2r * N;
74
- i = _constants.d2r * i;
75
- omega = _constants.d2r * omega;
76
- var cosI = Math.cos(i) * Math.cos(omega) - Math.sin(i) * Math.sin(omega) * Math.cos(N);
77
- return _constants.r2d * Math.acos(cosI);
78
- };
79
-
80
- exports._I = _I;
81
-
82
- var _xi = function _xi(N, i, omega) {
83
- N = _constants.d2r * N;
84
- i = _constants.d2r * i;
85
- omega = _constants.d2r * omega;
86
- var e1 = Math.cos(0.5 * (omega - i)) / Math.cos(0.5 * (omega + i)) * Math.tan(0.5 * N);
87
- var e2 = Math.sin(0.5 * (omega - i)) / Math.sin(0.5 * (omega + i)) * Math.tan(0.5 * N);
88
- e1 = Math.atan(e1);
89
- e2 = Math.atan(e2);
90
- e1 = e1 - 0.5 * N;
91
- e2 = e2 - 0.5 * N;
92
- return -(e1 + e2) * _constants.r2d;
93
- };
94
-
95
- exports._xi = _xi;
96
-
97
- var _nu = function _nu(N, i, omega) {
98
- N = _constants.d2r * N;
99
- i = _constants.d2r * i;
100
- omega = _constants.d2r * omega;
101
- var e1 = Math.cos(0.5 * (omega - i)) / Math.cos(0.5 * (omega + i)) * Math.tan(0.5 * N);
102
- var e2 = Math.sin(0.5 * (omega - i)) / Math.sin(0.5 * (omega + i)) * Math.tan(0.5 * N);
103
- e1 = Math.atan(e1);
104
- e2 = Math.atan(e2);
105
- e1 = e1 - 0.5 * N;
106
- e2 = e2 - 0.5 * N;
107
- return (e1 - e2) * _constants.r2d;
108
- }; // Schureman equation 224
109
-
110
-
111
- exports._nu = _nu;
112
-
113
- var _nup = function _nup(N, i, omega) {
114
- var I = _constants.d2r * _I(N, i, omega);
115
-
116
- var nu = _constants.d2r * _nu(N, i, omega);
117
-
118
- return _constants.r2d * Math.atan(Math.sin(2 * I) * Math.sin(nu) / (Math.sin(2 * I) * Math.cos(nu) + 0.3347));
119
- }; // Schureman equation 232
120
-
121
-
122
- exports._nup = _nup;
123
-
124
- var _nupp = function _nupp(N, i, omega) {
125
- var I = _constants.d2r * _I(N, i, omega);
126
-
127
- var nu = _constants.d2r * _nu(N, i, omega);
128
-
129
- var tan2nupp = Math.pow(Math.sin(I), 2) * Math.sin(2 * nu) / (Math.pow(Math.sin(I), 2) * Math.cos(2 * nu) + 0.0727);
130
- return _constants.r2d * 0.5 * Math.atan(tan2nupp);
131
- };
132
-
133
- exports._nupp = _nupp;
134
-
135
- var modulus = function modulus(a, b) {
136
- return (a % b + b) % b;
137
- };
138
-
139
- var astro = function astro(time) {
140
- var result = {};
141
- var polynomials = {
142
- s: _coefficients["default"].lunarLongitude,
143
- h: _coefficients["default"].solarLongitude,
144
- p: _coefficients["default"].lunarPerigee,
145
- N: _coefficients["default"].lunarNode,
146
- pp: _coefficients["default"].solarPerigee,
147
- 90: [90.0],
148
- omega: _coefficients["default"].terrestrialObliquity,
149
- i: _coefficients["default"].lunarInclination
150
- }; // Polynomials are in T, that is Julian Centuries; we want our speeds to be
151
- // in the more convenient unit of degrees per hour.
152
-
153
- var dTdHour = 1 / (24 * 365.25 * 100);
154
- Object.keys(polynomials).forEach(function (name) {
155
- result[name] = {
156
- value: modulus(polynomial(polynomials[name], T(time)), 360.0),
157
- speed: derivativePolynomial(polynomials[name], T(time)) * dTdHour
158
- };
159
- }); // Some other parameters defined by Schureman which are dependent on the
160
- // parameters N, i, omega for use in node factor calculations. We don't need
161
- // their speeds.
162
-
163
- var functions = {
164
- I: _I,
165
- xi: _xi,
166
- nu: _nu,
167
- nup: _nup,
168
- nupp: _nupp
169
- };
170
- Object.keys(functions).forEach(function (name) {
171
- var functionCall = functions[name];
172
- result[name] = {
173
- value: modulus(functionCall(result.N.value, result.i.value, result.omega.value), 360.0),
174
- speed: null
175
- };
176
- }); // We don't work directly with the T (hours) parameter, instead our spanning
177
- // set for equilibrium arguments #is given by T+h-s, s, h, p, N, pp, 90.
178
- // This is in line with convention.
179
-
180
- var hour = {
181
- value: (JD(time) - Math.floor(JD(time))) * 360.0,
182
- speed: 15.0
183
- };
184
- result['T+h-s'] = {
185
- value: hour.value + result.h.value - result.s.value,
186
- speed: hour.speed + result.h.speed - result.s.speed
187
- }; // It is convenient to calculate Schureman's P here since several node
188
- // factors need it, although it could be argued that these
189
- // (along with I, xi, nu etc) belong somewhere else.
190
-
191
- result.P = {
192
- value: result.p.value - result.xi.value % 360.0,
193
- speed: null
194
- };
195
- return result;
196
- };
197
-
198
- var _default = astro;
199
- exports["default"] = _default;
@@ -1,67 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var compoundConstituentFactory = function compoundConstituentFactory(name, members) {
9
- var coefficients = [];
10
- members.forEach(function (_ref) {
11
- var constituent = _ref.constituent,
12
- factor = _ref.factor;
13
- constituent.coefficients.forEach(function (coefficient, index) {
14
- if (typeof coefficients[index] === 'undefined') {
15
- coefficients[index] = 0;
16
- }
17
-
18
- coefficients[index] += coefficient * factor;
19
- });
20
- });
21
- var compoundConstituent = {
22
- name: name,
23
- coefficients: coefficients,
24
- speed: function speed(astro) {
25
- var speed = 0;
26
- members.forEach(function (_ref2) {
27
- var constituent = _ref2.constituent,
28
- factor = _ref2.factor;
29
- speed += constituent.speed(astro) * factor;
30
- });
31
- return speed;
32
- },
33
- value: function value(astro) {
34
- var value = 0;
35
- members.forEach(function (_ref3) {
36
- var constituent = _ref3.constituent,
37
- factor = _ref3.factor;
38
- value += constituent.value(astro) * factor;
39
- });
40
- return value;
41
- },
42
- u: function u(astro) {
43
- var u = 0;
44
- members.forEach(function (_ref4) {
45
- var constituent = _ref4.constituent,
46
- factor = _ref4.factor;
47
- u += constituent.u(astro) * factor;
48
- });
49
- return u;
50
- },
51
- f: function f(astro) {
52
- var f = [];
53
- members.forEach(function (_ref5) {
54
- var constituent = _ref5.constituent,
55
- factor = _ref5.factor;
56
- f.push(Math.pow(constituent.f(astro), Math.abs(factor)));
57
- });
58
- return f.reduce(function (previous, value) {
59
- return previous * value;
60
- });
61
- }
62
- };
63
- return Object.freeze(compoundConstituent);
64
- };
65
-
66
- var _default = compoundConstituentFactory;
67
- exports["default"] = _default;
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.astronomicValues = exports.astronomicSpeed = exports.astronimicDoodsonNumber = exports["default"] = void 0;
7
-
8
- var _index = _interopRequireDefault(require("../node-corrections/index"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
- /**
13
- * Computes the dot notation of two arrays
14
- * @param {*} a
15
- * @param {*} b
16
- */
17
- var dotArray = function dotArray(a, b) {
18
- var results = [];
19
- a.forEach(function (value, index) {
20
- results.push(value * b[index]);
21
- });
22
- return results.reduce(function (total, value) {
23
- return total + value;
24
- });
25
- };
26
-
27
- var astronimicDoodsonNumber = function astronimicDoodsonNumber(astro) {
28
- return [astro['T+h-s'], astro.s, astro.h, astro.p, astro.N, astro.pp, astro['90']];
29
- };
30
-
31
- exports.astronimicDoodsonNumber = astronimicDoodsonNumber;
32
-
33
- var astronomicSpeed = function astronomicSpeed(astro) {
34
- var results = [];
35
- astronimicDoodsonNumber(astro).forEach(function (number) {
36
- results.push(number.speed);
37
- });
38
- return results;
39
- };
40
-
41
- exports.astronomicSpeed = astronomicSpeed;
42
-
43
- var astronomicValues = function astronomicValues(astro) {
44
- var results = [];
45
- astronimicDoodsonNumber(astro).forEach(function (number) {
46
- results.push(number.value);
47
- });
48
- return results;
49
- };
50
-
51
- exports.astronomicValues = astronomicValues;
52
-
53
- var constituentFactory = function constituentFactory(name, coefficients, u, f) {
54
- if (!coefficients) {
55
- throw new Error('Coefficient must be defined for a constituent');
56
- }
57
-
58
- var constituent = {
59
- name: name,
60
- coefficients: coefficients,
61
- value: function value(astro) {
62
- return dotArray(coefficients, astronomicValues(astro));
63
- },
64
- speed: function speed(astro) {
65
- return dotArray(coefficients, astronomicSpeed(astro));
66
- },
67
- u: typeof u !== 'undefined' ? u : _index["default"].uZero,
68
- f: typeof f !== 'undefined' ? f : _index["default"].fUnity
69
- };
70
- return Object.freeze(constituent);
71
- };
72
-
73
- var _default = constituentFactory;
74
- exports["default"] = _default;
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _constituent = _interopRequireDefault(require("./constituent"));
9
-
10
- var _compoundConstituent = _interopRequireDefault(require("./compound-constituent"));
11
-
12
- var _index = _interopRequireDefault(require("../node-corrections/index"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- var constituents = {}; // Long Term
17
-
18
- constituents.Z0 = (0, _constituent["default"])('Z0', [0, 0, 0, 0, 0, 0, 0], _index["default"].uZero, _index["default"].fUnity);
19
- constituents.SA = (0, _constituent["default"])('Sa', [0, 0, 1, 0, 0, 0, 0], _index["default"].uZero, _index["default"].fUnity);
20
- constituents.SSA = (0, _constituent["default"])('Ssa', [0, 0, 2, 0, 0, 0, 0], _index["default"].uZero, _index["default"].fUnity);
21
- constituents.MM = (0, _constituent["default"])('MM', [0, 1, 0, -1, 0, 0, 0], _index["default"].uZero, _index["default"].fMm);
22
- constituents.MF = (0, _constituent["default"])('MF', [0, 2, 0, 0, 0, 0, 0], _index["default"].uMf, _index["default"].fMf); // Diurnals
23
-
24
- constituents.Q1 = (0, _constituent["default"])('Q1', [1, -2, 0, 1, 0, 0, 1], _index["default"].uO1, _index["default"].fO1);
25
- constituents.O1 = (0, _constituent["default"])('O1', [1, -1, 0, 0, 0, 0, 1], _index["default"].uO1, _index["default"].fO1);
26
- constituents.K1 = (0, _constituent["default"])('K1', [1, 1, 0, 0, 0, 0, -1], _index["default"].uK1, _index["default"].fK1);
27
- constituents.J1 = (0, _constituent["default"])('J1', [1, 2, 0, -1, 0, 0, -1], _index["default"].uJ1, _index["default"].fJ1);
28
- constituents.M1 = (0, _constituent["default"])('M1', [1, 0, 0, 0, 0, 0, 1], _index["default"].uM1, _index["default"].fM1);
29
- constituents.P1 = (0, _constituent["default"])('P1', [1, 1, -2, 0, 0, 0, 1], _index["default"].uZero, _index["default"].fUnity);
30
- constituents.S1 = (0, _constituent["default"])('S1', [1, 1, -1, 0, 0, 0, 0], _index["default"].uZero, _index["default"].fUnity);
31
- constituents.OO1 = (0, _constituent["default"])('OO1', [1, 3, 0, 0, 0, 0, -1], _index["default"].uOO1, _index["default"].fOO1); // Semi diurnals
32
-
33
- constituents['2N2'] = (0, _constituent["default"])('2N2', [2, -2, 0, 2, 0, 0, 0], _index["default"].uM2, _index["default"].fM2);
34
- constituents.N2 = (0, _constituent["default"])('N2', [2, -1, 0, 1, 0, 0, 0], _index["default"].uM2, _index["default"].fM2);
35
- constituents.NU2 = (0, _constituent["default"])('NU2', [2, -1, 2, -1, 0, 0, 0], _index["default"].uM2, _index["default"].fM2);
36
- constituents.M2 = (0, _constituent["default"])('M2', [2, 0, 0, 0, 0, 0, 0], _index["default"].uM2, _index["default"].fM2);
37
- constituents.LAM2 = (0, _constituent["default"])('LAM2', [2, 1, -2, 1, 0, 0, 2], _index["default"].uM2, _index["default"].fM2);
38
- constituents.L2 = (0, _constituent["default"])('L2', [2, 1, 0, -1, 0, 0, 2], _index["default"].uL2, _index["default"].fL2);
39
- constituents.T2 = (0, _constituent["default"])('T2', [2, 2, -3, 0, 0, 1, 0], _index["default"].uZero, _index["default"].fUnity);
40
- constituents.S2 = (0, _constituent["default"])('S2', [2, 2, -2, 0, 0, 0, 0], _index["default"].uZero, _index["default"].fUnity);
41
- constituents.R2 = (0, _constituent["default"])('R2', [2, 2, -1, 0, 0, -1, 2], _index["default"].uZero, _index["default"].fUnity);
42
- constituents.K2 = (0, _constituent["default"])('K2', [2, 2, 0, 0, 0, 0, 0], _index["default"].uK2, _index["default"].fK2); // Third diurnal
43
-
44
- constituents.M3 = (0, _constituent["default"])('M3', [3, 0, 0, 0, 0, 0, 0], function (a) {
45
- return _index["default"].uModd(a, 3);
46
- }, function (a) {
47
- return _index["default"].fModd(a, 3);
48
- }); // Compound
49
-
50
- constituents.MSF = (0, _compoundConstituent["default"])('MSF', [{
51
- constituent: constituents.S2,
52
- factor: 1
53
- }, {
54
- constituent: constituents.M2,
55
- factor: -1
56
- }]); // Diurnal
57
-
58
- constituents['2Q1'] = (0, _compoundConstituent["default"])('2Q1', [{
59
- constituent: constituents.N2,
60
- factor: 1
61
- }, {
62
- constituent: constituents.J1,
63
- factor: -1
64
- }]);
65
- constituents.RHO = (0, _compoundConstituent["default"])('RHO', [{
66
- constituent: constituents.NU2,
67
- factor: 1
68
- }, {
69
- constituent: constituents.K1,
70
- factor: -1
71
- }]); // Semi-Diurnal
72
-
73
- constituents.MU2 = (0, _compoundConstituent["default"])('MU2', [{
74
- constituent: constituents.M2,
75
- factor: 2
76
- }, {
77
- constituent: constituents.S2,
78
- factor: -1
79
- }]);
80
- constituents['2SM2'] = (0, _compoundConstituent["default"])('2SM2', [{
81
- constituent: constituents.S2,
82
- factor: 2
83
- }, {
84
- constituent: constituents.M2,
85
- factor: -1
86
- }]); // Third-Diurnal
87
-
88
- constituents['2MK3'] = (0, _compoundConstituent["default"])('2MK3', [{
89
- constituent: constituents.M2,
90
- factor: 1
91
- }, {
92
- constituent: constituents.O1,
93
- factor: 1
94
- }]);
95
- constituents.MK3 = (0, _compoundConstituent["default"])('MK3', [{
96
- constituent: constituents.M2,
97
- factor: 1
98
- }, {
99
- constituent: constituents.K1,
100
- factor: 1
101
- }]); // Quarter-Diurnal
102
-
103
- constituents.MN4 = (0, _compoundConstituent["default"])('MN4', [{
104
- constituent: constituents.M2,
105
- factor: 1
106
- }, {
107
- constituent: constituents.N2,
108
- factor: 1
109
- }]);
110
- constituents.M4 = (0, _compoundConstituent["default"])('M4', [{
111
- constituent: constituents.M2,
112
- factor: 2
113
- }]);
114
- constituents.MS4 = (0, _compoundConstituent["default"])('MS4', [{
115
- constituent: constituents.M2,
116
- factor: 1
117
- }, {
118
- constituent: constituents.S2,
119
- factor: 1
120
- }]);
121
- constituents.S4 = (0, _compoundConstituent["default"])('S4', [{
122
- constituent: constituents.S2,
123
- factor: 2
124
- }]); // Sixth-Diurnal
125
-
126
- constituents.M6 = (0, _compoundConstituent["default"])('M6', [{
127
- constituent: constituents.M2,
128
- factor: 3
129
- }]);
130
- constituents.S6 = (0, _compoundConstituent["default"])('S6', [{
131
- constituent: constituents.S2,
132
- factor: 3
133
- }]); // Eighth-Diurnals
134
-
135
- constituents.M8 = (0, _compoundConstituent["default"])('M8', [{
136
- constituent: constituents.M2,
137
- factor: 4
138
- }]);
139
- var _default = constituents;
140
- exports["default"] = _default;
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTimeline = exports.getDate = exports["default"] = void 0;
7
-
8
- var _prediction = _interopRequireDefault(require("./prediction"));
9
-
10
- var _index = _interopRequireDefault(require("../constituents/index"));
11
-
12
- var _constants = require("../astronomy/constants");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- var getDate = function getDate(time) {
17
- if (time instanceof Date) {
18
- return time;
19
- }
20
-
21
- if (typeof time === 'number') {
22
- return new Date(time * 1000);
23
- }
24
-
25
- throw new Error('Invalid date format, should be a Date object, or timestamp');
26
- };
27
-
28
- exports.getDate = getDate;
29
-
30
- var getTimeline = function getTimeline(start, end, seconds) {
31
- seconds = typeof seconds !== 'undefined' ? seconds : 10 * 60;
32
- var timeline = [];
33
- var endTime = end.getTime() / 1000;
34
- var lastTime = start.getTime() / 1000;
35
- var startTime = lastTime;
36
- var hours = [];
37
-
38
- while (lastTime <= endTime) {
39
- timeline.push(new Date(lastTime * 1000));
40
- hours.push((lastTime - startTime) / (60 * 60));
41
- lastTime += seconds;
42
- }
43
-
44
- return {
45
- items: timeline,
46
- hours: hours
47
- };
48
- };
49
-
50
- exports.getTimeline = getTimeline;
51
-
52
- var harmonicsFactory = function harmonicsFactory(_ref) {
53
- var harmonicConstituents = _ref.harmonicConstituents,
54
- phaseKey = _ref.phaseKey,
55
- offset = _ref.offset;
56
-
57
- if (!Array.isArray(harmonicConstituents)) {
58
- throw new Error('Harmonic constituents are not an array');
59
- }
60
-
61
- var constituents = [];
62
- harmonicConstituents.forEach(function (constituent, index) {
63
- if (typeof constituent.name === 'undefined') {
64
- throw new Error('Harmonic constituents must have a name property');
65
- }
66
-
67
- if (typeof _index["default"][constituent.name] !== 'undefined') {
68
- constituent._model = _index["default"][constituent.name];
69
- constituent._phase = _constants.d2r * constituent[phaseKey];
70
- constituents.push(constituent);
71
- }
72
- });
73
-
74
- if (offset !== false) {
75
- constituents.push({
76
- name: 'Z0',
77
- _model: _index["default"].Z0,
78
- _phase: 0,
79
- amplitude: offset
80
- });
81
- }
82
-
83
- var start = new Date();
84
- var end = new Date();
85
- var harmonics = {};
86
-
87
- harmonics.setTimeSpan = function (startTime, endTime) {
88
- start = getDate(startTime);
89
- end = getDate(endTime);
90
-
91
- if (start.getTime() >= end.getTime()) {
92
- throw new Error('Start time must be before end time');
93
- }
94
-
95
- return harmonics;
96
- };
97
-
98
- harmonics.prediction = function (options) {
99
- options = typeof options !== 'undefined' ? options : {
100
- timeFidelity: 10 * 60
101
- };
102
- return (0, _prediction["default"])({
103
- timeline: getTimeline(start, end, options.timeFidelity),
104
- constituents: constituents,
105
- start: start
106
- });
107
- };
108
-
109
- return Object.freeze(harmonics);
110
- };
111
-
112
- var _default = harmonicsFactory;
113
- exports["default"] = _default;