Ordinary min-max scaling needs the whole column up front: you find the smallest and largest values, then squeeze everything onto [0, 1]. A live system doesn't have that luxury — readings arrive one at a time and each has to be scaled the moment it lands, using only what has been seen so far.
Task: write streaming_minmax(stream) returning one scaled value per incoming value, each rounded to 4 decimal places.
For each value, in order:
(value - min_so_far) / (max_so_far - min_so_far).0.0 — it is simultaneously the smallest and largest thing seen.max - min is zero. Return 0.0 for that value rather than dividing by zero.That last rule is the honest part and the uncomfortable part: the same reading can map to different numbers depending on when it showed up. Offline scaling can't tell you that; a live pipeline has to live with it.