Skip to content

Instantly share code, notes, and snippets.

@timjonesdev
Created April 26, 2019 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timjonesdev/9361ceef3f77b7669941e88430262b82 to your computer and use it in GitHub Desktop.
Save timjonesdev/9361ceef3f77b7669941e88430262b82 to your computer and use it in GitHub Desktop.

Calculation of Projected Order Expiration

Sorting based on relative expiration time.

Algebra for calculating when value will equal zero: We project when value will equal zero, and compare number of seconds

v = (s - x) - (d * x)

Solve for the slope-intercept form:

v = -dx - x + s
v = -(d + 1)x + s
Slope = -(d + 1)
y-Intercept = s

When v = 0, the item is, by definition, expired. So, solve for x when v = 0 to find the order age when it expires.

0 = -(d + 1)x + s    ==>     -s = -(d +1)x     ==>      x = s / (d + 1)

This gives us the number of seconds from the beginning of the order when the item will expire. But what if the decay rate changes at any point? For example, if the order was moved to the overflow shelf at some point, then how do we project the new projected expiration? For this, let's examine the relationship between shelfLife and value.

We know that s is the y-intercept of the linear value equation. We can think of the initial shelfLife as the current value of the item before it begins to decay. Now we want to calculate the number of seconds before the item expires given any time t between order start and expiration. For this we can think of an entirely new function where s = [current value]. This gives us:

v = -(d + 1)x + [current value]

And we already know how to calculate the number of seconds until the item expires, so:

x = [current value] / (d + 1)

This allows us to continually update the projected expiration, and make better decisions about how to minimize waste in the system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment