Skip to content

Instantly share code, notes, and snippets.

@jaor
Last active May 3, 2019 03:37
Show Gist options
  • Save jaor/b7b75f4309fe274874f9c5d657b22aad to your computer and use it in GitHub Desktop.
Save jaor/b7b75f4309fe274874f9c5d657b22aad to your computer and use it in GitHub Desktop.
Remove constant fields
{
"name": "Remove constant fields",
"kind": "script",
"description": "Remove fields that are constant",
"source_code": "script.whizzml",
"imports":[
],
"inputs":[
{
"name": "input-dataset",
"type": "dataset-id",
"description": "The dataset to clean up"
},
{
"name": "keep-datetimes?",
"type": "boolean",
"default": false,
"description": "Whether to keep datetime fields (removed by default)"
}],
"outputs":[
{
"name": "dataset",
"type": "dataset-id",
"description": "The cleaned up dataset"
}]
}
(define (clean-up ds-id)
(let (fds (resource-fields ds-id)
fds (map (lambda (id f) (assoc f "id" id)) (keys fds) (values fds))
cf? (lambda (fd)
(and (or (not (datetime-field? fd))
(not keep-datetimes?))
(< (count (field-distribution fd)) 2)))
excl (map (lambda (f) (f "id")) (filter cf? fds)))
(wait (create-dataset ds-id {"excluded_fields" excl}))))
(define dataset (clean-up input-dataset))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment