-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(horoscope): add aspects to response (#7)
* Refactor aspect test * Add orbs when calculating aspects * Disable rules of arrow-line-body * Add direction of aspect (bidirecional/unidirectional) * Add aspects to /horoscope response (using huber orbs)
- Loading branch information
Showing
8 changed files
with
335 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
const { normalizeDegrees } = require("./utils"); | ||
|
||
const ASPECTS = { | ||
0: "conjunction", | ||
30: "semisextile", | ||
60: "sextile", | ||
90: "quadrature", | ||
120: "trigone", | ||
150: "quincunx", | ||
180: "opposition", | ||
}; | ||
|
||
// HUBER ORBS... but mars and jupiter modified... | ||
const DEFAULT_ORBS = { | ||
luminary: { | ||
0: 10, | ||
30: 3, | ||
60: 5, | ||
90: 6, | ||
120: 8, | ||
150: 5, | ||
180: 10 | ||
}, | ||
personal: { | ||
0: 7, | ||
30: 2, | ||
60: 4, | ||
90: 5, | ||
120: 6, | ||
150: 2, | ||
180: 7 | ||
}, | ||
social: { | ||
0: 6, | ||
30: 1.5, | ||
60: 3, | ||
90: 4, | ||
120: 5, | ||
150: 3, | ||
180: 6 | ||
}, | ||
transpersonal: { | ||
0: 5, | ||
30: 1, | ||
60: 2, | ||
90: 3, | ||
120: 4, | ||
150: 2, | ||
180: 5 | ||
}, | ||
other: { | ||
0: 5, | ||
30: 1, | ||
60: 2, | ||
90: 3, | ||
120: 4, | ||
150: 2, | ||
180: 5 | ||
} | ||
}; | ||
|
||
const calculateAspect = (first, second, orbs) => { | ||
return Object.keys({ ...ASPECTS }).filter( | ||
(a) => { | ||
const totalOrbsForAspect = orbs[a]; | ||
const from = parseFloat(a) - (totalOrbsForAspect / 2); | ||
const to = parseFloat(a) + (totalOrbsForAspect / 2); | ||
|
||
const firstLongitude = normalizeDegrees(first.position.longitude); | ||
const secondLongitude = normalizeDegrees(second.position.longitude); | ||
|
||
const diff = Math.abs(firstLongitude - secondLongitude); | ||
return diff >= from && diff <= to; | ||
} | ||
); | ||
}; | ||
|
||
const aspect = (first, second, orbs) => { | ||
if (orbs === undefined) { | ||
orbs = { ...DEFAULT_ORBS }; | ||
} | ||
|
||
const aspectsFirst = calculateAspect(first, second, orbs[first.type]); | ||
const aspectsSecond = calculateAspect(first, second, orbs[second.type]); | ||
|
||
if (aspectsFirst.length === 0 && aspectsSecond.length === 0) { | ||
return undefined; | ||
} | ||
|
||
const direction = aspectsFirst.length === 1 && aspectsSecond.length === 1 ? "bidirectional" : "unidirectional"; | ||
|
||
return { | ||
name: ASPECTS[aspectsFirst[0]], | ||
direction, | ||
first: { | ||
name: first.name, | ||
exist: aspectsFirst.length === 1 | ||
}, | ||
second: { | ||
name: second.name, | ||
exist: aspectsSecond.length === 1 | ||
}, | ||
}; | ||
}; | ||
|
||
const aspects = (planets) => { | ||
return Object.keys(planets).reduce((acc, planetKey) => { | ||
if (acc[planetKey]) { | ||
return acc; | ||
} | ||
|
||
acc[planetKey] = []; | ||
|
||
Object.values(planets).filter((p) => p.name !== planetKey).forEach((p) => { | ||
if (!acc[p.name]) { | ||
const aspectsFounds = aspect(planets[planetKey], p); | ||
if (aspectsFounds) { | ||
acc[planetKey].push(aspectsFounds); | ||
} | ||
} | ||
}); | ||
|
||
return acc; | ||
}, {}); | ||
}; | ||
|
||
module.exports = { | ||
aspect, | ||
aspects | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const astrologer = require("./../../src/astrologer"); | ||
|
||
describe("Calculate aspects between two planets", () => { | ||
const planetOne = { | ||
name: "sun", | ||
type: "luminary", | ||
position: { | ||
longitude: 10, | ||
}, | ||
}; | ||
|
||
const planetTwo = { | ||
name: "pluto", | ||
type: "transpersonal", | ||
position: { | ||
longitude: 30, | ||
}, | ||
}; | ||
|
||
it("2 planets may have no aspects", async () => { | ||
planetOne.position.longitude = 10; | ||
planetTwo.position.longitude = 30; | ||
const aspect = astrologer.aspect(planetOne, planetTwo); | ||
expect(aspect).toBe(undefined); | ||
}); | ||
|
||
it("If two planets longitude difference is equal to 30 then exist conjunction", async () => { | ||
planetOne.position.longitude = 30; | ||
planetTwo.position.longitude = 30; | ||
const aspect = astrologer.aspect(planetOne, planetTwo); | ||
expect(aspect.name).toBe("conjunction"); | ||
}); | ||
|
||
it("If two planets longitude difference is equal to 60 then exist sextile", async () => { | ||
planetOne.position.longitude = 30; | ||
planetTwo.position.longitude = 90; | ||
|
||
const aspect = astrologer.aspect(planetOne, planetTwo); | ||
expect(aspect.name).toBe("sextile"); | ||
}); | ||
|
||
it("If two planets longitude difference is equal to 90 then exist quadrature", async () => { | ||
planetOne.position.longitude = 0; | ||
planetTwo.position.longitude = 90; | ||
const aspect = astrologer.aspect(planetOne, planetTwo); | ||
expect(aspect.name).toBe("quadrature"); | ||
}); | ||
|
||
it("If two planets longitude difference is equal to 120 then exist trigone", async () => { | ||
planetOne.position.longitude = 355; | ||
planetTwo.position.longitude = 115; | ||
const aspect = astrologer.aspect(planetOne, planetTwo); | ||
expect(aspect.name).toBe("trigone"); | ||
}); | ||
|
||
it("If two planets longitude difference is equal to 180 then exist opposition", async () => { | ||
planetOne.position.longitude = -270; | ||
planetTwo.position.longitude = -90; | ||
const aspect = astrologer.aspect(planetOne, planetTwo); | ||
expect(aspect.name).toBe("opposition"); | ||
}); | ||
}); |
Oops, something went wrong.