Created
December 13, 2016 16:06
-
-
Save tpapp/d5de020e933ac559c89ec67e80b9a939 to your computer and use it in GitHub Desktop.
spell fractions
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 GZip | |
| using UnicodePlots | |
| using IntervalSets | |
| # if we want to pass around code, extend it with your own machine name | |
| # (gethostname# ()) and path | |
| AMDB_path = get(Dict("tamas" => | |
| "/home/tamas/research/AMDB/data/AMDB_subsample.jls.gz"), | |
| gethostname(), | |
| "/Users/emmamckeown/Documents/Thesis/AMDB_subsample.jls.gz") | |
| records = GZip.open(deserialize, AMDB_path, "r") | |
| """ | |
| Return an accumulator of total a time spent in spells within an interval. | |
| """ | |
| function spell_totals(records, interval) | |
| acc = Accumulator(AMP.Spell, Int) | |
| for (_, data) in records | |
| spells = data.AMP_spells | |
| for spell in spells | |
| l = convert(Int, | |
| IntervalSets.width(intersect(interval, spell.interval))) | |
| push!(acc, spell.status, l) | |
| end | |
| end | |
| acc | |
| end | |
| "Normalize an associative collection." | |
| function perc(acc) | |
| total = sum(acc) | |
| pairs = [Pair(key,value/total) for (key,value) in acc if value > 0] | |
| sort(pairs, by = x->x.second, rev = true) | |
| end | |
| showall(perc(spell_totals(records, Date("1990-01-01")..Date("1990-12-31")))) | |
| showall(perc(spell_totals(records, Date("2000-01-01")..Date("2000-12-31")))) | |
| showall(perc(spell_totals(records, Date("2010-01-01")..Date("2010-12-31")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment