private BasicMetricHour getMetricHour(String accountName, String guiPath, long hoursSince1970) {
    // logger.info("getting Metric Hour for account: " + accountName + " guiPath: " + guiPath + "
    // ts: " + hoursSince1970);
    BasicMetricHour metricHour = null;

    Bucket mhBucket = null;
    try {
      mhBucket = riakClient.fetchBucket(accountName + ";" + hoursSince1970).execute();
      metricHour = mhBucket.fetch("" + guiPath, BasicMetricHour.class).execute();
      logger.info("finding: " + accountName + ";" + hoursSince1970 + "/" + guiPath);
      if (metricHour != null) {
        metricHourCache.put(
            metricHour.getAccountName()
                + ";"
                + metricHour.getGuiPath()
                + ";"
                + metricHour.getHoursSince1970(),
            metricHour);
      }
    } catch (RiakRetryFailedException rrfe) {
      rrfe.printStackTrace();
    }

    return metricHour;
  }
  private List<LiveStatistics> createLivestatisticsFromMetricHour(
      BasicMetricHour metricHour,
      Integer minTimeperiodWithinTheHour,
      Integer maxTimeperiodWithinTheHour,
      Long hoursSince1970) {
    List<LiveStatistics> retList = new ArrayList<LiveStatistics>();

    if (maxTimeperiodWithinTheHour == null) {
      maxTimeperiodWithinTheHour = 239;
    }

    for (int index = minTimeperiodWithinTheHour; index <= maxTimeperiodWithinTheHour; index++) {
      Long timeperiod = (hoursSince1970 * 240) + index;

      // logger.info("Creating LiveStats for: " + metricHour.getId() + " with value: " +
      // metricHour.getValueAt(index));
      retList.add(
          new BasicLiveStatistics(
              metricHour.getGuiPath(),
              metricHour.getAccountName(),
              timeperiod,
              metricHour.getMetrics()[index],
              metricHour.getValueType(),
              metricHour.getUnitType()));
    }

    return retList;
  }
  @Override
  public void storeIncomingStatistics(List<LiveStatistics> liveStatisticsList) {
    for (LiveStatistics ls : liveStatisticsList) {
      long hoursSince1970 = ls.getTimeperiod() / 240;
      int fifteenSecondPeriodsSinceStartOfHour =
          LiveStatisticsUtil.getFifteensecondTimeperiodsSinceStartOfHour(ls.getTimeperiod() * 15);
      Double calculatedValue =
          LiveStatisticsUtil.calculateValueBasedOnUnitType(
              ls.getValue(), UnitType.fromValue(ls.getUnitType()));

      BasicMetricHour mhToStore =
          metricHoursToStoreHash.get(
              ls.getAccountName() + ";" + ls.getGuiPath() + ";" + hoursSince1970);
      boolean wasInStoreHash = mhToStore != null;

      if (mhToStore == null) {
        // Not in store-hash chech in metricHourCache
        mhToStore =
            metricHourCache.getIfPresent(
                ls.getAccountName() + ";" + ls.getGuiPath() + ";" + hoursSince1970);
      }

      if (mhToStore == null) {
        // Not in metricHourCache, fetch from Riak
        mhToStore = getMetricHour(ls.getAccountName(), ls.getGuiPath(), hoursSince1970);
      }

      if (mhToStore == null) {
        // Not in Riak, create
        mhToStore =
            new BasicMetricHour(
                ls.getGuiPath(),
                ls.getAccountName(),
                hoursSince1970,
                ls.getValueType(),
                ls.getUnitType());
      }

      mhToStore.getMetrics()[fifteenSecondPeriodsSinceStartOfHour] =
          LiveStatisticsUtil.calculateValueBasedOnValueType(
              ls, calculatedValue, ValueType.fromValue(ls.getValueType()));

      if (!wasInStoreHash) {
        metricHoursToStoreHash.put(
            ls.getAccountName() + ";" + ls.getGuiPath() + ";" + hoursSince1970, mhToStore);
      }
    }

    persistRecentMetricHours();
  }
  @Override
  public void storeIncomingStatistics(
      String guiPath,
      String accountName,
      Long timeperiod,
      String value,
      ValueType valueType,
      UnitType unitType) {
    Double valueDouble = LiveStatisticsUtil.parseDouble(value);
    Double calculatedValue =
        LiveStatisticsUtil.calculateValueBasedOnUnitType(valueDouble, unitType);

    long hoursSince1970 = timeperiod / 240;
    int fifteenSecondPeriodsSinceStartOfHour =
        LiveStatisticsUtil.getFifteensecondTimeperiodsSinceStartOfHour(timeperiod * 15);

    Bucket myBucket = null;
    try {
      myBucket = riakClient.fetchBucket(accountName + ";" + hoursSince1970).execute();
      BasicMetricHour storedMetricHour =
          myBucket.fetch("" + guiPath, BasicMetricHour.class).execute();
      if (storedMetricHour == null) {
        storedMetricHour =
            new BasicMetricHour(
                guiPath, accountName, hoursSince1970, valueType.toString(), unitType.toString());
      }

      Double prevValue = storedMetricHour.getMetrics()[fifteenSecondPeriodsSinceStartOfHour];
      if (prevValue == null) {
        storedMetricHour.getMetrics()[fifteenSecondPeriodsSinceStartOfHour] = calculatedValue;
      } else {
        storedMetricHour.getMetrics()[fifteenSecondPeriodsSinceStartOfHour] =
            LiveStatisticsUtil.calculateValueBasedOnValueType(
                prevValue, calculatedValue, valueType);
      }

      myBucket.store("" + guiPath, storedMetricHour).execute();
    } catch (RiakRetryFailedException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }