Consider the following:
data={{{3544128000, 80}, {3544732800, 80}, {3545337600, 80},
{3545942400, 80}, {3545942400, 160}, {3546547200, 160}, {3547152000, 0}}};
After the satisfying answers to my former question (Part 1), another issue occurred, but with the same background (List-operations only when restrictions are fulfilled):
After applying
Transpose[{#[[All, 1, 1]],
Total[#[[All, All, 2]], {2}]}] &[#] & /@ (GatherBy[#, First] & /@
data)
on data
(thanks to Andy Ross for the approach), I receive
{{{3544128000, 80}, {3544732800, 80}, {3545337600, 80}, {3545942400, 240},
{3546547200, 160}, {3547152000, 0}}}
which resembles to
{{x_-n*604800_, y_},...,{x_-604800_, y_}, {x_, u_},
{x+604800_, z_},{x_+2*604800_, z_},...,{x_+m*604800_, z_}}
I would like to do the following:
u_->y_
(Transform u_ to y_)
residual=(y_-u_)/(n+1)
(Calculate residual of y_ and u_ and divide it be n+1
)
{{x-n*604800_, y_+residual},...,{x-604800_, y_+residual}, {x_, y_+residual},{x+604800_, z_},{x_+2*604800_, z_},...,{x_+m*604800_, z_}}
(Distribute residual
to all periods from x_-n*604800
to x_
)
The result in case of data
will then be:
{{{3544128000, 120}, {3544732800, 120}, {3545337600, 120}, {3545942400, 120},
{3546547200, 160}, {3547152000, 0}}}