Skip to content

Instantly share code, notes, and snippets.

@tpapp
Created January 16, 2017 19:18
Show Gist options
  • Select an option

  • Save tpapp/a5bb2e99a8a282946edfcc0876347544 to your computer and use it in GitHub Desktop.

Select an option

Save tpapp/a5bb2e99a8a282946edfcc0876347544 to your computer and use it in GitHub Desktop.
spell durations in a year
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