Commit 8b6e8809 by 余根龙

路口总体评价指标开发

parent 62b6186f
...@@ -14,6 +14,9 @@ public class Cycle { ...@@ -14,6 +14,9 @@ public class Cycle {
// 路口编号 // 路口编号
private String crossCode; private String crossCode;
//信控机编号
private String signalCode;
// 周期开始时间 // 周期开始时间
private String beginDateTime; private String beginDateTime;
...@@ -26,6 +29,8 @@ public class Cycle { ...@@ -26,6 +29,8 @@ public class Cycle {
private int cycleOrder; private int cycleOrder;
//绿信比 //绿信比
private Double greenRatio; private Double greenRatio;
//损失时间
private int lossTime;
// 周期内相位列表(依次执行) // 周期内相位列表(依次执行)
private List<Stage> stageList; private List<Stage> stageList;
...@@ -93,4 +98,20 @@ public class Cycle { ...@@ -93,4 +98,20 @@ public class Cycle {
public void setGreenRatio(Double greenRatio) { public void setGreenRatio(Double greenRatio) {
this.greenRatio = greenRatio; this.greenRatio = greenRatio;
} }
public int getLossTime() {
return lossTime;
}
public void setLossTime(int lossTime) {
this.lossTime = lossTime;
}
public String getSignalCode() {
return signalCode;
}
public void setSignalCode(String signalCode) {
this.signalCode = signalCode;
}
} }
...@@ -8,7 +8,7 @@ import java.util.Date; ...@@ -8,7 +8,7 @@ import java.util.Date;
public class Stage { public class Stage {
//周期ID //周期ID
private Long cycleId; private Long cycleOrder;
// 路口编号 // 路口编号
private String crossCode; private String crossCode;
// 相位编号 // 相位编号
...@@ -31,12 +31,18 @@ public class Stage { ...@@ -31,12 +31,18 @@ public class Stage {
// 相位全红时间 // 相位全红时间
private int allRed; private int allRed;
//相位序号
private int phaseOrder;
// 阶段绿信比 // 阶段绿信比
private Double greenRatio; private Double greenRatio;
// 阶段有效绿灯时长 // 阶段有效绿灯时长
private int validGreen; private int validGreen;
//损失时间
private int lossTime;
public String getPhaseValue() { public String getPhaseValue() {
return phaseValue; return phaseValue;
} }
...@@ -93,12 +99,12 @@ public class Stage { ...@@ -93,12 +99,12 @@ public class Stage {
this.allRed = allRed; this.allRed = allRed;
} }
public Long getCycleId() { public Long getCycleOrder() {
return cycleId; return cycleOrder;
} }
public void setCycleId(Long cycleId) { public void setCycleOrder(Long cycleOrder) {
this.cycleId = cycleId; this.cycleOrder = cycleOrder;
} }
public String getCrossCode() { public String getCrossCode() {
...@@ -124,4 +130,20 @@ public class Stage { ...@@ -124,4 +130,20 @@ public class Stage {
public void setValidGreen(int validGreen) { public void setValidGreen(int validGreen) {
this.validGreen = validGreen; this.validGreen = validGreen;
} }
public int getPhaseOrder() {
return phaseOrder;
}
public void setPhaseOrder(int phaseOrder) {
this.phaseOrder = phaseOrder;
}
public int getLossTime() {
return lossTime;
}
public void setLossTime(int lossTime) {
this.lossTime = lossTime;
}
} }
...@@ -27,7 +27,7 @@ public class GreenRadioJob { ...@@ -27,7 +27,7 @@ public class GreenRadioJob {
// ] // ]
//} //}
// 造一条数据 // 造一条数据
DataStream<String> stream = env.fromElements("{\"id\":\"1\",\"crossCode\":\"0001\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"endTime\":\"2020-08-02 08:05:00\",\"duration\":\"300\",\"cycleOrder\":\"1\",\"stageList\":[{\"phaseValue\":\"101\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"beginDateTime\":\"2020-08-02 08:01:00\",\"duration\":\"60\",\"green\":\"30\",\"yellow\":\"3\",\"allRed\":\"0\"},{\"phaseValue\":\"102\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"beginDateTime\":\"2020-08-02 08:05:00\",\"duration\":\"240\",\"green\":\"120\",\"yellow\":\"3\",\"allRed\":\"0\"}]}"); DataStream<String> stream = env.fromElements("{\"id\":\"1\",\"crossCode\":\"0001\",\"signalCode\":\"1000001\",\"beginDateTime\":\"2020-08-02 08:10:03\",\"endDateTime\":\"2020-08-02 08:12:11\",\"duration\":\"300\",\"cycleOrder\":\"1\",\"stageList\":[{\"phaseValue\":\"101\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"endDateTime\":\"2020-08-02 08:01:00\",\"duration\":\"60\",\"green\":\"30\",\"yellow\":\"3\",\"allRed\":\"0\",\"phaseOrder\":\"1\"},{\"phaseValue\":\"102\",\"beginDateTime\":\"2020-08-02 08:00:00\",\"endDateTime\":\"2020-08-02 08:05:00\",\"duration\":\"240\",\"green\":\"120\",\"yellow\":\"3\",\"allRed\":\"0\",\"phaseOrder\":\"2\"}]}");
DataStream<Cycle> lxbStream = stream.map(new MapFunction<String, Cycle>() { DataStream<Cycle> lxbStream = stream.map(new MapFunction<String, Cycle>() {
@Override @Override
public Cycle map(String s) throws Exception { public Cycle map(String s) throws Exception {
...@@ -42,6 +42,7 @@ public class GreenRadioJob { ...@@ -42,6 +42,7 @@ public class GreenRadioJob {
int duration = cycle.getDuration(); int duration = cycle.getDuration();
String crossCode = cycle.getCrossCode(); String crossCode = cycle.getCrossCode();
double cycleGreenRatio = 0; double cycleGreenRatio = 0;
int cycleLossTime = 0;
List<Stage> stageList = cycle.getStageList(); List<Stage> stageList = cycle.getStageList();
for (Stage stage : stageList) { for (Stage stage : stageList) {
//相位号 //相位号
...@@ -66,15 +67,19 @@ public class GreenRadioJob { ...@@ -66,15 +67,19 @@ public class GreenRadioJob {
//阶段绿信比 //阶段绿信比
double phaseGreenRatio = Double.valueOf(phaseValidGreen)/duration; double phaseGreenRatio = Double.valueOf(phaseValidGreen)/duration;
System.out.println("******phaseGreenRatio:"+phaseGreenRatio); System.out.println("******phaseGreenRatio:"+phaseGreenRatio);
//组装阶段绿信比 //组装阶段绿信比、有效绿灯时间、损失时间
stage.setGreenRatio(phaseGreenRatio); stage.setGreenRatio(phaseGreenRatio);
stage.setValidGreen(phaseValidGreen); stage.setValidGreen(phaseValidGreen);
stage.setLossTime(phaseLossTime);
//周期绿信比= 各个阶段绿信比之和 //周期绿信比= 各个阶段绿信比之和
cycleGreenRatio = cycleGreenRatio + phaseGreenRatio; cycleGreenRatio = cycleGreenRatio + phaseGreenRatio;
//周期损失时间= 各个阶段损失时间之和
cycleLossTime = cycleLossTime + phaseLossTime;
System.out.println("******cycleGreenRatio:"+cycleGreenRatio); System.out.println("******cycleGreenRatio:"+cycleGreenRatio);
} }
// 组装周期绿信比 // 组装周期绿信比、损失时间
cycle.setGreenRatio(cycleGreenRatio); cycle.setGreenRatio(cycleGreenRatio);
cycle.setLossTime(cycleLossTime);
return cycle; return cycle;
} }
}); });
......
...@@ -2,12 +2,15 @@ package com.zhht.irn.sink; ...@@ -2,12 +2,15 @@ package com.zhht.irn.sink;
import com.zhht.irn.entity.Cycle; import com.zhht.irn.entity.Cycle;
import com.zhht.irn.entity.Stage; import com.zhht.irn.entity.Stage;
import com.zhht.irn.utils.DateUtils;
import com.zhht.irn.utils.MySQLUtils; import com.zhht.irn.utils.MySQLUtils;
import org.apache.flink.configuration.Configuration; import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction; import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -17,15 +20,17 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> { ...@@ -17,15 +20,17 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
Connection connection; Connection connection;
PreparedStatement insertCyclePstmt; PreparedStatement insertCyclePstmt;
PreparedStatement insertPhasePstmt; PreparedStatement insertPhasePstmt;
Date date = new Date();
SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd :hh:mm:ss");
@Override @Override
public void open(Configuration parameters) throws Exception { public void open(Configuration parameters) throws Exception {
super.open(parameters); super.open(parameters);
// path暂定为固定值 // path暂定为固定值
String path = "F:\\workbench\\ZHHT-IRN-BD-ANALYSIS\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties"; String path = "F:\\workbench\\ZHHT-IRN-BD-ANALYSIS\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties";
connection = MySQLUtils.getConnection(path); connection = MySQLUtils.getConnection(path);
String cycleSql="insert into app_cycle_green_ratio(cycle_id,cross_code,begin_time,end_time,duration,green_ratio) values (?,?,?,?,?,?)"; String cycleSql="insert into app_cycle_green_ratio(id,cross_code,signal_code,begin_time,end_time,duration,cycle_order,green_ratio,loss_time,update_time) values (?,?,?,?,?,?,?,?,?,?)";
insertCyclePstmt = connection.prepareStatement(cycleSql); insertCyclePstmt = connection.prepareStatement(cycleSql);
String phaseSql="insert into app_phase_green_ratio(cycle_id,cross_code,phase_value,begin_time,end_time,duration,green_ratio,valid_green) values (?,?,?,?,?,?,?,?)"; 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); insertPhasePstmt = connection.prepareStatement(phaseSql);
} }
@Override @Override
...@@ -46,22 +51,29 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> { ...@@ -46,22 +51,29 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
System.out.println("=====invoke======" + cycle.getId() + "-->" + cycle.getCrossCode()); System.out.println("=====invoke======" + cycle.getId() + "-->" + cycle.getCrossCode());
insertCyclePstmt.setLong(1, cycle.getId()); insertCyclePstmt.setLong(1, cycle.getId());
insertCyclePstmt.setString(2, cycle.getCrossCode()); insertCyclePstmt.setString(2, cycle.getCrossCode());
insertCyclePstmt.setString(3, cycle.getBeginDateTime()); insertCyclePstmt.setString(3, cycle.getSignalCode());
insertCyclePstmt.setString(4, cycle.getEndDateTime()); insertCyclePstmt.setString(4, cycle.getBeginDateTime());
insertCyclePstmt.setInt(5,cycle.getDuration()); insertCyclePstmt.setString(5, cycle.getEndDateTime());
insertCyclePstmt.setDouble(6,cycle.getGreenRatio()); insertCyclePstmt.setInt(6,cycle.getDuration());
insertCyclePstmt.setInt(7,cycle.getCycleOrder());
insertCyclePstmt.setDouble(8,cycle.getGreenRatio());
insertCyclePstmt.setInt(9,cycle.getLossTime());
insertCyclePstmt.setString(10, DateUtils.getTodayTime());
insertCyclePstmt.execute(); insertCyclePstmt.execute();
List<Stage> stageList = cycle.getStageList(); List<Stage> stageList = cycle.getStageList();
for(int i=0;i<stageList.size();i++){ for(int i=0;i<stageList.size();i++){
Stage phase = stageList.get(i); Stage phase = stageList.get(i);
insertPhasePstmt.setLong(1,cycle.getId()); insertPhasePstmt.setLong(1,cycle.getCycleOrder());
insertPhasePstmt.setString(2,phase.getCrossCode()); insertPhasePstmt.setString(2,phase.getCrossCode());
insertPhasePstmt.setString(3,phase.getPhaseValue()); insertPhasePstmt.setString(3,phase.getPhaseValue());
insertPhasePstmt.setString(4, cycle.getBeginDateTime()); insertPhasePstmt.setString(4, cycle.getBeginDateTime());
insertPhasePstmt.setString(5, cycle.getEndDateTime()); insertPhasePstmt.setString(5, cycle.getEndDateTime());
insertPhasePstmt.setInt(6,cycle.getDuration()); insertPhasePstmt.setInt(6,cycle.getDuration());
insertPhasePstmt.setDouble(7,phase.getGreenRatio()); insertPhasePstmt.setInt(7,phase.getPhaseOrder());
insertPhasePstmt.setInt(8,phase.getValidGreen()); insertPhasePstmt.setDouble(8,phase.getGreenRatio());
insertPhasePstmt.setInt(9,phase.getValidGreen());
insertPhasePstmt.setInt(10,phase.getLossTime());
insertPhasePstmt.setString(11, DateUtils.getTodayTime());
insertPhasePstmt.addBatch(); insertPhasePstmt.addBatch();
} }
insertPhasePstmt.executeBatch(); insertPhasePstmt.executeBatch();
......
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