How can I calculate rate (events per minute) in Google Sheets? - google-sheets

I am working on creating a spreadsheet template for a video observation tool that my organization will use. Specifically, we will watch ~20-minute long videos, and record the rate (occurrences per minute) of certain behaviors within subsections of the video. For example, "in the clip from 2:06 to 4:30, the speaker asked the audience an average of 2.5 questions per minute."
I think it would be easiest for users to denote individual clips by providing start and end times (e.g. Start: 22:40 End: 23:02). Users should be able to input a count of certain occurrences, and then the spreadsheet will divide that number by the time elapsed and calculate a rate per minute. That is to say, if the speaker asked 8 questions between the timestamps 22:40 and 24:20, the spreadsheet should return a value of 8/(1.67 minutes) = 4.8 questions per minute.
I'm having trouble figuring out a way to enter time values in Google Sheets without it treating them as actual times in a 24-hour day. For example, 22:40 shouldn't refer to 00:22:40am nor to 10:40pm; I just mean 22 minutes and 40 seconds. I guess in theory, I would need it to treat the End Time as x-many minutes (or fractions of a minute) after a given Start Time, so it would need to calculate the total number of seconds elapsed between two mm:ss values and divide that sum by 60 to get the time elapsed in minutes. Then, I could simply divide the count of occurrences (e.g. 8 questions) by that number (1.67 minutes), and get my answer.
Does anyone have any tips about how this could be done? Thank you so much for your help!!
Current State:
Start Time: 22:40
End Time: 24:20
Questions Asked: 8
When I enter =8/(End Time - Start Time), I get 0:00 for some reason. I want it to return 4.8.

Format those durations as Format > Number > Duration. Enter durations complete with elapsed hours, minutes and seconds, as in 0:22:40 and 0:24:20.
You can then calculate events per minute like this:
=E2 / 24 / 60 / (T2 - S2)
...where E2 is the total number of events, S2 is the start moment, and T2 is the end moment.
Format the formula cell as Format > Number > Number.
See this answer for an explanation of how date and time values work in spreadsheets.

Related

A Time Series with a strange behaviour

I hope everyone is doing well.
I am working on a time series project to predict hourly the waiting time (idle time) of a zone.
The idle time of a zone at a given hour is the average idle time of vehicles that start to wait at the given hour in that zone, and the idle time of a vehicle is the amount of time a vehicle should wait in that zone to be booked. For example, if we predict at 16h00 for zone A, a value of 90 minutes, it means a vehicle that starts to wait in this zone between 16h00 and 17h00 will wait 90 minutes to be booked.
For our idle time (our ground truth), at a given hour B, we have to wait 2 days (48 hours) to establish the complete ground truth value for hour B since we have to wait a maximum of two days for vehicles that start to wait at B and are not booked yet. So each time we want to make a prediction, the last 48 points are unstable. For example, if we want to make a prediction at time n, the ground truth of n-1 is partial and incomplete, and we have to wait 48–1 = 47 hours to establish the final value of the waiting time at n-1.
We can resume that problem as the recent past data at prediction time is changing and not fixed.
The following image illustrates what I explained above.enter image description here
My questions are :
Is this kind of behaviour known in the time series field? If that's the case, does it have a specific name?
2-How to mix stable and unstable points in order to make accurate predictions?
Any suggestions? and thank you ahead of time:)

Calculating sleep duration (before and after midnight) in Google Sheets

I am trying to calculate the total number of minutes spent in bed overnight by inputting the time entered bed (e.g. 9pm) and time exited bed (e.g. 6am).
Using those example inputs, the answer should be 9hours, or 540minutes (9*60).
Instead, my formula counts backwards, grabbing the duration from 6am to 9pm which is 15hours, or 900min.
Here is what I have so far. The formula on F2 works just fine until you cross midnight in C2. For example, if B2 is 9pm and C2 is 11pm, F2 is 120minutes. Once you change C2 to 12pm (0:00 in 24hour notation), the calculation flips and becomes 540minutes.
I'm thinking since the cells like to count backwards, I could maybe take 24 hours and subtract it by the value in F2, effectively getting back the other portion?
I stumbled into a weird pseudo-fix: if B2 is 21:00 (9pm) and I put 30:00 into C2, C2 displays 6:00 and F2 counts properly. Here is what that looks like. I am hoping to find a better solution than this-- the UX i'm looking to achieve is just putting my bed time and my wake time and the cells do the rest.
Thanks in advance!!
Drop the abs.
C2-B2
already assumes next day when C2<B2 as shown here:
The reason it works is that Google Sheet treats those as (duration of) time. And when displaying time, the "minus amount" is converted to a positive time value that represents a time of the previous day, as if modulus 24 hours. For example, 7:00 (hour) minus 21:00 (hour) gives -14:00 (hour) and it will be displayed as 24:00 (hour) - 14:00 (hour) = 10:00 (hour). Thus it is equivalent to the number you are looking for. However, modulus 24 hours effect is only for display. The minus sign is still inherent to the resultant value.
In order to display minutes or do other calculations with the result, you can wrap it with timevalue(). With that, the underlying value will be converted as described above.
To then display minutes, you can format the cell to display Elapsed minutes using the steps shown below.
And you will see minutes in the cell as shown below.
Your question implies that you may desire to do calculations on the result.
If that is that case, it helps to know that the output of timevalue is time duration in (fractions of) days without any inherent formatting. If not, you may skip the followings.
For example, in the preceding image, if you put =C1*2 in D1, with automatic formatting, D1 will inherit the format of C1, which was Elapsed minutes. You will thus see 1440. However, the actual underlying value is 1 because the real meaning of the data is half a day times 2. And you can confirm that by setting the format of D1 as numbers.
Thus, if you are only doing calculations with outputs of timevalue, you are fine without worrying about the above. However, if you mix the result of timevalue with other types of data, the fraction of day meaning is what will be used in your calculations.

Google sheets convert Decimal(0-100) to minutes(0-60)

I have a spreadsheet that receives data from an RPA, this data is HH:MM, the output is based on how long a task has taken to perform.
example:
Project
Time
Task 1
2:35
Task 2
3:45
Where 2:35 is equal to 2 hours and 35 minutes.
The issue that i am having is that when I add these numbers google sheets displays it as 5:80, where it should be 6:20, as that is the actual amount of hours and minutes represented in the table. In other words I would like the decimal counter to stop at 60 and add new, not at a 100?
Anybody have an idea of how to achieve this? :)
-- Toby
In order for the duration formatting to work the delimeter must be the correct standard according to the language you are working in.

How do I add duration to a time in Google Sheets?

I've found a few answers to questions similar to this elsewhere, except with adding or subtracting two times to get a duration, however, I haven't been able to figure it out enough to meet what I want.
I'm trying to get the time that I woke up using the time that I went to bed and the duration. I've tried doing [Time] + [Duration], however when I do that I get a value like 10060:25:00. I've also tried adding the hour value of the duration and the hour value of the time and dividing by 24, but that didn't work either. I did figure out the minutes though, all I did was =MOD([Time minute value]+[Duration minute value],60).
So to clarify, I just need to find the hour value now.
I am not exactly sure if this answers your question, but I think it is very similar. And I apologise in advance for an unnecessarily complicated description.
Sorry I didn't have time to provide a shorter answer.
I wanted to create a run sheet for a workshop with session durations.
I have a start time, and each session has a duration. I can then calculate start time for next session and cumulative duration of the sessions.
column label :> A || B || C || D
Heading label:> start_time || duration || hidden_duration || Elapsed
Number format:> date/time || number || duration ||duration
new start_time=previous_start_time+hidden_duration
hidden_duration=if(isblank(duration),"0:00:00","0:"&duration)
It seems time is particular about how it interprets a number. This is where the duration format fits in, as it formats correctly to add to time. However, a field formatted as a "duration number format", must then be entered as a duration. In other words, it is expected as 00:00:00.000 which is very particular. Or in fact, it appeared it at least needed 00:00 i.e. Hours and minutes separated by colon.
As I only had minutes, I didn't want to have to enter in this particular format all the time; and if I was to put 5 in the duration field, it was being interpreted as 5 milliseconds (or something). So I have used a simple number in the duration field and inserted it into a string in the hidden_duration field to form 0:duration. For example to add 5 into the minutes column of the hidden_duration entry it would be "0:"&5. The if(isblank(),...test was necessary to avoid blank durations voiding all the way down the column. i.e. If duration was blank, add 00:00:00 time to the start_time.
Start_time Duration Hidden_duration Elapsed
08:30:00 15 =if(isblank(B2),"0:00:00","0:"&B2&":00") =C2
=A2+C2 5 =if(isblank(B3),"0:00:00","0:"&B3&":00") =D2+C3
Drag the second row down to repeat however many entries you will have.
Don't forget to make the appropriate columns the correct number formats.
Also, you can modify the duration formats using Format | Number | More formats| Custom Number Formats and removing the unwanted display fields (such as seconds).
Then, I also made some conditional formatting rules, so that if a duration was blank, the Elapsed and time cells were white text on white background so they looked blank.
For your application you could do the same but have separate hours and minutes columns to make for easy data entry, both being used in the "hidden_duration" formula.
I hope I have helped here, as I found your question, trying to do the same and Googling an answer, but then ended up experimenting and discovering some new things myself.
Someone more knowledgable may be able to correct my entry or make more efficient. {Or at least explain more efficiently (; }
=HOUR(B2-A2)+(MINUTE(B2-A2)/60)
Basically, being B2 the end time and A2 the start time, you subtract B2-A2 and get the hour from the subtraction. Then you do the same and get the amount of minutes. After you have both, you sum the amount of hours with the amount of minutes divided by 60 (to get it in hours).
Don't forget to use the 24-hour format (i.e. 10:00 or 22:00).

HKUnit for Sleep Analysis?

I'm need to query HealthKit for HKCategoryTypeIdentifierSleepAnalysis data, but can't find the compatible HKUnit for quantity value. Apple documentation is silent on units for Sleep Analysis. Am hoping someone already knows the answer.
BTW, the iOS Health app shows Hrs & Minutes on the Sleep chart, but the HKUnit reference doesn't include options for such composite units.
In Apples documentation I found this:
By comparing the start and end times of these samples, apps can calculate a number of secondary statistics: the amount of time it took for the user to fall asleep, the percentage of time in bed that the user actually spent sleeping, the number of times the user woke while in bed, and the total amount of time spent both in bed and asleep.
This means that you have to use the startDate and endDate property of your sample to calculate sleep durations.
Sleep samples are instances of HKCategorySample, which is unit-less. You should perform calculations for sleep samples using the startDate and endDate properties on the sample.

Resources