Commit 1d750e2b9192d591ab6df9125741cfce41128255
1 parent
712c343e
update...
Showing
1 changed file
with
80 additions
and
0 deletions
src/main/java/com/bsth/data/gpsdata_v2/utils/SignalSchPlanMatcher.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata_v2.utils; | ||
| 2 | + | ||
| 3 | +import com.bsth.data.gpsdata_v2.entity.GpsEntity; | ||
| 4 | +import com.bsth.data.schedule.DayOfSchedule; | ||
| 5 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | ||
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.stereotype.Component; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 班次匹配器 | ||
| 13 | + * Created by panzhao on 2016/12/31. | ||
| 14 | + */ | ||
| 15 | +@Component | ||
| 16 | +public class SignalSchPlanMatcher { | ||
| 17 | + | ||
| 18 | + @Autowired | ||
| 19 | + DayOfSchedule dayOfSchedule; | ||
| 20 | + | ||
| 21 | + Logger log = LoggerFactory.getLogger(this.getClass()); | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 发车信号匹配 | ||
| 25 | + * @param gps | ||
| 26 | + * @param sch | ||
| 27 | + * @return | ||
| 28 | + */ | ||
| 29 | + public void outMatch(GpsEntity gps, ScheduleRealInfo sch){ | ||
| 30 | + long t = gps.getTimestamp(); | ||
| 31 | + if(t < sch.getDfsjT()) | ||
| 32 | + return; | ||
| 33 | + | ||
| 34 | + try{ | ||
| 35 | + //会不会是分班没有完成 | ||
| 36 | + if(sch.getBcType().equals("in") && t - sch.getDfsjT() > 1000 * 60 * 20){ | ||
| 37 | + ScheduleRealInfo fbFirst = dayOfSchedule.nextByBcType(sch, "normal"); | ||
| 38 | + | ||
| 39 | + if(fbFirst == null || !fbFirst.getQdzCode().equals(gps.getStopNo())) | ||
| 40 | + return; | ||
| 41 | + | ||
| 42 | + long dt = fbFirst.getDfsjT(); | ||
| 43 | + //晚于待发前4分钟 -执行分班的首个营运 | ||
| 44 | + if(dt - t < 1000 * 60 * 4){ | ||
| 45 | + dayOfSchedule.addExecPlan(fbFirst); | ||
| 46 | + return; | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + //线路编码不匹配 | ||
| 51 | + if("out".equals(sch.getBcType()) && !sch.getXlBm().equals(gps.getLineId())){ | ||
| 52 | + ScheduleRealInfo nextOut = dayOfSchedule.nextByBcType(sch, "out"); | ||
| 53 | + if(nextOut != null && nextOut.getXlBm().equals(gps.getLineId()) | ||
| 54 | + && fcSpace(sch, gps) > fcSpace(nextOut, gps)){ | ||
| 55 | + dayOfSchedule.addExecPlan(nextOut); | ||
| 56 | + return; | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + }catch (Exception e){ | ||
| 60 | + log.error("", e); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + //下一个相同走向的班次 | ||
| 64 | + ScheduleRealInfo next = dayOfSchedule.nextSame(sch); | ||
| 65 | + if(next == null || !next.getQdzCode().equals(sch.getQdzCode())) | ||
| 66 | + return; | ||
| 67 | + | ||
| 68 | + //晚于班次间隔百分之70,跳下一个班次 | ||
| 69 | + double s = (int) (next.getDfsjT() - sch.getDfsjT()); | ||
| 70 | + double r = (int) (t - sch.getDfsjT()); | ||
| 71 | + if(r / s > 0.7){ | ||
| 72 | + if(dayOfSchedule.addExecPlan(next)) | ||
| 73 | + outMatch(gps, next); | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public static int fcSpace(ScheduleRealInfo sch, GpsEntity gps){ | ||
| 78 | + return (int) Math.abs((sch.getDfsjT() - gps.getTimestamp())); | ||
| 79 | + } | ||
| 80 | +} |