Commit 2b17cfdc by 余根龙

增加阶段绿信比

parent fd066218
...@@ -50,6 +50,10 @@ public class GreenRadioJob { ...@@ -50,6 +50,10 @@ public class GreenRadioJob {
// 阶段绿信比 = 阶段有效绿灯时间/周期时长 // 阶段绿信比 = 阶段有效绿灯时间/周期时长
double phaseGreenRatio = Double.valueOf(phaseValidGreen) / cycle.getDuration(); double phaseGreenRatio = Double.valueOf(phaseValidGreen) / cycle.getDuration();
//组装阶段绿信比、有效绿灯时间、损失时间
stage.setGreenRatio(phaseGreenRatio);
stage.setValidGreen(phaseValidGreen);
stage.setLossTime(phaseLossTime);
// 周期绿信比 = 阶段绿信比之和 // 周期绿信比 = 阶段绿信比之和
cycleGreenRatioTotal = cycleGreenRatioTotal + phaseGreenRatio; cycleGreenRatioTotal = cycleGreenRatioTotal + phaseGreenRatio;
......
...@@ -34,6 +34,9 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> { ...@@ -34,6 +34,9 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
"(id,cross_code,signal_code,begin_time,end_time,duration,cycle_order,green_ratio,loss_time,update_time) " + "(id,cross_code,signal_code,begin_time,end_time,duration,cycle_order,green_ratio,loss_time,update_time) " +
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
insertCyclePstmt = connection.prepareStatement(cycleSql); insertCyclePstmt = connection.prepareStatement(cycleSql);
String phaseSql="insert into app_phase_green_ratio(cycle_order,cross_code,phase_value,begin_time,end_time,duration,phase_order,green_ratio,valid_green,loss_time,update_time) values (?,?,?,?,?,?,?,?,?,?,?)";
insertPhasePstmt = connection.prepareStatement(phaseSql);
} }
@Override @Override
public void close() throws Exception { public void close() throws Exception {
...@@ -56,5 +59,23 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> { ...@@ -56,5 +59,23 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
insertCyclePstmt.setInt(9, cycle.getLossTime()); insertCyclePstmt.setInt(9, cycle.getLossTime());
insertCyclePstmt.setString(10, DateUtils.getTodayTime()); insertCyclePstmt.setString(10, DateUtils.getTodayTime());
insertCyclePstmt.execute(); insertCyclePstmt.execute();
List<Stage> stageList = cycle.getStageList();
for(int i=0;i<stageList.size();i++){
Stage phase = stageList.get(i);
insertPhasePstmt.setLong(1,cycle.getCycleOrder());
insertPhasePstmt.setString(2,phase.getCrossCode());
insertPhasePstmt.setString(3,phase.getPhaseValue());
insertPhasePstmt.setString(4, cycle.getBeginDateTime());
insertPhasePstmt.setString(5, cycle.getEndDateTime());
insertPhasePstmt.setInt(6,cycle.getDuration());
insertPhasePstmt.setInt(7,phase.getPhaseOrder());
insertPhasePstmt.setDouble(8,phase.getGreenRatio());
insertPhasePstmt.setInt(9,phase.getValidGreen());
insertPhasePstmt.setInt(10,phase.getLossTime());
insertPhasePstmt.setString(11, DateUtils.getTodayTime());
insertPhasePstmt.addBatch();
}
insertPhasePstmt.executeBatch();
insertPhasePstmt.clearBatch();
} }
} }
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