Decay-o-meter
When will a number reach a given target?
Introducing Decay-o-meter
Are you a monitoring the decrease (or growth) of something? Whenever you have a (positive) number that varies with time, you may wonder when it will reach a given (positive) target value, assuming it will go on decaying (or rising) with the same linear or exponential trend.
Which number? Any number, its meaning doesn't matter. As long as you have two (positive) values at two distinct points in time and a (positive) target, you can estimate (by linear or exponential extrapolation) when the number will reach the target.
Decay-o-meter: the script
Decay-o-meter is a little AWK script that takes two successive points in time and corresponding (positive) values. It uses this input to (linearly and exponentially) extrapolate the trend and predict when the value will reach a given (positive) target, assuming that the same trend is kept.
Warning: it goes without saying that the estimated time of arrival is just that, an estimate: it will match reality, only if the same (linear or exponential) trend is kept.
Decay-o-meter is distributed under the terms of the Expat license and can be downloaded here.
The script is not difficult to use: just run it, passing five values as arguments, as shown in the following example:
$ decay-o-meter -v target=2.1 \ -v t1=$(date +%s -d '2025-01-01 18:00') -v v1=137.4 \ -v t2=$(date +%s -d '2025-01-08 18:00') -v v2=113.9 Previous values ---------------------------------------------- Wed, 01 Jan 2025 18:00:00 +0100: 137.4 Wed, 08 Jan 2025 18:00:00 +0100: 113.9 Value has decreased by 23.5 (17.1 %) in 604800.0 s (about 7 days) Slope: -3.88558e-05 / s (-3.35714 / day) Estimated (linear) time to 2.1: 2877303.8 s (about 33 days) Value will reach 2.1 on Tue, 11 Feb 2025 01:15:03 +0100 Half-life: 2.23492e+06 s (about 26 days) Estimated (exponential) time to 2.1: 12875872.6 s (about 149 days) Value will reach 2.1 on Fri, 06 Jun 2025 19:37:52 +0200 Forecast (lin) (exp) ------------------------------------------------------------ Wed, 15 Jan 2025 18:00:00 +0100: 90.4 94.4193 Wed, 22 Jan 2025 18:00:00 +0100: 66.9 78.2704 Wed, 29 Jan 2025 18:00:00 +0100: 43.4 64.8836 Wed, 05 Feb 2025 18:00:00 +0100: 19.9 53.7863 Wed, 12 Feb 2025 18:00:00 +0100: -3.6 44.587
The scripts wants the two instants (t1 and t2) as Unix times: date(1) has been used to convert dates to Unix times. The two corresponding values are v1 and v2, respectively, while the target value is target.
This work can be redistributed and/or modified under the terms of the Expat license. It comes with absolutely no warranty. See the permission notice for details.