问题:
我需要使用System.nanoTime()
将带有时间戳的数据集与使用SensorEvent.timestamp
的另一个带时间戳的数据集同步。
说明
我正在研究四轴飞行器的系统识别。数据采集使用Android API完成。我系统的输入是脉冲宽度调制(PWM),它使用频率为200 Hz的System.nanoTime()
加上时间戳。
系统的输出是Androids的传感器测量值,使用SensorEvent.timestamp
加上时间戳。
我检查了很多在线资源,但遗憾的是没有帮助。我可以随时访问SensorEvent.timestamp
所以我使用这个时钟给输入加时间戳吗?
答案 0 :(得分:2)
我担心这个问题有点复杂。 SensorEvent.timestamp
已在某个时刻从System.nanoTime()
切换到SystemClock.elapsedRealtimeNanos()
,但目前还不清楚这是在设备和API级别发生的时间。事实上,它似乎完全依赖于制造商:https://code.google.com/p/android/issues/detail?id=56561
此外,这些时钟相对于不同事件或时间点计数,nanoTime()
不一定在深度睡眠模式下继续计数; Android: time intervals with deep sleep (System.nanoTime(), System.currentTimeMillis(), SystemClock.elapsedRealtimeNanos())
我们找到解决问题的唯一方法是定期以原子方式记录System.currentTimeMillis()
,System.nanoTime()
和SystemClock.elapsedRealtimeNanos()
,并使用SensorEvent.timestamp
和System.nanoTime()
之间的偏移量SystemClock.elapsedRealtimeNanos()
和SensorEvent.timestamp
确定传感器正在使用哪一个。完成后,您可以为每个传感器事件获取绝对时间戳,将System.nanoTime()
和SystemClock.elapsedRealtimeNanos()
或System.currentTimeMillis()
(分别)之间的增量添加到Declare @Top int = null --<< Sets top of Hier Try 12
Declare @Nest varchar(25) ='|-----' --<< Optional: Added for readability
;with cteHB (Seq,Path,PROBLEM_TYPE_ID,PARENT_ID,Lvl,PROBLEM_TYPE_NAME) as (
Select Seq = cast(1000+Row_Number() over (Order by PROBLEM_TYPE_NAME) as varchar(500))
,Path = cast(PROBLEM_TYPE_ID as varchar(500))
,PROBLEM_TYPE_ID
,PARENT_ID
,Lvl=1
,PROBLEM_TYPE_NAME
From problem_type
Where IsNull(@Top,-1) = case when @Top is null then isnull(PARENT_ID,-1) else PROBLEM_TYPE_ID end
Union All
Select Seq = cast(concat(cteHB.Seq,'.',1000+Row_Number() over (Order by cteCD.PROBLEM_TYPE_NAME)) as varchar(500))
,Path = cast(concat(cteHB.Path,'.',cteCD.PROBLEM_TYPE_ID) as varchar(500))
,cteCD.PROBLEM_TYPE_ID
,cteCD.PARENT_ID,cteHB.Lvl+1
,cteCD.PROBLEM_TYPE_NAME
From problem_type cteCD
Join cteHB on cteCD.PARENT_ID = cteHB.PROBLEM_TYPE_ID)
,cteR1 as (Select Seq,PROBLEM_TYPE_ID,R1=Row_Number() over (Order By Seq) From cteHB)
,cteR2 as (Select A.Seq,A.PROBLEM_TYPE_ID,R2=Max(B.R1) From cteR1 A Join cteR1 B on (B.Seq like A.Seq+'%') Group By A.Seq,A.PROBLEM_TYPE_ID )
,cteFinalHier as (
Select B.R1
,C.R2
,A.PROBLEM_TYPE_ID
,A.PARENT_ID
,A.Lvl
,PROBLEM_TYPE_NAME = Replicate(@Nest,A.Lvl-1) + A.PROBLEM_TYPE_NAME
,A.Seq -- < Included for Illustration
,A.Path -- < Included for Illustration
From cteHB A
Join cteR1 B on A.PROBLEM_TYPE_ID=B.PROBLEM_TYPE_ID
Join cteR2 C on A.PROBLEM_TYPE_ID=C.PROBLEM_TYPE_ID
)
Select A.Job_ticket_id
,[Problem_Type_Name(Parent)]=C.PROBLEM_TYPE_NAME
,[Problem_Type_Name(Child)] =B.PROBLEM_TYPE_NAME
,B.PROBLEM_TYPE_ID
,HISTORY_ENTRY.ENTRY_DATE
,case when HISTORY_ENTRY.ENTRY_TEXT like '%Assigned to %Level 2%%' or HISTORY_ENTRY.ENTRY_TEXT like '%Escalated to %Level 2%%' or HISTORY_ENTRY.ENTRY_TEXT like '%Status changed from % to hold%%' or HISTORY_ENTRY.ENTRY_TEXT like '%Status changed from %Hold to %%' then HISTORY_ENTRY.ENTRY_TEXT end as 'History Entry'
,HISTORY_ENTRY.TECH_ID
,A.Report_Date
,A.LAST_UPDATED
,a.STATUS_TYPE_ID AS 'Ticket_Status'
,A.Close_Date
,A.TECH_GROUP_ID
,A.ASSIGNED_TECH_ID
,TECH_GROUP_LEVEL.LEVEL_NUMBER
,PRIORITY_TYPE_NAME
,TECH_GROUP.NAME
,DATEDIFF(MINute, A.REPORT_DATE,A.FIRST_RESPONSE_DATE) as 'time_to_accept'
, DATEDIFF(MINUTE,A.[FIRST_RESPONSE_DATE],A.[CLOSE_DATE]) as 'time_to_resolve'
-----------------------only for tickets open older than 72 hours------------------------------
,DATEDIFF(MINUTE,a.LAST_UPDATED,getdate()) as 'Time_after_Update'
------------------------------------------------------------------------------------------------
,case WHEN DATEDIFF(MINute, A.REPORT_DATE,A.FIRST_RESPONSE_DATE) <= 10 -- < for tickets accepted withiin 10 miniutes and resolved within their priority level minutes
and DATEDIFF(MINUTE,A.[FIRST_RESPONSE_DATE],A.[CLOSE_DATE]) <= case PRIORITY_TYPE_NAME
WHEN 'low' then 960
WHEN 'medium' then 480
WHEN 'high' then 120
WHEN 'Urgent' then 60
end
then 1
else 0
end
AS [SLA Compliant]
,CAST ((sum(case WHEN DATEDIFF(MINute, A.REPORT_DATE,A.FIRST_RESPONSE_DATE) <= 10 -- < for tickets accepted withiin 10 miniutes and resolved within their priority level minutes
and DATEDIFF(MINUTE,A.[FIRST_RESPONSE_DATE],A.[CLOSE_DATE]) <= case PRIORITY_TYPE_NAME
WHEN 'low' then 960
WHEN 'medium' then 480
WHEN 'high' then 120
WHEN 'Urgent' then 60
end
then 1
else 0
end)*100.0)/COUNT(*) as money) as Percent_Compliant
------------------------------JOINS--------------------------------------------------
From JOB_TICKET A
Join cteFinalHier B on A.PROBLEM_TYPE_ID=B.PROBLEM_TYPE_ID
INNER JOIN [SWHD01].[dbo].[PRIORITY_TYPE] ON A.[PRIORITY_TYPE_ID] = [PRIORITY_TYPE].[PRIORITY_TYPE_ID]
INNER JOIN [SWHD01].[dbo].[STATUS_TYPE] ON A.[STATUS_TYPE_ID] = [STATUS_TYPE].[STATUS_TYPE_ID]
inner join [SWHD01].[dbo].TECH_GROUP_LEVEL on A.TECH_GROUP_LEVEL_ID=TECH_GROUP_LEVEL.ID
join TECH_GROUP on TECH_GROUP.ID= TECH_GROUP_LEVEL.tech_group_id
join HISTORY_ENTRY on a.JOB_TICKET_ID=HISTORY_ENTRY.JOB_TICKET_ID
Cross Apply (Select Top 1 * from cteFinalHier Where B.R1 between R1 and R2 and Lvl=1) C
-------------Tickets for the Last 6 months---------------------------------------------------
where datediff(MONTH, A.REPORT_DATE, getdate()) <= 6
and TECH_GROUP.NAME like '%NOC%'
and LEVEL_NUMBER ='2'
Group By C.PROBLEM_TYPE_NAME,a.JOB_TICKET_ID,B.PROBLEM_TYPE_NAME,B.PROBLEM_TYPE_ID, a.REPORT_DATE,a.CLOSE_DATE,SWHD01.dbo.PRIORITY_TYPE.PRIORITY_TYPE_NAME,a.FIRST_RESPONSE_DATE,B.R1,a.LAST_UPDATED,a.STATUS_TYPE_ID,a.TECH_GROUP_ID,TECH_GROUP_LEVEL.LEVEL_NUMBER,TECH_GROUP.NAME,a.ASSIGNED_TECH_ID,HISTORY_ENTRY.ENTRY_DATE,HISTORY_ENTRY.ENTRY_TEXT,HISTORY_ENTRY.TECH_ID
Order By B.R1
。它并不完美,并且可能会在几毫秒内完成,但它可以达到它的最佳状态。
希望有所帮助!