Skip to content

Instantly share code, notes, and snippets.

@petersen-poul
Last active January 26, 2018 07:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petersen-poul/0cf5022ed1768837fe13af72b2488329 to your computer and use it in GitHub Desktop.
Save petersen-poul/0cf5022ed1768837fe13af72b2488329 to your computer and use it in GitHub Desktop.
{
"name": "Moon Phase",
"description": "Extends a dataset with a data field to include the moon phase percentage and name.",
"inputs": [
{
"name": "dataset-in",
"type": "dataset-id",
"description": "Dataset for extending with moon phase information."
},
{
"name": "date-field",
"type": "string",
"description": "The name/id of the date field to use to calculate the moon phase."
}
],
"outputs": [
{
"name": "dataset-out",
"type": "dataset-id",
"description": "The ID of the extended dataset"
}
]
}
; Given a dataset and the name/id of a date field, this
; extends the dataset with two new fields:
; The percentage of the moon phase new=0, full=50, new=100
; The name of the phase
; The phase is computed by modular division of the lunar phase
; from the UNIX epoch, and is therefore useless for dates before Jan 1, 1970
(define (moon-phase dataset-in date-field)
(create-and-wait-dataset {
"origin_dataset" dataset-in
"new_fields" [
{
"field" ( flatline "( / ( mod ( - ( / ( epoch ( field {{date-field}} )) 1000 ) 621300 ) 2551443 ) 2551442 )" )
"name" "Moon Phase%"
},
{
"field" ( flatline "( let ( pp ( / ( mod ( - ( / ( epoch ( field {{date-field}} )) 1000 ) 621300 ) 2551443 ) 2551442 )) ( cond ( < pp .05 ) \"New\" ( < pp .20 ) \"Waxing Crescent\" ( < pp .30 ) \"First Quarter\" ( < pp .45 ) \"Waxing Gibbous\" ( < pp .55 ) \"Full\" ( < pp .70 ) \"Waning Gibbous\" ( < pp .80 ) \"Third Quarter\" ( < pp .95 ) \"Waning Crescent\" \"New\" ))" )
"name" "Moon Phase"
}
]
})
)
(define dataset-out (moon-phase dataset-in date-field))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment