List of usage examples for org.joda.time DateTime minusMonths
public DateTime minusMonths(int months)
From source file:org.egov.pgr.dashboard.service.DashboardService.java
License:Open Source License
public List<Map<String, Object>> getWardwiseComplaintByComplaintType(Long complaintTypeId, String currentChartColor) { DateTime currentDate = new DateTime(); List<Map<String, Object>> wardWiseData = new LinkedList<>(); double topCount = -1; for (Object[] complaint : dashboardRepository.fetchComplaintsByComplaintTypeGroupByWard(complaintTypeId, startOfGivenDate(currentDate.minusMonths(6).withDayOfMonth(1).withTimeAtStartOfDay()), endOfGivenDate(currentDate))) { Map<String, Object> wardwiseCnt = new HashMap<>(); wardwiseCnt.put(WARDNAME, String.valueOf(complaint[0])); wardwiseCnt.put(WARDID, ((BigInteger) complaint[1]).intValue()); double count = ((BigInteger) complaint[2]).doubleValue(); wardwiseCnt.put(COUNT, count);//from ww w .j av a 2 s . c om if (topCount < 0) topCount = count; applyColorCodes(wardwiseCnt, count * 100 / topCount, currentChartColor); wardWiseData.add(wardwiseCnt); } return wardWiseData; }
From source file:org.egov.pgr.service.ComplaintTypeService.java
License:Open Source License
/** * List top 5 complaint types filed in last one month * * @return complaint Type list//from ww w .j a v a 2 s . c om */ @ReadOnly public List<ComplaintType> getFrequentlyFiledComplaints() { DateTime previousDate = new DateTime(); DateTime currentDate = new DateTime(); previousDate = previousDate.minusMonths(1); Criteria criteria = entityManager.unwrap(Session.class).createCriteria(Complaint.class, "complaint"); criteria.createAlias(COMPLAINT_COMPLAINT_TYPE, "compType"); criteria.setProjection(Projections.projectionList().add(Projections.property(COMPLAINT_COMPLAINT_TYPE)) .add(Projections.count(COMPLAINT_COMPLAINT_TYPE).as("count")) .add(Projections.groupProperty(COMPLAINT_COMPLAINT_TYPE))); criteria.add(Restrictions.between("complaint.createdDate", previousDate.toDate(), currentDate.toDate())); criteria.add(Restrictions.eq("compType.isActive", Boolean.TRUE)); criteria.setMaxResults(5).addOrder(Order.desc("count")); List<Object> resultList = criteria.list(); List<ComplaintType> complaintTypeList = new ArrayList<>(); for (Object row : resultList) { Object[] columns = (Object[]) row; complaintTypeList.add((ComplaintType) columns[0]); } return complaintTypeList; }
From source file:org.egov.pgr.service.dashboard.DashboardService.java
License:Open Source License
public List<Map<String, Object>> getMonthlyAggregate() { final DateTime currentDate = new DateTime(); final List<Map<String, Object>> dataHolder = constructMonthPlaceHolder(currentDate.minusMonths(6), currentDate, "MMM-yyyy"); for (final Object[] compCnt : dashboardRepository.fetchMonthlyAggregateBetween( startOfGivenDate(currentDate.minusMonths(6).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate())) for (final Map<String, Object> mapdata : dataHolder) if (mapdata.containsValue(StringUtils.capitalize(String.valueOf(compCnt[0]).toLowerCase()))) mapdata.put("y", Integer.valueOf(String.valueOf(compCnt[1]))); return dataHolder; }
From source file:org.egov.pgr.service.dashboard.DashboardService.java
License:Open Source License
public List<Map<String, Object>> getCompTypewiseAggregate() { final DateTime currentDate = new DateTime(); final List<Map<String, Object>> compTypeWiseData = new LinkedList<Map<String, Object>>(); long totalOthersCount = 0; int topCount = 1; for (final Object[] complaint : dashboardRepository.fetchComplaintTypeWiseBetween( startOfGivenDate(currentDate.minusMonths(6).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate())) { final Map<String, Object> compTypewiseCnt = new HashMap<String, Object>(); final Integer complaintCount = Integer.valueOf(String.valueOf(complaint[2])); if (topCount < 9) { compTypewiseCnt.put("name", String.valueOf(complaint[0])); compTypewiseCnt.put("ctId", complaint[1]); compTypewiseCnt.put("y", complaintCount); compTypeWiseData.add(compTypewiseCnt); topCount++;//from ww w. j av a 2 s.co m } else totalOthersCount += complaintCount; } if (totalOthersCount > 0) { final Map<String, Object> othersData = new HashMap<String, Object>(); othersData.put("name", "Others"); othersData.put("ctId", ""); othersData.put("y", totalOthersCount); compTypeWiseData.add(othersData); } return compTypeWiseData; }
From source file:org.egov.pgr.service.dashboard.DashboardService.java
License:Open Source License
public Map<String, Object> topComplaints() { final DateTime currentDate = new DateTime(); final List<Object> dataHolderNumber = constructListOfMonthPlaceHolder(currentDate.minusMonths(5), currentDate.plusMonths(1), "MM"); final List<Object> dataHolderString = constructListOfMonthPlaceHolder(currentDate.minusMonths(5), currentDate.plusMonths(1), "MMM"); final List<Object[]> topFiveCompTypeData = dashboardRepository.fetchTopComplaintsBetween( startOfGivenDate(currentDate.minusMonths(5).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate()); final List<Object[]> topFiveCompTypeCurrentMonth = dashboardRepository .fetchTopComplaintsForCurrentMonthBetween( startOfGivenDate(currentDate.minusMonths(5).withDayOfMonth(1)).toDate(), endOfGivenDate(currentDate).toDate()); final Map<Object, Object> constructResultPlaceholder = new LinkedHashMap<Object, Object>(); final Map<Object, Object> actualdata = new LinkedHashMap<Object, Object>(); for (final Object complaintType : topFiveCompTypeCurrentMonth) for (final Object month : dataHolderNumber) constructResultPlaceholder.put(month + "-" + complaintType, BigInteger.ZERO); for (final Object[] top5CompType : topFiveCompTypeData) actualdata.put(top5CompType[0] + "-" + top5CompType[2], top5CompType[1]); final Map<Object, Object> newdata = new LinkedHashMap<Object, Object>(); for (final Object placeholderMapKey : constructResultPlaceholder.keySet()) if (actualdata.get(placeholderMapKey) == null) newdata.put(placeholderMapKey, BigInteger.ZERO); else/*from w ww . j a v a 2 s .com*/ newdata.put(placeholderMapKey, actualdata.get(placeholderMapKey)); final Map<String, Object> topFiveCompDataHolder = new LinkedHashMap<String, Object>(); final List<Object> dataHolder = new LinkedList<Object>(); final List<Object> compCount = new ArrayList<Object>(); final Iterator<Entry<Object, Object>> entries = newdata.entrySet().iterator(); int index = 0; while (entries.hasNext()) { final Map<String, Object> tmpdata = new LinkedHashMap<String, Object>(); final Entry<Object, Object> entry = entries.next(); if (index < 5) { compCount.add(entry.getValue()); index++; } else if (index == 5) { compCount.add(entry.getValue()); final String[] parts = entry.getKey().toString().split("-"); tmpdata.put("name", parts[1]); tmpdata.put("data", new LinkedList<Object>(compCount)); final HashMap<String, Object> ctypeCountMap = new LinkedHashMap<String, Object>(); ctypeCountMap.putAll(tmpdata); dataHolder.add(ctypeCountMap); index = 0; compCount.clear(); tmpdata.clear(); } } topFiveCompDataHolder.put("year", dataHolderString); topFiveCompDataHolder.put("series", dataHolder); return topFiveCompDataHolder; }
From source file:org.egov.pgr.service.dashboard.DashboardService.java
License:Open Source License
public List<Map<String, Object>> getWardwiseComplaintByComplaintType(final Long complaintTypeId, final String currentChartColor) { final DateTime currentDate = new DateTime(); final List<Map<String, Object>> wardWiseData = new LinkedList<Map<String, Object>>(); double topCount = -1; for (final Object[] complaint : dashboardRepository.fetchComplaintsByComplaintTypeGroupByWard( complaintTypeId,// w w w . j av a2s . co m startOfGivenDate(currentDate.minusMonths(6).withDayOfMonth(1).withTimeAtStartOfDay()), endOfGivenDate(currentDate))) { final Map<String, Object> wardwiseCnt = new HashMap<String, Object>(); wardwiseCnt.put("wardName", String.valueOf(complaint[0])); wardwiseCnt.put("wardId", ((BigInteger) complaint[1]).intValue()); final double count = ((BigInteger) complaint[2]).doubleValue(); wardwiseCnt.put("count", count); if (topCount == -1) topCount = count; final double perc = count * 100 / topCount; final String[] colors = COLOR_GRADIENTS.get(currentChartColor); if (perc <= 20) wardwiseCnt.put("color", colors[4]); else if (perc > 20.0 && perc <= 40.0) wardwiseCnt.put("color", colors[3]); else if (perc > 40.0 && perc <= 60.0) wardwiseCnt.put("color", colors[2]); else if (perc > 60.0 && perc <= 80.0) wardwiseCnt.put("color", colors[1]); else wardwiseCnt.put("color", colors[0]); wardWiseData.add(wardwiseCnt); } return wardWiseData; }
From source file:org.egov.ptis.repository.dashboard.RevenueDashboardRepository.java
License:Open Source License
public Map<String, Collection<Double>> targetVsAchieved() { final DateTime currentDate = new DateTime(); final List<Object[]> targets = getQuery("revenue.ptis.target").list(); final List<Object[]> finyear = getCurrentFinYear().list(); final DateTime finYearStartDate = new DateTime(finyear.get(0)[0]); final DateTime finYearEndDate = new DateTime(finyear.get(0)[1]); final DateTime lastFinYearStartDate = finYearStartDate.minusMonths(12); final DateTime lastFinYearEndDate = finYearEndDate.minusMonths(12); final Map<String, Double> currentTarget = constructDatePlaceHolderForDouble(finYearStartDate, finYearEndDate, "MM-yyyy"); final Map<String, Double> cumilativeTarget = constructDatePlaceHolderForDouble(finYearStartDate, finYearEndDate, "MM-yyyy"); for (final Object[] target : targets) { currentTarget.put(String.valueOf(target[0]), Double.valueOf(String.valueOf(target[1]))); cumilativeTarget.put(String.valueOf(target[0]), Double.valueOf(String.valueOf(target[2]))); }/*from w w w . j av a2s . c o m*/ final Map<String, Double> currentAcheived = constructDatePlaceHolderForDouble(finYearStartDate, currentDate, "MM-yyyy"); final Map<String, Double> cumilativeAcheived = constructDatePlaceHolderForDouble(finYearStartDate, currentDate, "MM-yyyy"); final List<Object[]> achieved = getQuery("revenue.ptis.achieved").list(); for (final Object[] achieve : achieved) { currentAcheived.put(String.valueOf(achieve[0]), Double.valueOf(String.valueOf(achieve[1]))); cumilativeAcheived.put(String.valueOf(achieve[0]), Double.valueOf(String.valueOf(achieve[2]))); } final Map<String, Double> lastAcheived = constructDatePlaceHolderForDouble(lastFinYearStartDate, lastFinYearEndDate, "MM-yyyy"); final Map<String, Double> lastcumilativeAcheived = constructDatePlaceHolderForDouble(lastFinYearStartDate, lastFinYearEndDate, "MM-yyyy"); final Query qry = getQuery("revenue.ptis.last.achieved"); qry.setParameter("finStartDate", startOfGivenDate(lastFinYearStartDate).toDate()); qry.setParameter("finEndDate", startOfGivenDate(lastFinYearEndDate).toDate()); final List<Object[]> lastAchieved = qry.list(); for (final Object[] lastachieved : lastAchieved) { lastAcheived.put(String.valueOf(lastachieved[0]), Double.valueOf(String.valueOf(lastachieved[1]))); lastcumilativeAcheived.put(String.valueOf(lastachieved[0]), Double.valueOf(String.valueOf(lastachieved[2]))); } final Map<String, Collection<Double>> targetVsAchieved = new HashMap<String, Collection<Double>>(); targetVsAchieved.put("target", currentTarget.values()); targetVsAchieved.put("achieved", currentAcheived.values()); targetVsAchieved.put("lastAcheived", lastAcheived.values()); targetVsAchieved.put("cumilativetarget", cumilativeTarget.values()); targetVsAchieved.put("cumilativeachieved", cumilativeAcheived.values()); targetVsAchieved.put("lastcumilativeachieved", lastcumilativeAcheived.values()); return targetVsAchieved; }
From source file:org.egov.wtms.web.controller.application.MeterDemandNoticeController.java
License:Open Source License
/** * @param waterConnectionDetails/* w w w . j a v a 2s . co m*/ * @param session * @param formatter * @param assessmentDetails * @param ownerName * @param billObj * @param meterReadingpriviousObj * @param monthName * @param yearName */ private Map<String, Object> prepareReportParams(final WaterConnectionDetails waterConnectionDetails, final HttpSession session, final AssessmentDetails assessmentDetails, final String ownerName, final EgBill billObj, final MeterReadingConnectionDetails meterReadingPreviousObj) { final Format formatterMonth = new SimpleDateFormat("MMMM"); final Format formatterYear = new SimpleDateFormat("YYYY"); DateTime dateTime = new DateTime(); final String monthName; final String yearName; if (!waterConnectionDetails.getMeterConnection().isEmpty()) { final Date currentReadingDate = waterConnectionDetails.getMeterConnection().get(0) .getCurrentReadingDate(); dateTime = new DateTime(currentReadingDate); if (dateTime != null) { final int currentMidday = dateTime.dayOfMonth().getMaximumValue() / 2; final DateTime currentMidDate = new DateTime(currentReadingDate).withDayOfMonth(currentMidday); if (currentReadingDate.before(currentMidDate.toDate())) dateTime = dateTime.minusMonths(1); } } monthName = formatterMonth.format(dateTime.toDate()); yearName = formatterYear.format(dateTime.toDate()); final Map<String, Object> reportParams = new HashMap<>(); if (WaterTaxConstants.NEWCONNECTION.equalsIgnoreCase(waterConnectionDetails.getApplicationType().getCode()) || WaterTaxConstants.ADDNLCONNECTION .equalsIgnoreCase(waterConnectionDetails.getApplicationType().getCode())) reportParams.put("applicationType", WordUtils.capitalize(waterConnectionDetails.getApplicationType().getName())); reportParams.put("municipality", session.getAttribute("citymunicipalityname")); reportParams.put("district", session.getAttribute("districtName")); reportParams.put("waterCharges", waterConnectionDetails.getConnectionType().name()); reportParams.put("propertyassesmentNumber", waterConnectionDetails.getConnection().getPropertyIdentifier()); reportParams.put("consumerNumber", waterConnectionDetails.getConnection().getConsumerCode()); reportParams.put("pipeSize", waterConnectionDetails.getPipeSize().getSizeInInch()); reportParams.put("mterSerialNumber", waterConnectionDetails.getConnection().getMeterSerialNumber()); reportParams.put("applicantName", ownerName); reportParams.put("demandNoticeNumber", billObj != null && billObj.getBillNo() != null ? billObj.getBillNo() : ""); reportParams.put("billMonth", monthName + "-" + yearName); reportParams.put("demandNoticeDate", billObj == null || billObj.getCreateDate() == null ? null : toDefaultDateFormat(billObj.getCreateDate())); reportParams.put("previousReading", meterReadingPreviousObj.getCurrentReading()); if (meterReadingPreviousObj.getCurrentReadingDate() == null) reportParams.put("previousReadingDate", ""); else reportParams.put("previousReadingDate", toDefaultDateFormat(meterReadingPreviousObj.getCurrentReadingDate())); reportParams.put("currentReading", waterConnectionDetails.getMeterConnection().get(0).getCurrentReading()); reportParams.put("currrentReadingDate", toDefaultDateFormat(waterConnectionDetails.getMeterConnection().get(0).getCurrentReadingDate())); if (meterReadingPreviousObj.getCurrentReading() != null && !waterConnectionDetails.getMeterConnection().isEmpty() && waterConnectionDetails.getMeterConnection().get(0).getCurrentReading() != null) reportParams.put("noofunitsconsume", waterConnectionDetails.getMeterConnection().get(0).getCurrentReading() - meterReadingPreviousObj.getCurrentReading()); reportParams.put("totalBilltoCollect", waterConnectionDetailsService.getTotalAmount(waterConnectionDetails)); reportParams.put("currentMonthCharges", getCurrentMonthDemandAmount(waterConnectionDetails, dateTime.toDate())); reportParams.put("totalDueAmount", getTotalDue(waterConnectionDetails, dateTime.toDate())); reportParams.put("address", assessmentDetails.getPropertyAddress()); return reportParams; }
From source file:org.egov.wtms.web.controller.application.MeterReadingController.java
License:Open Source License
private WaterConnectionDetails calculateDemandForDamagedMeter( final WaterConnectionDetails waterConnectionDetails, final Date previousDate, final int noOfMonths, final Boolean currentMonthIncluded) { BigDecimal amountValue;/*from ww w .j av a 2s.c o m*/ new WaterConnectionDetails(); Installment currentInstallment; List<Installment> newInstallmentList; DateTime dateTime = new DateTime(previousDate); DateTime lastInstReadingDate; DateTime lastInstStartDate; newInstallmentList = installmentDao.getInstallmentsByModuleForGivenDateAndInstallmentType( moduleService.getModuleByName(MODULE_NAME), previousDate, MONTHLY); currentInstallment = connectionDemandService.getCurrentInstallment(MODULE_NAME, MONTHLY, new Date()); if (newInstallmentList.isEmpty() || !newInstallmentList.contains(currentInstallment)) newInstallmentList.add(currentInstallment); for (final Installment installment : newInstallmentList) { lastInstReadingDate = dateTime.minusMonths(6); lastInstStartDate = lastInstReadingDate.withDayOfMonth(1).withTimeAtStartOfDay(); final List<Installment> lastInstallmentList = installmentDao .getInstallmentsByModuleBetweenFromDateAndToDateAndInstallmentType( moduleService.getModuleByName(MODULE_NAME), lastInstStartDate.toDate(), installment.getFromDate(), MONTHLY); amountValue = calculateDamagedMeterAverageDemand(lastInstallmentList, waterConnectionDetails); if (amountValue.compareTo(BigDecimal.ZERO) > 0) connectionDemandService.updateDemandForMeteredConnection(waterConnectionDetails, amountValue, installment.getFromDate(), previousDate, noOfMonths, currentMonthIncluded); dateTime = new DateTime(installment.getFromDate()); dateTime = dateTime.plusMonths(1); } return waterConnectionDetails; }
From source file:org.elasticsearch.xpack.monitoring.cleaner.AbstractIndicesCleanerTestCase.java
License:Open Source License
public void testDeleteIndices() throws Exception { internalCluster().startNode();//from w ww . j av a 2 s.co m CleanerService.Listener listener = getListener(); final DateTime now = now(); createTimestampedIndex(now.minusYears(1)); createTimestampedIndex(now.minusMonths(6)); createTimestampedIndex(now.minusMonths(1)); createTimestampedIndex(now.minusDays(10)); createTimestampedIndex(now.minusDays(1)); assertIndicesCount(5); // Clean indices that have expired two years ago listener.onCleanUpIndices(years(2)); assertIndicesCount(5); // Clean indices that have expired 8 months ago listener.onCleanUpIndices(months(8)); assertIndicesCount(4); // Clean indices that have expired 3 months ago listener.onCleanUpIndices(months(3)); assertIndicesCount(3); // Clean indices that have expired 15 days ago listener.onCleanUpIndices(days(15)); assertIndicesCount(2); // Clean indices that have expired 7 days ago listener.onCleanUpIndices(days(7)); assertIndicesCount(1); // Clean indices until now listener.onCleanUpIndices(days(0)); assertIndicesCount(0); }