我正在开发一个项目,我必须确定驾驶事件何时结束。一个函数被赋予一个HashMap<Date, Integer>
,其中包含车辆/步行的置信水平,与unix时间戳一起以百分比的形式。Java HashMap迭代寻找驱动结束事件
我正试图迭代这个HashMap,确定一个驾驶事件是否已经结束。
我是一名PHP开发人员,使用这样的Java逻辑是一个真正的挑战,我努力实现一些应该很简单的事情。任何帮助赞赏。
继承人的逻辑,我想实现:
If
we have at least 1 minute worth of data with 10 items in our HashMap
then
loop HashMap
if past 30 seconds of time, from 30 seconds ago contain driving data of 60% confidence adverage or above then
AND past 30 seconds of time from now contains working data with average 60% confidence or above
then
mark isDriving as true
if isDriving == true
then
doSomething()`
我的HashMap中看起来是这样的:
private HashMap mActivityData = new HashMap<String, Long>();
mActivityData.putExtra("in_vehicle",80); // % confidence
mActivityData.putExtra("on_foot",10); // % confidence
mActivityData.putExtra("time",1461684458); // unix time stamp
让您的仿制药正确使用,例如对于显示的数据:'private HashMap mActivityData = new HashMap <>();' –
实际上,如果值是不同的类型(%vs timestamp),那么Map在这里看起来不正确。假设您不需要动态创建新的密钥,只需使用三个正确类型的变量:'double in_vehicle; double on_foot;日期时间;'。 –
你的问题到底是什么?你有什么尝试,哪里失败? –