Skip to content

Instantly share code, notes, and snippets.

@atamrawi
Last active April 26, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save atamrawi/a0f0f79b76d04618ff0420eb19b97dac to your computer and use it in GitHub Desktop.
Save atamrawi/a0f0f79b76d04618ff0420eb19b97dac to your computer and use it in GitHub Desktop.
A sample code to go with Problem 3 of SWEN 6301 Assignment 4.
public class SensorDataProcessor{
// Senson data and limits.
public double[][][] data;
public double[][] limit;
// constructor
public DataProcessor(double[][][] data, double[][] limit) {
this.data = data;
this.limit = limit;
}
// calculates average of sensor data
private double average(double[] array) {
int i = 0;
double val = 0;
for (i = 0; i < array.length; i++) {
val += array[i];
}
return val / array.length;
}
// calculate data
public void calculate(double d) {
int i, j, k = 0;
double[][][] data2 = new double[data.length][data[0].length][data[0][0].length];
BufferedWriter out;
// Write racing stats data into a file
try {
out = new BufferedWriter(new FileWriter("RacingStatsData.txt"));
for (i = 0; i < data.length; i++) {
for (j = 0; j < data[0].length; j++) {
for (k = 0; k < data[0][0].length; k++) {
data2[i][j][k] = data[i][j][k] / d - Math.pow(limit[i][j], 2.0);
if (average(data2[i][j]) > 10 && average(data2[i][j]) < 50)
break;
else if (Math.max(data[i][j][k], data2[i][j][k]) > data[i][j][k])
break;
else if (Math.pow(Math.abs(data[i][j][k]), 3) < Math.pow(Math.abs(data2[i][j][k]), 3)
&& average(data[i][j]) < data2[i][j][k] && (i + 1) * (j + 1) > 0)
data2[i][j][k] *= 2;
else
continue;
}
}
}
for (i = 0; i < data2.length; i++) {
for (j = 0; j < data2[0].length; j++) {
out.write(data2[i][j] + "\t");
}
}
out.close();
} catch (Exception e) {
System.out.println("Error= " + e);
}
}
}
@s2t6am
Copy link

s2t6am commented Apr 24, 2021

whats the answer ?

@atamrawi
Copy link
Author

We can discuss the solution in private - please contact me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment