Last active
December 17, 2015 17:29
-
-
Save BlackMaria/5646409 to your computer and use it in GitHub Desktop.
A simple linear function used to emulate accumulative ticks during a day ( 6am-6am). Code outputs two values +30% and the estimated ticks water marks. This is by first ruby code :)
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
#!/usr/bin/env ruby | |
# | |
# The idea here is, tick is almost a linear function. We really want a | |
# tick_function and compare based on time of day, but this will do for now. | |
# | |
# We can almost determine the typical linear increase of errors | |
# based on time of day. So here we assume that the linear starts | |
# at 6am and increases until 6am the next day. | |
# | |
# NB: One flaw is that the values are less relevant before noon :} | |
# *** BUT this is much better than a static number *** | |
max_tick_per_day=600 | |
day_in_seconds=86400 | |
warn_percent=1.30 | |
# get the time | |
now = Time.new | |
# | |
# Define the day as starting from 6am | |
today=Time.local(now.year, now.month, now.day, 6, 0).to_i | |
# Define tomorrw as staring as 6am | |
tomorrow=today + day_in_seconds | |
######################################################################### | |
# | |
# Calculate ticks ( we could pass a value once a tick_function has been devised ) | |
# | |
# My theory for future incarnations of this script | |
# If we get a big spike the same increase should still apply so... | |
# | |
# take the "current ticks" minus "what it should be" should give you an offset... | |
# So, then we offset the "max_tick_per_day" by this differance PLUS 10% to be sure | |
# add_offset_to_tick() = what_is_tick_now() - what_tick_should_be() | |
# | |
max_tick_per_sec=( max_tick_per_day.to_f / day_in_seconds.to_f ) | |
what_tick_should_be= ( max_tick_per_sec.to_f * ( now - today ).to_f ) + 10 | |
warning=what_tick_should_be / warn_percent | |
puts "#{what_tick_should_be.to_i} #{warning.to_i}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment