Skip to content
Snippets Groups Projects
Commit 723ebc11 authored by mario's avatar mario
Browse files

Subida código

parents
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>erss</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
package erss;
import java.util.List;
import java.io.File;
import java.io.PrintWriter;
public class ConvierteCSV {
public static void writeDataLineByLine(List<Medida> medidas) {
try {
PrintWriter pw= new PrintWriter(new File("resultados.csv"));
StringBuilder sb=new StringBuilder();
sb.append("Nombre Hilo");
sb.append(",");
sb.append("tiempo Respuesta");
sb.append("\r\n");
for (Medida b : medidas) {
sb.append(b.getName());
sb.append(",");
sb.append(b.getTiempo());
sb.append("\r\n");
}
sb.append("Jain resultado");
sb.append(",");
sb.append(Jain.calculaJain(medidas));
sb.append("\r\n");
pw.write(sb.toString());
pw.close();
System.out.println("CSV creado");
} catch (Exception e) {
System.out.println("Error creacion CSV, fichero en uso");
}
}
}
package erss;
import java.util.List;
public class Jain {
//Calculo de indice de equidad
public static double calculaJain(List<Medida> medidas) {
double sumatorio=0;
for (int i=0;i<medidas.size();i++) {
sumatorio=sumatorio+medidas.get(i).getTiempo();
}
double numerador=Math.pow(sumatorio,2);
double sumatorio2=0;
for (int i=0;i<medidas.size();i++) {
sumatorio2=sumatorio2+ Math.pow(medidas.get(i).getTiempo(),2);
}
double denominador= medidas.size()*sumatorio2;
double resultado= numerador/denominador;
return resultado;
}
}
package erss;
import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
public class LectorJTL {
/**
* Se encarga de tomar todas las medidas, clasificarlas por nombre de hilo y hacer la media de esta
*
*
* @param medidas
* @return
*/
public static List<Medida> getMedias(List<Medida> medidas ){
TreeMap<String, Integer> conjunto
= new TreeMap<String, Integer>();
//aadidos los tiempos totales de cada hilo
for (Medida b : medidas) {
if(conjunto.containsKey(b.getName())) {
int tiempoacumulado= conjunto.get(b.getName());
tiempoacumulado=tiempoacumulado+b.getTiempo();
conjunto.put(b.getName(), tiempoacumulado);
}else {
conjunto.put(b.getName(), b.getTiempo());
}
}
int numMedidas=medidas.size();
int numHilos=conjunto.size();
int numeroMedidasHilo=numMedidas/numHilos; //1500/30 en este caso
//Lista de nombre y valores de tiempos totales
List<String> nombres = new ArrayList<String>(conjunto.keySet());
List<Integer> valores = new ArrayList<Integer>(conjunto.values());
//Loop para calcular la media y meterla en el treemap
for (int i=0;i<conjunto.size();i++) {
String nombre=nombres.get(i);
int total=valores.get(i);
total=total/numeroMedidasHilo;
conjunto.put(nombre, total);
}
//metemos en la lista los valores de los tiempos medios
valores = new ArrayList<Integer>(conjunto.values());
List<Medida> resultado=transformaListas(nombres , valores);
return resultado;
}
private static List<Medida> transformaListas(List<String> nombres ,List<Integer> valores){
List<Medida> medidas = new ArrayList<>();
for (int i=0;i<nombres.size();i++) {
medidas.add(new Medida(nombres.get(i),valores.get(i)));
}
return medidas;
}
public static List<Medida> readDataFromCSV(String fileName) {
List<Medida> medidas = new ArrayList<>();
Path pathToFile = Paths.get(fileName);
try (BufferedReader br = Files.newBufferedReader(pathToFile,
StandardCharsets.US_ASCII)) {
// leemos la primera linea de cabecera y la segunda la asignamos para empezar lectura
String line = br.readLine();
line=br.readLine();
while (line != null) {
// lee cada separacion del jtl
String[] attributes = line.split(",");
Medida una = createMedida(attributes);
medidas.add(una);
//lee siguiente linea del loop
line = br.readLine();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
return medidas;
}
private static Medida createMedida(String[] metadata) {
String name = metadata[5];
int tiempo = Integer.parseInt(metadata[1]);
return new Medida(name, tiempo);
}
}
package erss;
class Medida {
private String name;
private int tiempo;
public Medida(String name, int tiempo) {
this.name = name;
this.tiempo=tiempo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getTiempo() {
return tiempo;
}
public void setTiempo(int tiempo) {
this.tiempo = tiempo;
}
@Override
public String toString() {
return "Medida [hilo=" + name + ", tiempoR (ms)=" + tiempo +
"]";
}
}
\ No newline at end of file
package erss;
import java.io.File;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileSystemView;
public class traductor {
public static void main(String[] args) {
//obtenemos una lista de medidas del jtl
List<Medida> medidas = LectorJTL.readDataFromCSV(getFichero());
//resultado de las medias de las medidas
List <Medida> resultado =LectorJTL.getMedias(medidas);
//creamos un csv
ConvierteCSV.writeDataLineByLine(resultado);
}
// Vista para introducir fichero
private static String getFichero() {
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
int returnValue = jfc.showOpenDialog(null);
// int returnValue = jfc.showSaveDialog(null);
String fichero=null;
if (returnValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
fichero=selectedFile.getAbsolutePath();
}
return fichero;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment