From 5888eadaa753cb7f34c63a8ebc03126ef56687a8 Mon Sep 17 00:00:00 2001 From: Marcos Corona Date: Tue, 26 Jul 2022 14:34:35 -0400 Subject: [PATCH] feat: add support to different houses system (#27) --- README.md | 40 +++++++- src/api/index.js | 4 +- src/astrologer/charts.js | 14 ++- src/astrologer/houses.js | 4 +- .../support-additionals-house-systems.spec.js | 97 +++++++++++++++++++ 5 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 test/features/support-additionals-house-systems.spec.js diff --git a/README.md b/README.md index 6549e8f..8b8dd20 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ ### Usage -Example: Get the horoscope for date `1993-08-06`, time `16:50:00` and timezone `-04:00` at Santiago, Chile (latitude `-33.41167` and longitude `-70.66647`). +Example: Get the horoscope for date `1993-08-06`, time `16:50:00` with timezone `-04:00` at Santiago, Chile (latitude `-33.41167` and longitude `-70.66647`) using Placidus houses system. Fist, you need to transform the date & time to ISO8601, for this example `1993-08-06T16:50:00-04:00`. @@ -49,6 +49,8 @@ If you don't want to escape the date and time, you can always send it to UTC In UTC: `1993-08-06T20:50:00Z` +Then, you need to select the house system from the houses system table.. in this case for the placidus system you need to send the `P` value in the `houseSystem` query param. + Now you can send this... ##### Using cURL @@ -56,11 +58,43 @@ Now you can send this... ```bash # escaped curl --request GET \ - --url 'http://localhost:3000/horoscope?time=1993-08-06T16%3A50%3A00-04%3A00&latitude=-33.41167&longitude=-70.66647' + --url 'http://localhost:3000/horoscope?time=1993-08-06T16%3A50%3A00-04%3A00&latitude=-33.41167&longitude=-70.66647&houseSystem=P' ``` ```bash # in utc curl --request GET \ - --url 'http://localhost:3000/horoscope?time=1993-08-06T20:50:00Z&latitude=-33.41167&longitude=-70.66647' + --url 'http://localhost:3000/horoscope?time=1993-08-06T20:50:00Z&latitude=-33.41167&longitude=-70.66647&houseSystem=P' ``` + + +### House system table + +The values from each house system is extracted from sweph source code + +| Code value | House system | +|--- | --- +| A | equal | +| B | Alcabitius | +| C | Campanus | +| D | equal (MC) | +| E | equal | +| F | Carter poli-equ. | +| G | Gauquelin sectors | +| H | horizon/azimut | +| I | Sunshine | +| i | Sunshine/alt. | +| K | Koch | +| L | Pullen SD | +| M | Morinus | +| N | equal/1=Aries | +| O | Porphyry | +| Q | Pullen SR | +| R | Regiomontanus | +| S | Sripati | +| T | Polich/Page | +| U | Krusinski-Pisa-Goelzer | +| V | equal/Vehlow | +| W | equal/ whole sign | +| X | axial rotation system/Meridian houses | +| Y | APC houses | \ No newline at end of file diff --git a/src/api/index.js b/src/api/index.js index b29ba00..6cf8ee7 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -7,9 +7,9 @@ router.get('/', async (req, res) => res.status(200).json({ message: 'Welcome to router.get('/horoscope', async (req, res) => { const date = new Date(req.query.time) - const { latitude, longitude } = req.query + const { latitude, longitude, houseSystem } = req.query - const chart = astrologer.natalChart(date, latitude, longitude) + const chart = astrologer.natalChart(date, latitude, longitude, houseSystem) res.status(200).json({ data: chart diff --git a/src/astrologer/charts.js b/src/astrologer/charts.js index 8368a10..a442fef 100644 --- a/src/astrologer/charts.js +++ b/src/astrologer/charts.js @@ -2,13 +2,17 @@ const { houses } = require('./houses') const { aspects } = require('./aspects') const { planets } = require('./astros') -const natalChart = (date, latitude, longitude) => { +const natalChart = (date, latitude, longitude, houseSystem = 'P') => { const astrosList = planets(date) const aspectsList = aspects(astrosList) - const housesList = houses(date, { - latitude: parseFloat(latitude), - longitude: parseFloat(longitude) - }) + const housesList = houses( + date, + { + latitude: parseFloat(latitude), + longitude: parseFloat(longitude) + }, + houseSystem + ) return { astros: { diff --git a/src/astrologer/houses.js b/src/astrologer/houses.js index 6dee405..dbb37be 100644 --- a/src/astrologer/houses.js +++ b/src/astrologer/houses.js @@ -5,7 +5,7 @@ sweph.set_ephe_path(path.join(__dirname, '/../../eph')) const { utcToJulianUt, degreesToDms, zodiacSign } = require('./utils') -const houses = (date, position) => { +const houses = (date, position, houseSystem = 'P') => { const julianDayUT = utcToJulianUt(date) const withoutGeoposition = !(position?.latitude && position?.longitude) @@ -26,7 +26,7 @@ const houses = (date, position) => { julianDayUT, position.latitude, position.longitude, - 'P' // placidus system... + houseSystem // placidus system... ).data const houseCollection = housesPositions.map((cuspid) => ({ position: degreesToDms(cuspid), sign: zodiacSign(cuspid) })) diff --git a/test/features/support-additionals-house-systems.spec.js b/test/features/support-additionals-house-systems.spec.js new file mode 100644 index 0000000..1e970d1 --- /dev/null +++ b/test/features/support-additionals-house-systems.spec.js @@ -0,0 +1,97 @@ +const request = require('supertest') +const app = require('./../../app') + +describe('Get Koch houses system cuspids for 1991-07-06T16:50:00-04:00', () => { + let response + + beforeEach(async () => { + response = await request(app) + .get('/horoscope') + .query({ + time: '1991-07-06T16:50:00-04:00', + latitude: '-33.41167', + longitude: '-70.66647', + houseSystem: 'K' // Koch system... + }) + .send() + }) + + const expectCuspids = ( + cuspid, + expectedSign, + expectedDegrees, + expectedMinutes, + expectedSeconds + ) => { + expect(cuspid.position.degrees).toBe(expectedDegrees) + expect(cuspid.position.minutes).toBe(expectedMinutes) + expect(cuspid.position.seconds).toBe(expectedSeconds) + expect(cuspid.position.longitude).not.toBeNull() + expect(cuspid.position.longitude).not.toBeUndefined() + expect(cuspid.sign).toBe(expectedSign) + } + + it('/horoscope return the ASC axis (cuspid of the house I)', () => { + expectCuspids(response.body.data.axes.asc, 10, 2, 32, 26) + }) + + it('/horoscope return the DC axis (cuspid of the house VII)', () => { + expectCuspids(response.body.data.axes.dc, 4, 2, 32, 26) + }) + + it('/horoscope return the MC axis (cuspid of the house X)', () => { + expectCuspids(response.body.data.axes.mc, 6, 14, 58, 42) + }) + + it('/horoscope return the IC axis (cuspid of the house IV)', () => { + expectCuspids(response.body.data.axes.ic, 12, 14, 58, 42) + }) + + it('/horoscope response has cuspid of house I', () => { + expectCuspids(response.body.data.houses[0], 10, 2, 32, 26) + }) + + it('/horoscope response has cuspid of house II', () => { + expectCuspids(response.body.data.houses[1], 10, 27, 14, 48) + }) + + it('/horoscope response has cuspid of house III', () => { + expectCuspids(response.body.data.houses[2], 11, 20, 59, 20) + }) + + it('/horoscope response has cuspid of house IV', () => { + expectCuspids(response.body.data.houses[3], 12, 14, 58, 42) + }) + + it('/horoscope response has cuspid of house V', () => { + expectCuspids(response.body.data.houses[4], 1, 27, 58, 29) + }) + + it('/horoscope response has cuspid of house VI', () => { + expectCuspids(response.body.data.houses[5], 3, 4, 6, 36) + }) + + it('/horoscope response has cuspid of house VII', () => { + expectCuspids(response.body.data.houses[6], 4, 2, 32, 26) + }) + + it('/horoscope response has cuspid of house VIII', () => { + expectCuspids(response.body.data.houses[7], 4, 27, 14, 48) + }) + + it('/horoscope response has cuspid of house IX', () => { + expectCuspids(response.body.data.houses[8], 5, 20, 59, 20) + }) + + it('/horoscope response has cuspid of house X', () => { + expectCuspids(response.body.data.houses[9], 6, 14, 58, 42) + }) + + it('/horoscope response has cuspid of house XI', () => { + expectCuspids(response.body.data.houses[10], 7, 27, 58, 29) + }) + + it('/horoscope response has cuspid of house XII', () => { + expectCuspids(response.body.data.houses[11], 9, 4, 6, 36) + }) +})