From 82fd5feb9242a720e8afbfed6c03ee65e63754b6 Mon Sep 17 00:00:00 2001 From: Ali Camarata Date: Sat, 11 Nov 2023 17:23:30 +0700 Subject: [PATCH] initial commit --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 3 ++ CHANGELOG.md | 7 ++++ LICENSE | 7 ++++ README.md | 36 +++++++++++++++++++++ index.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 27 ++++++++++++++++ test.js | 17 ++++++++++ 8 files changed, 187 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.js create mode 100644 package.json create mode 100644 test.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 0) { + output.angles = angles.map(angle => { + let customSpaData = adjustForCustomAngle({ ...data }, angle); + return { + sunrise: customSpaData.sunrise, + sunset: customSpaData.sunset + }; + }); + } + } else { + console.error('SPA Calculation failed'); + } + + return output; +} + +function calcSpa(date, lat, lng, params = null, angles = []) { + let rawData = getSpa(date, lat, lng, params, angles); + rawData.sunrise = fractalTime(rawData.sunrise); + rawData.solarNoon = fractalTime(rawData.solarNoon); + rawData.sunset = fractalTime(rawData.sunset); + + if (rawData.angles) { + rawData.angles = rawData.angles.map(angleData => { + return { + sunrise: fractalTime(angleData.sunrise), + sunset: fractalTime(angleData.sunset) + }; + }); + } + + return rawData; +} + +module.exports = { + getSpa, + calcSpa, + fractalTime +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..f271628 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "nrel-spa", + "version": "1.0.0", + "description": "NREL SPA native implementation in JS", + "main": "index.js", + "scripts": { + "test": "node test.js" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ussunnah/nrel-spa.git" + }, + "keywords": [ + "spa", + "nrel", + "solar", + "calculator" + ], + "author": "USF", + "license": "ISC", + "bugs": { + "url": "https://github.com/ussunnah/nrel-spa/issues" + }, + "homepage": "https://github.com/ussunnah/nrel-spa#readme", + "devDependencies": { + } +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..96fb274 --- /dev/null +++ b/test.js @@ -0,0 +1,17 @@ +const { getSpa, calcSpa } = require('./index'); + +// Constants for testing +const myLat = 40.7128; // Latitude for New York City +const myLng = -74.006; // Longitude for New York City +const nyDate = new Date(new Date().toLocaleString("en-US", { timeZone: "America/New_York" })); +const myDate = new Date(); // Date object for today with NY time zone +const myAngles = [63.435]; // Custom angles for twilight calculations + +// Get results +const get = getSpa(myDate, myLat, myLng, null, myAngles); +const calc = calcSpa(myDate, myLat, myLng, null, myAngles); + +// Print results +console.log("\nTest: Using NYC and current time:\n") +console.log("getSpa =", JSON.stringify(get, null, 2), "\n"); +console.log("calcSpa =", JSON.stringify(calc, null, 2), "\n");