Custom Weighted Formula I'm in need of a mathematical formula that will be ultimately utilized in any programming language that would give me a value that I could ultimately sort or rank by. I have 2 variables:
variable 1 = just some arbitrary count (could be something like 0, 1, 5, 20, 50, 100)
variable 2 = number of days that passed since current date (could be 0, 1, 2, 50, 100)
I'm in need of a weighted custom formula where:


*

*between 0-30 days from current date, variable 1 (count) starts at 100% weight and variable 2 at 0% weight. As each day passes up to 30 days, variable 1 weight goes down to 50% on day 30 and variable 2 (number of days passed) increases from 0% to 50% on day 30

*between 31-60 days from current date, variable 1 starts increasing from 50% to 100% peaking at day 60 and variable 2 starts decreasing to 0 and goes to 0 on day 60

*beyond day 60, variable 1 is always at 100% and variable 2 obviously at 0%


To provide a few examples:
1) set #1: x1 = 5,x2 = 1; set #2: x1 = 5,x2 = 2 -> set #1 should rank higher
2) set #1: x1 = 5,x2 = 1; set #2: x1 = 6, x2 = 2 -> set #2 should rank much higher because it's in the beginning of 1st 30 days and x1 should be around 90% and x2 close to 10% so x1 is what counts here
As x2 increases and reaches day 30, x1 and x2 become equal in their weight. After day 30, x2 starts to lose its weight and on day 60 becomes meaningless and stays at 0. On day 15 though, x1 has much bigger weight than x2.
Note: All things being equal x1 = 100 is equivalent as x2 = 30. x1 is an arbitrary count and x2 is number of days so I can't do x1 != x2 != 1
I have the following but it does not cover the 2 examples above:

    float k = abs(x2-30.0);
    if (k < 30.0) {
        // Rule 1 and 2
        rank = k/60.0 + (60.0-k) * x1 / 60.0;
    } else {
        // Rule 3
        rank = x1;
    }
    return rank;

I apologize as I do not know which tags to apply. If this post is unclear, please suggest and I will edit so it makes more sense. I figured providing rules and few examples would suffice.

Let $k$ be the number of days since the current date.  Then $60-k$ is the number of days remaining till $60$ days after the current date.
When $k \leq 30$ your first weight $w_1$ can be calculated as:
$$w_1 = 100\% - w_2 = 100\%*\left(1 - \frac{k}{60}\right)$$
and the second one is the remaining weight
$$w_2 = 100\% * \frac{k}{60}$$
When $k > 30$ your first weight $w_1$ can be calculated as:
$$w_1 = 100\% * \frac{k}{60}$$
and the second one is the remaining weight
$$w_2 = 100\% - w_1 = 100\%*\left(1 - \frac{k}{60}\right)$$
For $k > 60$ just set $w_1 = 100\%$ and $w_2 = 0\%$.
