Commit fea0a991 authored by 潘栩锋's avatar 潘栩锋 🚴

修复 TimeGridAdvHelperExt 的 GetAD AD数据时间不对

parent 11ba095b
......@@ -517,38 +517,28 @@ namespace FlyADBase
DateTime lastTime = reponse2.Last().dt;
reponse_endTime = lastTime;
return GetAD(reponse2, begin);
return GetAD(reponse2);
}
public static List<int> GetAD(List<DateTimeUnit3> adPool)
{
//通过adPool[0].dt 与 adPool[1].dt 的时间差,计算adPool[0].dt的开始时间
//如果没有adPool[1].dt,就当 adPool[0].dt 的开始时间为 adPool[0].dt - adPool[0].datas.Count() * ad_ts_ms;
DateTime begin;
if (adPool.Count() >= 2)
{
begin = adPool[0].dt - (adPool[1].dt - adPool[0].dt);
}
else {
double t_ms = adPool.First().datas.Count() * ad_ts_ms;
begin = adPool.First().dt - TimeSpan.FromTicks((long)(t_ms * TimeSpan.TicksPerMillisecond));
}
return GetAD(adPool, begin);
return GetAD(adPool, DateTime.MinValue);
}
public static List<int> GetAD(List<DateTimeUnit3> adPool, DateTime begin)
{
List<int> reponse = new List<int>();
DateTime lastTime = adPool.Last().dt;
//每个ad包的每个数据不是准确的1.28ms,肯定比1.28ms大,每次需要准确计算
//导出数据的时间
DateTime idealTime = adPool.Last().dt;
//每个ad包的每个数据不是准确的1.28ms,肯定比1.28ms大,每次需要准
for (int i = 0; i < adPool.Count(); i++)
{
int idx = adPool.Count() - 1 - i;
double curr_ad_ts_ms;
//当前缓存区包,数据的时间间隔
TimeSpan curr_ad_ts;
//计算这个包每个数据的时间间隔
DateTime end_dt = adPool[idx].dt;
......@@ -556,38 +546,37 @@ namespace FlyADBase
{
var begin_dt = adPool[idx - 1].dt;
double total_ms = (end_dt - begin_dt).Ticks / TimeSpan.TicksPerMillisecond;
curr_ad_ts_ms = total_ms / adPool[idx].datas.Count();
var curr_ad_ts_ms = total_ms / adPool[idx].datas.Count();
curr_ad_ts = TimeSpan.FromTicks((long)(curr_ad_ts_ms * TimeSpan.TicksPerMillisecond));
}
else if (adPool.Count() > 1)
{
var begin_dt = adPool[idx].dt - (adPool[idx + 1].dt - adPool[idx].dt);
double total_ms = (end_dt - begin_dt).Ticks / TimeSpan.TicksPerMillisecond;
curr_ad_ts_ms = total_ms / adPool[idx].datas.Count();
var curr_ad_ts_ms = total_ms / adPool[idx].datas.Count();
curr_ad_ts = TimeSpan.FromTicks((long)(curr_ad_ts_ms * TimeSpan.TicksPerMillisecond));
}
else
{
curr_ad_ts_ms = ad_ts_ms;
curr_ad_ts = ad_ts;
}
DateTime actTime = adPool[idx].dt;//从缓存区获取数据的时间
double act_ms = 0;
double ideal_ms = 0;//插值,让输出可以有准确的间隔为 ad_ts_ms
for (int j = 0; j < adPool[idx].datas.Count(); j++)
{
int idx2 = adPool[idx].datas.Count() - 1 - j;
int ad = adPool[idx].datas[idx2];
actTime -= curr_ad_ts;
act_ms += curr_ad_ts_ms;
while (ideal_ms < act_ms)
while (idealTime > actTime)
{
reponse.Add(ad);
ideal_ms += ad_ts_ms;
lastTime -= ad_ts;
reponse.Add(ad);//导出数据
idealTime -= ad_ts;//导出数据时间累加
}
if (lastTime < begin)
goto _end;//完成
}
if (idealTime < begin)
goto _end;//完成
}
_end:
//反转
......@@ -596,10 +585,6 @@ namespace FlyADBase
}
/// <summary>
/// 获取 时间在 begin~end 的 AD数据包
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment