List of usage examples for org.jfree.data.time RegularTimePeriod getStart
@Override
public Date getStart()
From source file:org.tolven.analysis.bean.PercentTimeSeriesBean.java
@Override public JFreeChart getChart(MenuStructure snapshotListMS, MenuPath snapshotPH, Long chartRange, Class<?> intervalUnitClass, String chartDataTitle, String chartTargetTitle, AccountUser accountUser, Date now) {//w w w . jav a 2s .co m MenuQueryControl ctrl = new MenuQueryControl(); ctrl.setMenuStructure(snapshotListMS); ctrl.setAccountUser(accountUser); ctrl.setNow(now); ctrl.setOriginalTargetPath(snapshotPH); ctrl.setRequestedPath(snapshotPH); ctrl.setSortOrder("Date"); ctrl.setSortDirection("DESC"); ctrl.setLimit(1); List<MenuData> singleItemList = menuBean.findMenuData(ctrl); Date lastSnapshotDate = null; if (singleItemList.isEmpty()) { lastSnapshotDate = now; } else { MenuData snapshotListItem = singleItemList.get(0); MenuData snapshot = snapshotListItem.getReference(); lastSnapshotDate = new Date(snapshot.getDate01().getTime()); } RegularTimePeriod endTimePeriod = RegularTimePeriod.createInstance(intervalUnitClass, lastSnapshotDate, TimeZone.getDefault()); long milliseconds = Math.max(1, chartRange - 1) * (endTimePeriod.getEnd().getTime() - endTimePeriod.getStart().getTime()); Date fDate = new Date(endTimePeriod.getEnd().getTime() - milliseconds); RegularTimePeriod startTimePeriod = RegularTimePeriod.createInstance(intervalUnitClass, fDate, TimeZone.getDefault()); Date fromDate = startTimePeriod.getStart(); Date toDate = endTimePeriod.getEnd(); ctrl.setSortDirection("ASC"); ctrl.setLimit(0); ctrl.setFromDate(fromDate); ctrl.setToDate(toDate); List<MenuData> snapshotListItems = menuBean.findMenuData(ctrl); List<MenuData> snapshots = new ArrayList<MenuData>(); for (MenuData snapshotListItem : snapshotListItems) { snapshots.add(snapshotListItem.getReference()); } return getChart(chartDataTitle, chartTargetTitle, snapshots, fromDate, toDate, intervalUnitClass); }
From source file:sdmx.net.service.nomis.NOMISRESTServiceRegistry.java
@Override public void query(Query q, ParseDataCallbackHandler handler) { if (SdmxIO.isDumpQuery()) { }//from w w w . ja va 2s .c o m String flowid = q.getFlowRef(); String agency = q.getProviderRef(); int geogIndex = flowid.lastIndexOf("_"); ; String geog = flowid.substring(geogIndex + 1, flowid.length()); String geography_string = "&geography=" + geog; if ("NOGEOG".equals(geog)) { geography_string = ""; } String id = flowid.substring(0, geogIndex); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q.size(); i++) { QueryDimension dim = q.getQueryDimension(i); boolean addedParam = false; String concept = dim.getConcept(); List<String> params = dim.getValues(); if (params.size() > 0) { addedParam = true; sb.append(concept + "="); for (int j = 0; j < params.size(); j++) { sb.append(params.get(j)); if (j < params.size() - 1) { sb.append(","); } } } if (addedParam && i < q.size() - 1) { sb.append("&"); } addedParam = false; } StringBuilder times = new StringBuilder(); try { StructureType st = retrieve3(getServiceURL() + "/v01/dataset/" + id + "/time/def.sdmx.xml"); CodelistType timesCL = st.getStructures().getCodelists().getCodelists().get(0); Date startTime = q.getQueryTime().getStartTime(); Date endTime = q.getQueryTime().getEndTime(); boolean comma = true; for (int i = 0; i < timesCL.size(); i++) { RegularTimePeriod rtp = TimeUtil.parseTime("", timesCL.getCode(i).getId().toString()); if ((rtp.getStart().equals(startTime) || rtp.getStart().after(startTime)) && (rtp.getEnd().before(endTime) || rtp.getEnd().equals(endTime))) { if (!comma) { times.append(","); } times.append(timesCL.getCode(i).getId().toString()); comma = false; } } } catch (IOException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } try { queryStream(getServiceURL() + "/v01/dataset/" + id + ".compact.sdmx.xml?" + q + "&time=" + times.toString() + /* We don't want the geography string at all, because its name clashes with a dimension name this causes the nomis service to send each geography code in the message... we will just specify the codes we want... and not specify the geography type. */ //geography_string "&" + options, handler); } catch (IOException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:sdmx.net.service.nomis.NOMISRESTServiceRegistry.java
@Override public DataMessage query(Query q) { if (SdmxIO.isDumpQuery()) { }// www.j a v a 2s .c om String flowid = q.getFlowRef(); String agency = q.getProviderRef(); int geogIndex = flowid.lastIndexOf("_"); ; String geog = flowid.substring(geogIndex + 1, flowid.length()); String geography_string = "&geography=" + geog; if ("NOGEOG".equals(geog)) { geography_string = ""; } String id = flowid.substring(0, geogIndex); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q.size(); i++) { QueryDimension dim = q.getQueryDimension(i); boolean addedParam = false; String concept = dim.getConcept(); List<String> params = dim.getValues(); if (params.size() > 0) { addedParam = true; sb.append(concept + "="); for (int j = 0; j < params.size(); j++) { sb.append(params.get(j)); if (j < params.size() - 1) { sb.append(","); } } } if (addedParam && i < q.size() - 1) { sb.append("&"); } addedParam = false; } StringBuilder times = new StringBuilder(); try { StructureType st = retrieve3(getServiceURL() + "/v01/dataset/" + id + "/time/def.sdmx.xml"); CodelistType timesCL = st.getStructures().getCodelists().getCodelists().get(0); Date startTime = q.getQueryTime().getStartTime(); Date endTime = q.getQueryTime().getEndTime(); boolean comma = true; for (int i = 0; i < timesCL.size(); i++) { RegularTimePeriod rtp = TimeUtil.parseTime("", timesCL.getCode(i).getId().toString()); if ((rtp.getStart().equals(startTime) || rtp.getStart().after(startTime)) && (rtp.getEnd().before(endTime) || rtp.getEnd().equals(endTime))) { if (!comma) { times.append(","); } times.append(timesCL.getCode(i).getId().toString()); comma = false; } } } catch (IOException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } DataMessage msg = null; try { msg = queryBatch(getServiceURL() + "/v01/dataset/" + id + ".compact.sdmx.xml?" + q + "&time=" + times.toString() + /* We don't want the geography string at all, because its name clashes with a dimension name this causes the nomis service to send each geography code in the message... we will just specify the codes we want... and not specify the geography type. */ //geography_string "&" + options); } catch (IOException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } catch (ParseException ex) { Logger.getLogger(NOMISRESTServiceRegistry.class.getName()).log(Level.SEVERE, null, ex); } return msg; }