diff --git a/astro_functions.php b/astro_functions.php index df7c6d9..4702ade 100644 --- a/astro_functions.php +++ b/astro_functions.php @@ -120,5 +120,12 @@ function sortPlanetsByLongitude(array $planets): array function getSegmentFromLongitude(float $longitude): int { $longitude = normalizeLongitude($longitude); + + // Each zodiac sign = 30° + // 0-30 → 1 + // 30-60 → 2 + // ... + // 330-360 → 12 + return ((int) floor($longitude / 30)) + 1; } \ No newline at end of file diff --git a/ephemeris_engine.php b/ephemeris_engine.php new file mode 100644 index 0000000..f80cb70 --- /dev/null +++ b/ephemeris_engine.php @@ -0,0 +1,128 @@ + false, + 'error' => $curlErr ?: ('Remote API returned HTTP ' . $httpCode), + 'data' => [] + ]; + } + } else { + $context = stream_context_create([ + 'http' => [ + 'timeout' => SWISSEPH_API_TIMEOUT + ] + ]); + + $response = @file_get_contents($url, false, $context); + + if ($response === false) { + return [ + 'success' => false, + 'error' => 'Could not connect to remote Swiss Ephemeris API.', + 'data' => [] + ]; + } + } + + $decoded = json_decode($response, true); + + if (!is_array($decoded)) { + return [ + 'success' => false, + 'error' => 'Invalid JSON received from remote API.', + 'data' => [] + ]; + } + + return [ + 'success' => true, + 'error' => '', + 'data' => $decoded + ]; +} + +function getRealPlanetaryData( + string $date, + string $time, + float $latitude, + float $longitude, + string $timezone = 'Asia/Kathmandu' +): array { + $remote = fetchRemoteSwissephResponse($date, $time, $latitude, $longitude, $timezone); + + if (!$remote['success']) { + return [ + 'planets' => [], + 'ascendant' => null, + 'error' => $remote['error'] + ]; + } + + $data = $remote['data']; + $results = []; + + if (isset($data['planets']) && is_array($data['planets'])) { + foreach ($data['planets'] as $planet) { + if (!is_array($planet) || !isset($planet['key']) || !isset($planet['longitude'])) { + continue; + } + + if (!in_array($planet['key'], PLANET_KEYS, true)) { + continue; + } + + $results[] = [ + 'key' => $planet['key'], + 'longitude' => normalizeLongitude((float)$planet['longitude']) + ]; + } + } + + return [ + 'planets' => $results, + 'ascendant' => isset($data['ascendant']) ? (float)$data['ascendant'] : null, + 'error' => '' + ]; +} \ No newline at end of file diff --git a/index.php b/index.php index 16a1147..109826d 100644 --- a/index.php +++ b/index.php @@ -1,9 +1,9 @@ - @@ -113,7 +122,6 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets); -
@@ -183,8 +191,20 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
+ +
+

Ascendant Longitude:

+

Ascendant Sign:

+

Ascendant Degree:

+

Ascendant Nakshatra:

+
+ - + +
+ +
+
@@ -200,13 +220,13 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
+
Table 1: Positions by Planets
- @@ -216,21 +236,22 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets); - - - - + + + + + + + + + + + - - - - - + - - - +
PlanetNakshatra
No planetary data available.
@@ -242,7 +263,6 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
Table 2: Positions in Order
- @@ -252,21 +272,22 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets); - - - - + + + + + + + + + + + - - - - - + - - - +
SegmentNakshatra
No ordered planetary data available.
@@ -280,12 +301,11 @@ $positionsInOrder = sortPlanetsByLongitude($samplePlanets);
- - + + - \ No newline at end of file