use of org.jfree.data.time.TimeSeries in project nimbus by nimbus-org.
the class MovingAverageFactoryService method createDataset.
public Dataset createDataset(DatasetCondition[] dsConditions) throws DatasetCreateException {
if (dsConditions == null || dsConditions.length == 0) {
return null;
}
Dataset dataset = null;
try {
dataset = datasetFactory.createDataset(dsConditions);
} catch (DatasetCreateException e) {
throw new MovingAverageCreateException(e);
}
Dataset datasetMV = dataset;
if (dataset instanceof TimeSeriesCollection) {
final List seriesList = ((TimeSeriesCollection) dataset).getSeries();
final int seriesLength = seriesList.size();
final TimeSeriesCollection newCollection = new TimeSeriesCollection();
for (int i = 0; i < periodCounts.length; i++) {
for (int j = 0; j < seriesLength; j++) {
TimeSeries series = (TimeSeries) seriesList.get(j);
series = MovingAverage.createMovingAverage(series, series.getKey() + (suffixs == null ? "" : suffixs[i]), (int) periodCounts[i], (int) (skips == null ? 0 : skips[i]));
newCollection.addSeries(series);
}
}
datasetMV = newCollection;
} else if (dataset instanceof XYDataset) {
XYSeriesCollection newCollection = new XYSeriesCollection();
XYDataset inDataset = (XYDataset) dataset;
for (int i = 0; i < periodCounts.length; i++) {
for (int j = 0; j < inDataset.getSeriesCount(); j++) {
XYSeries series = MovingAverage.createMovingAverage(inDataset, j, inDataset.getSeriesKey(j) + (suffixs == null ? "" : suffixs[i]), periodCounts[i], skips == null ? 0 : skips[i]);
newCollection.addSeries(series);
}
}
datasetMV = newCollection;
}
return datasetMV;
}
use of org.jfree.data.time.TimeSeries in project nimbus by nimbus-org.
the class TimeSeriesCollectionFactoryService method createDataset.
/**
* データセットを生成する。<p>
*
* @param dsConditions データセット条件配列
* @return データセット
* @exception DatasetCreateException
*/
public Dataset createDataset(DatasetCondition[] dsConditions) throws DatasetCreateException {
DatasetConnection connection = createConnection(dsConditions);
TimeSeriesCollection dataset = new TimeSeriesCollection();
try {
List cursors = connection.getSeriesCursorList();
if (cursors == null) {
return dataset;
}
Calendar workCal = Calendar.getInstance();
Holder inOut = new Holder();
Record record = new Record();
DoubleList sameDateValues = null;
OHLCList ohlcList = null;
for (int i = 0, imax = cursors.size(); i < imax; i++) {
TimeSeriesCursor cursor = (TimeSeriesCursor) cursors.get(i);
String series = cursor.getSeriesName();
Class timePeriodClass = (Class) timePeriodClassMap.get(series);
int periodType = 0;
TimeSeries timeSeries = null;
if (collateDataType != 0) {
if (timePeriodClass == null) {
timePeriodClass = Millisecond.class;
}
timeSeries = new TimeSeries(series, timePeriodClass);
} else {
if (timePeriodClass != null) {
timeSeries = new TimeSeries(series, timePeriodClass);
} else {
timeSeries = new TimeSeries(series);
timePeriodClass = timeSeries.getTimePeriodClass();
if (timePeriodClass == null) {
timePeriodClass = Millisecond.class;
}
}
}
periodType = convertPeriodType(timePeriodClass);
double value = 0d;
if (sameDateValues != null) {
sameDateValues.clear();
}
if (ohlcList != null) {
ohlcList.clear();
}
inOut.clear();
record.clear();
Date date = null;
boolean hasNext = cursor.next();
while (hasNext) {
// 同値の最後のデータを追加する際に使う日付
if (inOut.date == null || inOut.preDate == null) {
inOut.preDate = inOut.date;
} else {
inOut.preDate.setTime(inOut.date.getTime());
}
date = cursor.getDate();
if (date == null) {
throw new DatasetCreateException("date is null.");
}
value = cursor.getValue();
boolean wasNull = cursor.wasNull();
if (!wasNull) {
inOut.date = date;
if (isAutoTimesharing) {
// 自動時分割を行う
if (inOut.preDate != null && inOut.preDate.equals(date)) {
// 同じ時間の値を溜め込む
record.setDate(date);
record.add(value);
hasNext = cursor.next();
if (hasNext) {
continue;
}
} else {
record.setPeriodMillis(getPeriodMillis(workCal, inOut.lastDate, inputDataField, inputDataPeriod));
// 溜め込んだ同じ時間の値をTimeSeriesに追加
inOut.date = inOut.preDate;
double tmpValue = Double.NaN;
while (record.hasNext()) {
if (inOut.date == null || inOut.preDate == null) {
inOut.preDate = (Date) inOut.date.clone();
} else {
inOut.preDate.setTime(inOut.date.getTime());
}
inOut.date = record.nextDate();
tmpValue = record.nextValue();
addTimeSeries(date, tmpValue, workCal, timeSeries, periodType, false, inOut);
}
record.clear();
inOut.date = date;
}
}
}
if (hasNext) {
hasNext = cursor.next();
}
if (!hasNext) {
// collateDataTypeが設定されていない(0)時はすでにすべての値が追加されているので処理する必要なし
if (collateDataType != 0) {
if (isAutoTimesharing && record.size() != 0) {
record.setPeriodMillis(getPeriodMillis(workCal, inOut.lastDate, inputDataField, inputDataPeriod));
// 溜め込んだ同じ時間の値をTimeSeriesに追加
inOut.date = inOut.preDate;
double tmpValue = Double.NaN;
while (record.hasNext()) {
if (inOut.date == null || inOut.preDate == null) {
inOut.preDate = (Date) inOut.date.clone();
} else {
inOut.preDate.setTime(inOut.date.getTime());
}
inOut.date = record.nextDate();
tmpValue = record.nextValue();
addTimeSeries(date, tmpValue, workCal, timeSeries, periodType, wasNull && !record.hasNext(), inOut);
}
record.clear();
inOut.date = date;
} else {
// 現在の値を追加
addTimeSeries(date, value, workCal, timeSeries, periodType, false, inOut);
}
}
if (!wasNull) {
// 最後の期間の値を追加
addTimeSeries(date, value, workCal, timeSeries, periodType, true, inOut);
}
} else if (!wasNull) {
// 現在の値を追加
addTimeSeries(date, value, workCal, timeSeries, periodType, false, inOut);
}
}
dataset.addSeries(timeSeries);
timePeriodClass = null;
cursor.close();
}
} finally {
connection.close();
}
return dataset;
}
use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.
the class ObdDataPanel method setPidPvs.
/**
* Setter for property pidPvs.
*
* @param pidPvs New value of property pidPvs.
*/
@SuppressWarnings("unchecked")
public void setPidPvs(PvList pidPvs) {
TimeSeries ts;
// if there is an o previous instance registered, unregister ...
if (this.pidPvs instanceof PvList)
this.pidPvs.removePvChangeListener(this);
this.pidPvs = pidPvs;
tblPids.setProcessVar(pidPvs);
tblPids.setDefaultRenderer(Object.class, new ObdItemTableRenderer());
pidPvs.addPvChangeListener(this);
// update all TimeSeries with PIDs from PV-List
plotter.dataset.removeAllSeries();
selPids.clear();
Iterator<EcuDataPv> it = pidPvs.values().iterator();
while (it.hasNext()) {
EcuDataPv pv = it.next();
// create new data series
ts = new TimeSeries(String.valueOf(pv.get(EcuDataPv.FID_DESCRIPT)));
ts.setDescription(String.valueOf(pv.get(EcuDataPv.FID_DESCRIPT)));
ts.setRangeDescription(String.valueOf(pv.get(EcuDataPv.FID_UNITS)));
// set graph time of new element
ts.setMaximumItemAge(slGraphTime.getValue() * 60);
// and add to selectable PID list
selPids.put(getPvId(pv), ts);
}
updateColumnWidths();
}
use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.
the class ObdDataPanel method slGraphTimeStateChanged.
// GEN-LAST:event_btnClearHistActionPerformed
private // GEN-FIRST:event_slGraphTimeStateChanged
void slGraphTimeStateChanged(// GEN-FIRST:event_slGraphTimeStateChanged
javax.swing.event.ChangeEvent evt) {
// GEN-HEADEREND:event_slGraphTimeStateChanged
TimeSeries ts;
lblHistTime.setText(String.valueOf(slGraphTime.getValue()) + " min");
if (!slGraphTime.getValueIsAdjusting()) {
Iterator<TimeSeries> it = selPids.values().iterator();
while (it.hasNext()) {
ts = it.next();
ts.setMaximumItemAge(slGraphTime.getValue() * 60);
}
}
}
use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.
the class ObdDataPanel method addDataSeries.
private void addDataSeries(ProcessVar pv) {
TimeSeries ts;
// create new data series
ts = new TimeSeries(String.valueOf(pv.get(EcuDataPv.FID_DESCRIPT)), null, String.valueOf(pv.get(EcuDataPv.FID_UNITS)));
// set graph time of new element
ts.setMaximumItemAge(slGraphTime.getValue() * 60);
// and add to selectable PID list
selPids.put(getPvId(pv), ts);
}
Aggregations