Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using AMDB
  2. using DataStructures
  3. using UnicodePlots
  4. using IntervalSets # need to Pkg.checkout the latest version
  5.  
  6. # i made a new function to read the data, replace path for your own machine
  7. records = deserialize_gz(expanduser("~/research/AMDB/data/AMDB_subsample.jls.gz"))
  8.  
  9. # suppose we are counting in 2005
  10. date_interval = Date(2005,1,1)..Date(2005,12,31)
  11.  
  12. # let's look at this spell
  13. # (observe: we can use "values" for extracting Dict values)
  14. spell = first(values(records)).AMP_spells[1]
  15.  
  16. # intersection
  17. intersect(spell.interval, date_interval)
  18.  
  19. # this many days
  20. IntervalSets.width(intersect(spell.interval, date_interval))
  21.  
  22. # but we want an integer
  23. convert(Int, IntervalSets.width(intersect(spell.interval, date_interval)))
  24.  
  25. # we would then push! the above to an accumulator
  26. # ...
  27.  
  28. # wrap this in a function
  29. function spell_durations_in_year(data, date_interval)
  30. c = counter(AMP.Spell)
  31. for d in data
  32. for spell in data.AMP_spells
  33. # do what we did above
  34. end
  35. end
  36. c
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement