UNPKG

@nrweb/astro-calc

Version:

Comprehensive astrological calculations using Swiss Ephemeris and astronomy-engine for positions, aspects, houses, lots, and scoring metrics

100 lines 4.91 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateMonthlyScores = calculateMonthlyScores; const index_1 = require("./index"); const constants_1 = require("./constants"); const SunCalc = __importStar(require("suncalc")); function getSunriseTime(date, latitude, longitude) { const times = SunCalc.getTimes(date, latitude, longitude); return times.sunrise; } function getDaysInMonth(year, month) { const days = []; const firstDay = new Date(year, month, 1); const lastDay = new Date(year, month + 1, 0); for (let day = 1; day <= lastDay.getDate(); day++) { days.push(new Date(year, month, day)); } return days; } function formatDateKey(date) { return date.toISOString().split("T")[0]; // YYYY-MM-DD format } function calculateMonthlyScores(latitude = constants_1.DEFAULT_LATITUDE, longitude = constants_1.DEFAULT_LONGITUDE) { const now = new Date(); const currentYear = now.getFullYear(); const currentMonth = now.getMonth(); const daysInMonth = getDaysInMonth(currentYear, currentMonth); const monthlyScores = {}; console.log(`Calculating scores for ${daysInMonth.length} days in ${new Date(currentYear, currentMonth).toLocaleDateString("en-US", { month: "long", year: "numeric" })}...`); for (const day of daysInMonth) { try { // Get sunrise time for this day const sunriseTime = getSunriseTime(day, latitude, longitude); // Calculate astrological positions for sunrise time const astrologicalData = (0, index_1.getAstrologicalPositions)(sunriseTime, latitude, longitude); // Use the original per-score functions const positions = astrologicalData.positions; const houses = astrologicalData.houses.map((house) => ({ number: house.number, startSign: house.startSign, startDegrees: house.startDegrees, endSign: house.endSign, endDegrees: house.endDegrees, bodies: [], })); const lots = astrologicalData.lots; const moonPhaseData = { phase: astrologicalData.moonPhase.phase }; const dailyScores = { romanceScore: (0, index_1.calculateRomanceScore)(positions, houses, lots, moonPhaseData), careerScore: (0, index_1.calculateCareerScore)(positions, houses, lots, moonPhaseData), wealthScore: (0, index_1.calculateWealthScore)(positions, houses, lots, moonPhaseData), magicScore: (0, index_1.calculateMagicScore)(positions, houses, lots, moonPhaseData), friendshipScore: (0, index_1.calculateFriendshipScore)(positions, houses, lots, moonPhaseData), healthScore: (0, index_1.calculateHealthScore)(positions, houses, lots, moonPhaseData), }; const dateKey = formatDateKey(day); monthlyScores[dateKey] = dailyScores; console.log(`${dateKey}: R:${dailyScores.romanceScore.toFixed(2)} C:${dailyScores.careerScore.toFixed(2)} W:${dailyScores.wealthScore.toFixed(2)} M:${dailyScores.magicScore.toFixed(2)} F:${dailyScores.friendshipScore.toFixed(2)} H:${dailyScores.healthScore.toFixed(2)}`); } catch (error) { console.error(`Error calculating scores for ${formatDateKey(day)}:`, error); // Continue with next day instead of failing completely } } return monthlyScores; } //# sourceMappingURL=monthly-scores.js.map