コード例 #1
0
    @Override
    public void execute() {
      // store the data in an accessible way
      organiseData();

      // get the unit
      List<IStoreItem> outputs = new ArrayList<IStoreItem>();

      // put the names into a string
      String title = _tx.getName() + " and " + _rx.getName();

      // ok, generate the new series
      IQuantityCollection<?> target = getOutputCollection(title);

      outputs.add(target);

      // store the output
      super.addOutput(target);

      // start adding values.
      performCalc(outputs);

      // tell each series that we're a dependent
      Iterator<ICollection> iter = data.values().iterator();
      while (iter.hasNext()) {
        ICollection iCollection = iter.next();
        iCollection.addDependent(this);
      }

      // ok, done
      List<IStoreItem> res = new ArrayList<IStoreItem>();
      res.add(target);
      getStore().addAll(res);
    }
コード例 #2
0
    @SuppressWarnings("unchecked")
    public double valueAt(ICollection iCollection, long thisTime, Unit<?> requiredUnits) {
      Measurable<Quantity> res;
      if (iCollection.isQuantity()) {
        IQuantityCollection<?> iQ = (IQuantityCollection<?>) iCollection;

        if (iCollection.isTemporal()) {
          TemporalQuantityCollection<?> tQ = (TemporalQuantityCollection<?>) iCollection;
          res = (Measurable<Quantity>) tQ.interpolateValue(thisTime, InterpMethod.Linear);
        } else {
          IQuantityCollection<?> qC = (IQuantityCollection<?>) iCollection;
          res = (Measurable<Quantity>) qC.getValues().iterator().next();
        }

        if (res != null) {
          UnitConverter converter = iQ.getUnits().getConverterTo(requiredUnits);
          Unit<?> sourceUnits = iQ.getUnits();
          double doubleValue = res.doubleValue((Unit<Quantity>) sourceUnits);
          double result = converter.convert(doubleValue);
          return result;
        } else {
          return 0;
        }
      } else {
        throw new RuntimeException("Tried to get value of non quantity data type");
      }
    }
コード例 #3
0
    /**
     * find the best collection to use as a time-base. Which collection has the most values within
     * the specified time period?
     *
     * @param period
     * @param items
     * @return most suited collection
     */
    public IBaseTemporalCollection getOptimalTimes(
        TimePeriod period, Collection<ICollection> items) {
      IBaseTemporalCollection res = null;
      long resScore = 0;

      Iterator<ICollection> iter = items.iterator();
      while (iter.hasNext()) {
        ICollection iCollection = (ICollection) iter.next();
        if (iCollection.isTemporal()) {
          IBaseTemporalCollection timeC = (IBaseTemporalCollection) iCollection;
          Iterator<Long> times = timeC.getTimes().iterator();
          int score = 0;
          while (times.hasNext()) {
            long long1 = (long) times.next();
            if (period.contains(long1)) {
              score++;
            }
          }

          if ((res == null) || (score > resScore)) {
            res = timeC;
            resScore = score;
          }
        }
      }

      return res;
    }
コード例 #4
0
    public TimePeriod getBoundingTime(final Collection<ICollection> items) {
      TimePeriod res = null;

      Iterator<ICollection> iter = items.iterator();
      while (iter.hasNext()) {
        ICollection iCollection = (ICollection) iter.next();
        if (iCollection.isTemporal()) {
          IBaseTemporalCollection timeC = (IBaseTemporalCollection) iCollection;
          if (res == null) {
            res = new TimePeriod(timeC.start(), timeC.finish());
          } else {
            res.startTime = Math.max(res.startTime, timeC.start());
            res.endTime = Math.min(res.endTime, timeC.finish());
          }
        }
      }

      return res;
    }
コード例 #5
0
 private Geometry locationFor(ICollection iCollection, Long thisTime) {
   Geometry res;
   if (iCollection.isTemporal()) {
     TemporalLocation tLoc = (TemporalLocation) iCollection;
     res = tLoc.interpolateValue(thisTime, InterpMethod.Linear);
   } else {
     NonTemporal.Location tLoc =
         (info.limpet.data.impl.samples.StockTypes.NonTemporal.Location) iCollection;
     res = tLoc.getValues().iterator().next();
   }
   return res;
 }
コード例 #6
0
  private void showData(List<IStoreItem> res) {
    Iterator<IStoreItem> iter = res.iterator();

    // clear the graph
    ISeries[] coll = chart.getSeriesSet().getSeries();
    for (int i = 0; i < coll.length; i++) {
      ISeries iSeries = coll[i];
      chart.getSeriesSet().deleteSeries(iSeries.getId());
    }

    while (iter.hasNext()) {
      ICollection iCollection = (ICollection) iter.next();
      TimeFrequencyBins.BinnedData bins = null;
      if (iCollection.isTemporal()) {
        if (iCollection.size() > 1) {
          if (iCollection.size() <= MAX_SIZE) {
            IBaseTemporalCollection thisQ = (IBaseTemporalCollection) iCollection;
            bins = TimeFrequencyBins.doBins(iCollection, thisQ);

            String seriesName = iCollection.getName();
            ILineSeries newSeries =
                (ILineSeries) chart.getSeriesSet().createSeries(SeriesType.LINE, seriesName);
            newSeries.setSymbolType(PlotSymbolType.NONE);
            newSeries.enableArea(true);
            newSeries.setLineColor(PlottingHelpers.colorFor(seriesName));

            Date[] xData = new Date[bins.size() * 2];
            double[] yData = new double[bins.size() * 2];

            // put the data into series
            int ctr = 0;
            Iterator<Bin> iter2 = bins.iterator();
            while (iter2.hasNext()) {
              Bin bin = (TimeFrequencyBins.Bin) iter2.next();
              xData[ctr] = new Date(bin.lowerVal);
              yData[ctr++] = bin.freqVal;
              xData[ctr] = new Date(bin.upperVal);
              yData[ctr++] = bin.freqVal;
            }

            newSeries.setXDateSeries(xData);
            newSeries.setYSeries(yData);

            newSeries.enableStack(true);
            newSeries.enableArea(true);

            // adjust the axis range
            chart.getAxisSet().adjustRange();
            IAxis xAxis = chart.getAxisSet().getXAxis(0);
            xAxis.enableCategory(false);

            // set the y axis min to be zero
            Range yRange = chart.getAxisSet().getYAxis(0).getRange();
            chart.getAxisSet().getYAxis(0).setRange(new Range(0, yRange.upper));

            chart.redraw();
          }
        }
      }
    }
  }