Example usage for org.jfree.data.time TimeSeries addOrUpdate

List of usage examples for org.jfree.data.time TimeSeries addOrUpdate

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries addOrUpdate.

Prototype

public TimeSeriesDataItem addOrUpdate(RegularTimePeriod period, Number value) 

Source Link

Document

Adds or updates an item in the times series and sends a SeriesChangeEvent to all registered listeners.

Usage

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Some checks for the getMinY() method.
 *///from  w ww .  j ava  2 s. c o  m
public void testGetMinY() {
    TimeSeries s1 = new TimeSeries("S1");
    assertTrue(Double.isNaN(s1.getMinY()));

    s1.add(new Year(2008), 1.1);
    assertEquals(1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2009), 2.2);
    assertEquals(1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2000), 99.9);
    assertEquals(1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2002), -1.1);
    assertEquals(-1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2003), null);
    assertEquals(-1.1, s1.getMinY(), EPSILON);

    s1.addOrUpdate(new Year(2002), null);
    assertEquals(1.1, s1.getMinY(), EPSILON);
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Some checks for the getMaxY() method.
 *///w  w  w  .j ava2 s  . c om
public void testGetMaxY() {
    TimeSeries s1 = new TimeSeries("S1");
    assertTrue(Double.isNaN(s1.getMaxY()));

    s1.add(new Year(2008), 1.1);
    assertEquals(1.1, s1.getMaxY(), EPSILON);

    s1.add(new Year(2009), 2.2);
    assertEquals(2.2, s1.getMaxY(), EPSILON);

    s1.add(new Year(2000), 99.9);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.add(new Year(2002), -1.1);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.add(new Year(2003), null);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.addOrUpdate(new Year(2000), null);
    assertEquals(2.2, s1.getMaxY(), EPSILON);
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Some checks for the getMinY() method.
 *//*w w  w  .  j  a v  a 2  s. co  m*/
@Test
public void testGetMinY() {
    TimeSeries s1 = new TimeSeries("S1");
    assertTrue(Double.isNaN(s1.getMinY()));

    s1.add(new Year(2008), 1.1);
    assertEquals(1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2009), 2.2);
    assertEquals(1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2000), 99.9);
    assertEquals(1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2002), -1.1);
    assertEquals(-1.1, s1.getMinY(), EPSILON);

    s1.add(new Year(2003), null);
    assertEquals(-1.1, s1.getMinY(), EPSILON);

    s1.addOrUpdate(new Year(2002), null);
    assertEquals(1.1, s1.getMinY(), EPSILON);
}

From source file:org.jfree.data.time.TimeSeriesTest.java

/**
 * Some checks for the getMaxY() method.
 *//*from  www.  j a  v a  2  s. c o m*/
@Test
public void testGetMaxY() {
    TimeSeries s1 = new TimeSeries("S1");
    assertTrue(Double.isNaN(s1.getMaxY()));

    s1.add(new Year(2008), 1.1);
    assertEquals(1.1, s1.getMaxY(), EPSILON);

    s1.add(new Year(2009), 2.2);
    assertEquals(2.2, s1.getMaxY(), EPSILON);

    s1.add(new Year(2000), 99.9);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.add(new Year(2002), -1.1);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.add(new Year(2003), null);
    assertEquals(99.9, s1.getMaxY(), EPSILON);

    s1.addOrUpdate(new Year(2000), null);
    assertEquals(2.2, s1.getMaxY(), EPSILON);
}

From source file:lucee.runtime.tag.Chart.java

private XYDataset createTimeSeriesCollection() {
    TimeZone tz = ThreadLocalPageContext.getTimeZone();
    final TimeSeriesCollection coll = new TimeSeriesCollection(tz);

    //final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Iterator<ChartSeriesBean> it = _series.iterator();
    //int seriesCount=_series.size();
    Iterator itt;/*  w w w.  j a  v a 2  s  .  c om*/
    List datas;
    ChartSeriesBean csb;
    ChartDataBean cdb;
    int count = 0;
    smallest = Double.MAX_VALUE;
    biggest = Double.MIN_VALUE;
    String label;
    boolean hasLabels = false;
    while (it.hasNext()) {
        count++;
        csb = it.next();
        label = csb.getSeriesLabel();
        if (StringUtil.isEmpty(label))
            label = "" + count;
        else
            hasLabels = true;
        datas = csb.getDatas();
        if (sortxaxis)
            Collections.sort(datas);
        itt = datas.iterator();
        TimeSeries ts = new TimeSeries(label, Second.class);
        while (itt.hasNext()) {
            cdb = (ChartDataBean) itt.next();
            if (smallest > cdb.getValue())
                smallest = cdb.getValue();
            if (biggest < cdb.getValue())
                biggest = cdb.getValue();
            //if(seriesCount>1)
            ts.addOrUpdate(new Second(
                    DateCaster.toDateSimple(cdb.getItem(), DateCaster.CONVERTING_TYPE_NONE, false, tz, null)),
                    cdb.getValue());

            //else dataset.addValue(cdb.getValue(), cdb.getItem(),"");

        }
        coll.addSeries(ts);
    }
    if (!hasLabels)
        showlegend = false;
    return coll;
}

From source file:org.openmrs.web.controller.ConceptStatsFormController.java

/**
 * Called prior to form display. Allows for data to be put in the request to be used in the view
 *
 * @see org.springframework.web.servlet.mvc.SimpleFormController#referenceData(javax.servlet.http.HttpServletRequest)
 *//*from  w w w.j av a 2s. c o m*/
protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {

    Map<String, Object> map = new HashMap<String, Object>();
    if (!Context.hasPrivilege("View Observations")) {
        return map;
    }

    MessageSourceAccessor msa = getMessageSourceAccessor();
    Locale locale = Context.getLocale();
    ConceptService cs = Context.getConceptService();
    String conceptId = request.getParameter("conceptId");
    //List<Obs> obs = new Vector<Obs>();
    //List<Obs> obsAnswered = new Vector<Obs>();

    if (conceptId != null) {
        Concept concept = cs.getConcept(Integer.valueOf(conceptId));
        ObsService obsService = Context.getObsService();

        if (concept != null) {

            // previous/next ids for links
            map.put("previousConcept", cs.getPrevConcept(concept));
            map.put("nextConcept", cs.getNextConcept(concept));

            //obs = obsService.getObservations(concept, "valueNumeric, obsId");
            //obsAnswered = obsService.getObservationsAnsweredByConcept(concept);

            if (ConceptDatatype.NUMERIC.equals(concept.getDatatype().getHl7Abbreviation())) {
                map.put("displayType", "numeric");

                List<Obs> numericAnswers = obsService.getObservations(null, null,
                        Collections.singletonList(concept), null,
                        Collections.singletonList(OpenmrsConstants.PERSON_TYPE.PERSON), null,
                        Collections.singletonList("valueNumeric"), null, null, null, null, false);

                if (numericAnswers.size() > 0) {
                    Double min = numericAnswers.get(0).getValueNumeric();
                    Double max = (Double) numericAnswers.get(numericAnswers.size() - 1).getValueNumeric();
                    Double median = (Double) numericAnswers.get(numericAnswers.size() / 2).getValueNumeric();

                    Map<Double, Integer> counts = new HashMap<Double, Integer>(); // counts for the histogram
                    Double total = 0.0; // sum of values. used for mean

                    // dataset setup for lineChart
                    TimeSeries timeSeries = new TimeSeries(concept.getName().getName(), Day.class);
                    TimeSeriesCollection timeDataset = new TimeSeriesCollection();
                    Calendar calendar = Calendar.getInstance();

                    // array for histogram
                    double[] obsNumerics = new double[(numericAnswers.size())];

                    Integer i = 0;
                    for (Obs obs : numericAnswers) {
                        Date date = (Date) obs.getObsDatetime();
                        Double value = (Double) obs.getValueNumeric();

                        // for mean calculation
                        total += value;

                        // for histogram
                        obsNumerics[i++] = value;
                        Integer count = counts.get(value);
                        counts.put(value, count == null ? 1 : count + 1);

                        // for line chart
                        calendar.setTime(date);
                        Day day = new Day(calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.MONTH) + 1, // January = 0 
                                calendar.get(Calendar.YEAR) < 1900 ? 1900 : calendar.get(Calendar.YEAR) // jfree chart doesn't like the 19th century
                        );
                        timeSeries.addOrUpdate(day, value);
                    }

                    Double size = new Double(numericAnswers.size());
                    Double mean = total / size;

                    map.put("size", numericAnswers.size());
                    map.put("min", min);
                    map.put("max", max);
                    map.put("mean", mean);
                    map.put("median", median);

                    // create histogram chart
                    HistogramDataset histDataset = new HistogramDataset(); // dataset for histogram
                    histDataset.addSeries(concept.getName().getName(), obsNumerics, counts.size());

                    JFreeChart histogram = ChartFactory.createHistogram(concept.getName().getName(),
                            msa.getMessage("Concept.stats.histogramDomainAxisTitle"),
                            msa.getMessage("Concept.stats.histogramRangeAxisTitle"), histDataset,
                            PlotOrientation.VERTICAL, false, true, false);
                    map.put("histogram", histogram);

                    if (size > 25) {
                        // calculate 98th percentile of the data:
                        Double x = 0.98;
                        Integer xpercentile = (int) (x * size);
                        Double upperQuartile = numericAnswers.get(xpercentile).getValueNumeric();
                        Double lowerQuartile = numericAnswers.get((int) (size - xpercentile)).getValueNumeric();
                        Double innerQuartile = upperQuartile - lowerQuartile;
                        Double innerQuartileLimit = innerQuartile * 1.5; // outliers will be greater than this from the upper/lower quartile
                        Double upperQuartileLimit = upperQuartile + innerQuartileLimit;
                        Double lowerQuartileLimit = lowerQuartile - innerQuartileLimit;

                        List<Obs> outliers = new Vector<Obs>();

                        // move outliers to the outliers list
                        // removing lower quartile outliers
                        for (i = 0; i < size - xpercentile; i++) {
                            Obs possibleOutlier = numericAnswers.get(i);
                            if (possibleOutlier.getValueNumeric() >= lowerQuartileLimit) {
                                break; // quit if this value is greater than the lower limit
                            }
                            outliers.add(possibleOutlier);
                        }

                        // removing upper quartile outliers
                        for (i = size.intValue() - 1; i >= xpercentile; i--) {
                            Obs possibleOutlier = numericAnswers.get(i);
                            if (possibleOutlier.getValueNumeric() <= upperQuartileLimit) {
                                break; // quit if this value is less than the upper limit
                            }
                            outliers.add(possibleOutlier);
                        }
                        numericAnswers.removeAll(outliers);

                        double[] obsNumericsOutliers = new double[(numericAnswers.size())];
                        i = 0;
                        counts.clear();
                        for (Obs values : numericAnswers) {
                            Double value = values.getValueNumeric();
                            obsNumericsOutliers[i++] = value;
                            Integer count = counts.get(value);
                            counts.put(value, count == null ? 1 : count + 1);
                        }

                        // create outlier histogram chart
                        HistogramDataset outlierHistDataset = new HistogramDataset();
                        outlierHistDataset.addSeries(concept.getName().getName(), obsNumericsOutliers,
                                counts.size());

                        JFreeChart histogramOutliers = ChartFactory.createHistogram(concept.getName().getName(),
                                msa.getMessage("Concept.stats.histogramDomainAxisTitle"),
                                msa.getMessage("Concept.stats.histogramRangeAxisTitle"), outlierHistDataset,
                                PlotOrientation.VERTICAL, false, true, false);
                        map.put("histogramOutliers", histogramOutliers);
                        map.put("outliers", outliers);

                    }

                    // create line graph chart
                    timeDataset.addSeries(timeSeries);
                    JFreeChart lineChart = ChartFactory.createTimeSeriesChart(concept.getName().getName(),
                            msa.getMessage("Concept.stats.lineChartDomainAxisLabel"),
                            msa.getMessage("Concept.stats.lineChartRangeAxisLabel"), timeDataset, false, true,
                            false);
                    map.put("timeSeries", lineChart);

                }
            } else if (ConceptDatatype.BOOLEAN.equals(concept.getDatatype().getHl7Abbreviation())) {
                // create bar chart for boolean answers
                map.put("displayType", "boolean");

                List<Obs> obs = obsService.getObservations(null, null, Collections.singletonList(concept), null,
                        Collections.singletonList(OpenmrsConstants.PERSON_TYPE.PERSON), null, null, null, null,
                        null, null, false);

                DefaultPieDataset pieDataset = new DefaultPieDataset();

                // count the number of unique answers
                Map<String, Integer> counts = new HashMap<String, Integer>();
                for (Obs o : obs) {
                    Boolean answer = o.getValueAsBoolean();
                    if (answer == null) {
                        answer = false;
                    }
                    String name = answer.toString();
                    Integer count = counts.get(name);
                    counts.put(name, count == null ? 1 : count + 1);
                }

                // put the counts into the dataset
                for (Map.Entry<String, Integer> entry : counts.entrySet()) {
                    pieDataset.setValue(entry.getKey(), entry.getValue());
                }

                JFreeChart pieChart = ChartFactory.createPieChart(concept.getName().getName(), pieDataset, true,
                        true, false);
                map.put("pieChart", pieChart);

            } else if (ConceptDatatype.CODED.equals(concept.getDatatype().getHl7Abbreviation())) {
                // create pie graph for coded answers
                map.put("displayType", "coded");

                List<Obs> obs = obsService.getObservations(null, null, Collections.singletonList(concept), null,
                        Collections.singletonList(OpenmrsConstants.PERSON_TYPE.PERSON), null, null, null, null,
                        null, null, false);

                DefaultPieDataset pieDataset = new DefaultPieDataset();

                // count the number of unique answers
                Map<String, Integer> counts = new HashMap<String, Integer>();
                for (Obs o : obs) {
                    Concept value = o.getValueCoded();
                    String name;
                    if (value == null) {
                        name = "[value_coded is null]";
                    } else {
                        name = value.getName().getName();
                    }
                    Integer count = counts.get(name);
                    counts.put(name, count == null ? 1 : count + 1);
                }

                // put the counts into the dataset
                for (Map.Entry<String, Integer> entry : counts.entrySet()) {
                    pieDataset.setValue(entry.getKey(), entry.getValue());
                }

                JFreeChart pieChart = ChartFactory.createPieChart(concept.getName().getName(), pieDataset, true,
                        true, false);
                map.put("pieChart", pieChart);

            }
        }

    }

    //map.put("obs", obs);
    //map.put("obsAnswered", obsAnswered);

    map.put("locale", locale.getLanguage().substring(0, 2));

    return map;
}

From source file:org.sakaiproject.sitestats.impl.chart.ChartServiceImpl.java

private AbstractDataset getTimeSeriesCollectionDataset(Report report) {
    List<Stat> reportData = report.getReportData();

    // fill dataset
    TimeSeriesCollection dataSet = new TimeSeriesCollection();
    String dataSource = report.getReportDefinition().getReportParams().getHowChartSource();
    String seriesFrom = report.getReportDefinition().getReportParams().getHowChartSeriesSource();
    if (StatsManager.T_TOTAL.equals(seriesFrom) || StatsManager.T_NONE.equals(seriesFrom)) {
        seriesFrom = null;//  w  w  w.  j  a va2 s.  c  o m
    }
    Class periodGrouping = null;
    if (StatsManager.CHARTTIMESERIES_DAY
            .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())
            || StatsManager.CHARTTIMESERIES_WEEKDAY
                    .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) {
        periodGrouping = org.jfree.data.time.Day.class;
    } else if (StatsManager.CHARTTIMESERIES_MONTH
            .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) {
        periodGrouping = org.jfree.data.time.Month.class;
    } else if (StatsManager.CHARTTIMESERIES_YEAR
            .equals(report.getReportDefinition().getReportParams().getHowChartSeriesPeriod())) {
        periodGrouping = org.jfree.data.time.Year.class;
    }
    boolean visitsTotalsChart = ReportManager.WHAT_VISITS_TOTALS
            .equals(report.getReportDefinition().getReportParams().getWhat())
            || report.getReportDefinition().getReportParams().getHowTotalsBy().contains(StatsManager.T_VISITS)
            || report.getReportDefinition().getReportParams().getHowTotalsBy()
                    .contains(StatsManager.T_UNIQUEVISITS);
    Set<RegularTimePeriod> keys = new HashSet<RegularTimePeriod>();
    if (!visitsTotalsChart && seriesFrom == null) {
        // without additional series
        String name = msgs.getString("th_total");
        TimeSeries ts = new TimeSeries(name, periodGrouping);
        for (Stat s : reportData) {
            RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping);
            if (key != null) {
                Number existing = null;
                if ((existing = ts.getValue(key)) == null) {
                    ts.add(key, getTotalValue(s, report));
                } else {
                    ts.addOrUpdate(key, getTotalValue(existing, s, report));
                }
                keys.add(key);
            }
        }
        dataSet.addSeries(ts);
    } else if (!visitsTotalsChart && seriesFrom != null) {
        // with additional series
        Map<Comparable, TimeSeries> series = new HashMap<Comparable, TimeSeries>();
        //TimeSeries ts = new TimeSeries(dataSource, org.jfree.data.time.Day.class);
        for (Stat s : reportData) {
            RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping);
            Comparable serie = (Comparable) getStatValue(s, seriesFrom);

            if (key != null && serie != null) {
                // determine appropriate serie
                TimeSeries ts = null;
                if (!series.containsKey(serie)) {
                    ts = new TimeSeries(serie.toString(), periodGrouping);
                    series.put(serie, ts);
                } else {
                    ts = series.get(serie);
                }

                Number existing = null;
                if ((existing = ts.getValue(key)) == null) {
                    ts.add(key, getTotalValue(s, report));
                } else {
                    ts.addOrUpdate(key, getTotalValue(existing, s, report));
                }
                keys.add(key);
            }
        }

        // add series
        for (TimeSeries ts : series.values()) {
            dataSet.addSeries(ts);
        }
    } else if (visitsTotalsChart) {
        // 2 series: visits & unique visitors
        TimeSeries tsV = new TimeSeries(msgs.getString("th_visits"), periodGrouping);
        TimeSeries tsUV = new TimeSeries(msgs.getString("th_uniquevisitors"), periodGrouping);
        for (Stat _s : reportData) {
            SiteVisits s = (SiteVisits) _s;
            RegularTimePeriod key = (RegularTimePeriod) getStatValue(s, dataSource, periodGrouping);
            if (key != null) {
                Number existing = null;
                if ((existing = tsV.getValue(key)) == null) {
                    tsV.add(key, s.getTotalVisits());
                    tsUV.add(key, s.getTotalUnique());
                } else {
                    tsV.addOrUpdate(key, s.getTotalVisits() + existing.longValue());
                    tsUV.addOrUpdate(key, s.getTotalVisits() + existing.longValue());
                }
                keys.add(key);
            }
        }
        dataSet.addSeries(tsV);
        dataSet.addSeries(tsUV);
    }

    // fill missing values with zeros
    /*for(TimeSeries ts : (List<TimeSeries>) dataSet.getSeries()) {
       for(RegularTimePeriod tp : keys) {
    if(ts.getValue(tp) == null) {
       ts.add(tp, 0.0);
    }
       }
    }*/
    dataSet.setXPosition(TimePeriodAnchor.MIDDLE);

    return dataSet;
}

From source file:org.tolven.web.MenuAction.java

/**
 * Creates a dataset from menuData./*from   w  w w .  ja  v  a2s.  c  o  m*/
 *
 * @return An XY dataset
 */
public XYDataset createDataset(String path) {
    // Adjust the path to make this work
    MenuStructure msLab = getMenuLocal().findMenuStructure(getAccountId(), path);
    if (msLab == null)
        throw new IllegalArgumentException("Path not valid for this account");
    // Create a new path based on the matching id(s) from the called path
    // for example, if patient were specified in the input nodeValues and the new path has a patient node, then
    // it's pulled.
    MenuPath mdPath = new MenuPath(msLab.getPath(), getTargetMenuPath());
    //        TolvenLogger.info("dataset: Query from " + msLab.getPath() + " for requested path: " + getTargetMenuPath(), MenuAction.class);
    MenuQueryControl ctrl = new MenuQueryControl();
    ctrl.setLimit(5000); // TODO: This is a hard coded hard query limit that should be in a property or something
    ctrl.setMenuStructure(msLab);
    ctrl.setAccountUser(TolvenRequest.getInstance().getAccountUser());
    ctrl.setNow(getNow());
    ctrl.setOffset(0);
    ctrl.setOriginalTargetPath(mdPath);
    ctrl.setRequestedPath(mdPath);
    List<MenuData> menuData = getMenuLocal().findMenuData(ctrl);
    TimeSeries s1 = new TimeSeries("triglycerides (mg/dL)", Month.class);
    TimeSeries s2 = new TimeSeries("low-density lipoprotein - LDL (mg/dL)", Month.class);
    for (MenuData md : menuData) {
        TimeSeries sx;
        //            TolvenLogger.info("MD Item: " + md.getId(), MenuAction.class);
        String result = md.getString02();
        if ("triglycerides".equals(result)) {
            sx = s1;
        } else if (result != null && result.startsWith("low-density")) {
            sx = s2;
        } else
            continue;
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(md.getDate01());
        Month m = new Month(cal.get(GregorianCalendar.MONTH) + 1, cal.get(GregorianCalendar.YEAR));
        //           TolvenLogger.info( "Graph Data: " + m.getMonth() + "/" + m.getYear() + "=" + md.getPqValue01(), MenuAction.class);
        sx.addOrUpdate(m, md.getPqValue01());
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);

    dataset.setDomainIsPointsInTime(true);
    TolvenLogger.info("Done preparing Dataset", MenuAction.class);

    return dataset;

}

From source file:org.tolven.web.MenuAction.java

/**
  * Creates a dataset from menuData./*from  w ww . j  a va  2s.  c o m*/
  *
  * @return An XY dataset
  */
public XYDataset createDataset3(String path) {
    // Adjust the path to make this work
    MenuStructure msLab = getMenuLocal().findMenuStructure(getAccountId(), path);
    if (msLab == null)
        throw new IllegalArgumentException("Path not valid for this account");
    // Create a new path based on the matching id(s) from the called path
    // for example, if patient were specified in the input nodeValues and the new path has a patient node, then
    // it's pulled.
    MenuPath mdPath = new MenuPath(msLab.getPath(), getTargetMenuPath());
    //        TolvenLogger.info("dataset: Query from " + msLab.getPath() + " for requested path: " + getTargetMenuPath(), MenuAction.class);
    MenuQueryControl ctrl = new MenuQueryControl();
    ctrl.setLimit(5000); // TODO: This is a hard coded hard query limit that should be in a property or something
    ctrl.setMenuStructure(msLab);
    ctrl.setAccountUser(TolvenRequest.getInstance().getAccountUser());
    ctrl.setNow(getNow());
    ctrl.setOffset(0);
    ctrl.setOriginalTargetPath(mdPath);
    ctrl.setRequestedPath(mdPath);
    List<MenuData> menuData = getMenuLocal().findMenuData(ctrl);
    TimeSeries s1 = new TimeSeries("Peak Flow", TolvenHour.class);
    for (MenuData md : menuData) {
        TimeSeries sx;
        //            TolvenLogger.info("MD Item: " + md.getId(), MenuAction.class);
        String result = md.getString01().toLowerCase();
        if ("peak flow".equals(result) || "peakflow".equals(result)) {
            sx = s1;
        } else
            continue;
        Hour d = new TolvenHour(md.getDate01());
        //           TolvenLogger.info( "Graph Data: " + m.getMonth() + "/" + m.getYear() + "=" + md.getPqValue01(), MenuAction.class);
        TimeSeriesDataItem di = sx.getDataItem(d);
        if (di != null)
            TolvenLogger.info(
                    "Date: " + di.getPeriod() + " replacing " + di.getValue() + " with " + md.getPqValue01(),
                    MenuAction.class);
        sx.addOrUpdate(d, md.getPqValue01());
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    //        dataset.setDomainIsPointsInTime(true);
    TolvenLogger.info("Done preparing Dataset", MenuAction.class);

    return dataset;

}

From source file:org.tolven.web.MenuAction.java

/**
  * Creates a dataset from menuData./*from w  w  w . j ava 2 s .c  o m*/
  *
  * @return An XY dataset
  */
public XYDataset createDataset2(String path) {
    // Adjust the path to make this work
    MenuStructure msLab = getMenuLocal().findMenuStructure(getAccountId(), path);
    if (msLab == null)
        throw new IllegalArgumentException("Path not valid for this account");
    // Create a new path based on the matching id(s) from the called path
    // for example, if patient were specified in the input nodeValues and the new path has a patient node, then
    // it's pulled.
    MenuPath mdPath = new MenuPath(msLab.getPath(), getTargetMenuPath());
    //        TolvenLogger.info("dataset: Query from " + msLab.getPath() + " for requested path: " + getTargetMenuPath(), MenuAction.class);
    MenuQueryControl ctrl = new MenuQueryControl();
    ctrl.setLimit(5000); // TODO: This is a hard coded hard query limit that should be in a property or something
    ctrl.setMenuStructure(msLab);
    ctrl.setAccountUser(TolvenRequest.getInstance().getAccountUser());
    ctrl.setNow(getNow());
    ctrl.setOffset(0);
    ctrl.setOriginalTargetPath(mdPath);
    ctrl.setRequestedPath(mdPath);
    List<MenuData> menuData = getMenuLocal().findMenuData(ctrl);
    TimeSeries s1 = new TimeSeries("glucose (mg/dL)", TolvenHour.class);
    TimeSeries s2 = new TimeSeries("Weight (lb)", TolvenHour.class);
    for (MenuData md : menuData) {
        TimeSeries sx;
        //            TolvenLogger.info("MD Item: " + md.getId(), MenuAction.class);
        String result = md.getString01();
        if ("Blood Glucose".equals(result)) {
            sx = s1;
        } else if ("Weight".equals(result)) {
            sx = s2;
        } else
            continue;
        Hour d = new TolvenHour(md.getDate01());
        //           TolvenLogger.info( "Graph Data: " + m.getMonth() + "/" + m.getYear() + "=" + md.getPqValue01(), MenuAction.class);
        TimeSeriesDataItem di = sx.getDataItem(d);
        if (di != null)
            TolvenLogger.info(
                    "Date: " + di.getPeriod() + " replacing " + di.getValue() + " with " + md.getPqValue01(),
                    MenuAction.class);
        sx.addOrUpdate(d, md.getPqValue01());
    }
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(s1);
    dataset.addSeries(s2);
    //        dataset.setDomainIsPointsInTime(true);
    TolvenLogger.info("Done preparing Dataset", MenuAction.class);

    return dataset;

}