コード例 #1
1
ファイル: LinkChart.java プロジェクト: printmiles/JavaNews
 /**
  * Updates the data set for both charts with the contents of the supplied Hashtable. The Hashtable
  * is expected to contain the following items:
  *
  * <ul>
  *   <li>down - The number of links currently in a down state
  *   <li>up - The number of links currently in an up state
  *   <li>unknown - The number of links currently in an unknown state
  * </ul>
  *
  * @param linkStats The hashtable containing the entries indicating current link statistics.
  */
 public void updateData(Hashtable<String, Integer> linkStats) {
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
 }
コード例 #2
0
  @Override
  public JPanel getChart(int type, Object parameter1, Object parameter2)
      throws ApplicationException {
    // TODO Methode ausfertigen

    JFreeChart chart = null;

    switch (type) {
      case VISUALISIERUNG_ANTEIL_TESTATABNAHMEN:
        {

          /* Parameter 1 muss String sein, Parameter 2 muss NULL sein.*/
          if (!(parameter1 instanceof String && parameter2 == null)) {
            throw new ApplicationException(
                "Die übergebenen Basisparameter passen nicht zum Visualisierungstyp.");
          }

          String semester = (String) parameter1;
          DefaultCategoryDataset dataset = new DefaultCategoryDataset();

          /* Iteration über alle Studienrichtungen. */
          for (Studienrichtung studr : this.getAllStudienrichtung()) {

            /* Anzahl der Studenten die sich für ein Praktikum eines
            Moduls in einem bestimmten Semester angemeldet haben. */
            String sql =
                "SELECT M.MKUERZEL AS Modul, Count(*) AS Anmeldungen"
                    + " FROM MODUL M, PRAKTIKUMSTEILNAHME P, STUDENT S"
                    + " WHERE P.MATRIKEL = S.MATRIKEL"
                    + " AND M.MKUERZEL = P.MKUERZEL"
                    + " AND M.PR > 0"
                    + " AND P.SEMESTER = '"
                    + semester
                    + "'"
                    + " AND S.SKUERZEL = '"
                    + studr.getKuerzel()
                    + "'"
                    + " GROUP BY M.MKUERZEL";

            ResultSet resultSet = null;
            try {

              resultSet = executeQuery(sql);
              while (resultSet.next()) {
                /* Speichern der Anzahl der ANmeldungen zu einem
                 * Modul */
                String modul = resultSet.getString("Modul");
                int anmeldungen = resultSet.getInt("Anmeldungen");

                /* Anzahl der Bestandenen Praktikas eines Moduls
                in einem bestimmten Semester*/
                sql =
                    "SELECT M.MKUERZEL AS Modul, Count(*) AS Bestanden"
                        + " FROM MODUL M, PRAKTIKUMSTEILNAHME P, STUDENT S"
                        + " WHERE P.MATRIKEL = S.MATRIKEL"
                        + " AND M.MKUERZEL = P.MKUERZEL"
                        + " AND M.MKUERZEL = '"
                        + modul
                        + "'"
                        + " AND M.PR > 0"
                        + " AND P.SEMESTER = '"
                        + semester
                        + "'"
                        + " AND S.SKUERZEL = '"
                        + studr.getKuerzel()
                        + "'"
                        + " AND P.TESTAT > 0"
                        + " GROUP BY M.MKUERZEL";

                int bestanden = 0;
                ResultSet resultSet1 = executeQuery(sql);
                if (resultSet1.next()) {
                  bestanden = resultSet1.getInt("Bestanden");
                }

                /* Berechnung des Prozentualen Anteils von
                bestanden zu teilgenommen */
                double wert =
                    (bestanden == 0) ? 0 : (double) bestanden / (double) anmeldungen * 100;

                /* Dataset die Werte übergeben
                % - Wert, Modulname, Studienrichtung */
                dataset.addValue(wert, modul, studr.getKuerzel());
              }

            } catch (SQLException ex) {
              System.out.println(ex.getMessage());
            }
          }
          /* Neues Balken Diagramm erzeugen mit folgenden Werte:
           * Titel, X-Achse Beschreibung, Y-Achse Beschreibung, Daten,
           * Vertical/Horizontal, Legende, Tooltip, URL.
           */
          chart =
              ChartFactory.createBarChart(
                  semester,
                  "Praktikumsmodule nach Studienrichtung",
                  "Erfolgreiche Teilnahme in %",
                  dataset,
                  PlotOrientation.VERTICAL,
                  true,
                  true,
                  false);
        }
        break;

      case VISUALISIERUNG_AUFTEILUNG_ANMELDUNGEN:
        {
          if (!(parameter1 instanceof Studienrichtung && parameter2 instanceof String)) {
            throw new ApplicationException(
                "Die übergebenen Basisparameter passen nicht zum Visualisierungstyp.");
          }

          Studienrichtung studienrichtung = (Studienrichtung) parameter1;
          String semester = (String) parameter2;

          DefaultPieDataset dataset = new DefaultPieDataset();

          String sql =
              "SELECT M.MKUERZEL AS Modul, Count(*) AS Anmeldungen"
                  + " FROM MODUL M, PRAKTIKUMSTEILNAHME P, STUDENT S"
                  + " WHERE P.MATRIKEL = S.MATRIKEL"
                  + " AND M.MKUERZEL = P.MKUERZEL"
                  + " AND M.PR > 0"
                  + " AND P.SEMESTER = '"
                  + semester
                  + "'"
                  + " AND S.SKUERZEL = '"
                  + studienrichtung.getKuerzel()
                  + "'"
                  + " GROUP BY M.MKUERZEL";
          try {
            ResultSet resultSet = executeQuery(sql);

            int i = 0;

            while (resultSet.next()) {

              int tmpAnmelungen = resultSet.getInt("Anmeldungen");
              String tmpModul = resultSet.getString("Modul");

              /* SchlüsselText zusammenbauen */
              String key = tmpModul + ": " + tmpAnmelungen + " Anmeldungen";

              dataset.insertValue(i, key, tmpAnmelungen);
              i++;
            }
          } catch (SQLException ex) {
            System.out.println(ex.getMessage());
          }

          /* PieChart erstellen: Titel, Daten, Legende, ToolTip, URL */
          chart =
              ChartFactory.createPieChart(
                  studienrichtung.toString() + " (" + semester + ")", dataset, true, true, false);
        }
        break;

      case VISUALISIERUNG_ENTWICKLUNG_ANMELDUNGEN:
        {
          if (!(parameter1 instanceof Modul && parameter2 == null)) {
            throw new ApplicationException(
                "Die übergebenen Basisparameter passen nicht zum Visualisierungstyp.");
          }

          Modul modul = (Modul) parameter1;

          DefaultCategoryDataset dataset = new DefaultCategoryDataset();

          /* Anmeldungen/Testate zu einem Modul in allen Semestern*/
          String sql =
              "SELECT count(*) AS Anmeldungen, P.SEMESTER, SUM(P.TESTAT) AS Testatvergaben"
                  + " FROM PRAKTIKUMSTEILNAHME P"
                  + " WHERE P.MKUERZEL = '"
                  + modul.getKuerzel()
                  + "'"
                  + " GROUP BY P.SEMESTER";
          try {
            ResultSet resultSet = executeQuery(sql);

            while (resultSet.next()) {
              String semester = resultSet.getString("Semester");
              int anmeldungen = resultSet.getInt("Anmeldungen");
              int testate = resultSet.getInt("Testatvergaben");
              dataset.addValue(anmeldungen, "Anmeldungen", semester);
              dataset.addValue(testate, "Testatvergaben", semester);
            }
          } catch (SQLException ex) {
            System.out.println(ex.getMessage());
          }

          chart =
              ChartFactory.createLineChart(
                  modul.getName() + " (" + modul.getKuerzel() + ")",
                  "Semester",
                  "Studierende",
                  dataset,
                  PlotOrientation.VERTICAL,
                  true,
                  true,
                  false);
        }
        break;

      case VISUALISIERUNG_ANMELDUNGEN_TESTATE:
        {
          if (!(parameter1 instanceof Studienrichtung && parameter2 instanceof String)) {
            throw new ApplicationException(
                "Die übergebenen Basisparameter passen nicht zum Visualisierungstyp.");
          }

          Studienrichtung studienrichtung = (Studienrichtung) parameter1;
          String semester = (String) parameter2;

          DefaultCategoryDataset dataset = new DefaultCategoryDataset();

          String sql =
              "SELECT count(*) AS Anmeldungen, SUM(P.TESTAT) AS Testatvergaben, P.MKUERZEL AS Modul"
                  + " FROM PRAKTIKUMSTEILNAHME P, KATEGORIEUMFANG K"
                  + " WHERE P.SEMESTER = '"
                  + semester
                  + "'"
                  + " AND P.MKUERZEL = K.MKUERZEL"
                  + " AND K.SKUERZEL = '"
                  + studienrichtung.getKuerzel()
                  + "'"
                  + " GROUP BY P.MKUERZEL";
          try {
            ResultSet resultSet = executeQuery(sql);

            while (resultSet.next()) {
              String modulName = resultSet.getString("Modul");
              int anmeldungen = resultSet.getInt("Anmeldungen");
              int testatvergaben = resultSet.getInt("Testatvergaben");

              dataset.addValue(anmeldungen, "Anmeldungen", modulName);
              dataset.addValue(testatvergaben, "Testatvergaben", modulName);
            }

          } catch (SQLException ex) {
            System.out.println(ex.getMessage());
          }

          chart =
              ChartFactory.createBarChart(
                  studienrichtung.getName() + " (" + studienrichtung.getKuerzel() + ")",
                  "Modul",
                  "Studierende",
                  dataset,
                  PlotOrientation.VERTICAL,
                  true,
                  true,
                  false);
        }
        break;

      default:
        {
          throw new ApplicationException("Der Visualisierungstyp ist nicht definiert.");
        }
    }

    return new ChartPanel(chart);
  }
コード例 #3
0
ファイル: LinkChart.java プロジェクト: printmiles/JavaNews
 /**
  * Initialises the class and internal logger. Uses the supplied arguments to receive data from the
  * application and add data to the charts dynamically.
  *
  * @param title The title of the charts on display. Whether the displayed data is for <code>new
  *     </code> or <code>old</code> links. That is whether the data is for newly discovered links
  *     or existing (old) links already stored within the database.
  * @param parent The instance of <code>COMPortClient</code> that acts as the data source for the
  *     charts.
  */
 public LinkChart(String title, COMPortClient parent) {
   super("Charts", true, true, true, true);
   super.setLayer(1);
   identifier = title.toLowerCase();
   // Obtain an instance of Logger for the class
   log = LoggerFactory.getLogger(className);
   owner = parent;
   // Setup a hashtable to hold the values for up, down and unknown link states
   Hashtable<String, Integer> linkStats = new Hashtable<String, Integer>();
   if (identifier.equals("old")) {
     this.setTitle("Recognised Link Status on " + owner.getPortName() + ":");
     // Get the current figures from the link table
     linkStats = ((LinkTable) owner.getLinkTable().getModel()).getInitialFigures();
   } else if (identifier.equals("new")) {
     this.setTitle("Discovered Link Status on " + owner.getPortName() + ":");
     linkStats = ((LinkTable) owner.getNewLinkTable().getModel()).getInitialFigures();
   } else {
     // If the identifier was set to something other than old or new then it's not right.
     log.warning("An instance of LinkChart has been created for an unknown purpose.");
     return;
   }
   // Initialise the dataset for the pie chart
   dpdCurrentData = new DefaultPieDataset();
   dpdCurrentData.insertValue(0, "Link Down", linkStats.get("down"));
   dpdCurrentData.insertValue(1, "Link Up", linkStats.get("up"));
   dpdCurrentData.insertValue(2, "Link State Unknown", linkStats.get("unknown"));
   // Initialise the dataset for the line chart
   dcdPreviousData = new DefaultCategoryDataset();
   dcdPreviousData.addValue(
       linkStats.get("down"), "Link Down", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("up"), "Link Up", Calendar.getInstance().getTime().toString());
   dcdPreviousData.addValue(
       linkStats.get("unknown"),
       "Link State Unknown",
       Calendar.getInstance().getTime().toString());
   // Set the variables we need for holding the charts
   JFreeChart jfcCurrentStatus; // This will be displayed as a pie chart
   JFreeChart jfcPreviousStatus; // This will be displayed as a line chart
   ChartPanel cpCurrent; // Chartpanels hold the JFreeChart
   ChartPanel cpPrevious;
   // Use the factory to create the charts
   jfcCurrentStatus =
       ChartFactory.createPieChart("Current Status", dpdCurrentData, true, true, false);
   jfcPreviousStatus =
       ChartFactory.createLineChart(
           "Previous Status",
           "Time received",
           "Number of Links",
           dcdPreviousData,
           PlotOrientation.VERTICAL,
           true,
           true,
           false);
   // Add them to the chart panels
   cpCurrent = new ChartPanel(jfcCurrentStatus);
   cpPrevious = new ChartPanel(jfcPreviousStatus);
   // Add the chart panels to the content pane
   this.add(cpCurrent, BorderLayout.EAST);
   this.add(cpPrevious, BorderLayout.WEST);
   // Change the layout to show them next to each other
   this.setLayout(new GridLayout(1, 2));
   // Add a listener to the window
   this.addInternalFrameListener(new CloseLinkChart(this));
   log.finest("Adding frame to the desktop");
   // Set the window properties and display it
   Client.getJNWindow().addToDesktop(this);
   this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
   this.setSize(650, 400);
   this.setVisible(true);
   owner.addChartWindow(title, this);
 }