Created
January 16, 2017 19:18
-
-
Save tpapp/a5bb2e99a8a282946edfcc0876347544 to your computer and use it in GitHub Desktop.
spell durations in a year
This file contains hidden or 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
| using AMDB | |
| using DataStructures | |
| using UnicodePlots | |
| using IntervalSets # need to Pkg.checkout the latest version | |
| # i made a new function to read the data, replace path for your own machine | |
| records = deserialize_gz(expanduser("~/research/AMDB/data/AMDB_subsample.jls.gz")) | |
| # suppose we are counting in 2005 | |
| date_interval = Date(2005,1,1)..Date(2005,12,31) | |
| # let's look at this spell | |
| # (observe: we can use "values" for extracting Dict values) | |
| spell = first(values(records)).AMP_spells[1] | |
| # intersection | |
| intersect(spell.interval, date_interval) | |
| # this many days | |
| IntervalSets.width(intersect(spell.interval, date_interval)) | |
| # but we want an integer | |
| convert(Int, IntervalSets.width(intersect(spell.interval, date_interval))) | |
| # we would then push! the above to an accumulator | |
| # ... | |
| # wrap this in a function | |
| function spell_durations_in_year(data, date_interval) | |
| c = counter(AMP.Spell) | |
| for d in data | |
| for spell in data.AMP_spells | |
| # do what we did above | |
| end | |
| end | |
| c | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment