0

I have been trying to figure out a practical way to select events of specific period of a machine. I have a historical data of product arrival/process_start/process_finish times (DateTime) to a machine and events (breakdown,repair,maintenance etc.) of the machine with event_start/event_type/event_finish times (DateTime).

I want to identify those events happened at the machine for a product from time it arrives to it finishes the process.

     foreach(var product in productList)
     var resultEvents = from events in eventList 
                        where (data.Machine == product.Machine) && (events.Start<product.Arrival && event.Finish < product.Finish)

This is not giving me proper states, and it gets confusing and ambigious as I outline options when a machine may go down... Is it that I should also use process start or am I looking at more && statements?

A quick feedback is greatly appreciated :) Thanks!

invictus
  • 5
  • 2

1 Answers1

1

You appear to be asking about detecting overlapping ranges, that is - determining if any time within the two ranges intersect. The test for that is in the duplicate post I provided. Using your variable names, it would be as follows:

event.Start <= product.Finish && event.Finish >= product.Arrival

That assumes fully inclusive ranges. More commonly, we use ranges that are inclusive at the start and exclusive at the end. This is also known as a "half-open interval", denoted by [start,end). This prevents any moment being in two different ranges. I highly suggest you use these. If you do, the test changes slightly to this:

event.Start < product.Finish && event.Finish >= product.Arrival

The change is subtle, but it means that it won't include events that start exactly at the product's finish time.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • exactly, great tip! I've tested when you first sent the link; and so far it seems to be doing the job! – invictus Sep 04 '13 at 14:50