Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Fixing COCOMO implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegueul committed Nov 12, 2019
1 parent e9c2c28 commit 92d1e97
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.scava.platform,
com.googlecode.pongo.runtime,
org.eclipse.scava.repository.model
org.eclipse.scava.repository.model,
org.eclipse.scava.metricprovider.rascal,
rascal_eclipse
Export-Package: org.eclipse.scava.factoid.cocomo
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
******************************************************************************/
package org.eclipse.scava.factoid.cocomo;

import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Random;

import org.eclipse.scava.metricprovider.rascal.PongoToRascal;
import org.eclipse.scava.metricprovider.rascal.RascalMetricProvider;
import org.eclipse.scava.metricprovider.rascal.trans.model.RascalMetrics;
import org.eclipse.scava.platform.AbstractFactoidMetricProvider;
import org.eclipse.scava.platform.Configuration;
import org.eclipse.scava.platform.delta.ProjectDelta;
import org.eclipse.scava.platform.factoids.Factoid;
import org.eclipse.scava.platform.factoids.FactoidCategory;
Expand All @@ -23,13 +29,17 @@
import com.mongodb.DB;
import com.mongodb.Mongo;

public class CocomoFactoid extends AbstractFactoidMetricProvider{
import io.usethesource.vallang.IInteger;
import io.usethesource.vallang.IMap;
import io.usethesource.vallang.IValue;

public class CocomoFactoid extends AbstractFactoidMetricProvider {

@Override
public String getShortIdentifier() {
return "cocomo";
}

@Override
public String getIdentifier() {
return getShortIdentifier();
Expand All @@ -42,7 +52,8 @@ public String getFriendlyName() {

@Override
public String getSummaryInformation() {
return "COCOMO is crazy."; // This method will be removed in a later version.
return "COCOMO is crazy."; // This method will be removed in a later
// version.
}

@Override
Expand All @@ -52,49 +63,58 @@ public boolean appliesTo(Project project) {

@Override
public List<String> getIdentifiersOfUses() {
return null;
return Arrays.asList("trans.rascal.LOC.genericLOC");
}

@Override
public void measureImpl(Project project, ProjectDelta delta, Factoid factoid) {
// Assumes ALL projects are "semi-detached"
// Assumes ALL projects are "semi-detached" with cost driver ratings =
// nominal (EAF = 1.0)
double a = 3.0;
double b = 1.12;
double c = 2.5;
double d = 0.35;

int kloc = new Random().nextInt(50000000); // FIXME get from metric
kloc /= 1000;

double effortApplied = a * Math.pow(kloc, b); // person months
double devTime = c * Math.pow(effortApplied, d); // months
double peopleRequired = effortApplied / devTime; // count

int years = (int)effortApplied / 12;

factoid.setFactoid("Took an estimated " + years + " years (COCOMO model).");
factoid.setCategory(FactoidCategory.CODE);

if (years < 5) {
double eaf = 1.0;

RascalMetricProvider locMetric = (RascalMetricProvider) uses.get(0);
if (locMetric == null) {
factoid.setFactoid("Couldn\t calculate COCOMO for this project (no LOC information).");
factoid.setCategory(FactoidCategory.CODE);
factoid.setStars(StarRating.ONE);
} else if (years < 10) {
factoid.setStars(StarRating.TWO);
} else if (years < 50) {
factoid.setStars(StarRating.THREE);
} else {
factoid.setStars(StarRating.FOUR);
}
}
// List<Pongo> values = locMetric.
try {
Mongo mongo;
mongo = Configuration.getInstance().getMongoConnection();
DB db = mongo.getDB(project.getShortName());
RascalMetrics rascalMetrics = new RascalMetrics(db, locMetric.getIdentifier());
IMap values = (IMap) PongoToRascal.toValue(rascalMetrics, locMetric.getReturnType(), false);

public static void main(String[] args) throws Exception {
Mongo mongo = new Mongo();
DB db = mongo.getDB("Xtext");

CocomoFactoid f = new CocomoFactoid();
f.adapt(db);
f.measure(null, null, new Factoids(db));

System.out.println(FactoidCategory.valueOf("asdasdasdd"));
}
if (values != null) {
int kloc = 0;
Iterator<IValue> it = values.valueIterator();
while (it.hasNext())
kloc += ((IInteger) it.next()).intValue();

kloc /= 1000;

double effort = a * Math.pow(kloc, b) * eaf; // person-months
int years = (int) effort / 12;

factoid.setFactoid("Took an estimated " + years + " years (COCOMO model).");
factoid.setCategory(FactoidCategory.CODE);

if (years < 5) {
factoid.setStars(StarRating.ONE);
} else if (years < 10) {
factoid.setStars(StarRating.TWO);
} else if (years < 50) {
factoid.setStars(StarRating.THREE);
} else {
factoid.setStars(StarRating.FOUR);
}
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
}

0 comments on commit 92d1e97

Please sign in to comment.