Commit 9bf58b0b by 余根龙

优化周期时长为0时报错

parent edee39b8
......@@ -22,7 +22,7 @@ public class GreenRadioJob {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
FlinkUtils.createKafkaStream(args, env, "signal_cycle_data")
FlinkUtils.createKafkaStream(args, env, "signal_cycle_data","greenRadioJob")
.map(record -> {
// 字符串解析为实体类
Cycle cycle = JSON.parseObject(record, Cycle.class);
......@@ -49,7 +49,15 @@ public class GreenRadioJob {
int phaseValidGreen = green + yellow + allRed - phaseLossTime;
// 阶段绿信比 = 阶段有效绿灯时间/周期时长
double phaseGreenRatio = Double.valueOf(phaseValidGreen) / cycle.getDuration();
Integer duration = cycle.getDuration();
System.out.println("********duration:"+duration);
double phaseGreenRatio = 0;
if(duration!=null && duration!=0){
phaseGreenRatio = Double.valueOf(phaseValidGreen) / duration;
}
if(duration==0) {
System.out.println("********phaseGreenRatio:" + phaseGreenRatio);
}
//组装阶段绿信比、有效绿灯时间、损失时间
stage.setGreenRatio(phaseGreenRatio);
stage.setValidGreen(phaseValidGreen);
......
......@@ -28,8 +28,8 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
public void open(Configuration parameters) throws Exception {
super.open(parameters);
// path暂定为固定值
String path = "F:\\workspace\\ZHHT-IRN-BD-ANALYSIS\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties";
connection = MySQLUtils.getConnection(path);
//String path = ".\\realtime\\hologram-streaming\\src\\main\\resources\\mysql.properties";
connection = MySQLUtils.getConnection();
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
......@@ -63,7 +63,7 @@ public class GreenRadioSink extends RichSinkFunction<Cycle> {
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(2,cycle.getCrossCode());
insertPhasePstmt.setString(3,phase.getPhaseValue());
insertPhasePstmt.setString(4, cycle.getBeginDateTime());
insertPhasePstmt.setString(5, cycle.getEndDateTime());
......
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