Commit 5dc08888 authored by hanbing's avatar hanbing

[update] 运行评价-干线方案停车次数改为小数

parent 6913ee14
...@@ -6,6 +6,7 @@ import net.wanji.opt.dto.PhaseEmptyResult; ...@@ -6,6 +6,7 @@ import net.wanji.opt.dto.PhaseEmptyResult;
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords; import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.consumer.OffsetAndTimestamp;
import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.kafka.common.serialization.StringDeserializer;
...@@ -37,18 +38,22 @@ public class KafkaConsumerUtil { ...@@ -37,18 +38,22 @@ public class KafkaConsumerUtil {
public List<PhaseEmptyResult> consumeEmptyPhaseForTimeRange( public List<PhaseEmptyResult> consumeEmptyPhaseForTimeRange(
String topic, int partition, long startTime, long endTime) { String topic, int partition, long startTime, long endTime) {
List<PhaseEmptyResult> results = new ArrayList<>();
TopicPartition topicPartition = new TopicPartition(topic, partition); TopicPartition topicPartition = new TopicPartition(topic, partition);
consumer.assign(Collections.singletonList(topicPartition)); consumer.assign(Collections.singletonList(topicPartition));
HashMap<TopicPartition, Long> timestampToSearch = new HashMap<>(); HashMap<TopicPartition, Long> timestampToSearch = new HashMap<>();
timestampToSearch.put(topicPartition, startTime); timestampToSearch.put(topicPartition, startTime);
long startOffset = consumer.offsetsForTimes(timestampToSearch).get(topicPartition).offset(); OffsetAndTimestamp offsetAndTimestamp = consumer.offsetsForTimes(timestampToSearch).get(topicPartition);
if (offsetAndTimestamp == null) {
return results;
}
long startOffset = offsetAndTimestamp.offset();
// 开始消费 // 开始消费
consumer.seek(topicPartition, startOffset); consumer.seek(topicPartition, startOffset);
int emptyPollCount = 0; // 记录空轮询次数的计数器 int emptyPollCount = 0; // 记录空轮询次数的计数器
int maxEmptyPolls = 10; // 设置最大空轮询次数 int maxEmptyPolls = 10; // 设置最大空轮询次数
List<PhaseEmptyResult> results = new ArrayList<>();
try { try {
boolean keepConsuming = true; boolean keepConsuming = true;
while (keepConsuming) { while (keepConsuming) {
......
...@@ -1342,9 +1342,9 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -1342,9 +1342,9 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
.orElse(0.0)) .orElse(0.0))
.sum(); .sum();
int value = (int) sumOfAverages; BigDecimal bd = new BigDecimal(sumOfAverages).setScale(2, RoundingMode.HALF_UP);
double rounded = bd.doubleValue();
curveElement.setValue((double) value); curveElement.setValue(rounded);
curveElementList.add(curveElement); curveElementList.add(curveElement);
} }
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.AVERAGE_DELAY.getDescription())) { } else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.AVERAGE_DELAY.getDescription())) {
...@@ -1362,9 +1362,9 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService { ...@@ -1362,9 +1362,9 @@ public class MainlineEvaluateServiceImpl implements MainlineEvaluateService {
.orElse(0.0)) .orElse(0.0))
.sum(); .sum();
int value = (int) sumOfAverages; BigDecimal bd = new BigDecimal(sumOfAverages).setScale(2, RoundingMode.HALF_UP);
double rounded = bd.doubleValue();
curveElement.setValue( (double)value); curveElement.setValue(rounded);
curveElementList.add(curveElement); curveElementList.add(curveElement);
} }
} else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.AVERAGE_SPEED.getDescription())) { } else if (Objects.equals(metricName, StrategyAndMetricsEnum.Metrics.AVERAGE_SPEED.getDescription())) {
......
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