org.jfree.data.time.FixedMillisecond Java Examples

The following examples show how to use org.jfree.data.time.FixedMillisecond. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChartVirtualSensor.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method adds the specified stream elements to the timeSeries of the
 * appropriate plot.
 * 
 * @param streamElement
 */
public synchronized void addData ( StreamElement streamElement ) {
   for ( int i = 0 ; i < streamElement.getFieldNames( ).length ; i++ ) {
      TimeSeries timeSeries = dataForTheChart.get( streamElement.getFieldNames( )[ i ] );
      if ( timeSeries == null ) {
         dataForTheChart.put( streamElement.getFieldNames( )[ i ] , timeSeries = new TimeSeries( streamElement.getFieldNames( )[ i ] , org.jfree.data.time.FixedMillisecond.class ) );
         if(isTimeBased){
         	timeSeries.setMaximumItemAge(historySize);
         }else{
             timeSeries.setMaximumItemCount(historySize);
         }
         dataCollectionForTheChart.addSeries( timeSeries );
      }
      try {
         timeSeries.addOrUpdate( new FixedMillisecond( new Date( streamElement.getTimeStamp( ) ) ) , Double.parseDouble( streamElement.getData( )[ i ].toString( ) ) );
      } catch ( SeriesException e ) {
         logger.warn( e.getMessage( ) , e );
      }
      
   }
   changed = true;
}
 
Example #2
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for the bug report 1075255.
 */
public void testBug1075255() {
    TimeSeries ts = new TimeSeries("dummy");
    ts.add(new FixedMillisecond(0L), 0.0);
    TimeSeries ts2 = new TimeSeries("dummy2");
    ts2.add(new FixedMillisecond(0L), 1.0);
    try {
        ts.addAndOrUpdate(ts2);
    }
    catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
    assertEquals(1, ts.getItemCount());
}
 
Example #3
Source File: FixedMillisecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashcode() {
    FixedMillisecond m1 = new FixedMillisecond(500000L);
    FixedMillisecond m2 = new FixedMillisecond(500000L);
    assertTrue(m1.equals(m2));
    int h1 = m1.hashCode();
    int h2 = m2.hashCode();
    assertEquals(h1, h2);
}
 
Example #4
Source File: FixedMillisecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for immutability.
 */
public void testImmutability() {
    Date d = new Date(20L);
    FixedMillisecond fm = new FixedMillisecond(d);
    d.setTime(22L);
    assertEquals(20L, fm.getFirstMillisecond());
}
 
Example #5
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for the bug report 1075255.
 */
public void testBug1075255() {
    TimeSeries ts = new TimeSeries("dummy", FixedMillisecond.class);
    ts.add(new FixedMillisecond(0L), 0.0);
    TimeSeries ts2 = new TimeSeries("dummy2", FixedMillisecond.class);
    ts2.add(new FixedMillisecond(0L), 1.0);
    try {
        ts.addAndOrUpdate(ts2);
    }
    catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
    assertEquals(1, ts.getItemCount());
}
 
Example #6
Source File: FixedMillisecondTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    FixedMillisecond m1 = new FixedMillisecond(500000L);
    FixedMillisecond m2 = new FixedMillisecond(500000L);
    assertTrue(m1.equals(m2));
    int h1 = m1.hashCode();
    int h2 = m2.hashCode();
    assertEquals(h1, h2);
}
 
Example #7
Source File: FixedMillisecondTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The {@link FixedMillisecond} class is immutable, so should not be
 * {@link Cloneable}.
 */
public void testNotCloneable() {
    FixedMillisecond m = new FixedMillisecond(500000L);
    assertFalse(m instanceof Cloneable);
}
 
Example #8
Source File: FixedMillisecondTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The {@link FixedMillisecond} class is immutable, so should not be 
 * {@link Cloneable}.
 */
public void testNotCloneable() {
    FixedMillisecond m = new FixedMillisecond(500000L);
    assertFalse(m instanceof Cloneable);
}
 
Example #9
Source File: DiagramRenderer.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
public TimeSeriesCollection createDataset(Map<String, OXFFeatureCollection> entireCollMap, TimeseriesProperties prop, String observedProperty, boolean compress) {

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        OXFFeatureCollection obsColl = entireCollMap.get(prop.getOffering() + "@" + prop.getServiceUrl());

        String foiID = prop.getFeature();
        String obsPropID = prop.getPhenomenon();
        String procID = prop.getProcedure();

        // only if the observation concerns the observedProperty, it
        // will be added to the dataset
        if (obsPropID.equals(observedProperty)) {

            String[] foiIds = new String[] { foiID };
            String[] procedureIds = new String[] { procID };
            String[] observedPropertyIds = new String[] { obsPropID };
            ObservationSeriesCollection seriesCollection = new ObservationSeriesCollection(obsColl, foiIds, observedPropertyIds, procedureIds, true);


            //
            // now let's put in the date-value pairs.
            // ! But put it only in if it differs from the previous
            // one !
            //



            TimeSeries timeSeries = new TimeSeries(prop.getTimeseriesId(), FixedMillisecond.class);




            TimeseriesFactory factory = new TimeseriesFactory(seriesCollection);
            if (seriesCollection.getSortedTimeArray().length > 0) {
                if (compress) {
                    timeSeries = factory.compressToTimeSeries(prop.getTimeseries(), isOverview, prop.getGraphStyle());
                } else {
                    timeSeries = factory.createTimeSeries(prop.getTimeseries(), prop.getGraphStyle());
                }
            }
            dataset.addSeries(timeSeries);
        }

        dataset.setDomainIsPointsInTime(true);

        return dataset;
    }
 
Example #10
Source File: TimeseriesFactory.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
public TimeSeries createTimeSeries(SosTimeseries timeseries, String seriesType) {
    TimeSeries timeSeries = new TimeSeries(timeseries.getTimeseriesId());

    ITimePosition timeArray[] = collection.getSortedTimeArray();
    ObservedValueTuple prevObservation;
    ObservedValueTuple nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null), timeArray[0]);
    ObservedValueTuple observation = nextObservation;

    int counter = 0;
    Double sum = 0.0;

    // all obs
    LOGGER.debug("Compressionlevel none");
    for (int i = 0; i < timeArray.length; i++) {

        prevObservation = observation;
        observation = nextObservation;

        if (i + 1 < timeArray.length) {
            nextObservation = collection.getTuple(new OXFFeature(timeseries.getFeatureId(), null), timeArray[i + 1]);
        }

        // String obsVal = observation.getValue(0).toString();
        // String prevObsVal = prevObservation.getValue(0).toString();
        // String nextObsVal = nextObservation.getValue(0).toString();

        // if ((i == 0) || // first observation --> in
        // (i == timeArray.length - 1) || // last observation --> in
        // (!(prevObsVal.equals(obsVal) && nextObsVal.equals(obsVal)))) {

        counter++;

        Double resultVal = getValidData(observation.getValue(0).toString());

        if (seriesType.equals("1")) {
            // nothing
        } else if (seriesType.equals("2")) {
            if (resultVal != null) {
                resultVal += sum;
            } else {
                resultVal = sum;
            }
        } else {
            // nothing
        }

        sum = resultVal;

        ITimePosition timePos = (ITimePosition) observation.getTime();
        DateTime time = DateTime.parse(timePos.toISO8601Format());
        timeSeries.add(new FixedMillisecond(time.getMillis()), resultVal);
    }

    // }

    LOGGER.debug("Compressed observations from " + timeArray.length + " to " + counter);

    return timeSeries;

}