Fix analyzeData
This commit is contained in:
parent
5f18a8f3ea
commit
d78d422a07
@ -1,28 +1,13 @@
|
||||
package fr.ntr;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import fr.ntr.scheduler.Scheduler;
|
||||
|
||||
public class AccessPoint {
|
||||
/**
|
||||
* nombre de slots
|
||||
*/
|
||||
private static int timeSlotNb;
|
||||
/**
|
||||
* Nombre de sous-porteuses
|
||||
*/
|
||||
private static int subCarrierNb;
|
||||
|
||||
private final Cell cell1;
|
||||
private final Cell cell2;
|
||||
private FileOutputStream outputDataFile;
|
||||
|
||||
private final List<Cell> cellList;
|
||||
|
||||
public AccessPoint(Cell cell1, Cell cell2){
|
||||
@ -38,14 +23,6 @@ public class AccessPoint {
|
||||
* @param duration
|
||||
*/
|
||||
public void startSimulation(int duration, List<User> users) {
|
||||
try{
|
||||
this.outputDataFile = new FileOutputStream("export" + File.separator + users.size() + ".csv", true);
|
||||
outputDataFile.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
|
||||
} catch(IOException e) {
|
||||
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
for (int ticks = 0; ticks < duration; ++ticks) {
|
||||
// Simulation
|
||||
cell1.reset();
|
||||
@ -58,7 +35,8 @@ public class AccessPoint {
|
||||
computeInterference();
|
||||
// traite les données et les enregistre dans un fichier
|
||||
try {
|
||||
analyseData(ticks, users);
|
||||
cell1.analyseData(ticks, users);
|
||||
cell2.analyseData(ticks, users);
|
||||
} catch (IOException e) {
|
||||
System.out.println("Can't export data");
|
||||
}
|
||||
@ -92,32 +70,4 @@ public class AccessPoint {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void analyseData(int tick, List<User> users) throws IOException {
|
||||
/* double delayAverage = 0.0;
|
||||
int nbPacketsSent = 0;
|
||||
for(User u: users){
|
||||
List<Packets> packets = u.getPacketsSent();
|
||||
nbPacketsSent += packets.size();
|
||||
for (Packets p: packets){
|
||||
delayAverage += p.getDurationSending();
|
||||
}
|
||||
}
|
||||
delayAverage = delayAverage/nbPacketsSent;
|
||||
for(int i = 0; i < frame.length; i++) {
|
||||
for(int j = 0; j < frame[i].length; j++) {
|
||||
ResourceBlock ur = frame[i][j];
|
||||
if(ur.getUser() != null) {
|
||||
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n");
|
||||
try{
|
||||
outputDataFile.write(data.getBytes());
|
||||
}catch(IOException e){
|
||||
System.err.println("Cannot write the data in the output file");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package fr.ntr;
|
||||
|
||||
import fr.ntr.scheduler.Scheduler;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@ -24,10 +27,21 @@ public class Cell {
|
||||
* Trame
|
||||
*/
|
||||
private final ResourceBlock[][] frame;
|
||||
public Cell(Scheduler scheduler, ResourceBlock[][] frame, List<User> users) {
|
||||
private final FileOutputStream outputDataFile;
|
||||
|
||||
public Cell(Scheduler scheduler, ResourceBlock[][] frame, List<User> users, String filename) {
|
||||
this.users = users;
|
||||
this.scheduler = scheduler;
|
||||
this.frame = frame;
|
||||
FileOutputStream output = null;
|
||||
try{
|
||||
output = new FileOutputStream(filename, true);
|
||||
output.write("tick;x;y;user;bandwidth;delay;\n".getBytes());
|
||||
} catch(IOException e) {
|
||||
System.err.println(e.getClass().getSimpleName() + " : " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
this.outputDataFile = output;
|
||||
}
|
||||
|
||||
public void updateBandwidth(int ticks) {
|
||||
@ -57,6 +71,34 @@ public class Cell {
|
||||
scheduler.scheduling(tick);
|
||||
}
|
||||
|
||||
public void analyseData(int tick, List<User> users) throws IOException {
|
||||
double delayAverage = 0.0;
|
||||
int nbPacketsSent = 0;
|
||||
for(User u: users){
|
||||
List<Packets> packets = u.getPacketsSent();
|
||||
nbPacketsSent += packets.size();
|
||||
for (Packets p: packets){
|
||||
delayAverage += p.getDurationSending();
|
||||
}
|
||||
}
|
||||
delayAverage = delayAverage/nbPacketsSent;
|
||||
for(int i = 0; i < frame.length; i++) {
|
||||
for(int j = 0; j < frame[i].length; j++) {
|
||||
ResourceBlock ur = frame[i][j];
|
||||
if(ur.getUser() != null) {
|
||||
String data = (tick + ";" + i + ";" + j + ";" + this.users.indexOf(ur.getUser()) + ";" + ur.getBandwidth() + ";" + delayAverage +";\n");
|
||||
try{
|
||||
outputDataFile.write(data.getBytes());
|
||||
}catch(IOException e){
|
||||
System.err.println("Cannot write the data in the output file");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceBlock[][] getFrame() {
|
||||
return frame;
|
||||
}
|
||||
|
@ -59,8 +59,8 @@ public class Main {
|
||||
Scheduler schedulerCell1 = new RoundRobin(frame, users);
|
||||
Scheduler schedulerCell2 = new RoundRobin(frame, users);
|
||||
|
||||
Cell cell1 = new Cell(schedulerCell1, frame, users);
|
||||
Cell cell2 = new Cell(schedulerCell2, frame, users);
|
||||
Cell cell1 = new Cell(schedulerCell1, frame, users, "export" + File.separator + users.size() + "_cell1" + ".csv");
|
||||
Cell cell2 = new Cell(schedulerCell2, frame, users, "export" + File.separator + users.size() + "_cell2" + ".csv");
|
||||
AccessPoint accessPoint = new AccessPoint(cell1, cell2);
|
||||
executor.submit(() -> accessPoint.startSimulation(numberOfTicks, users));
|
||||
}
|
||||
|
Reference in New Issue
Block a user