Last active
May 3, 2019 03:37
-
-
Save jaor/b7b75f4309fe274874f9c5d657b22aad to your computer and use it in GitHub Desktop.
Remove constant fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
}] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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