Пример #1
0
  @PostConstruct
  public void load() {
    membershipGrowthModel = new CartesianChartModel();
    membershipCumulativeGrowthModel = new CartesianChartModel();

    String[] months = {
      ResourceBundleHelper.INSTANCE.getMessage("januaryShort"),
      ResourceBundleHelper.INSTANCE.getMessage("februaryShort"),
      ResourceBundleHelper.INSTANCE.getMessage("marchShort"),
      ResourceBundleHelper.INSTANCE.getMessage("aprilShort"),
      ResourceBundleHelper.INSTANCE.getMessage("mayShort"),
      ResourceBundleHelper.INSTANCE.getMessage("juneShort"),
      ResourceBundleHelper.INSTANCE.getMessage("julyShort"),
      ResourceBundleHelper.INSTANCE.getMessage("augustShort"),
      ResourceBundleHelper.INSTANCE.getMessage("septemberShort"),
      ResourceBundleHelper.INSTANCE.getMessage("octoberShort"),
      ResourceBundleHelper.INSTANCE.getMessage("novemberShort"),
      ResourceBundleHelper.INSTANCE.getMessage("decemberShort")
    };

    Calendar lastDay = Calendar.getInstance();
    lastDay.set(Calendar.MONTH, Calendar.DECEMBER);
    lastDay.set(Calendar.DATE, 31);
    lastDay.set(Calendar.HOUR, 11);
    lastDay.set(Calendar.MINUTE, 59);
    lastDay.set(Calendar.SECOND, 59);
    lastDay.set(Calendar.AM_PM, Calendar.PM);
    Date to = lastDay.getTime();

    Calendar firstDay = lastDay;
    firstDay.add(Calendar.YEAR, -1);
    firstDay.set(Calendar.DAY_OF_MONTH, 1);
    firstDay.set(Calendar.MONTH, 0);
    firstDay.set(Calendar.HOUR, 0);
    firstDay.set(Calendar.MINUTE, 0);
    lastDay.set(Calendar.SECOND, 0);
    lastDay.set(Calendar.AM_PM, Calendar.AM);
    Date from = firstDay.getTime();

    List<UserAccount> userAccounts = userAccountBean.findConfirmedAccounts(from, to);

    Calendar registrationDate;
    Calendar deactivationDate;
    int[][] data = new int[2][12];
    int year, month, currentYear = 0;
    for (UserAccount userAccount : userAccounts) {
      registrationDate = Calendar.getInstance();
      registrationDate.setTime(userAccount.getRegistrationDate());
      if (currentYear == 0) {
        currentYear = registrationDate.get(Calendar.YEAR);
      }

      year = registrationDate.get(Calendar.YEAR) - currentYear;
      month = registrationDate.get(Calendar.MONTH);
      data[year][month] += 1;

      if (userAccount.getDeactivationDate() != null) {
        deactivationDate = Calendar.getInstance();
        deactivationDate.setTime(userAccount.getDeactivationDate());

        year = deactivationDate.get(Calendar.YEAR) - currentYear;
        month = deactivationDate.get(Calendar.MONTH);
        data[year][month] -= 1;
      }
    }

    ChartSeries annualSeries;
    for (int i = 0; i < 2; i++) {
      annualSeries = new ChartSeries();
      annualSeries.setLabel(String.valueOf(currentYear + i));
      for (int j = 0; j < 12; j++) {
        annualSeries.set(months[j], data[i][j]);
      }
      membershipGrowthModel.addSeries(annualSeries);
    }

    ChartSeries accumulatedSeries;
    int accumulated;
    for (int i = 0; i < 2; i++) {
      accumulated = 0;
      accumulatedSeries = new ChartSeries();
      accumulatedSeries.setLabel(String.valueOf(currentYear + i));
      for (int j = 0; j < 12; j++) {
        accumulated = data[i][j] + accumulated;
        accumulatedSeries.set(months[j], accumulated);
      }
      membershipCumulativeGrowthModel.addSeries(accumulatedSeries);
    }
  }
Пример #2
0
 public List<UserAccount> getInhabitants() {
   return userAccountBean.findInhabitantsFrom(this.city);
 }