Skip to content

Commit

Permalink
feat(astro): add retrograde and speed field in api response
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuphi committed Aug 20, 2021
1 parent 064b3cb commit 748cc3d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -41,6 +41,6 @@
"express-promise-router": "^3.0.3",
"helmet": "^3.21.3",
"morgan": "^1.9.1",
"swisseph": "^0.5.15"
"swisseph": "^0.5.16"
}
}
19 changes: 12 additions & 7 deletions src/astrologer/astros.js
Expand Up @@ -2,7 +2,7 @@ const swisseph = require("swisseph");

swisseph.swe_set_ephe_path(`${__dirname}/../../eph`);

const { utcToJulianEt, utcToJulianUt, zodiacSign, degreesToDms } = require("./utils");
const { utcToJulianEt, zodiacSign, degreesToDms } = require("./utils");

const PLANETS = {
sun: swisseph.SE_SUN,
Expand Down Expand Up @@ -46,21 +46,27 @@ const FLAG = swisseph.SEFLG_SPEED | swisseph.SEFLG_SWIEPH;

const getPositionOfAstro = (astro, julianDay) => swisseph.swe_calc(julianDay, PLANETS[astro], FLAG);

const isRetrograde = (speed) => speed < 0;

const position = (astrologyObject, moment) => {
const julianDay = utcToJulianEt(moment);
const astro = getPositionOfAstro(astrologyObject, julianDay);
const dms = degreesToDms(astro.longitude);
const { longitude, longitudeSpeed: speed } = getPositionOfAstro(astrologyObject, julianDay);
const dms = degreesToDms(longitude);
const retrograde = isRetrograde(speed);

return {
position: {
longitude: astro.longitude,
longitude,
...dms,
},
sign: zodiacSign(astro.longitude),
speed,
retrograde,
sign: zodiacSign(longitude),
};
};

const planets = (date) => {
const astros = Object.keys(PLANETS)
return Object.keys(PLANETS)
.reduce(
(accumulator, name) => {
const planetPosition = position(name, date);
Expand All @@ -73,7 +79,6 @@ const planets = (date) => {
},
{}
);
return astros;
};

module.exports = {
Expand Down

0 comments on commit 748cc3d

Please sign in to comment.