Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MySQL/MariaDB astronomical function

License

NotificationsYou must be signed in to change notification settings

curzon01/lib_mysqludf_astro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

masterLicense

MySQL sun/moon astronomy functions

This repository contains the source code for aMySQL loadable function library (previously called UDF - User Defined Functions), which provides an additonal SQL astrononmy function to get astro sun and moon information for a given geographical location and time.

The calculations are based on an adaptation of the C++ Astronomy class fromESP32-Astronomie.

If you likelib_mysqludf_astro give it a star or fork it:

GitHub starsGitHub forks

Build instructions for GNU Make

Build and install

From the base directory run:

make cleanmakesudo make install

This will build and install the library file.

Localized binary

To create a country-specific version, call make command with the parameter LANG=-DLANG_xx, where xx is the country code: DE=German, ES=Spanish, FR=French, IT=Italian, NL=Netherlands, EN=English (default).

Example: Create and install a Dutch binary use

make cleanmake LANG=-DLANG_NLsudo make install

Finally we activate the loadable function in MySQL Server (replaceusername by a local MySQL user which has the permission to create functions, e. g. root)

mysql -u username -p< install.sql

Uninstall

To uninstall first deactive the loadable function within your MySQL server using the SQL queries:

DROPFUNCTION IF EXISTS astro_info;DROPFUNCTION IF EXISTS astro;

then uninstall the library using command line:

sudo make uninstall

Usage

astro(date, latitude, longitude, timezone)

Returns astro info for given date, geolocation and timezone as JSON string.

Parameter

date

A given valid date in 'YYYY-MM-DD hh:mm:ss' format. Invalid dates results in a NULL value.

latitude

North–south position of a point in degrees format

longitude

East-West position of a point in degrees format

timezone

Time zone offset from UTC in hours

Return

The function returns the astro info as JSON string with the following keys:

JSON KeyDescriptionFormat/Unit
$.TimeDate for the given result'YYYY-MM-DDThh:mm:ss'
$.ZoneTime zone offset from UTC in hourshour
$.LatitudeGeographic latitudedegrees
$.LongitudeGeographic longitudedegrees
$.deltaTdeltaTdecimal
$.JulianDateJulian Datedecimal
$.GMSTGreenwich sidereal time'hh:mm:ss'
$.LMSTLocal sidereal time'hh:mm:ss'
$.Sun.Distance.EarthDistance to the sun (earth's center)km
$.Sun.Distance.ObserverDistance to the sun (from the observer)km
$.Sun.EclipticEcliptic length of the sundegrees
$.Sun.DeclinationDeclination of the sundegrees
$.Sun.AzimuthAzimuth of the sundegrees
$.Sun.HeightHeight of the sun above the horizondegrees
$.Sun.DiameterDiameter of the sunarc seconds
$.Sun.Rise.AstronomicalAstronomical dawn'hh:mm:ss'
$.Sun.Rise.NauticalNautical dawn'hh:mm:ss'
$.Sun.Rise.CivilCivil dawn'hh:mm:ss'
$.Sun.Rise.SunriseSunrise'hh:mm:ss'
$.Sun.CulminationCulmination of the sun'hh:mm:ss'
$.Sun.Set.SunsetSunset'hh:mm:ss'
$.Sun.Set.CivilCivil dusk'hh:mm:ss'
$.Sun.Set.NauticalNautical dusk'hh:mm:ss'
$.Sun.Set.AstronomicalAstronomical dusk'hh:mm:ss'
$.Sun.AscensionRight ascension of the sun'hh:mm:ss'
$.Sun.ZodiacZodiacAries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio,Sagittarius, Capricorn, Aquarius, Pisces
$.Moon.Distance.EarthDistance to the moon (earth's center)km
$.Moon.Distance.ObserverDistance to the moon (from the observer)km
$.Moon.Ecliptic.LatitudeEcliptic latitude of the moondegrees
$.Moon.Ecliptic.LongitudeEcliptic longitude of the moondegrees
$.Moon.DeclinationDeclination of the moondegrees
$.Moon.AzimuthAzimuth of the moondegrees
$.Moon.HeightHeight of the moon above the horizondegrees
$.Moon.DiameterDiameter of the moonarc seconds
$.Moon.RiseMoonrise'hh:mm:ss'
$.Moon.CulminationCulmination of the moon'hh:mm:ss'
$.Moon.SetMoonset'hh:mm:ss'
$.Moon.AscensionRight ascension of the moon'hh:mm:ss'
$.Moon.Phase.NameMoon phase nameNew Moon, Waxing crescent, First quarter, Waxing gibbous, Full Moon, Waning gibbous, Third quarter, Waning crescent
$.Moon.Phase.ValueMoon phase as index0..7
$.Moon.Phase.NumberAge of moon in since New Moon (0) - Full Moon (1)decimal
$.Moon.AgeAge of moon in radians0..359
$.Moon.SignMoon signAries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio,Sagittarius, Capricorn, Aquarius, Pisces

Example:

{"Time":"2023-01-18T09:00:00","Zone":1,"Latitude":53.182153,"Longitude":4.854429,"deltaT":65,"JulianDate":2459962.83333,"GMST":"15:49:54","LMST":"16:09:19","Sun": {"Distance": {"Earth":147182898.6,"Observer":147182769.4    },"Ecliptic":297.968,"Declination":-20.565,"Azimuth":127.65,"Height":1.5,"Diameter":32.51,"Rise": {"Astronomical":"06:39:38","Nautical":"07:21:00","Civil":"08:04:22","Sunrise":"08:44:23"    },"Culmination":"12:50:58","Set": {"Sunset":"16:58:02","Civil":"17:38:04","Nautical":"18:21:28","Astronomical":"19:02:52"    },"Ascension":"20:00:14","Zodiac":"Capricorn"  },"Moon": {"Distance": {"Earth":370620.2,"Observer":369274.6    },"Ecliptic": {"Latitude":-2.528,"Longitude":248.606    },"Declination":-25.195,"Azimuth":176.16,"Height":12,"Diameter":32.24,"Rise":"05:33:24","Culmination":"09:17:17","Set":"12:52:19","Ascension":"16:25:58","Phase": {"Name":"Waning crescent","Value":7,"Number":0.174    },"Age":310.737,"Sign":"Sagittarius"  }}

Examples

Get sun rise/set

SET @ts= NOW();SET @latitude=53.182153;SET @longitude=4.854429;SET @timezone= TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW());SELECT    JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Time')AS`Time`,    JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Sun.Rise.Sunrise')AS`Sunrise`,    JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Sun.Set.Sunset')AS`Sunset`;

returns

+---------------------+----------+----------+|Time                | Sunrise  | Sunset   |+---------------------+----------+----------+|2023-01-18T09:00:00 |08:44:23 |16:58:02 |+---------------------+----------+----------+

Get some moon info

SET @ts= NOW();SET @latitude=53.182153;SET @longitude=4.854429;SET @timezone= TIMESTAMPDIFF(HOUR, UTC_TIMESTAMP(), NOW());SELECT     JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Time')AS`Time`,    JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Moon.Rise')AS`Moonrise`,    JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Moon.Set')AS`Moonset`,    JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Moon.Phase.Name')AS`Phase`,    ROUND(CAST(JSON_VALUE(astro(@ts, @latitude, @longitude, @timezone),'$.Moon.Age')AS FLOAT)/3.6,0)AS`% Age`;

returns

+---------------------+----------+----------+-----------------+-------+|Time                | Moonrise | Moonset  | Phase           | % Age |+---------------------+----------+----------+-----------------+-------+|2023-01-18T09:00:00 |05:33:24 |12:52:19 | Waning crescent |86 |+---------------------+----------+----------+-----------------+-------+

astro_info()

Returns library info as JSON string

Examples:

>SELECT     JSON_UNQUOTE(JSON_VALUE(astro_info(),'$.Name'))AS Name,    JSON_UNQUOTE(JSON_VALUE(astro_info(),'$."Version"'))AS Version,    JSON_UNQUOTE(JSON_VALUE(astro_info(),'$."Build"'))AS Build;+--------------------+---------+----------------------+| Name               | Version | Build                |+--------------------+---------+----------------------+| lib_mysqludf_astro |1.0.0   | Jan18202309:00:00 |+--------------------+---------+----------------------+

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp