Commit bf02e380 authored by Marc Jeanmougin's avatar Marc Jeanmougin

use Exception + first try to write csv

parent a3e1090c
package fr.tpt.mem4csd.sefa.trajectory.control;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.Object;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
......@@ -14,11 +17,14 @@ import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;
import org.osate.aadl2.instance.ComponentInstance;
import org.osate.aadl2.instance.SystemInstance;
import org.osate.aadl2.modelsupport.resources.OsateResourceUtil;
import fr.tpt.aadl.ramses.analysis.AnalysisResultFactory;
import fr.tpt.aadl.ramses.control.support.analysis.AnalysisArtifact;
import fr.tpt.mem4csd.sefa.trajectory.model.Flow;
import fr.tpt.mem4csd.sefa.trajectory.model.Node;
......@@ -67,14 +73,14 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
LatencyAnalyzer la = new LatencyAnalyzer();
//TODO use performAnalysis
TrajectoryAnalysisResult ar = la.trajectoryAnalysis(instance);
// if(monitor.isCanceled())
// {
// String msg = "analysis has been canceled after execution" ;
// //_LOGGER.trace(msg);
// throw new OperationCanceledException(msg) ;
// }
TrajectoryAnalysisResult ar;
try {
ar = la.trajectoryAnalysis(instance);
} catch (Exception e2) {
e2.printStackTrace();
throw new ExecutionException(e2.getMessage(),e2);
}
AnalysisResultFactory f = AnalysisResultFactory.eINSTANCE ;
AnalysisArtifact result = f.createAnalysisArtifact() ;
......@@ -85,12 +91,47 @@ public class AadlToTrajectoryActionHandler extends AbstractHandler {
ResourceSet rset = resource.getResourceSet();
Resource analysisResource = rset.createResource(resUri);
analysisResource.getContents().add(result);
try {
analysisResource.save(null);
} catch (IOException e) {
throw new ExecutionException(e.getMessage(),e);
}
URI csvUri = resource.getURI().trimFileExtension().appendFileExtension("csv");
Resource r = rset.createResource(csvUri);
System.out.println(csvUri.toString());
File f1 = new File(csvUri.toString());
try {
PrintWriter writer =
new PrintWriter(f1);
writer.println("");
for(ComponentInstance ci: ar._virtualLink2WCTT.keySet())
{
DetailLogger res = ar._virtualLink2WCTT.get(ci);
Flow flow = ar._fm.get(ci);
for(DetailLogger.Log l:res.cur.get(0).a) {
if(l.n==null) writer.println(" , , "+l.value);
}
for(Node nn:flow.getPath().getNodes()) {
for(DetailLogger.Log l:res.cur.get(0).a) {
if(l.n==nn) writer.println(l.n.getId()+", "+(l.f==null ? "" : l.f.getId()) +", "+l.value);
}
}
writer.println("Flow "+ci.getFullName()+" : WCRT = "+res.cur.get(0).value);
}
writer.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
r.save(null);
} catch (IOException e) {
throw new ExecutionException(e.getMessage(),e);
}
return null;
}
......
......@@ -9,17 +9,19 @@ import fr.tpt.aadl.ramses.analysis.AnalysisSource;
import fr.tpt.aadl.ramses.analysis.QualitativeAnalysisResult;
import fr.tpt.aadl.ramses.analysis.QuantitativeAnalysisResult;
import fr.tpt.aadl.ramses.control.support.analysis.AnalysisArtifact;
import fr.tpt.mem4csd.sefa.trajectory.model.Flow;
public class TrajectoryAnalysisResult {
Map<ComponentInstance, Float> _virtualLink2WCTT;
Map<ComponentInstance, DetailLogger> _virtualLink2WCTT;
Map<ComponentInstance, Float> _deadlines;
public TrajectoryAnalysisResult(Map<ComponentInstance, Float> results,
Map<ComponentInstance, Float> deadlines)
Map<ComponentInstance, Flow> _fm;
public TrajectoryAnalysisResult(Map<ComponentInstance, DetailLogger> results,
Map<ComponentInstance, Float> deadlines, Map<ComponentInstance, Flow> flowMap)
{
_virtualLink2WCTT = results;
_deadlines = deadlines;
_fm = flowMap;
}
public void normalize(AnalysisArtifact result) {
......@@ -40,11 +42,11 @@ public class TrajectoryAnalysisResult {
quantar.setSource(as);
quantar.setValue(_virtualLink2WCTT.get(ci));
quantar.setValue((float)_virtualLink2WCTT.get(ci).cur.get(0).value);
if(_deadlines.get(ci)!=null && _deadlines.get(ci)>0)
{
quantar.setMargin((_deadlines.get(ci)-_virtualLink2WCTT.get(ci))/_deadlines.get(ci));
quantar.setMargin((_deadlines.get(ci)-(float)_virtualLink2WCTT.get(ci).cur.get(0).value)/_deadlines.get(ci));
QualitativeAnalysisResult qualar = factory.createQualitativeAnalysisResult();
......@@ -53,7 +55,7 @@ public class TrajectoryAnalysisResult {
as_qual.setScope(ci.getComponentInstancePath());
qualar.setSource(as_qual);
qualar.setNfpId(nfpId);
boolean res = _virtualLink2WCTT.get(ci)<_deadlines.get(ci);
boolean res = _virtualLink2WCTT.get(ci).cur.get(0).value<_deadlines.get(ci);
qualar.setValidated(res);
result.getResults().add(qualar);
}
......
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