Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package client;
- import java.text.DecimalFormat;
- import java.util.ArrayList;
- import java.util.HashMap;
- import datamodel.IResult;
- import datamodel.MeasurementRecord;
- public class Result implements IResult {
- private ArrayList<MeasurementRecord> inputMeasurements;
- private String aggregatorType;
- private String aggFunction;
- private String description;
- public Result(ArrayList<MeasurementRecord> inputMeasurements, String aggregatorType, String aggFunction, String description) {
- this.inputMeasurements = inputMeasurements;
- this.aggregatorType = aggregatorType;
- this.aggFunction = aggFunction;
- this.description = description;
- }
- @Override
- public int add(String timeUnit, MeasurementRecord record) {
- inputMeasurements.add(record);
- return inputMeasurements.size();
- }
- @Override
- public String getDescription() {
- return description;
- }
- @Override
- public HashMap<String, ArrayList<MeasurementRecord>> getDetailedResults() {
- HashMap<String, ArrayList<MeasurementRecord>> result = new HashMap<String, ArrayList<MeasurementRecord>>();
- for (MeasurementRecord record : inputMeasurements) {
- if (result.containsKey(record.getMonth().name())) {
- result.get(record.getMonth().name()).add(record);
- } else {
- ArrayList<MeasurementRecord> records = new ArrayList<MeasurementRecord>();
- records.add(record);
- result.put(record.getMonth().name(), records);
- }
- }
- return result;
- }
- @Override
- public HashMap<String, Double> getAggregateMeterKitchen() {
- HashMap<String, Double> result = new HashMap<String, Double>();
- HashMap<String, Integer> sz = new HashMap<String, Integer>();
- for (MeasurementRecord record : inputMeasurements) {
- String aggType = "";
- if (aggregatorType.equalsIgnoreCase("season")) {
- aggType = record.getSeason();
- } else if (aggregatorType.equalsIgnoreCase("month")) {
- aggType = new DecimalFormat("00").format(record.getMonth().getValue());
- } else if (aggregatorType.equalsIgnoreCase("dayofweek")) {
- aggType = new DecimalFormat("00").format(record.getDay().getValue());
- } else if (aggregatorType.equalsIgnoreCase("period")) {
- aggType = record.getTimePeriod();
- }
- if (result.containsKey(aggType)) {
- result.put(aggType, result.get(aggType)+record.getKitchen());
- sz.put(aggType, sz.get(aggType)+1);
- } else {
- result.put(aggType, record.getKitchen());
- sz.put(aggType, 1);
- }
- }
- if (aggFunction.equalsIgnoreCase("avg")) {
- for (String str : result.keySet()) {
- result.put(str, result.get(str)/sz.get(str));
- }
- }
- return result;
- }
- @Override
- public HashMap<String, Double> getAggregateMeterLaundry() {
- HashMap<String, Double> result = new HashMap<String, Double>();
- HashMap<String, Integer> sz = new HashMap<String, Integer>();
- for (MeasurementRecord record : inputMeasurements) {
- String aggType = "";
- if (aggregatorType.equalsIgnoreCase("season")) {
- aggType = record.getSeason();
- } else if (aggregatorType.equalsIgnoreCase("month")) {
- aggType = new DecimalFormat("00").format(record.getMonth().getValue());
- } else if (aggregatorType.equalsIgnoreCase("dayofweek")) {
- aggType = new DecimalFormat("00").format(record.getDay().getValue());
- } else if (aggregatorType.equalsIgnoreCase("period")) {
- aggType = record.getTimePeriod();
- }
- if (result.containsKey(aggType)) {
- result.put(aggType, result.get(aggType)+record.getLaundry());
- sz.put(aggType, sz.get(aggType)+1);
- } else {
- result.put(aggType, record.getLaundry());
- sz.put(aggType, 1);
- }
- }
- if (aggFunction.equalsIgnoreCase("avg")) {
- for (String str : result.keySet()) {
- result.put(str, result.get(str)/sz.get(str));
- }
- }
- return result;
- }
- @Override
- public HashMap<String, Double> getAggregateMeterAC() {
- HashMap<String, Double> result = new HashMap<String, Double>();
- HashMap<String, Integer> sz = new HashMap<String, Integer>();
- for (MeasurementRecord record : inputMeasurements) {
- String aggType = "";
- if (aggregatorType.equalsIgnoreCase("season")) {
- aggType = record.getSeason();
- } else if (aggregatorType.equalsIgnoreCase("month")) {
- aggType = new DecimalFormat("00").format(record.getMonth().getValue());
- } else if (aggregatorType.equalsIgnoreCase("dayofweek")) {
- aggType = new DecimalFormat("00").format(record.getDay().getValue());
- } else if (aggregatorType.equalsIgnoreCase("period")) {
- aggType = record.getTimePeriod();
- }
- if (result.containsKey(aggType)) {
- result.put(aggType, result.get(aggType)+record.getHeating());
- sz.put(aggType, sz.get(aggType)+1);
- } else {
- result.put(aggType, record.getHeating());
- sz.put(aggType, 1);
- }
- }
- if (aggFunction.equalsIgnoreCase("avg")) {
- for (String str : result.keySet()) {
- result.put(str, result.get(str)/sz.get(str));
- }
- }
- return result;
- }
- @Override
- public String getAggregateFunction() {
- return aggFunction;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement