LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with Creating Cluster from 2D Array and Adding Flag for Overlapping Time in LabVIEW

Solved!
Go to solution

Hi all,

 

I'm working on where I have a 2D array of timestamps.

 

One 2D Array represents Total Working Hours

The other 2D Array represents Break Times

 

I want to convert this data into a cluster that includes:

1.Start time

2.End time

3.A flag (0 or 1) indicating whether the entry is break time (1) or working time (0)

 

However, I'm facing an issue where overlapping data is being generated in my current logic, especially when break times and work times cross over or overlap.

 

My goal is to have a clean list of non-overlapping time intervals with the correct flag set.

 

Can someone suggest the right way to structure this logic or share a method to handle overlaps when building the cluster?

 

Any help or sample VI would be much appreciated!

 

Thanks in advance!

0 Kudos
Message 1 of 12
(770 Views)

OK, let's define the problem a little better.

 

  • It would help to show the label of the two input array constants so we can tell what's what.
  • What is the significance of the columns (start and end time?)
  • If intervals overlap, what should take precedence (work or break?)
  • Are boundaries always quantized to 60 minutes (aligned at 0.5 hours), or is this just a simplified dataset?
  • Are the scheduled hours always continuous?
  • Does the day always end in a non-break?
  • Are breaks always 1 hour?

 

Also: do you know that index array is resizable and if you want elements in order, you don't need to wire indices?

0 Kudos
Message 2 of 12
(724 Views)

Thanks for your reply! Here are the clarifications:

 

1. Labels of input arrays:

The first 2D array column is Scheduled Work Time – each row has a start and end timestamp.

 

The second 2D array column is Break Time – again, each row has a start and end timestamp.

 

2. Significance of columns:
Yes, both arrays represent start and end times (i.e., time intervals).


3. If intervals overlap, what should take precedence?
Breaks take precedence — if a break overlaps with work time, that portion should be flagged as a break (flag = 1).


4. Time alignment (quantization):
No, the times are not always quantized to 60 minutes or 0.5 hours. It's just a simplified example. Actual timestamps may have arbitrary minute-level resolution.


5. Are scheduled hours always continuous?
No, there might be gaps between scheduled work periods.


6. Does the day always end in a non-break?
Not necessarily — the day could end during a break.


7. Are breaks always 1 hour?
Not always. Break durations can vary.


8. About Index Array:
Thanks for the tip — yes, I'm aware Index Array is resizable, but I’ll double-check if I’m using it efficiently.

0 Kudos
Message 3 of 12
(701 Views)

@Tusharvp4 wrote:

4. Time alignment (quantization):
No, the times are not always quantized to 60 minutes or 0.5 hours. It's just a simplified example. Actual timestamps may have arbitrary minute-level resolution.


I was curious why you would show millisecond resolution in your timestamps. So the times are quantized to whole minutes?

 


@Tusharvp4 wrote:

5. Are scheduled hours always continuous?
No, there might be gaps between scheduled work periods.


OK that complicates things. So you have three states (scheduled, break off), but don't want to show the off intervals. Can there bet gaps (1) between two work periods, (2) within a break period, (3) immediately before or after a break? (4)....

 


@Tusharvp4 wrote:

8. About Index Array:
Thanks for the tip — yes, I'm aware Index Array is resizable, but I’ll double-check if I’m using it efficiently.


Compare the picture!

 

altenbach_0-1750522562587.png

 

0 Kudos
Message 4 of 12
(688 Views)

Thanks again for your follow-up! Let me clarify a few things:

 

Question - Millisecond resolution in timestamps — are they quantized to whole minutes?

You're right to notice that. In reality, the timestamps are only relevant to the minute level — so quantized to whole minutes. Millisecond precision isn't needed and was just a byproduct of how the timestamps were generated or displayed. I’ll clean that up for clarity.

 

 

Question : Gaps in scheduled time mean three states (work, break, off)?

Correct — in theory, we could say there are three logical states:

 

1. Scheduled Work (flag = 0)

 

2. Break (flag = 1)

 

3. Off (no schedule or break)

 

 

But for now, I want to ignore the "off" state and just build a clean list of non-overlapping work and break intervals, flagged accordingly.

 

Question: Incorrect photo for Index Array usage

Yes — you're absolutely right, I posted the wrong image. I will update the VI screenshot with the correct version showing the resizable Index Array so it’s more readable and aligned with best practices.

 

Thanks again for the sharp observations.

0 Kudos
Message 5 of 12
(679 Views)

Timestamp Format:
All timestamps are in the format:
yyyy-mm-dd hh:mm:ss.000
However, the precision needed is only to the minute — so seconds and milliseconds can be ignored for logic purposes. The .000 is just default formatting.

 

Main Objective:
My primary goal is to build a cluster (or array of clusters) with the following structure:

Flag → 0 for Work, 1 for Break

Start Time

End Time

 

I want to generate a clean, non-overlapping list of time intervals from the input arrays (scheduled work and break times), with each interval correctly flagged.


Just for clarification..I am not currently concerned with visualizing or processing "off" times — only interested in work and break intervals.

 

Appreciate your support and suggestions.

0 Kudos
Message 6 of 12
(674 Views)

@Tusharvp4 wrote:

Just for clarification..I am not currently concerned with visualizing or processing "off" times — only interested in work and break intervals.


But they do overlap, because the end time of one state is the same as the start time of the other state.

Message 7 of 12
(657 Views)

Yes, you are correct — in many cases, the end time of one interval is exactly equal to the start time of the next (e.g., work ends at 12:00 and break starts at 12:00). I don’t consider that an “overlap” — just a clean hand-off between intervals.

 

To clarify:

 

This is expected behavior, and I treat such adjacent intervals as non-overlapping.

 

The logic should simply preserve these as separate clusters, like:

 

As for Examples 

 

Start: 08:00, End: ,09:00, Flag: 0 (work)

 

Start: 09:00, End: ,10:00, Flag: 0 (work)

.

.

.

Start: 12:00, End: 13:00, Flag: 1 (break)

 

 

0 Kudos
Message 8 of 12
(651 Views)

Here are a few suggestions:

  • When you have two or more discrete choices (here, I think you have three -- Work, Break, and Idle, which means "Neither working nor on break", i.e. maybe end of shift, went home for dinner and a good night's sleep).  Note this makes it easy to add, say, "Lunch" without having to do much recording.
  • To make an Enum, go to the Front Panel, right-click where you want it, and from the Drop-Down, choose "Ring & Enum", then "Enum".  Rename it ("Work, Break, other"), then right-click in the middle.and select "Edit Items".  You'll go to the "Properties Page" for this Enum, where you'll define its values, which will be "mapped" to 0, 1, 2, ...  I suggest typing "Work" in the first slot, "Break" in the second, and "Home" or "Idle" on the third (though you can leave it as only two entries, if you want).  
  • Once you've made your Enum (you might give it a name, like "Time Code", and maybe even make it a TypeDef), try it out.  Go to the Front Panel and press the "Up Arrow" three times.  Notice it cycles between Work, Break, Home, Work, Break, Home ... -- it only takes on the values you've created for it, and never "gets stuck" (just like Booleans cycle between 2 states, T or F).  
  • Even if you only want two states, Work or Break, I'd still suggest using an Enum rather than a Boolean, largely because it tells you want the entry means (where as True doesn't intuitively mean either Work or Break -- you have to do something like name the entry "Working?" or something like that.
  • This is also a good time to look at some of the other useful Timing features.  For what you want to do, I'd recommend you create a little LabVIEW VI and do the following:
    1. Go to the Block Diagram.
    2. Drop "Get Date/Time String" from the Timing Palette.
    3. Wire a String Indicator to Date String, and another String Indictor to Time String (use those names for the Indicators.
    4. Run the program.  Note that you have a pair of ready-to-use strings for the Date and Time, with Time to the nearest minute (without hardly doing any work!).
  • When curious about other functions, right-click them, choose Help, and read the Summary help and Detailed Help.

Bob Schor

Message 9 of 12
(613 Views)
Solution
Accepted by topic author Tusharvp4

See if this can give you some ideas:

 

Basically we iterate over all minutes to find state changes. We must assume that each of the input arrays is clean (i.e.  sorted without overlapping ranges between rows. (Rows can overlap between the two input arrays, of course!)

 

altenbach_0-1750534013803.png

 

I am sure things can be simplified more. There could also be bugs, of course.

Message 10 of 12
(606 Views)