Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement