Created
October 29, 2020 00:03
-
-
Save joshooaj/2e50bdde5f46db9994d39d9b7523a4d0 to your computer and use it in GitHub Desktop.
Generate an interval report of sorts, showing the amount of time motion was detected and video was recorded for a given camera over a period of time, split into a given interval of time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Measure-SequenceData { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
| [VideoOS.Platform.ConfigurationItems.Camera] | |
| $Camera, | |
| [Parameter()] | |
| [DateTime] | |
| $Start = [DateTime]::MinValue, | |
| [Parameter()] | |
| [DateTime] | |
| $End = [DateTime]::UtcNow, | |
| [Parameter()] | |
| [TimeSpan] | |
| $Interval = [TimeSpan]::FromDays(1) | |
| ) | |
| begin { | |
| if ($End - $Start -lt $Interval) { | |
| throw "Interval is larger than the time between Start and End" | |
| } | |
| } | |
| process { | |
| $Start = $Start.ToUniversalTime() | |
| $End = $End.ToUniversalTime() | |
| $recordingSequences = ($Camera | Get-SequenceData -SequenceType RecordingSequence -StartTime $Start -EndTime $End -CropToTimeSpan).EventSequence | |
| $motionSequences = ($Camera | Get-SequenceData -SequenceType MotionSequence -StartTime $Start -EndTime $End -CropToTimeSpan).EventSequence | |
| $cursor = $Start | |
| do { | |
| $intervalRecordings = [TimeSpan]::Zero | |
| $intervalMotion = [TimeSpan]::Zero | |
| foreach ($sequence in $recordingSequences) { | |
| # Sequence is after current interval so break out of the foreach and skip to the next interval | |
| if ($sequence.StartDateTime -ge $cursor + $Interval) { | |
| break | |
| } | |
| # Sequence ends before current interval so we need to skip to the next sequence | |
| if ($sequence.EndDateTime -le $cursor) { | |
| continue | |
| } | |
| # Sequence must at least overlap so lets count how much | |
| $tempStart = if ($sequence.StartDateTime -lt $cursor) { $cursor } else { $sequence.StartDateTime } | |
| $tempEnd = if ($sequence.EndDateTime -gt $cursor + $Interval) { $cursor + $Interval } else { $sequence.EndDateTime } | |
| $intervalRecordings = $intervalRecordings.Add($tempEnd - $tempStart) | |
| } | |
| foreach ($sequence in $motionSequences) { | |
| # Sequence is after current interval so break out of the foreach and skip to the next interval | |
| if ($sequence.StartDateTime -ge $cursor + $Interval) { | |
| break | |
| } | |
| # Sequence ends before current interval so we need to skip to the next sequence | |
| if ($sequence.EndDateTime -le $cursor) { | |
| continue | |
| } | |
| # Sequence must at least overlap so lets count how much | |
| $tempStart = if ($sequence.StartDateTime -lt $cursor) { $cursor } else { $sequence.StartDateTime } | |
| $tempEnd = if ($sequence.EndDateTime -gt $cursor + $Interval) { $cursor + $Interval } else { $sequence.EndDateTime } | |
| $intervalMotion = $intervalMotion.Add($tempEnd - $tempStart) | |
| } | |
| [pscustomobject]@{ | |
| IntervalStart = $cursor.ToLocalTime() | |
| IntervalEnd = $cursor.Add($Interval).ToLocalTime() | |
| Recording = $intervalRecordings | |
| Motion = $intervalMotion | |
| PercentRecording = $intervalRecordings.TotalMilliseconds / $Interval.TotalMilliseconds * 100 | |
| PercentMotion = $intervalMotion.TotalMilliseconds / $Interval.TotalMilliseconds * 100 | |
| } | |
| $cursor = $cursor.Add($Interval) | |
| } while ($cursor -lt $End) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment