Package com.ubx1.pdpscanner.client.views.project

Source Code of com.ubx1.pdpscanner.client.views.project.BadPracticeLineChart

package com.ubx1.pdpscanner.client.views.project;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.visualization.client.AbstractDataTable;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.corechart.LineChart;
import com.google.gwt.visualization.client.visualizations.corechart.Options;
import com.ubx1.pdpscanner.client.views.AbstractView;
import com.ubx1.pdpscanner.shared.FindbugsBugInstance;
import com.ubx1.pdpscanner.shared.Project;

/**
* The widget for showing the evolution of bad practices through the project
* versions
*
* @author wbraik
*
*/
public class BadPracticeLineChart extends AbstractView {

  /**
   * The associated Project object
   */
  protected Project project = null;

  // View components

  private LineChart chart = null;

  public BadPracticeLineChart(Project project) {

    super(new VerticalPanel());
    this.project = project;

    // this.viewPanel.setStyleName("");
  }

  @Override
  public void buildView() {

    this.viewPanel.clear();

    this.chart = new LineChart(createChartDataTable(), createChartOptions());

    this.viewPanel.add(this.chart);
  }

  /**
   * Create the data table for populating the chart
   *
   * @return the data table for the chart
   */
  private AbstractDataTable createChartDataTable() {

    Project p = this.project;

    DataTable data = DataTable.create();
    data.addColumn(ColumnType.STRING, "Version");

    ArrayList<FindbugsBugInstance> allBp = new ArrayList<FindbugsBugInstance>();
    for (int i = 0; i < p.getVersionCount(); i++) {

      if (p.getBp(i + 1) != null)
        allBp.addAll(p.getBp(i + 1));
    }

    Set<String> usedAbbrevs = new TreeSet<String>();
    for (int i = 0; i < allBp.size(); i++) {

      usedAbbrevs.add(allBp.get(i).getAbbrev());
    }

    data.addRows(p.getVersionCount());

    Iterator<String> it = usedAbbrevs.iterator();
    while (it.hasNext()) {

      String abbrev = it.next();

      int col = data.addColumn(ColumnType.NUMBER,
          FindbugsBugInstance.getAbbrevDescription(abbrev));

      // Unavailable stats counter
      int z = 0;

      for (int i = 0; i < p.getVersionCount(); i++) {

        if (p.getBp(i + 1) == null) {
          z++;
        } else {

          // Version
          data.setValue(i - z, 0, String.valueOf(i + 1));

          int abbrevErrCount = getAbbrevErrorCount(abbrev, i + 1);

          data.setValue(i - z, col, abbrevErrCount);
        }
      }
    }

    return data;
  }

  /**
   * Create the options for customizing the chart
   *
   * @return the options for customizing the chart
   */
  private Options createChartOptions() {

    Options options = Options.create();
    options.setWidth(900);
    options.setHeight(400);
    options.setTitle("Nombre de mauvaises pratiques par catégorie "
        + "en fonction de la version");

    return options;
  }

  /**
   * Get the number of bad practice bug instances which match an abbreviation
   * and a version
   *
   * @param abbrev
   *            the abbreviation
   * @param version
   *            the version
   * @return the number of bad practice bug instances which match abbrev as
   *         their abbreviation and version as their corresponding project
   *         version
   */
  private int getAbbrevErrorCount(String abbrev, int version) {

    int count = 0;

    ArrayList<FindbugsBugInstance> bp = this.project.getBp(version);

    for (int i = 0; i < bp.size(); i++) {

      if (bp.get(i).getAbbrev().equals(abbrev)) {

        count++;
      }
    }

    return count;
  }
}
TOP

Related Classes of com.ubx1.pdpscanner.client.views.project.BadPracticeLineChart

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.