mercredi 8 juin 2016

Many to many relationship users to times logged in/out - how to make scalable calculation of total avail time?

I've been trying to do the following:

I have a list of data - can be anything from 10k-200k entries.

The schema is along the lines of:

Username | Status (logged in/out) | time of login/logout

We could have multiple entries per username, and a user can log in or out as many times in a day as required.

The data will always be for a particular day (0000 to 2359 each day)

I'm trying to figure out the percentage of logged in time against total session time.

I can easily find the total session time by creating a pivot, and working out the max-min to get the total session time.

What I'm struggling with is creating a formula to calculate the actual logged in time.

So for example:

User1 logs in at 0800, logs out at 0830, back in again at 1000, off again at 1200, logs in at 1500 and finally logs out for the day at 1600.

Total time here would be 8 hours. Actual in use time would be:

0830-0800 = 0.5 hours
+
1200-1000 = 2 hours
+
1600-1500 = 1 hour
= 3.5 hours total.

This would mean a calculation that will check the first user it starts with (User1), checks if it's User1 we're dealing with (if not, will reset total time to 0 for the next user).

This then needs to check if the status associated with the time is "Logged in" or "Logged out".

It then needs to perform the calculations as above.

To complicate matters, sometimes a machine won't register a disconnect/log off, and we might have another logged in entry after a previous logged in entry.

I don't have use of IFS as I have only Excel 2013.

I come from an OOP background, but Excel logic somehow escapes me.

Is there a way to do this, or am I going about this in completely the wrong fashion?

Sorry if this question is unclear, it's the best that I can articulate it. If you need clarification, I'll try my best.

Thanks all,

Aucun commentaire:

Enregistrer un commentaire