Skip to content

Commit

Permalink
fix in Stat
Browse files Browse the repository at this point in the history
  • Loading branch information
simonAllier committed Dec 19, 2013
1 parent 6a8f82e commit d51eb89
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 40 deletions.
6 changes: 3 additions & 3 deletions CodeCity/SourceCity-Diversify.st

Large diffs are not rendered by default.

41 changes: 23 additions & 18 deletions R.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
nbOfGoodDiversification <- function(data) {
return(length(subset(data, failure == 0)$failure))
nbOfSosie <- function(data) {
return(length(subset(data, sosie == 'true')$sosie))
}

nbOfFailDiversification <- function(data) {
return(length(subset(data, failure != 0)$failure))
nbOfCompile <- function(data) {
return(length(subset(data, compile == 'true')$compile))
}

nbOfDiversification <- function(data) {
return(length(data$failure))
nbOfTrial <- function(data) {
return(length(data$sosie))
}

chiTestTab <- function(data, index) {
Expand Down Expand Up @@ -38,21 +38,26 @@ diversiticationStat <- function(data, index) {
result <- data.frame ();
for(i in set(data[,index])) {
sub <- subset(data, data[,index] == i);
good <- nbOfGoodDiversification(sub);
fail <- nbOfFailDiversification(sub);
result[paste(i,sep=""),"trial"] <- good + fail;
trial <- nbOfTrial(sub)
sosie <- nbOfSosie(sub);
compile <- nbOfCompile(sub);
result[paste(i,sep=""),"trial"] <- trial;

result[paste(i,sep=""),"incorrect"] <- fail;
result[paste(i,sep=""),"sosie"] <- good;
result[paste(i,sep=""),"% sosie"] <- 100*good/(fail + good);
# result[paste(i,sep=""),"% total"] <- 100*(fail + good)/nbOfDiversification(data);
result[paste(i,sep=""),"compile"] <- compile;
result[paste(i,sep=""),"% compile"] <- 100*compile/(trial);
result[paste(i,sep=""),"sosie"] <- sosie;
result[paste(i,sep=""),"% sosie"] <- 100*sosie/(trial);
}
good <- nbOfGoodDiversification(data);
fail <- nbOfFailDiversification(data);
sosie <- nbOfSosie(data);
trial <- nbOfTrial(data)
compile <- nbOfCompile(data);


result["all","incorrect"] <- fail;
result["all","trial"] <- good + fail;
result["all","% sosie"] <- 100*good/(fail + good);
result["all","trial"] <- trial;
result["all","compile"] <- compile;
result["all,"% compile"] <- 100*compile/(trial);
result["all","sosie"] <- sosie;
result["all","% sosie"] <- 100*sosie/(trial);
# result["all","% total"] <- 100*(fail + good)/nbOfDiversification(data);
return(result)
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/fr/inria/diversify/DiversifyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,23 +247,18 @@ protected void computeDiversifyStat(String transDir, String fileName) throws IOE
TransformationParser tf = new TransformationParser(codeFragments);
List<Transformation> transformations = tf.parseDir(transDir);
TransformationsWriter write = new TransformationsWriter(transformations, fileName);
int i = 0;
for (Transformation t : transformations)
if(t.numberOfFailure() == -1)
i++;

Log.debug("i: "+i);

Log.debug("all transformation type : {}", getAllTransformationType(transformations));
String name = write.writeAllTransformation(null);
statForR(name);
for(String type : getAllTransformationType(transformations)) {
Log.debug("all transformation for: "+type);
name = write.writeAllTransformation(type);
// statForR(name);
}

name = write.writeGoodTransformation(null);
// statForR(name);

for(String type : getAllTransformationType(transformations)) {
Log.debug("good transformation for: "+type);
name = write.writeGoodTransformation(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void writeStat(String output) {
writeDetail(output+detailFileSuffix);
writeSourceCity(output+sourceCityFileSuffix);
writeDetailForTransformationType(output+typeFileSuffix);

Log.debug("end");
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -190,7 +190,8 @@ protected void writeSourceCity(String fileName) throws IOException {
Log.debug("write data for source city");
bw.write("type"+separator+"package"+separator+"class"+separator
+"classReplaceOrAdd"+separator+"method"+separator+
"size"+separator+"nbMethod"+separator+"compile"+separator+"sosie\n");
"size"+separator+"nbMethod"+separator+"compile"+separator+
"sosie"+separator+"stmtType"+separator+"level"+"\n");
for(Transformation trans : transformations) {
StringBuffer sb = new StringBuffer();
try {
Expand All @@ -211,6 +212,10 @@ protected void writeSourceCity(String fileName) throws IOException {
sb.append(trans.getCompile());
sb.append(separator);
sb.append(trans.numberOfFailure() == 0);
sb.append(separator);
sb.append(trans.stmtType());
sb.append(separator);
sb.append(trans.level());
sb.append("\n");
bw.write(sb.toString());
}catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public interface Transformation {
public String packageLocationName();
public String methodLocationName();
public boolean getCompile();
public String level();
public String stmtType();


void setCompile(boolean b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ protected Transformation parseTransformation(JSONObject jsonObject) throws Excep
// trans.addParent(parseTransformation(array.getJSONObject(i)));
// }
// }
try {
trans.setJUnitResult(jsonObject.getInt("Failures"));
if(trans.numberOfFailure() ==0 ) {
}
} catch (Exception e) {}

trans.setCompile(jsonObject.getBoolean("setCompile"));
return trans;
}
Expand Down Expand Up @@ -144,10 +150,9 @@ protected ASTTransformation parseASTDelete(JSONObject jsonObject) throws Excepti
JSONObject t = getTransformation(jsonObject);
CodeFragment d = findCodeFragment(t.getJSONObject("CodeFragmentDelete"));
trans.setPosition(d);
// }

if(jsonObject.getBoolean("allTestRun"))
trans.setJUnitResult(jsonObject.getInt("Failures"));
// if(jsonObject.getBoolean("allTestRun"))
// trans.setJUnitResult(jsonObject.getInt("Failures"));

return trans;
}
Expand All @@ -165,8 +170,8 @@ protected ASTTransformation parseASTAdd(JSONObject jsonObject) throws Exception
} catch (Exception e) {}

// }
if(jsonObject.getBoolean("allTestRun"))
trans.setJUnitResult(jsonObject.getInt("Failures"));
// if(jsonObject.getBoolean("allTestRun"))
// trans.setJUnitResult(jsonObject.getInt("Failures"));

return trans;
}
Expand All @@ -181,10 +186,6 @@ protected ASTTransformation parseASTReplace(JSONObject jsonObject) throws Except
trans.setCodeFragmentToReplace(findCodeFragment(t.getJSONObject("CodeFragmentReplace")));
trans.setVarMapping(parseVariableMapping(t.getJSONObject("VariableMapping")));

// }
if(jsonObject.getBoolean("allTestRun"))
trans.setJUnitResult(jsonObject.getInt("Failures"));

return trans;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,14 @@ public void addTransformation(ASTTransformation transformation) {
public void setCompile(boolean b){
compile = b;
}

@Override
public String level() {
return "multi";
}

@Override
public String stmtType() {
return "multi";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import fr.inria.diversify.util.Log;
import org.apache.commons.io.FileUtils;
import spoon.compiler.Environment;
import spoon.reflect.code.*;
import spoon.reflect.cu.CompilationUnit;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtSimpleType;
Expand All @@ -23,7 +24,7 @@
*/
public abstract class ASTTransformation implements Transformation {
protected CodeFragment position;
protected Integer failures;
protected Integer failures = -1;
protected List<ASTTransformation> parents;
protected boolean compile;

Expand Down Expand Up @@ -128,6 +129,27 @@ public void setCompile(boolean b){
compile = b;
}

@Override
public String level() {
CtCodeElement stmt = position.getCtCodeFragment();
if(stmt instanceof CtLocalVariable
|| stmt instanceof CtNewClass
|| stmt instanceof CtBreak
|| stmt instanceof CtUnaryOperator
|| stmt instanceof CtAssignment
|| stmt instanceof CtReturn
|| stmt instanceof CtOperatorAssignment
|| stmt instanceof CtContinue
|| stmt instanceof CtInvocation)
return "statement";
return "block";
}

@Override
public String stmtType() {
return position.getCtCodeFragment().getClass().getSimpleName();
}

// public abstract void add(ASTTransformation replace);

// public String positionString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,14 @@ public int nbMethodInClassLocation() {
public void setCompile(boolean b){
compile = b;
}

@Override
public String level() {
return "bytecode";
}

@Override
public String stmtType() {
return "bytecode";
}
}

0 comments on commit d51eb89

Please sign in to comment.