Find the period of over speed ?
Posted
by Vimvq1987
on Stack Overflow
See other posts from Stack Overflow
or by Vimvq1987
Published on 2010-06-01T07:33:41Z
Indexed on
2010/06/01
7:43 UTC
Read the original article
Hit count: 165
Just something interesting come in my mind. Assume that we have a table (in SQL Server) like this:
- Location
- Velocity
- Time
What is the best way to determine over speed periods (speed barrier is defined) ? My first idea was loading the table into an array, and then iterate over array to find these periods:
(Pseudo C# code)
bool isOverSpeed = false;
for (int i =0;i<arr.Length;i++)
{
if (!isOverSpeed)
if (arr[i].Velocity > speedBarrier)
{
#insert the first record into another array.
isOverSpeed = true;
}
if(isOverSpeed)
if (arr[i].Velocity < speedBarrier)
{
#insert the record into that array
isOverSpeed = false;
}
}
It works, but somewhat "not very effectively". Is there a "smarter" way, such as a T-SQL query or another algorithm to do this?
© Stack Overflow or respective owner