I have the following data which I randomally generated in kusto.
let data = datatable(BatchNumber: int,Timestamp:datetime, Power1:int, Power2: int, Speed1: int, Speed2: int, Enabled1: bool, Enabled2: bool)
[
1, datetime(2022-02-18 10:00:00 AM), 100, 200, 50, 80, false, true,
1, datetime(2022-02-18 10:01:00 AM), 100, 200, 50, 80, true, true,
1, datetime(2022-02-18 10:02:00 AM), 100, 200, 50, 80, false, true,
1, datetime(2022-02-18 10:03:00 AM), 100, 200, 50, 80, true, true,
1, datetime(2022-02-18 10:04:00 AM), 100, 200, 50, 80, false, true,
1, datetime(2022-02-18 10:05:00 AM), 100, 200, 50, 80, true, true,
1, datetime(2022-02-18 10:06:00 AM), 100, 200, 50, 80, false, true,
1, datetime(2022-02-18 10:07:00 AM), 100, 200, 50, 80, true, true,
2, datetime(2022-02-18 10:08:00 AM), 100, 200, 50, 80, false, true,
2, datetime(2022-02-18 10:09:00 AM), 100, 200, 50, 80, true, true,
2, datetime(2022-02-18 10:10:00 AM), 100, 200, 50, 80, false, true,
2, datetime(2022-02-18 10:11:00 AM), 100, 200, 50, 80, true, true,
2, datetime(2022-02-18 10:12:00 AM), 100, 200, 50, 80, false, true,
2, datetime(2022-02-18 10:13:00 AM), 100, 200, 50, 80, true, true,
2, datetime(2022-02-18 10:14:00 AM), 100, 200, 50, 80, false, true,
2, datetime(2022-02-18 10:15:00 AM), 100, 200, 50, 80, true, true,
2, datetime(2022-02-18 10:15:00 AM), 100, 200, 50, 80, false, true
];
What I am trying to achieve here is to check when is the batch finished. The logic to do that is to get the last value of a batch number and check the value after it. If the next value is different from the one before then the previous batch is finished. So in this case, batch number = 1 is finished but batch number 2 not yet. However, in this case I shouldn't be checking for a specific batch number because we are getting values in real time. The script should know by itself when is the batch finished probably by doing a scheduler which runs every 5 minutes to check if the batch is finished based on the logic I explained above (in bold), and when it knows that the batch is finished, it should project this batch number, Batch_Date (in this case for batch number = 1, the date is 2022-02-18 10:07:00 AM), and total power (which is based on some calculations only for this finished batch)
For example expected result for BatchNumber = 1:
In this case, once the script knows that batch number 2 is also finished a new record will be added with this batch number. Let us assume that one addition row was added to the dataset with batch number = 3, so the expected result would be:
So everytime the script knows that a batch is finished it should directly add it as a new record as shown in the screenshots, projecting the new batch, the date when it was finished and some calculations specifically for newly added batch.
I am a bit confused how can I do this in Kusto? If it is possible or not ? I don't know if a scheduler is needed in this case or if there is a better and efficient way to do it?

