mirror of
https://github.com/acamarata/nrel-spa.git
synced 2026-07-01 19:34:25 +00:00
updated format and docs
This commit is contained in:
parent
4a5c28261e
commit
e2c6dbe6ba
5 changed files with 48 additions and 11 deletions
|
|
@ -5,3 +5,12 @@ All notable changes to this project will be documented in this file.
|
||||||
## [1.0.0] - 2023-11-11
|
## [1.0.0] - 2023-11-11
|
||||||
|
|
||||||
- Initial release
|
- Initial release
|
||||||
|
|
||||||
|
## [1.1.0] - 2023-11-11
|
||||||
|
|
||||||
|
- Unignored "dist" folder in git (major)
|
||||||
|
|
||||||
|
## [1.2.1] - 2023-11-12
|
||||||
|
|
||||||
|
- Moved timezone to main args and changed default behavior (major)
|
||||||
|
- Updated test cases and readme to reflect new usage (minor)
|
||||||
|
|
|
||||||
42
README.md
42
README.md
|
|
@ -13,19 +13,47 @@ npm install nrel-spa
|
||||||
Basic usage examples:
|
Basic usage examples:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const { calcSpa } = require('nrel-spa');
|
const { getSpa, calcSpa } = require('./index');
|
||||||
|
|
||||||
const myLat = 40.7128; // Latitude for New York City
|
const date = new Date();
|
||||||
const myLng = -74.006; // Longitude for New York City
|
console.log(date)
|
||||||
const myDate = new Date(); // Current date
|
|
||||||
|
|
||||||
const solarData = calcSpa(myDate, myLat, myLng);
|
// NYC - minimum params
|
||||||
console.log(solarData);
|
const city = "New York"
|
||||||
|
const lat = 40.7128;
|
||||||
|
const lng = -74.006;
|
||||||
|
const tz = null // optional
|
||||||
|
const params = null // optional
|
||||||
|
const angles = [] // optional
|
||||||
|
|
||||||
|
/* Jakarta - all params
|
||||||
|
const city = "Jakarta"
|
||||||
|
const lat = -6.2088
|
||||||
|
const lng = 106.8456
|
||||||
|
const tz = 0
|
||||||
|
const elevation = 18
|
||||||
|
const temperature = 26.56
|
||||||
|
const pressure = 1017
|
||||||
|
const params = {elevation, temperature, pressure}
|
||||||
|
const angles = [63.435] */
|
||||||
|
|
||||||
|
// Get results
|
||||||
|
const get = getSpa(date, lat, lng); // minimum args
|
||||||
|
const calc = calcSpa(date, lat, lng, tz, params, angles);
|
||||||
|
|
||||||
|
// Print results
|
||||||
|
console.log(`\nTest: ${city} with current Date():\n`)
|
||||||
|
console.log("getSpa =", get, "\n");
|
||||||
|
console.log("calcSpa =", calc, "\n");
|
||||||
```
|
```
|
||||||
|
|
||||||
## API
|
## API
|
||||||
|
|
||||||
Describe the functions and their parameters briefly.
|
Exporting getSpa, calcSpa, and fractalTime. Only date, lat, lng are required but if timezone (tz) is null, will return in UTC.
|
||||||
|
|
||||||
|
- getSpa(date, lat, lng, tz, params, angles) // returns SPA results in fractal times
|
||||||
|
- getSpa(date, lat, lng, tz, params, angles) // returns SPA results in formatted times
|
||||||
|
- fractalTime(fractionalHour) // formats time from 10.767407706732804 to 10:46:02.667
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|
|
||||||
4
index.js
4
index.js
|
|
@ -18,7 +18,7 @@ function adjustForCustomAngle(baseSpaData, zenithAngle) {
|
||||||
return adjustedData;
|
return adjustedData;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSpa(date, lat, lng, tz, params = null, angles = []) {
|
function getSpa(date, lat, lng, tz = 0, params = null, angles = []) {
|
||||||
let data = new spa.SpaData();
|
let data = new spa.SpaData();
|
||||||
data.year = date.getFullYear();
|
data.year = date.getFullYear();
|
||||||
data.month = date.getMonth() + 1; // JavaScript months are 0-indexed
|
data.month = date.getMonth() + 1; // JavaScript months are 0-indexed
|
||||||
|
|
@ -64,7 +64,7 @@ function getSpa(date, lat, lng, tz, params = null, angles = []) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcSpa(date, lat, lng, tz, params = null, angles = []) {
|
function calcSpa(date, lat, lng, tz = 0, params = null, angles = []) {
|
||||||
let rawData = getSpa(date, lat, lng, tz, params, angles);
|
let rawData = getSpa(date, lat, lng, tz, params, angles);
|
||||||
rawData.sunrise = fractalTime(rawData.sunrise);
|
rawData.sunrise = fractalTime(rawData.sunrise);
|
||||||
rawData.solarNoon = fractalTime(rawData.solarNoon);
|
rawData.solarNoon = fractalTime(rawData.solarNoon);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "nrel-spa",
|
"name": "nrel-spa",
|
||||||
"version": "1.2.0",
|
"version": "1.2.1",
|
||||||
"description": "NREL SPA native implementation in JS",
|
"description": "NREL SPA native implementation in JS",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
2
test.js
2
test.js
|
|
@ -16,7 +16,7 @@ const angles = []
|
||||||
const city = "Jakarta"
|
const city = "Jakarta"
|
||||||
const lat = -6.2088
|
const lat = -6.2088
|
||||||
const lng = 106.8456
|
const lng = 106.8456
|
||||||
const tz = 7
|
const tz = 0
|
||||||
const elevation = 18
|
const elevation = 18
|
||||||
const temperature = 26.56
|
const temperature = 26.56
|
||||||
const pressure = 1017
|
const pressure = 1017
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue