@Override public void addSeries(agentgui.ontology.DataSeries series){ org.jfree.data.time.TimeSeries newSeries = new org.jfree.data.time.TimeSeries(series.getLabel()); List valuePairs = ((agentgui.ontology.TimeSeries)series).getTimeSeriesValuePairs(); for (int i = 0; i < valuePairs.size(); i++) { TimeSeriesValuePair valuePair = (TimeSeriesValuePair) valuePairs.get(i); Simple_Long simpleLong = valuePair.getTimestamp(); Simple_Float simpleFloat = valuePair.getValue(); Long timeStampLong = simpleLong.getLongValue(); Float floatValue = simpleFloat.getFloatValue(); if (timeStampLong!=null) { TimeSeriesDataItem newItem = new TimeSeriesDataItem(new FixedMillisecond(timeStampLong), floatValue); newSeries.addOrUpdate(newItem); } } this.getTimeSeriesCollection().addSeries(newSeries); this.setChanged(); this.notifyObservers(ChartModel.EventType.SERIES_ADDED); }
/** * Update the time stamp in all series that contain it * @param oldKey The old time stamp * @param newKey The new time stamp */ public void updateKey(Number oldKey, Number newKey) { // --- Iterate over all series ------------------------------ for (int i=0; i < this.getSeriesCount(); i++) { org.jfree.data.time.TimeSeries series = this.getSeries(i); // Try to find a value pair with the old time stamp TimeSeriesDataItem oldValuePair = series.getDataItem(new FixedMillisecond(oldKey.longValue())); // If found, remove it and add a new one with the new time stamp and the old value if(oldValuePair != null){ series.delete(new FixedMillisecond(oldKey.longValue())); series.addOrUpdate(new FixedMillisecond(newKey.longValue()), oldValuePair.getValue()); } } }
/** * Edits the data series by adding data. * @param series the series * @param targetDataSeriesIndex the target data series index */ public void editSeriesAddData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException { if (targetDataSeriesIndex<=(this.getSeriesCount()-1)) { // --- Get the series ------------------------- org.jfree.data.time.TimeSeries addToSeries = (org.jfree.data.time.TimeSeries) this.getSeries(targetDataSeriesIndex); List valuePairs = ((agentgui.ontology.TimeSeries)series).getTimeSeriesValuePairs(); for (int i = 0; i < valuePairs.size(); i++) { TimeSeriesValuePair valuePair = (TimeSeriesValuePair) valuePairs.get(i); Simple_Long simpleLong = valuePair.getTimestamp(); Simple_Float simpleFloat = valuePair.getValue(); Long timeStampLong = simpleLong.getLongValue(); Float floatValue = simpleFloat.getFloatValue(); if (timeStampLong!=null) { TimeSeriesDataItem newItem = new TimeSeriesDataItem(new FixedMillisecond(timeStampLong), floatValue); addToSeries.addOrUpdate(newItem); } } } else { throw new NoSuchSeriesException(); } }
/** * Edits the data series by adding or exchanging data. * @param series the series * @param targetDataSeriesIndex the target data series index */ public void editSeriesAddOrExchangeData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException { if (targetDataSeriesIndex<=(this.getSeriesCount()-1)) { org.jfree.data.time.TimeSeries addToSeries = (org.jfree.data.time.TimeSeries) this.getSeries(targetDataSeriesIndex); List valuePairs = ((agentgui.ontology.TimeSeries)series).getTimeSeriesValuePairs(); for (int i = 0; i < valuePairs.size(); i++) { TimeSeriesValuePair valuePair = (TimeSeriesValuePair) valuePairs.get(i); Simple_Long simpleLong = valuePair.getTimestamp(); Simple_Float simpleFloat = valuePair.getValue(); Long timeStampLong = simpleLong.getLongValue(); Float floatValue = simpleFloat.getFloatValue(); if (timeStampLong!=null) { TimeSeriesDataItem newItem = new TimeSeriesDataItem(new FixedMillisecond(timeStampLong), floatValue); addToSeries.addOrUpdate(newItem); } } } else { throw new NoSuchSeriesException(); } }
/** * Edits the data series by exchanging data. * @param series the series * @param targetDataSeriesIndex the target data series index */ public void editSeriesExchangeData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException { if (targetDataSeriesIndex<=(this.getSeriesCount()-1)) { org.jfree.data.time.TimeSeries exchangeSeries = (org.jfree.data.time.TimeSeries) this.getSeries(targetDataSeriesIndex); List valuePairs = ((agentgui.ontology.TimeSeries)series).getTimeSeriesValuePairs(); for (int i = 0; i < valuePairs.size(); i++) { TimeSeriesValuePair valuePair = (TimeSeriesValuePair) valuePairs.get(i); Simple_Long simpleLong = valuePair.getTimestamp(); Simple_Float simpleFloat = valuePair.getValue(); Long timeStampLong = simpleLong.getLongValue(); Float floatValue = simpleFloat.getFloatValue(); if (timeStampLong!=null) { try { exchangeSeries.update(new FixedMillisecond(timeStampLong), floatValue); } catch (SeriesException se) { // --- Nothing to do here, just take the next value --- } } } } else { throw new NoSuchSeriesException(); } }
/** * Edits the data series by remove data. * @param series the series * @param targetDataSeriesIndex the target data series index */ public void editSeriesRemoveData(DataSeries series, int targetDataSeriesIndex) throws NoSuchSeriesException { if (targetDataSeriesIndex<=(this.getSeriesCount()-1)) { org.jfree.data.time.TimeSeries removeSeries = (org.jfree.data.time.TimeSeries) this.getSeries(targetDataSeriesIndex); List valuePairs = ((agentgui.ontology.TimeSeries)series).getTimeSeriesValuePairs(); for (int i = 0; i < valuePairs.size(); i++) { TimeSeriesValuePair valuePair = (TimeSeriesValuePair) valuePairs.get(i); Simple_Long simpleLong = valuePair.getTimestamp(); Long timeStampLong = simpleLong.getLongValue(); if (timeStampLong!=null) { removeSeries.delete(new FixedMillisecond(timeStampLong)); } } } else { throw new NoSuchSeriesException(); } }
public void add(final CalendarDateSeries<?> aSeries) { final String tmpName = aSeries.getName(); final TimeSeries tmpSeries = new TimeSeries(tmpName); for (final Entry<CalendarDate, ? extends Number> tmpEntry : aSeries.entrySet()) { final CalendarDate tmpKey = tmpEntry.getKey(); final FixedMillisecond tmpPeriod = new FixedMillisecond(tmpKey.millis); final Number tmpValue = tmpEntry.getValue(); final TimeSeriesDataItem tmpItem = new TimeSeriesDataItem(tmpPeriod, tmpValue); tmpSeries.add(tmpItem); } myCollection.addSeries(tmpSeries); ColourData tmpColour2 = aSeries.getColour(); if (tmpColour2 == null) { tmpColour2 = ColourData.random(); aSeries.colour(tmpColour2); } final int tmpRgb = tmpColour2.getRGB(); final Color tmpColour = new Color(tmpRgb); this.putColour(tmpName, tmpColour); }
/** * Callback to process a sync event. */ @Override void processSyncEvent(EventContainer event, int auth, long startTime, long stopTime, String details, boolean newEvent, int syncSource) { if (!newEvent) { // Details arrived for a previous sync event // Remove event before reinserting. int lastItem = mDatasetsSync[auth].getItemCount(); mDatasetsSync[auth].delete(lastItem-1, lastItem-1); mTooltipsSync[auth].remove(lastItem-1); } double height = getHeightFromDetails(details); height = height / (stopTime - startTime + 1) * 10000; if (height > 30) { height = 30; } mDatasetsSync[auth].add(new SimpleTimePeriod(startTime, stopTime), height); mTooltipsSync[auth].add(getTextFromDetails(auth, details, syncSource)); mTooltipGenerators[auth].addToolTipSeries(mTooltipsSync[auth]); if (details.indexOf('x') >= 0 || details.indexOf('X') >= 0) { long msec = event.sec * 1000L + (event.nsec / 1000000L); mDatasetError.addOrUpdate(new FixedMillisecond(msec), -1); } }
/** * 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; }
@Override public void exchangeSeries(int seriesIndex, DataSeries series) throws NoSuchSeriesException { if(seriesIndex < this.getSeriesCount()){ // --- edit series --- org.jfree.data.time.TimeSeries editSeries = (org.jfree.data.time.TimeSeries) this.getSeries(seriesIndex); editSeries.clear(); if (series.getLabel()!=null) { editSeries.setKey(series.getLabel()); } List valuePairs = ((agentgui.ontology.TimeSeries)series).getTimeSeriesValuePairs(); for (int i = 0; i < valuePairs.size(); i++) { TimeSeriesValuePair valuePair = (TimeSeriesValuePair) valuePairs.get(i); Simple_Long simpleLong = valuePair.getTimestamp(); Simple_Float simpleFloat = valuePair.getValue(); Long timeStampLong = simpleLong.getLongValue(); Float floatValue = simpleFloat.getFloatValue(); if (timeStampLong!=null) { TimeSeriesDataItem newItem = new TimeSeriesDataItem(new FixedMillisecond(timeStampLong), floatValue); editSeries.addOrUpdate(newItem); } } } else { throw new NoSuchSeriesException(); } this.setChanged(); this.notifyObservers(ChartModel.EventType.SERIES_EXCHANGED); }
/** * Adds or updates a value to/in a data series. * @param seriesIndex The index of the series that should be changed * @param key The key for the value pair to be added/updated * @param value The new value for the value pair * @throws NoSuchSeriesException Will be thrown if there is no series with the specified index */ public void addOrUpdateValuePair(int seriesIndex, Number key, Number value) throws NoSuchSeriesException { if(seriesIndex < this.getSeriesCount()){ org.jfree.data.time.TimeSeries series = this.getSeries(seriesIndex); series.addOrUpdate(new FixedMillisecond(key.longValue()), value.floatValue()); }else{ throw new NoSuchSeriesException(); } }
/** * Removes the value pair with the given key from the series with the given index. * @param seriesIndex The series index * @param key The key * @throws NoSuchSeriesException Thrown if there is no series with the specified index */ public void removeValuePair(int seriesIndex, Number key) throws NoSuchSeriesException { if(seriesIndex < this.getSeriesCount()){ org.jfree.data.time.TimeSeries series = getSeries(seriesIndex); series.delete(new FixedMillisecond(key.longValue())); }else{ throw new NoSuchSeriesException(); } }
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { final FixedMillisecond m1 = new FixedMillisecond(500000L); final FixedMillisecond m2 = new FixedMillisecond(500000L); assertTrue(m1.equals(m2)); final int h1 = m1.hashCode(); final int h2 = m2.hashCode(); assertEquals(h1, h2); }
/** * 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()); }
/** * 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); }
/** * Updates the display with a new event. * * @param event The event * @param logParser The parser providing the event. */ @Override void newEvent(EventContainer event, EventLogParser logParser) { super.newEvent(event, logParser); // Handle sync operation try { if (event.mTag == EVENT_TICKLE) { int auth = getAuth(event.getValueAsString(0)); if (auth >= 0) { long msec = event.sec * 1000L + (event.nsec / 1000000L); mDatasetsSyncTickle[auth].addOrUpdate(new FixedMillisecond(msec), -1); } } } catch (InvalidTypeException e) { } }
/** * 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()); }
/** * A check for immutability. */ public void testImmutability() { Date d = new Date(20L); FixedMillisecond fm = new FixedMillisecond(d); d.setTime(22L); assertEquals(20L, fm.getFirstMillisecond()); }
private TimeSeries constructSeries(String name, CSVStream stream) { TimeSeries series = new TimeSeries(name, FixedMillisecond.class); while (stream.hasMoreEntries()) { CSVEntry entry = stream.nextEntry(); series.addOrUpdate(new FixedMillisecond(entry.getDate()), entry.getValue()); } return series; }
/** * The {@link FixedMillisecond} class is immutable, so should not be * {@link Cloneable}. */ public void testNotCloneable() { FixedMillisecond m = new FixedMillisecond(500000L); assertFalse(m instanceof Cloneable); }
/** * Resets the display. */ @Override void resetUI() { super.resetUI(); XYPlot xyPlot = mChart.getXYPlot(); XYBarRenderer br = new XYBarRenderer(); mDatasetsSync = new TimePeriodValues[NUM_AUTHS]; @SuppressWarnings("unchecked") List<String> mTooltipsSyncTmp[] = new List[NUM_AUTHS]; mTooltipsSync = mTooltipsSyncTmp; mTooltipGenerators = new CustomXYToolTipGenerator[NUM_AUTHS]; TimePeriodValuesCollection tpvc = new TimePeriodValuesCollection(); xyPlot.setDataset(tpvc); xyPlot.setRenderer(0, br); XYLineAndShapeRenderer ls = new XYLineAndShapeRenderer(); ls.setBaseLinesVisible(false); mDatasetsSyncTickle = new TimeSeries[NUM_AUTHS]; TimeSeriesCollection tsc = new TimeSeriesCollection(); xyPlot.setDataset(1, tsc); xyPlot.setRenderer(1, ls); mDatasetError = new TimeSeries("Errors", FixedMillisecond.class); xyPlot.setDataset(2, new TimeSeriesCollection(mDatasetError)); XYLineAndShapeRenderer errls = new XYLineAndShapeRenderer(); errls.setBaseLinesVisible(false); errls.setSeriesPaint(0, Color.RED); xyPlot.setRenderer(2, errls); for (int i = 0; i < NUM_AUTHS; i++) { br.setSeriesPaint(i, AUTH_COLORS[i]); ls.setSeriesPaint(i, AUTH_COLORS[i]); mDatasetsSync[i] = new TimePeriodValues(AUTH_NAMES[i]); tpvc.addSeries(mDatasetsSync[i]); mTooltipsSync[i] = new ArrayList<String>(); mTooltipGenerators[i] = new CustomXYToolTipGenerator(); br.setSeriesToolTipGenerator(i, mTooltipGenerators[i]); mTooltipGenerators[i].addToolTipSeries(mTooltipsSync[i]); mDatasetsSyncTickle[i] = new TimeSeries(AUTH_NAMES[i] + " tickle", FixedMillisecond.class); tsc.addSeries(mDatasetsSyncTickle[i]); ls.setSeriesShape(i, ShapeUtilities.createUpTriangle(2.5f)); } }
public ExtendedTimeSeries(RecordingItem recItem2, Class<FixedMillisecond> class1) { timeSeries = new TimeSeries(recItem2.getName(), class1); recordingItem=recItem2; // TODO Auto-generated constructor stub }
public void addToChart(Map<Integer, Float> commandDists) { for (Map.Entry<Integer, Float> e : commandDists.entrySet()) { series.get(e.getKey()).add(new FixedMillisecond(counter), e.getValue()); } counter++; }
private void parseEbur128Line(String message) { splited_line = message.substring(message.indexOf("]") + 1).trim().split(" "); /** * [Parsed_ebur128_0 @ 0x7fb594000a00] t: 130.4 M: -6.9 S: -7.4 I: -9.2 LUFS LRA: 4.1 LU FTPK: -0.1 0.0 dBFS TPK: 0.3 0.4 dBFS * Convert spaces to params. */ line_entries.clear(); for (int pos = 0; pos < splited_line.length; pos++) { if (splited_line[pos].equals("")) { /** * Remove empty spaces */ continue; } line_entries.add(splited_line[pos]); } /** * [t:, 102.9, M:, -10.3, S:, -10.0, I:, -9.6, LUFS, LRA:, 4.6, LU, FTPK:, -3.9, -2.6, dBFS, TPK:, 0.3, 0.4, dBFS] */ entry_time = 0f; entry_momentary = 0f; entry_short_term = 0f; entry_integrated = 0f; entry_true_peak_per_frame_L = 0f; entry_true_peak_per_frame_R = 0f; String entry; for (int pos = 0; pos < line_entries.size(); pos++) { entry = line_entries.get(pos); if (entry.equalsIgnoreCase("t:")) { entry_time = protectedParseFloat(line_entries.get(pos + 1)); } else if (entry.equalsIgnoreCase("M:")) { entry_momentary = protectedParseFloat(line_entries.get(pos + 1)); } else if (entry.equalsIgnoreCase("S:")) { entry_short_term = protectedParseFloat(line_entries.get(pos + 1)); } else if (entry.equalsIgnoreCase("I:")) { entry_integrated = protectedParseFloat(line_entries.get(pos + 1)); } else if (entry.equalsIgnoreCase("FTPK:")) { entry_true_peak_per_frame_L = protectedParseFloat(line_entries.get(pos + 1)); entry_true_peak_per_frame_R = protectedParseFloat(line_entries.get(pos + 2)); } else { continue; } } /*System.out.print(time); System.out.print("\t\t"); System.out.print(momentary); System.out.print("M\t"); System.out.print(short_term); System.out.print("S\t"); System.out.print(integrated); System.out.print("I\t"); System.out.print(Math.max(true_peak_per_frame_L, true_peak_per_frame_R)); System.out.print("FTPK"); System.out.println();*/ try { FixedMillisecond now = new FixedMillisecond(Math.round(Math.ceil(entry_time * 1000f))); if (entry_momentary == 0) { entry_momentary = protectedParseFloat(null); } series_momentary.add(now, entry_momentary); if (entry_short_term == 0) { entry_short_term = protectedParseFloat(null); } series_short_term.add(now, entry_short_term); series_integrated.add(now, entry_integrated); series_true_peak_per_frame.add(now, Math.max(entry_true_peak_per_frame_L, entry_true_peak_per_frame_R)); } catch (SeriesException e) { e.printStackTrace(); return; } }
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; }
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; }