Package de.hpi.eworld.simulationstatistic.model

Examples of de.hpi.eworld.simulationstatistic.model.StatisticsDataManager


    // TODO
    // dataSetBox.currentIndexChanged.disconnect(this, "onDataSetSelected()");
   
    String prevDatasetId = (String) dataSetBox.getItemAt(dataSetBox.getSelectedIndex());
    dataSetBox.removeAllItems();
    StatisticsDataManager smm = StatisticsDataManager.getInstance();
    if (smm.numDatasets() != 0) {
      for (StatDataset dataset : smm.getDatasets()) {
        // add item to visualizer combo box, if it belongs to
        // the current map
        if (dataset.belongsToCurrentMap()) {
          // TODO
          // dataSetBox.addItem(dataset.getDisplayText(), dataset.getId());
View Full Code Here


  /**
   * Test all variants for model manager creation
   */
  @Test
  public void testModelManagerCreation() {
    StatisticsDataManager mm = StatisticsDataManager.getInstance();
    Assert.assertSame(mm, StatisticsDataManager.getInstance());
    // clear manager to avoid side effects from other tests
    mm.clear();

    Assert.assertNull(mm.getLastDataset());
    Assert.assertEquals(0, mm.numDatasets());
    Assert.assertEquals(0, mm.getDatasets().size());
  }
View Full Code Here

  /**
   * Tests functionality for actually managing the models
   */
  @Test
  public void addingRemovingModelsTest() {
    StatisticsDataManager mm = StatisticsDataManager.getInstance();
    StatDataset model1 = new StatDataset();
    StatDataset model2 = new StatDataset();
    StatDataset model3 = new StatDataset();

    mm.addDataset(model1);
    Assert.assertEquals(model1.getId(), mm.getLastDataset().getId());
    Assert.assertEquals(1, mm.numDatasets());
    Assert.assertEquals(1, mm.getDatasets().size());

    mm.addDataset(model2);
    Assert.assertEquals(model2.getId(), mm.getLastDataset().getId());
    Assert.assertEquals(2, mm.numDatasets());
    Assert.assertEquals(2, mm.getDatasets().size());

    mm.addDataset(model3);
    Assert.assertEquals(model3.getId(), mm.getLastDataset().getId());
    Assert.assertEquals(3, mm.numDatasets());
    Assert.assertEquals(3, mm.getDatasets().size());

    Assert.assertSame(model1, mm.getDataset(model1.getId()));
    Assert.assertSame(model2, mm.getDataset(model2.getId()));
    Assert.assertSame(model3, mm.getDataset(model3.getId()));

    mm.removeDataset(model3.getId());
    Assert.assertEquals(model2.getId(), mm.getLastDataset().getId());
    Assert.assertNull(mm.getDataset(model3.getId()));
    Assert.assertEquals(2, mm.numDatasets());
    Assert.assertSame(model1, mm.getDataset(model1.getId()));
    Assert.assertSame(model2, mm.getDataset(model2.getId()));

    mm.clear();
    Assert.assertNull(mm.getLastDataset());
    Assert.assertNull(mm.getDataset(model3.getId()));
    Assert.assertNull(mm.getDataset(model2.getId()));
    Assert.assertNull(mm.getDataset(model1.getId()));
    Assert.assertEquals(0, mm.numDatasets());
  }
View Full Code Here

    ArrayList<ModelElement> allElements = TestCaseUtil
        .createSampleTestcase();
    ModelManager mm = ModelManager.getInstance();
    mm.clearModel();

    StatisticsDataManager smm = StatisticsDataManager.getInstance();
    smm.clear();
    EdgeModel testEdge = null;

    // create 2 dummy models
    StatDataset model1 = new StatDataset();
    model1.setBelongsToCurrentMap(true);
    StatInterval interval1 = new StatInterval("int1", 0, 100);
    model1.addInterval(interval1);
    StatDataset model2 = new StatDataset();
    model2.setBelongsToCurrentMap(true);
    StatInterval interval2 = new StatInterval("int2", 0, 100);
    model2.addInterval(interval2);

    for (ModelElement element : allElements) {
      if (element instanceof WayModel) {
        WayModel way = (WayModel) element;
        //add way to ModelManager
        mm.addModelElement(way);
       
        List<EdgeModel> edges = way.getBackwardEdges();
        edges.addAll(way.getForwardEdges());
        for (EdgeModel edge : edges) {
          // for each edge in the testcase add a StatEdge to the dummy
          // model...
          // with defaults for the values to be tested for (maxspeed, minspeed,
          // street name) and ...
          // ...without lanes (model1)
          StatEdge edge1 = TestCaseUtil.createTestStatEdge(true,
              false, 0, edge.getInternalID());
          edge1.setMaxSpeed(0);
          edge1.setMinSpeed(0);
          edge1.setStreetName(null);
          interval1.addStatEdge(edge1);

          // ...with same number of lanes as the edge has (model2)
          int lanes = edge.getNoOfLanes();
          //however, eWorlds edges have 1 lane by default, SUMOs do not
          lanes = (lanes == 1)? 0: lanes;
          StatEdge edge2 = TestCaseUtil.createTestStatEdge(true,
              true, lanes, edge.getInternalID());
          edge2.setMaxSpeed(0);
          edge2.setMinSpeed(0);
          edge2.setStreetName(null);
          interval2.addStatEdge(edge2);
         
         
          //System.out.println("Lanes   edge:" + edge.getNoOfLanes() +
          //    "statedge:" + edge2.numLanes());
          // also look for an edge, that has all attributes we want to
          // test for
          if (testEdge == null) {
            if ((edge.getMaxspeed() != 0)
                && (edge.getMinspeed() != 0)
                && (edge.getParentWay().getDescription() != null)) {
              testEdge = edge;
            }//end if
          }//end if
        }//end for edges
      }//end instanceof
    }//end for allElements

    // add models to statmodelmanager and test if testcase data was added to
    // them
    smm.addDataset(model1);
    StatEdge testStatEdge = model1.getInterval(0).getStatEdge(
        testEdge.getInternalID());
    Assert.assertFalse((testStatEdge.getValue(Value.MAXSPEED) == 0));
    Assert.assertFalse((testStatEdge.getValue(Value.MINSPEED) == 0));
    Assert.assertNotNull(testStatEdge.getStreetName());

    smm.clear();
    smm.addDataset(model2);
    testStatEdge = model2.getInterval(0).getStatEdge(
        testEdge.getInternalID());
    Assert.assertFalse((testStatEdge.getValue(Value.MAXSPEED) == 0));
    Assert.assertFalse((testStatEdge.getValue(Value.MINSPEED) == 0));
    Assert.assertNotNull(testStatEdge.getStreetName());
View Full Code Here

   * emits {@link #dataImported} signal
   */
  private void threadDone() {
    observable.notifyObservers(new ObserverNotification(NotificationType.dataImported));
    //set status bar text
    StatisticsDataManager statManager = StatisticsDataManager.getInstance();
    int size = statManager.getLastDataset().numIntervals();
    MainStatusBar.getInstance().showMessage( "SUMO import successful. " + String.valueOf(size) + " intervals imported", 10000 );
   
    progressDialog.dispose();
    dispose();
  }
View Full Code Here

    super(menuItem);
   
    mainPanel = new JPanel();
   
    this.logger = Logger.getLogger(this.getClass());
    StatisticsDataManager smm = StatisticsDataManager.getInstance();
    smm.addObserver(new Observer() {
      @Override
      public void update(Observable o, Object arg) {
        if (arg instanceof ObserverNotification) {
          final ObserverNotification notification = (ObserverNotification) arg;
          final NotificationType type = notification.getType();
         
          if (type.equals(NotificationType.displayInfoBox)) {
            showInfoBox((String) notification.getObj1(), (String) notification.getObj2());
          }
        }
      }
    });
   
    //setAllowedAreas(Qt.DockWidgetArea.RightDockWidgetArea, Qt.DockWidgetArea.LeftDockWidgetArea);
//    setTitle(title);
    tabWidget = new JPanel();
    tabWidget.setMinimumSize(new Dimension(150, 200));
    tabWidget.setMaximumSize(new Dimension(235,9999));

    // statDataWidget
    // ------------------------------------------------------------
    statDataWidget = new JPanel();
    GridBagLayout dataLayout = new GridBagLayout();

    listModel = new DefaultListModel<ListValue>();
    datasetsList = new JList<Object>();
   
    datasetsListPopup = new JPopupMenu();
    datasetsListPopup.addPopupMenuListener(new PopupMenuListener() {
      @Override
      public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
        displayDatasetItem((ListValue) e.getSource());
      }
     
      @Override
      public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
     
      @Override
      public void popupMenuCanceled(PopupMenuEvent e) {}
    });
   
    // context actions
    JMenuItem showPropertiesAction = new JMenuItem("Properties");
    showPropertiesAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        showProperties();
      }
    });
    datasetsListPopup.add(showPropertiesAction);
   
    JMenuItem showChartsAction = new JMenuItem("Show charts");
    showChartsAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        showCharts();
      }
    });
    datasetsListPopup.add(showChartsAction);
   
    showOnMapAction = new JMenuItem("Show on map");
    showOnMapAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        initShowOnMap();
      }
    });
    datasetsListPopup.add(showOnMapAction);
   
    JMenuItem showRawAction = new JMenuItem("Open data file");
    showRawAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        showRawData();
      }
    });
    datasetsListPopup.add(showRawAction);
   
    JMenuItem renameSetAction = new JMenuItem("Rename");
    renameSetAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        onRenameDataset();
      }
    });
    datasetsListPopup.add(renameSetAction);
   
    JMenuItem deleteSetAction = new JMenuItem("Remove");
    deleteSetAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        onDeleteDataset();
      }
    });
    datasetsListPopup.add(deleteSetAction);
   
    JMenuItem deleteAllAction = new JMenuItem("Remove all");
    deleteAllAction.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        super.mouseClicked(e);
        onDeleteAllDatasets();
      }
    });
    datasetsListPopup.add(deleteAllAction);

    //datasetsList.setContextMenuPolicy(Qt.ContextMenuPolicy.NoContextMenu);
    datasetsList.addListSelectionListener(new ListSelectionListener() {
      @Override
      public void valueChanged(ListSelectionEvent e) {
        checkBelongingToMap();
      }
    });
   
    statAutoImport = new JCheckBox("Automatically import data");
    statAutoImport.setToolTipText("Import of the SUMO dump data will be triggered automatically when the simulation finishes");
    statAutoImport.setSelected(true);

    final GridBagConstraints datasetsListConstraints = new GridBagConstraints();
    datasetsListConstraints.gridx = 0;
    datasetsListConstraints.gridy = 0;
    datasetsListConstraints.fill = GridBagConstraints.HORIZONTAL;
    dataLayout.setConstraints(datasetsList, datasetsListConstraints);
    mainPanel.add(datasetsList);
   
    final GridBagConstraints statAutoImportConstraints = new GridBagConstraints();
    statAutoImportConstraints.gridx = 1;
    statAutoImportConstraints.gridy = 0;
    statAutoImportConstraints.gridwidth = 1;
    statAutoImportConstraints.fill = GridBagConstraints.HORIZONTAL;
    dataLayout.setConstraints(statAutoImport, statAutoImportConstraints);
    mainPanel.add(statAutoImport);

    statDataWidget.setLayout(dataLayout);


    //simulationDock.set(tabWidget.indexOf(statDataWidget));

    smm.addObserver(new Observer() {
      @Override
      public void update(Observable o, Object arg) {
        if (arg instanceof ObserverNotification) {
          final ObserverNotification notification = (ObserverNotification) arg;
          final NotificationType type = notification.getType();
         
          if (type.equals(NotificationType.datasetsChanged)) {
            onDatasetsChanged();
          }
        }
      }
    });
   
    smm.addObserver(new Observer() {
      @Override
      public void update(Observable o, Object arg) {
        if (arg instanceof ObserverNotification) {
          final ObserverNotification notification = (ObserverNotification) arg;
          final NotificationType type = notification.getType();
View Full Code Here

   * Dis-/Enables visualizer tab depending on existence of visualizable data
   */
  private void onDatasetsChanged() {
    logger.debug("Received 'datasets changed' signal");
    datasetsListPopup.removeAll();
    StatisticsDataManager smm = StatisticsDataManager.getInstance();
    if (smm.numDatasets() == 0) {
      datasetListEmpty(true);
    } else {
      datasetListEmpty(false);

      for (final StatDataset dataset : smm.getDatasets()) {
        // create new ListWidgetItem
        ListValue itemToAdd = new ListValue(dataset.getDisplayText(), dataset.getId());
        // add the item to the list widget
        listModel.addElement(itemToAdd);
      }
View Full Code Here

TOP

Related Classes of de.hpi.eworld.simulationstatistic.model.StatisticsDataManager

Copyright © 2018 www.massapicom. 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.