Skip to content

Commit

Permalink
Indicador 3, rendimiento de un desarrollador
Browse files Browse the repository at this point in the history
Rendimiento de un desarrollador en comparación con el equipo
Tiene problemas, sobre todo no obtiene las métricas bien

También se hacen Arreglos Gradle
  • Loading branch information
Isabel-Roman committed Feb 22, 2025
1 parent 5361913 commit da4d75c
Show file tree
Hide file tree
Showing 12 changed files with 749 additions and 105 deletions.
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ plugins {
//para poder publicar paquetes en github
id 'maven-publish'
//Plugin para análisis estático de código
id "nebula.lint" version "17.7.0"
//id "nebula.lint" version "17.7.0"
}

//version = '2.0'

//Para publicar paquetes en github
//group = 'A4I'

publishing {
repositories {
maven {
Expand All @@ -41,14 +41,15 @@ publishing {

groupId = 'us.mitfs.samples'
artifactId = 'a4i'
version = '0.0'
version = '0.2'

from components.java
}

}
}
version = '0.2'
//group = 'us.mitfs.samples'
tasks.withType(JavaCompile) {
//Añadir la opción Xlint
options.deprecation = true
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-wrapper.jar.sha256
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
*
*/
package us.muit.fs.a4i.control.strategies;

import us.muit.fs.a4i.control.IndicatorStrategy;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import us.muit.fs.a4i.exceptions.NotAvailableMetricException;
import us.muit.fs.a4i.exceptions.ReportItemException;
import us.muit.fs.a4i.model.entities.Indicator;
import us.muit.fs.a4i.model.entities.IndicatorI.IndicatorState;
import us.muit.fs.a4i.model.entities.ReportItem;
import us.muit.fs.a4i.model.entities.ReportItemI;

/**
* Strategy for the calculation of a developer performance comparing him with
* the rest of developers
*
* @author fracrusan (year 23/24)
* @author Isabel Román
*/
public class DeveloperPerformanceStrategy implements IndicatorStrategy<Double> {

private static Logger log = Logger.getLogger(Indicator.class.getName());
// M�tricas necesarias para calcular el indicador
private static final List<String> REQUIRED_METRICS = Arrays.asList("issuesLastMonth", "closedIssuesLastMonth",
"issues4DevLastMonth", "meanClosedIssuesLastMonth");

@Override
public ReportItemI calcIndicator(List metrics) throws NotAvailableMetricException {
// Se obtienen y se comprueba que se pasan las m�tricas necesarias para calcular
// el indicador.
Optional<ReportItemI<Integer>> issuesLastMonth = metrics.stream()
.filter(m -> REQUIRED_METRICS.get(0).equals(((ReportItemI) m).getName())).findAny();
Optional<ReportItemI<Integer>> closedIssuesLastMonth = metrics.stream()
.filter(m -> REQUIRED_METRICS.get(1).equals(((ReportItemI) m).getName())).findAny();
Optional<ReportItemI<Double>> issues4DevLastMonth = metrics.stream()
.filter(m -> REQUIRED_METRICS.get(2).equals(((ReportItemI) m).getName())).findAny();
Optional<ReportItemI<Double>> meanClosedIssuesLastMonth = metrics.stream()
.filter(m -> REQUIRED_METRICS.get(3).equals(((ReportItemI) m).getName())).findAny();
ReportItemI<Double> indicatorReport = null;

if (issuesLastMonth.isPresent() && closedIssuesLastMonth.isPresent() && issues4DevLastMonth.isPresent()
&& meanClosedIssuesLastMonth.isPresent()) {
Double rendimientoMiembro;

// calculating indicator
if (issuesLastMonth.get().getValue() != 0 && issues4DevLastMonth.get().getValue() != 0
&& meanClosedIssuesLastMonth.get().getValue() != 0)
rendimientoMiembro = (closedIssuesLastMonth.get().getValue() / issuesLastMonth.get().getValue())
/ (meanClosedIssuesLastMonth.get().getValue() / issues4DevLastMonth.get().getValue());
else if (meanClosedIssuesLastMonth.get().getValue() != 0)
rendimientoMiembro = 1.0;
else
rendimientoMiembro = 0.0;

try {
// Se crea el indicador
indicatorReport = new ReportItem.ReportItemBuilder<Double>("rendimientoMiembro", rendimientoMiembro)
.metrics(Arrays.asList(issuesLastMonth.get(), closedIssuesLastMonth.get(),
issues4DevLastMonth.get(), meanClosedIssuesLastMonth.get()))
.indicator(IndicatorState.UNDEFINED).build();
} catch (ReportItemException e) {
log.info("Error en ReportItemBuilder.");
e.printStackTrace();
}

} else {
log.info("No se han proporcionado las m�tricas necesarias");
throw new NotAvailableMetricException(REQUIRED_METRICS.toString());
}

return indicatorReport;
}

@Override
public List<String> requiredMetrics() {
// Para calcular el indicador "rendimientoMiembro", ser�n necesarias las
// m�tricas
// "openIssues" y "closedIssues".
return REQUIRED_METRICS;
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package us.muit.fs.a4i.control;
package us.muit.fs.a4i.control.strategies;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.logging.Logger;

import us.muit.fs.a4i.control.IndicatorStrategy;
import us.muit.fs.a4i.exceptions.NotAvailableMetricException;
import us.muit.fs.a4i.exceptions.ReportItemException;
import us.muit.fs.a4i.model.entities.Indicator;
Expand All @@ -23,16 +24,18 @@ public class IssuesRatioIndicatorStrategy implements IndicatorStrategy<Double> {
public ReportItemI<Double> calcIndicator(List<ReportItemI<Double>> metrics) throws NotAvailableMetricException {
// Se obtienen y se comprueba que se pasan las m�tricas necesarias para calcular
// el indicador.
Optional<ReportItemI<Double>> openIssues = metrics.stream().filter(m -> REQUIRED_METRICS.get(0).equals(m.getName())).findAny();
Optional<ReportItemI<Double>> closedIssues = metrics.stream().filter(m -> REQUIRED_METRICS.get(1).equals(m.getName())).findAny();
Optional<ReportItemI<Double>> openIssues = metrics.stream()
.filter(m -> REQUIRED_METRICS.get(0).equals(m.getName())).findAny();
Optional<ReportItemI<Double>> closedIssues = metrics.stream()
.filter(m -> REQUIRED_METRICS.get(1).equals(m.getName())).findAny();
ReportItemI<Double> indicatorReport = null;

if (openIssues.isPresent() && closedIssues.isPresent()) {
Double issuesRatio;

// Se realiza el c�lculo del indicador
if(closedIssues.get().getValue()!=0)
issuesRatio = openIssues.get().getValue()/closedIssues.get().getValue();
if (closedIssues.get().getValue() != 0)
issuesRatio = openIssues.get().getValue() / closedIssues.get().getValue();
else
issuesRatio = openIssues.get().getValue();

Expand All @@ -51,7 +54,7 @@ public ReportItemI<Double> calcIndicator(List<ReportItemI<Double>> metrics) thro
throw new NotAvailableMetricException(REQUIRED_METRICS.toString());
}

return indicatorReport;
return indicatorReport;
}

@Override
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/us/muit/fs/a4i/model/remote/GitHubDeveloperEnquirer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/**
*
*/
package us.muit.fs.a4i.model.remote;

import java.util.List;
import java.util.logging.Logger;

import org.kohsuke.github.GHEvent;
import org.kohsuke.github.GHEventInfo;
import org.kohsuke.github.GHEventPayload;
import org.kohsuke.github.GHProject;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHUser;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.PagedIterable;

import us.muit.fs.a4i.exceptions.MetricException;
import us.muit.fs.a4i.model.entities.ReportI;
import us.muit.fs.a4i.model.entities.ReportItem;

import us.muit.fs.a4i.model.entities.ReportItem.ReportItemBuilder;

/**
* Deuda técnica
* Esta clase debe consultar datos sobre un desarrollador concreto de github
* Ahora mismo está en estado lamentable
* Simplemente busca los eventos de un desarrollador
* No localiza eventos de tipo ISSUE, que son los que se quería
*/
public class GitHubDeveloperEnquirer extends GitHubEnquirer {
public GitHubDeveloperEnquirer() {
super();
metricNames.add("closedIssuesLastMonth");
metricNames.add("assignedIssuesLastMonth");
log.info("Incluidos nombres metricas en Enquirer");
}

private static Logger log = Logger.getLogger(GitHubDeveloperEnquirer.class.getName());
/**
* <p>
* Identificador unívoco de la entidad a la que se refire el informe en el
* servidor remoto que se va a utilizar
* </p>
*/
private String entityId;
@Override
public ReportI buildReport(String developerId) {
// TODO Auto-generated method stub
return null;
}

@Override
public ReportItem getMetric(String metricName, String developerId) throws MetricException {
GHUser developer;

GitHub gb = getConnection();
try {
developer = gb.getUser(developerId);
log.info("Localizado el desarrollador "+developer.getName());
} catch (Exception e) {
e.printStackTrace();
throw new MetricException(
"No se puede acceder al desarrollador " + developerId + " para recuperarlo");
}

return getMetric(metricName, developer);
}

private ReportItem getMetric(String metricName, GHUser developer) throws MetricException {
log.info("Localizando la metrica "+metricName);
ReportItem metric;
if (developer == null) {
throw new MetricException("Intenta obtener una métrica de desarrollador sin haber obtenido el desarrollador");
}
switch (metricName) {
case "closedIssuesLastMonth":
metric = getClosedIssuesLastMonth(developer);
break;
case "assignedIssuesLastMonth":
metric = getAssignedIssuesLastMonth(developer);
break;
default:
throw new MetricException("La métrica " + metricName + " no está definida para un repositorio");
}

return metric;
}

private ReportItem getClosedIssuesLastMonth(GHUser developer) {
log.info("Consultando los issues asignados a un desarrollador");
ReportItemBuilder<Integer> builder = null;
int issues=0;

try {
PagedIterable <GHEventInfo> events=developer.listEvents();
for(GHEventInfo event:events) {
log.info("Evento tipo"+event.getType()+" en la fecha "+event.getCreatedAt());
if(event.getType()==GHEvent.ISSUES) {

GHEventPayload.Issue payload=event.getPayload(GHEventPayload.Issue.class);
log.info(payload.getAction());
issues++;

}

}
builder = new ReportItem.ReportItemBuilder<Integer>("closedIssuesLastMonth", issues);
builder.source("GitHub");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return builder.build();
}

private ReportItem getAssignedIssuesLastMonth(GHUser developer) {
// TODO Auto-generated method stub
return null;
}


}
Loading

0 comments on commit da4d75c

Please sign in to comment.