Skip to content

Commit

Permalink
feat: add support to different houses system (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuphi committed Jul 26, 2022
1 parent b87b5fc commit 5888ead
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 12 deletions.
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -49,18 +49,52 @@ 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

```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 |
4 changes: 2 additions & 2 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions src/astrologer/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions src/astrologer/houses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) }))
Expand Down
97 changes: 97 additions & 0 deletions test/features/support-additionals-house-systems.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 5888ead

Please sign in to comment.