Last active
December 6, 2021 16:21
-
-
Save danielharan/8f23928bc97051e21d77c93c96baaeed to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env ruby | |
require 'optparse' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: example.rb [options]" | |
opts.on("-r", "--rt [Float]", Float, "Rt value") do |v| | |
options[:rt] = v | |
end | |
opts.on("-c", "--cases [Integer]", Integer, "Number of cases today") do | v| | |
options[:cases] = v | |
end | |
opts.on("-l", "--lower [Float]", Float, "Lower bound of Rt's 95% CI") do |v| | |
options[:lower_bound] = v | |
end | |
opts.on("-u", "--upper [Float]", Float, "Upper bound of Rt's 95% CI") do |v| | |
options[:upper_bound] = v | |
end | |
end.parse! | |
def estimate(rt, days_from_now, cases) | |
((rt**(1/2.9))**days_from_now * cases).floor | |
end | |
# formula given by Ryan Imgrund; 2.9 is the generation time | |
# https://twitter.com/imgrund/status/1467516798656466946 | |
days_from_now = 24 - Time.now.day | |
xmas_estimate = estimate(options[:rt],days_from_now, options[:cases]) | |
upper_estimate = estimate(options[:upper_bound],days_from_now,options[:cases]) | |
lower_estimate = estimate(options[:lower_bound],days_from_now,options[:cases]) | |
tweet = "Given an Rt value of #{options[:rt]} (95% CI: #{options[:lower_bound]}-#{options[:upper_bound]}) #{options[:cases]} cases today would lead to #{xmas_estimate} cases by December 24th (#{lower_estimate}- #{upper_estimate})" | |
# KLUDGE: quick DIY encoding that will be tolerated by Twitter | |
tweet = tweet.gsub("%", "%25").gsub(" ", "%20").gsub(":", "%3A") | |
p tweet | |
# p tweet.length | |
system("xdg-open", "https://twitter.com/compose/tweet?text=#{tweet}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment