Skip to content

Commit

Permalink
Type bug (#399)
Browse files Browse the repository at this point in the history
* tmp commit

* fix type error

* spotless

* spotless
  • Loading branch information
l2280212 authored Jan 18, 2024
1 parent dd70993 commit ca6e9ab
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions core/src/main/java/cn/edu/tsinghua/iot/benchmark/conf/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,15 +502,15 @@ public void initSensorFunction() {

/** According to the number of sensors, initialize the sensor number */
void initSensorCodes() {
int TYPE_NUMBER = 6;
double[] probabilities = generateProbabilities(TYPE_NUMBER);
if (probabilities == null) {
int typeNumber = 6;
double[] probabilities = generateProbabilities(typeNumber);
if (probabilities.length == 0) {
return;
}
for (int sensorIndex = 0; sensorIndex < SENSOR_NUMBER; sensorIndex++) {
double sensorPosition = (sensorIndex + 1) * 1.0 / SENSOR_NUMBER;
int i;
for (i = 1; i <= TYPE_NUMBER; i++) {
for (i = 1; i <= typeNumber; i++) {
if (sensorPosition > probabilities[i - 1] && sensorPosition <= probabilities[i]) {
break;
}
Expand All @@ -521,37 +521,32 @@ void initSensorCodes() {
}

/** Generate Probabilities according to proportion(e.g. 1:1:1:1:1:1) */
private double[] generateProbabilities(int TYPE_NUMBER) {
private double[] generateProbabilities(int typeNumber) {
// Probabilities for Types
double[] probabilities = new double[TYPE_NUMBER + 1];
double[] probabilities = new double[typeNumber + 1];
// Origin proportion array
double[] proportions = new double[TYPE_NUMBER];
// unified proportion array
List<Double> proportion = new ArrayList<>();
double[] proportions = new double[typeNumber];
LOGGER.info(
"Init SensorTypes: BOOLEAN:INT32:INT64:FLOAT:DOUBLE:TEXT=" + INSERT_DATATYPE_PROPORTION);
"Init SensorTypes: BOOLEAN:INT32:INT64:FLOAT:DOUBLE:TEXT= {}", INSERT_DATATYPE_PROPORTION);

String[] split = INSERT_DATATYPE_PROPORTION.split(":");
if (split.length != TYPE_NUMBER) {
if (split.length != typeNumber) {
LOGGER.error("INSERT_DATATYPE_PROPORTION error, please check this parameter.");
return null;
return new double[0];
}
double sum = 0;
for (int i = 0; i < TYPE_NUMBER; i++) {
proportions[i] = Double.parseDouble(split[i]);
sum += proportions[i];
}
for (int i = 0; i < TYPE_NUMBER; i++) {
if (sum != 0) {
proportion.add(proportions[i] / sum);
} else {
proportion.add(0.0);
LOGGER.error("The sum of INSERT_DATATYPE_PROPORTION is zero!");
for (int i = 0; i < typeNumber; i++) {
if (i != 0) {
proportions[i] += proportions[i - 1];
}
proportions[i] += Double.parseDouble(split[i]);
sum += Double.parseDouble(split[i]);
}
if (sum == 0) {
return probabilities;
}
probabilities[0] = 0.0;
for (int i = 1; i <= TYPE_NUMBER; i++) {
probabilities[i] = probabilities[i - 1] + proportion.get(i - 1);
for (int i = 1; i <= typeNumber; i++) {
probabilities[i] = proportions[i - 1] / sum;
}
return probabilities;
}
Expand Down

0 comments on commit ca6e9ab

Please sign in to comment.