Index: DCWoRMS/branches/coolemall/src/simulator/ConfigurationOptions.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/ConfigurationOptions.java	(revision 1279)
+++ DCWoRMS/branches/coolemall/src/simulator/ConfigurationOptions.java	(revision 1299)
@@ -8,4 +8,6 @@
 import java.util.PropertyResourceBundle;
 import java.util.ResourceBundle;
+
+import test.CoolingModelData;
 
 /**
@@ -189,11 +191,12 @@
 	public String [] resForUtilizationChart;
 	
-	public static double pressureDrop;
-	public static double outletRoomAirTempeature;
-	public static double inletRoomAirTempeature;
-	public static double ambientAirTempeature;
-	public static double airFlowVolume;
-	public static double alpha
-	;
+	public double pressureDrop;
+	public double outletRoomAirTempeature;
+	public double inletRoomAirTempeature;
+	public double ambientAirTempeature;
+	public double airFlowVolume;
+	public double alpha;
+	
+	public static CoolingModelData coolingData;
 	/**
 	 * An empty constructor.
@@ -389,39 +392,40 @@
 
 		try {
-			ConfigurationOptions.pressureDrop = Double.valueOf(bundle.getString(PRESSURE_DROP)).doubleValue();
-		} catch(MissingResourceException e){
-			ConfigurationOptions.pressureDrop = 65;
-		}
-		
-		try {
-			ConfigurationOptions.outletRoomAirTempeature = Double.valueOf(bundle.getString(OUTLET_ROOM_AIR_TEMPERATURE)).doubleValue();
-		} catch(MissingResourceException e){
-			ConfigurationOptions.outletRoomAirTempeature = 23;
-		}
-		
-		try {
-			ConfigurationOptions.inletRoomAirTempeature = Double.valueOf(bundle.getString(INLET_ROOM_AIR_TEMPERATURE)).doubleValue();
-		} catch(MissingResourceException e){
-			ConfigurationOptions.inletRoomAirTempeature = 17;
-		}
-		
-		try {
-			ConfigurationOptions.ambientAirTempeature = Double.valueOf(bundle.getString(AMBIENT_AIR_TEMPERATURE)).doubleValue();
-		} catch(MissingResourceException e){
-			ConfigurationOptions.ambientAirTempeature = 17;
-		}
-		
-		try {
-			ConfigurationOptions.airFlowVolume = Double.valueOf(bundle.getString(AIR_FLOW_VOLUME)).doubleValue();
-		} catch(MissingResourceException e){
-			ConfigurationOptions.airFlowVolume = 4;
-		}
-		
-		try {
-			ConfigurationOptions.alpha = Double.valueOf(bundle.getString(ALPHA)).doubleValue();
-		} catch(MissingResourceException e){
-			ConfigurationOptions.alpha = 0.2;
-		}
-		
+			co.pressureDrop = Double.valueOf(bundle.getString(PRESSURE_DROP)).doubleValue();
+		} catch(MissingResourceException e){
+			co.pressureDrop = -1;
+		}
+		
+		try {
+			co.outletRoomAirTempeature = Double.valueOf(bundle.getString(OUTLET_ROOM_AIR_TEMPERATURE)).doubleValue();
+		} catch(MissingResourceException e){
+			co.outletRoomAirTempeature = -1;
+		}
+		
+		try {
+			co.inletRoomAirTempeature = Double.valueOf(bundle.getString(INLET_ROOM_AIR_TEMPERATURE)).doubleValue();
+		} catch(MissingResourceException e){
+			co.inletRoomAirTempeature = -1;
+		}
+		
+		try {
+			co.ambientAirTempeature = Double.valueOf(bundle.getString(AMBIENT_AIR_TEMPERATURE)).doubleValue();
+		} catch(MissingResourceException e){
+			co.ambientAirTempeature = -1;
+		}
+		
+		try {
+			co.airFlowVolume = Double.valueOf(bundle.getString(AIR_FLOW_VOLUME)).doubleValue();
+		} catch(MissingResourceException e){
+			co.airFlowVolume = -1;
+		}
+		
+		try {
+			co.alpha = Double.valueOf(bundle.getString(ALPHA)).doubleValue();
+		} catch(MissingResourceException e){
+			co.alpha = -1;
+		}
+		
+		ConfigurationOptions.coolingData = new CoolingModelData(co.pressureDrop, co.outletRoomAirTempeature, co.inletRoomAirTempeature, co.ambientAirTempeature, co.airFlowVolume, co.alpha);
 		return co;
 	}
Index: DCWoRMS/branches/coolemall/src/simulator/DataCenterWorkloadSimulator.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/DataCenterWorkloadSimulator.java	(revision 1207)
+++ DCWoRMS/branches/coolemall/src/simulator/DataCenterWorkloadSimulator.java	(revision 1299)
@@ -21,5 +21,4 @@
 import org.joda.time.DateTimeUtilsExt;
 
-import schedframe.Initializable;
 import schedframe.SimulatedEnvironment;
 import simulator.reader.ResourceReader;
@@ -252,10 +251,15 @@
 		// (default 1)
 		
-		Date date = workload.getSimulationStartTime();
 		Calendar calendar = Calendar.getInstance();
-		if (date == null)
+		if(workload == null){
 			calendar.setTimeInMillis(0L);
-		else
-			calendar.setTime(date);
+		} else {
+			Date date = workload.getSimulationStartTime();
+			if (date == null)
+				calendar.setTimeInMillis(0L);
+			else
+				calendar.setTime(date);			
+		}
+
 
 		boolean traceFlag = true; // means: trace GridSim events/activities
@@ -268,14 +272,15 @@
 		ResourceReader resourceReader = new ResourceReader(
 				options.resdescFileName);
-		SimulatedEnvironment rc = resourceReader.read();
-		eventManager = new EventManager("eventManager", rc);
-		
-		for(Initializable initObj: rc.getToInit()){
+		SimulatedEnvironment simEnv = resourceReader.read();
+		
+		eventManager = new EventManager("eventManager", simEnv);
+		
+		/*for(Initializable initObj: rc.getToInit()){
 			initObj.initiate();
 		}
-		rc.setInitList(null);
+		rc.setInitList(null);*/
 		
 		DCWormsUsers users = new DCWormsUsers("Users",
-				rc.getScheduler().get_name(), workload);
+				simEnv.getScheduler().get_name(), workload);
 		
 		System.out.println("Starting simulation...");
@@ -287,5 +292,5 @@
 
 		DCWormsStatistics stats = new DCWormsStatistics(simulationIdentifier,
-				options, users, statsOutputPath, rc);
+				options, users, statsOutputPath, simEnv);
 		accumulatedStatistics.add(stats);
 		if (log.isInfoEnabled())
@@ -309,18 +314,14 @@
 	private WorkloadLoader loadWorkload(ConfigurationOptions options) throws IOException, MarshalException, ValidationException{
 		XMLJobReader<org.qcg.broker.schemas.jobdesc.Job> xmlJobReader = null;
-		WAReader<org.qcg.broker.schemas.jobdesc.Job> swfReader = null;
+		WAReader<org.qcg.broker.schemas.jobdesc.Job> workloadReader = null;
 
 		String wlFileName = options.inputWorkloadFileName;
 
-		String appProfilesFolder = options.appProfilesFolder;
+		if(wlFileName == null){
+			return null;
+		}
+		
 		if (options.inputFolder != null) {
-			File f = null;
-			if (options.inputTar != null) {
-				f = new File(options.inputFolder + File.separator
-						+ options.inputTar);
-			} else {
-				f = new File(options.inputFolder);
-			}
-
+			File f = new File(options.inputFolder);
 			xmlJobReader = new QcgXmlJobReader(f);
 
@@ -329,7 +330,9 @@
 		}
 
-		swfReader = AbstractWAReader.getInstace(wlFileName);
-
-		WorkloadLoader workload = new WorkloadLoader(xmlJobReader, swfReader, appProfilesFolder);
+		workloadReader = AbstractWAReader.getInstace(wlFileName);
+		
+		String appProfilesFolderName = options.appProfilesFolder;
+		
+		WorkloadLoader workload = new WorkloadLoader(xmlJobReader, workloadReader, appProfilesFolderName);
 		workload.load();
 
Index: DCWoRMS/branches/coolemall/src/simulator/stats/MetricsCalculator.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/stats/MetricsCalculator.java	(revision 1207)
+++ DCWoRMS/branches/coolemall/src/simulator/stats/MetricsCalculator.java	(revision 1299)
@@ -1,455 +1,16 @@
 package simulator.stats;
 
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import simulator.stats.implementation.MetricsStats;
-import example.energy.coolemall.CoolEmAllTestbedMeasurements;
 
-public class MetricsCalculator {
+public interface MetricsCalculator {
 	
-	protected static final double MILLI_SEC = 1000;
-	protected static final double SEC_IN_HOUR = 3600;
+	public List<MetricsStats> calulateMetrics();
 	
-	protected Map<String, List<GSSAccumulator>> metricsData = new HashMap<String, List<GSSAccumulator>>();
-	protected long timestamp;
-	protected long startTime;
-	protected long endTime;
-
-	public List<MetricsStats> calulateMetrics(long timestamp){
-		this.timestamp = timestamp;
-		List<MetricsStats> metrics = new ArrayList<MetricsStats>();
-		/*for(String resourceTypeName: metricsData.keySet()){
-			MetricsStats metric = new MetricsStats(resourceTypeName, "energyUsage", metricsData.get(resourceTypeName).getMax());
-			metrics.add(metric);}
-		}*/
-		metrics.add(calculateITComputingEnergyConsumption());
-		metrics.add(calculateITEnergyConsumption());
-		metrics.add(calculateNodeGroupFansEnergyConsumption());
-		
-		metrics.add(calculateRackEnergyConsumption());
-		metrics.add(calculateDataCenterFansEnergyConsumption());
-		metrics.add(calculateCoolingDeviceEnergyConsumption());
-		metrics.add(calculateOtherDevicesEnergyConsumption());
-		
-		metrics.add(calculateTotalEnergyConsumption());
-		
-		metrics.add(calculateMeanRackPower());
-		metrics.add(calculateMeanPower());
-		metrics.add(calculateMaxRackPower());
-		metrics.add(calculateMaxPower());
-		
-		metrics.add(calculatePUE());
-		metrics.add(calculatePUELevel4());
-		metrics.add(calculateEnergyWasteRate());
-		
-		metrics.add(calculateUsefulWork());
-		metrics.add(calculateProductivity());
-
-		return metrics;
-	}
+	public void addMetricsData(String resourceTypeName, GSSAccumulator resourceEnergyAccumulator);
 	
-	public void addMetricsData(String resourceTypeName, GSSAccumulator resourceEnergyAccumulator){
-		List<GSSAccumulator> resourceEnergyAccumulatorList = metricsData.get(resourceTypeName);
-		if(resourceEnergyAccumulatorList == null){
-			resourceEnergyAccumulatorList = new ArrayList<GSSAccumulator>();
-		}
-		resourceEnergyAccumulatorList.add(resourceEnergyAccumulator);
-		metricsData.put(resourceTypeName, resourceEnergyAccumulatorList);
-	}
+	public Map<String, List<GSSAccumulator>> getMetricsData();
 	
-	public Map<String, List<GSSAccumulator>> getMetricsData(){
-		return metricsData;
-	}
-	
-	private MetricsStats calculateTotalEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Room")){
-				roomPower = roomPower + acc.getSum();
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_energy_consumption", roomPower, timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_energy_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculateITComputingEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double itComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor")){
-				itComputingPower = itComputingPower + acc.getSum();
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_processors_energy_consumption", (itComputingPower), timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_processors_energy_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculateITEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double totalSitePower = 0; 
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				totalSitePower = totalSitePower + acc.getSum();
-			}
-			double nodeComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Node")){
-				nodeComputingPower = nodeComputingPower+ acc.getSum();
-			}
-			double itComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor")){
-				itComputingPower = itComputingPower + acc.getSum();
-			}
-			double fanPowerConumspion = nodeComputingPower - itComputingPower;
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_IT_energy_consumption", (totalSitePower * CoolEmAllTestbedMeasurements.POWER_SUPPLY_EFFICIENCY - fanPowerConumspion), timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_IT_energy_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculateNodeGroupFansEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double nodeComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Node")){
-				nodeComputingPower = nodeComputingPower+ acc.getSum();
-			}
-			double itComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor")){
-				itComputingPower = itComputingPower + acc.getSum();
-			}
-			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_node_group_fans_energy_consumption", nodeGroupFansPowerConumspion, timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_node_group_fans_energy_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculatePUELevel4(){
-		
-		MetricsStats metric;
-		try{
-			
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Room")){
-				roomPower = roomPower + acc.getSum();
-			}
-			
-			double totalSitePower = 0;
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				totalSitePower = totalSitePower + acc.getSum();
-			}
-			
-		
-			double nodeComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Node")){
-				nodeComputingPower = nodeComputingPower+ acc.getSum();
-			}
-			double itComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor")){
-				itComputingPower = itComputingPower + acc.getSum();
-			}
-			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
-
-			metric = new MetricsStats("CoolEmAllTestbed", "PUE_Level_4", roomPower/(totalSitePower * CoolEmAllTestbedMeasurements.POWER_SUPPLY_EFFICIENCY - nodeGroupFansPowerConumspion), timestamp, "");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "PUE_Level_4", -1, timestamp, "");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculatePUE(){
-		
-		MetricsStats metric;
-		try{
-			
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Room")){
-				roomPower = roomPower + acc.getSum();
-			}
-			
-			double totalSitePower = 0;
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				totalSitePower = totalSitePower + acc.getSum();
-			}
-
-
-			metric = new MetricsStats("CoolEmAllTestbed", "PUE", roomPower/totalSitePower, timestamp, "");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "PUE", -1, timestamp, "");
-		}
-		return metric;
-	}
-
-	private MetricsStats calculateUsefulWork(){
-		
-		MetricsStats metric;
-		try{
-			double usefulWork = 0;
-			for(String key: metricsData.keySet()){
-				if(key.contains("/")){
-					for(GSSAccumulator acc: metricsData.get(key)){
-						usefulWork= usefulWork + acc.getSum();
-					}
-				}
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Useful_Work", usefulWork, timestamp, "UW units");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Useful_Work", -1, timestamp, "UW units");
-		}
-		
-		return metric;
-	}
-	
-	private MetricsStats calculateProductivity(){
-		
-		MetricsStats metric;
-		try{
-			double usefulWork = 0;
-			for(String key: metricsData.keySet()){
-				if(key.contains("/")){
-					for(GSSAccumulator acc: metricsData.get(key)){
-						usefulWork= usefulWork + acc.getSum();
-					}
-				}
-			}
-			double totalSitePower = 0; 
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				totalSitePower = totalSitePower + acc.getSum();
-			}
-			
-			metric = new MetricsStats("CoolEmAllTestbed", "Productivity", usefulWork/totalSitePower, timestamp, "UW units/Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Productivity", -1, timestamp, "UW units/Wh");
-		}
-		
-		return metric;
-	}
-	
-	
-	private MetricsStats calculateMaxRackPower(){
-		
-		MetricsStats metric;
-		try{
-			double maxPower = 0;
-			
-			for(GSSAccumulator acc: metricsData.get("Rack_MAX")){
-				maxPower = maxPower + acc.getSum();
-			}
-
-			metric = new MetricsStats("CoolEmAllTestbed", "Max_rack_power", maxPower, timestamp, "W");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Max_rack_power", -1, timestamp, "W");
-		}
-		
-		return metric;
-	}
-	
-	private MetricsStats calculateMaxPower(){
-		
-		MetricsStats metric;
-		try{
-			double maxPower = 0;
-			
-			for(GSSAccumulator acc: metricsData.get("Room_MAX")){
-				maxPower = maxPower + acc.getSum();
-			}
-
-			metric = new MetricsStats("CoolEmAllTestbed", "Max_power", maxPower, timestamp, "W");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Max_power", -1, timestamp, "W");
-		}
-		
-		return metric;
-	}
-	
-	private MetricsStats calculateDataCenterFansEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double inletsPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Inlet")){
-				inletsPower = inletsPower + acc.getSum();
-			}
-			
-			double outletsPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Outlet")){
-				outletsPower = outletsPower + acc.getSum();
-			}
-			
-			double nodeComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Node")){
-				nodeComputingPower = nodeComputingPower+ acc.getSum();
-			}
-			double itComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor")){
-				itComputingPower = itComputingPower + acc.getSum();
-			}
-			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
-			
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_data_center_fans_energy_consumption", (inletsPower + outletsPower - nodeGroupFansPowerConumspion), timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_data_center_fans_energy_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	
-	private MetricsStats calculateRackEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				roomPower = roomPower + acc.getSum();
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_rack_energy_consumption", roomPower, timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_rack_device_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculateCoolingDeviceEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double coolingDevicePower = 0;
-			for(GSSAccumulator acc: metricsData.get("CoolingDevice")){
-				coolingDevicePower = coolingDevicePower + acc.getSum();
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_cooling_device_energy_consumption", coolingDevicePower, timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_cooling_device_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculateOtherDevicesEnergyConsumption(){
-		
-		MetricsStats metric;
-		try{
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Room")){
-				roomPower = roomPower + acc.getSum();
-			}
-			
-			double totalSitePower = 0;
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				totalSitePower = totalSitePower + acc.getSum();
-			}
-			
-			double coolingDevicePower = 0;
-			for(GSSAccumulator acc: metricsData.get("CoolingDevice")){
-				coolingDevicePower = coolingDevicePower + acc.getSum();
-			}
-			
-			double inletsPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Inlet")){
-				inletsPower = inletsPower + acc.getSum();
-			}
-			
-			double outletsPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Outlet")){
-				outletsPower = outletsPower + acc.getSum();
-			}
-			
-			double nodeComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Node")){
-				nodeComputingPower = nodeComputingPower+ acc.getSum();
-			}
-			double itComputingPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor")){
-				itComputingPower = itComputingPower + acc.getSum();
-			}
-			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
-			
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_other_devices_energy_consumption", roomPower - (totalSitePower + coolingDevicePower + (inletsPower + outletsPower - nodeGroupFansPowerConumspion)), timestamp, "Wh");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Total_other_devices_consumption", -1, timestamp, "Wh");
-		}
-		return metric;
-	}
-
-	
-	private MetricsStats calculateMeanPower(){
-		
-		MetricsStats metric;
-		try{
-			
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Room")){
-				roomPower = roomPower + acc.getSum();
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Mean_power", roomPower/((this.endTime - this.startTime)/(SEC_IN_HOUR * MILLI_SEC)), timestamp, "W");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Mean_power", -1, timestamp, "W");
-		}
-		return metric;
-	}
-	
-	
-	private MetricsStats calculateMeanRackPower(){
-		
-		MetricsStats metric;
-		try{
-			
-			double roomPower = 0;
-			for(GSSAccumulator acc: metricsData.get("Rack")){
-				roomPower = roomPower + acc.getSum();
-			}
-			metric = new MetricsStats("CoolEmAllTestbed", "Mean_rack_power", roomPower/((this.endTime - this.startTime)/(SEC_IN_HOUR * MILLI_SEC)), timestamp, "W");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Mean_rack_power", -1, timestamp, "W");
-		}
-		return metric;
-	}
-	
-	private MetricsStats calculateEnergyWasteRate(){
-		
-		MetricsStats metric;
-		try{
-			double itComputingEnergy = 0;
-			for(GSSAccumulator acc: metricsData.get("Processor_CALC")){
-				itComputingEnergy = itComputingEnergy + acc.getSum();
-			}
-			itComputingEnergy = itComputingEnergy + CoolEmAllTestbedMeasurements.OTHER_DEVICES_POWER_CONSUMPTION * (this.endTime - this.startTime)/(SEC_IN_HOUR * MILLI_SEC);
-			double itEnergy = calculateITEnergyConsumption().getValue();
-			
-			metric = new MetricsStats("CoolEmAllTestbed", "Energy_waste_rate", (1 - itComputingEnergy/itEnergy) * 100, timestamp, "%");
-		} catch (Exception e){
-			metric = new MetricsStats("CoolEmAllTestbed", "Energy_waste_rate", -1, timestamp, "%");
-		}
-		return metric;
-	}
-	
-	public long getStartTime() {
-		return startTime;
-	}
-
-	public void setStartTime(long startTime) {
-		this.startTime = startTime;
-	}
-
-	public long getEndTime() {
-		return endTime;
-	}
-
-	public void setEndTime(long endTime) {
-		this.endTime = endTime;
-	}
 }
Index: DCWoRMS/branches/coolemall/src/simulator/stats/AbstractMetricsCalculator.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/stats/AbstractMetricsCalculator.java	(revision 1299)
+++ DCWoRMS/branches/coolemall/src/simulator/stats/AbstractMetricsCalculator.java	(revision 1299)
@@ -0,0 +1,43 @@
+package simulator.stats;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import simulator.stats.implementation.MetricsStats;
+
+public abstract class AbstractMetricsCalculator implements MetricsCalculator{
+	
+	protected static final double MILLI_SEC = 1000;
+	protected static final double SEC_IN_HOUR = 3600;
+	
+	protected Map<String, List<GSSAccumulator>> metricsData = new HashMap<String, List<GSSAccumulator>>();
+
+	protected long startTime;
+	protected long endTime;
+	protected long timestamp;
+	
+	public AbstractMetricsCalculator(long startTime, long endTime, long timestamp) {
+		super();
+		this.startTime = startTime;
+		this.endTime = endTime;
+		this.timestamp = timestamp;
+	}
+	
+	abstract public List<MetricsStats> calulateMetrics();
+	
+	public void addMetricsData(String resourceTypeName, GSSAccumulator resourceEnergyAccumulator){
+		List<GSSAccumulator> resourceEnergyAccumulatorList = metricsData.get(resourceTypeName);
+		if(resourceEnergyAccumulatorList == null){
+			resourceEnergyAccumulatorList = new ArrayList<GSSAccumulator>();
+		}
+		resourceEnergyAccumulatorList.add(resourceEnergyAccumulator);
+		metricsData.put(resourceTypeName, resourceEnergyAccumulatorList);
+	}
+	
+	public Map<String, List<GSSAccumulator>> getMetricsData(){
+		return metricsData;
+	}
+
+}
Index: DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java	(revision 1207)
+++ DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java	(revision 1299)
@@ -62,11 +62,14 @@
 import schedframe.resources.UserResourceType;
 import schedframe.resources.computing.ComputingResource;
+import schedframe.resources.computing.Processor;
 import schedframe.resources.computing.extensions.Extension;
 import schedframe.resources.computing.extensions.ExtensionList;
 import schedframe.resources.computing.extensions.ExtensionType;
 import schedframe.resources.computing.profiles.energy.EnergyExtension;
+import schedframe.resources.computing.profiles.energy.MeasurementHistory;
 import schedframe.resources.computing.profiles.energy.airthroughput.AirFlowValue;
 import schedframe.resources.computing.profiles.energy.power.PowerUsage;
 import schedframe.resources.computing.profiles.energy.thermal.TemperatureValue;
+import schedframe.resources.computing.profiles.load.LoadExtension;
 import schedframe.resources.devices.Device;
 import schedframe.resources.devices.PhysicalResource;
@@ -85,8 +88,9 @@
 import simulator.DataCenterWorkloadSimulator;
 import simulator.GenericUser;
+import simulator.stats.CoolEmAllMetricsCalculator;
+import simulator.stats.DCwormsMetricsCalculator;
 import simulator.stats.GSSAccumulator;
 import simulator.stats.MetricsCalculator;
 import simulator.stats.SimulationStatistics;
-import simulator.stats.implementation.out.AbstractStringSerializer;
 import simulator.stats.implementation.out.CoolEmAllStringSerializer;
 import simulator.stats.implementation.out.StringSerializer;
@@ -110,8 +114,9 @@
 	protected static final int MILLI_SEC = 1000;
 
-	protected static final String RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME = "Tasks.txt";
+	protected static final String TASKS_STATISTICS_OUTPUT_FILE_NAME = "Tasks.txt";
 	protected static final String JOBS_STATISTICS_OUTPUT_FILE_NAME = "Jobs.txt";
 
 	protected static final String SIMULATION_STATISTICS_OUTPUT_FILE_NAME = "Simulation.txt";
+	protected static final String RESOURCEOCCUPANCY_STATISTICS_OUTPUT_FILE_NAME = "ResourceOccupancy.txt";
 	protected static final String RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME = "ResourceUtilization.txt";
 	protected static final String ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME = "EnergyUsage.txt";
@@ -141,10 +146,10 @@
 	protected SimulatedEnvironment resourceController;
 	protected boolean generateDiagrams = true;
-	protected AbstractStringSerializer serializer;
+	protected StringSerializer serializer;
 	protected long startSimulationTime;
 	protected long endSimulationTime;
 	
 	//RESOURCES
-	protected Map<String, List<ResStat>> basicResStats;
+	protected Map<String, List<ResStat>> pesStats;
 	protected Map<String, Double> basicResLoad;
 	
@@ -156,5 +161,6 @@
 	protected Map<String, List<XYDataset>> resourceAirFlowDiagrams;
 	protected Map<String, List<XYDataset>> resourceTemperatureDiagrams;
-	protected Map<String, List<XYDataset>> resourceLoadDiagrams;
+	protected Map<String, List<XYDataset>> resourceOccupancyDiagrams;
+	protected Map<String, List<XYDataset>> resourceUtilizationDiagrams;
 	
 	//TASKS
@@ -178,28 +184,18 @@
 
 		this.outputFolderName = outputFolderName;
-
-		this.serializer = new StringSerializer();
-		
-		if(DataCenterWorkloadSimulator.MODE.equals("CoolEmAll")){
-			this.serializer = new CoolEmAllStringSerializer();	
-		}
-		this.serializer.setDefaultNumberFormat(DataCenterWorkloadSimulator.DFAULT_NUMBER_FORMAT);
-
 		this.resourceController = resourceController;
 		this.jr = new JobRegistryImpl("");
-		init();
-		metCalc = new MetricsCalculator();
-	}
-
-	public void generateStatistics() {
-
+		
 		if(users.isSimStartTimeDefined())
 			this.startSimulationTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis();
 		else
 			this.startSimulationTime = new DateTime(users.getSubmissionStartTime() * 1000l).getMillis();
+		
 		this.endSimulationTime = DateTimeUtilsExt.currentTimeMillis();
 
-		metCalc.setStartTime(startSimulationTime);
-		metCalc.setEndTime(endSimulationTime);
+		init();
+	}
+
+	public void generateStatistics() {
 		
 		long s = 0;
@@ -234,4 +230,13 @@
 		accStats = new GSSAccumulatorsStats();
 		statsData = new HashMap<String, GSSAccumulator>();
+		
+		this.serializer = new StringSerializer();		
+		this.metCalc =  new DCwormsMetricsCalculator(startSimulationTime, endSimulationTime, endSimulationTime);
+		
+		if(DataCenterWorkloadSimulator.MODE.equals("CoolEmAll")){
+			this.serializer = new CoolEmAllStringSerializer();
+			this.metCalc = new CoolEmAllMetricsCalculator(startSimulationTime, endSimulationTime, endSimulationTime);
+		}
+		this.serializer.setDefaultNumberFormat(DataCenterWorkloadSimulator.DFAULT_NUMBER_FORMAT);
 	}
 
@@ -262,7 +267,9 @@
 			System.out.println("#STATS " + "===== Performance statistics =====");
 			System.out.println("#STATS " + "Makespan: " + df.format(accStats.makespan.getMean()) + " [s]");
-			System.out.println("#STATS " + "Task completion time - " + "min: " + df.format(accStats.meanTaskCompletionTime.getMin()) + " [s]" + "; max: " + df.format(accStats.meanTaskCompletionTime.getMax()) + " [s]");
+			System.out.println("#STATS " + "Task completion time - " + "min: " + df.format(accStats.meanTaskCompletionTime.getMin()) + " [s]" + "; max: " + df.format(accStats.meanTaskCompletionTime.getMax()) + " [s]" + "; mean: " + df.format(accStats.meanTaskCompletionTime.getMean()) + " [s]");
 			System.out.println("#STATS " + "Mean task execution time: " + df.format(accStats.meanTaskExecutionTime.getMean()) + " [s]");
+			System.out.println("#STATS " + "System occupancy: " + df.format(accStats.meanTotalOccupancy.getMean() * 100) + " [%]");
 			System.out.println("#STATS " + "System load: " + df.format(accStats.meanTotalLoad.getMean() * 100) + " [%]");
+			
 			
 			simulationStatsFile.println(txt);
@@ -300,5 +307,6 @@
 		taskGanttMap = new HashMap<String, TimetableEventGroup>();		
 		
-		resourceLoadDiagrams = new HashMap<String, List<XYDataset>>();
+		resourceOccupancyDiagrams = new HashMap<String, List<XYDataset>>();
+		resourceUtilizationDiagrams = new HashMap<String, List<XYDataset>>();
 		resourcePowerUsageDiagrams = new HashMap<String, List<XYDataset>>();
 		resourceAirFlowDiagrams = new HashMap<String, List<XYDataset>>();
@@ -309,12 +317,22 @@
 		
 		
-		PrintStream resourceLoadStatsFile = null;
+		PrintStream resourceOccupancyStatsFile = null;
+		try {
+			File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX
+					+ simulationIdentifier + "_"
+					+ RESOURCEOCCUPANCY_STATISTICS_OUTPUT_FILE_NAME);
+			resourceOccupancyStatsFile = new PrintStream(new FileOutputStream(file));
+		} catch (IOException e) {
+			resourceOccupancyStatsFile = null;
+		}
+		
+		PrintStream resourceUtilizationStatsFile = null;
 		try {
 			File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX
 					+ simulationIdentifier + "_"
 					+ RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME);
-			resourceLoadStatsFile = new PrintStream(new FileOutputStream(file));
+			resourceUtilizationStatsFile = new PrintStream(new FileOutputStream(file));
 		} catch (IOException e) {
-			resourceLoadStatsFile = null;
+			resourceUtilizationStatsFile = null;
 		}
 		
@@ -389,10 +407,10 @@
 		}
 		
-		basicResStats = gatherPEStats(jr.getTasks());
-		peStatsPostProcessing(basicResStats);
-		basicResLoad = calculatePELoad( basicResStats);
+		pesStats = gatherPEStats(jr.getTasks());
+		peStatsPostProcessing(pesStats);
+		basicResLoad = calculatePELoad(pesStats);
 
 		if (configuration.creatediagrams_gantt) {
-			createPEGanttDiagram(basicResStats);
+			createPEGanttDiagram(pesStats);
 		}
 		
@@ -412,5 +430,6 @@
 				
 				for(ComputingResource compResource: compResources){
-					ResourceUsageStats resourceUsage = null;
+					ResourceUsageStats resourceUtilization = null;					
+					ResourceUsageStats resourceOccupancy = null;
 					ResourcePowerStats energyUsage = null;
 					ResourceAirFlowStats airFlow = null;
@@ -418,15 +437,22 @@
 					ResourceUsefulWorkStats usefulWork = null;
 					if(type_stats.get(resourceTypeName).contains(Stats.textLoad)){
-						resourceUsage = gatherResourceLoadStats(compResource, basicResStats);
-						resourceUsage.setMeanValue(calculateMeanValue(resourceUsage));
-						if (resourceLoadStatsFile != null) {
-							Object txt = resourceUsage.serialize(serializer);
-							resourceLoadStatsFile.print(txt);
+						resourceOccupancy = gatherResourceOccupancyStats(compResource, pesStats);
+						resourceOccupancy.setMeanValue(calculateMeanValue(resourceOccupancy));
+						if (resourceOccupancyStatsFile != null) {
+							Object txt = resourceOccupancy.serialize(serializer);
+							resourceOccupancyStatsFile.print(txt);
 						}
-
+						
+						resourceUtilization = gatherResourceUtlizationStats(compResource);
+						resourceUtilization.setMeanValue(calculateMeanValue(resourceUtilization));
+						if (resourceUtilizationStatsFile != null) {
+							Object txt = resourceUtilization.serialize(serializer);
+							resourceUtilizationStatsFile.print(txt);
+						}
 					}
 					if(type_stats.get(resourceTypeName).contains(Stats.chartLoad)){
 						if (configuration.creatediagrams_resutilization) {
-							createResourceLoadDiagram(resourceUsage);
+							createResourceOccupancyDiagram(resourceOccupancy);
+							createResourceUtilizationDiagram(resourceUtilization);
 						}
 					}
@@ -437,41 +463,34 @@
 						resourceEnergyAccumulator.add(energyUsage.getSumValue());
 						maxResourceEnergyAccumulator.add(calculateMaxValue(energyUsage));
-						double calulcationsEnergy = 0;
+						double calculationsEnergy = 0;
 						try {
-							/*boolean doCalc = false;
-							double prevTimestamp = 0;
-							for(Long key: resourceUsage.getHistory().keySet()){
-								if(doCalc){
-									System.out.println(energyUsage.getHistory().get(key));
-									calulcationsEnergy = calulcationsEnergy + energyUsage.getHistory().get(prevTimestamp) * (key - prevTimestamp) /(3600 * MILLI_SEC);
-									doCalc  = false;
-								}
-								if(resourceUsage.getHistory().get(key)>0){
-									prevTimestamp = key;
-									doCalc = true;
-								}
-							}*/
 							boolean doCalc = false;
+							double load = 0;
 							long prevTimestamp = 0;
 							for(Long key: energyUsage.getHistory().keySet()){
 								if(doCalc){
-									double load = 0;
-									if(resourceUsage.getHistory().get(prevTimestamp)!= null){
-										load = resourceUsage.getHistory().get(prevTimestamp);
+									if(resourceTypeName.equals("Rack")){
+										calculationsEnergy = calculationsEnergy + CoolEmAllTestbedMeasurements.OTHER_DEVICES_POWER_CONSUMPTION * (key - prevTimestamp) /(3600.0 * MILLI_SEC);
+									}/* else if(resourceTypeName.equals("Processor")){
+										Processor proc =( Processor) compResource;
+										double maxPower = proc.getPowerInterface().getLowestPState().getLoadPowerUsage().get(100.0);
+										calculationsEnergy = calculationsEnergy + load * maxPower * (key - prevTimestamp) /(3600.0 * MILLI_SEC);
+									}*/
+									else 
+										calculationsEnergy = calculationsEnergy + load * energyUsage.getHistory().get(prevTimestamp) * (key - prevTimestamp) /(3600.0 * MILLI_SEC);
+									doCalc = false;
+									load = 0;
+								}
+								
+								if(resourceUtilization.getHistory().get(key) != null){
+									load = resourceUtilization.getHistory().get(key);
+									if(load > 0 ){
+										doCalc = true;
+										prevTimestamp = key;
 									}
-									calulcationsEnergy = calulcationsEnergy + load * energyUsage.getHistory().get(prevTimestamp) * (key - prevTimestamp) /(3600.0 * MILLI_SEC);
-									doCalc = false;
-								}
-								if(energyUsage.getHistory().get(key) > compResource.getPowerInterface().getSupportedPowerStates().get(0).getPowerUsage() - CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_POWER_CONSUMPTION){
-									
-									prevTimestamp = key;
-									doCalc = true;
 								}
 							}
-							//calulcationsEnergy = energyUsage.getSumValue() - 
-							//	((1 - resourceUsage.getMeanValue()) * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)) * 
-							//	(compResource.getPowerInterface().getSupportedPowerStates().get(0).getPowerUsage() - CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_POWER_CONSUMPTION);
-							//System.out.println(compResource.getFullName() + ";" + resourceUsage.getMeanValue() +":"+ calulcationsEnergy  + ":" + energyUsage.getSumValue());
-							calculationsEnergyAccumulator.add(calulcationsEnergy);
+
+							calculationsEnergyAccumulator.add(calculationsEnergy);
 						} catch (Exception e) {
 							e.printStackTrace();
@@ -510,4 +529,5 @@
 							devAccumulator.add(deviceEnergyUsage.getSumValue());
 							metCalc.addMetricsData(device.getType().getName(), devAccumulator);
+							metCalc.addMetricsData(device.getFullName(), devAccumulator);
 							if (deviceStatsFile != null) {
 								Object txt = deviceEnergyUsage.serialize(serializer);
@@ -666,5 +686,5 @@
 			//log.info("#STATS " + "Metrics");
 			System.out.println("#STATS " + "===== Metrics =====");
-			for(MetricsStats metric: metCalc.calulateMetrics(endSimulationTime)){
+			for(MetricsStats metric: metCalc.calulateMetrics()){
 				Object txt = metric.serialize(serializer);
 				//log.info("#STATS " +  metric.getResourceName() + " " + metric.getMetricName() + ": " + metric.getValue());
@@ -676,5 +696,5 @@
 			}
 		}
-		saveResourceUsageDiagrams();
+		saveResourceDiagrams();
 		createAccumulatedResourceSimulationStatistic();
 		
@@ -688,6 +708,9 @@
 			energyStatsFile.close();
 		}
-		if (resourceLoadStatsFile != null) {
-			resourceLoadStatsFile.close();
+		if (resourceOccupancyStatsFile != null) {
+			resourceOccupancyStatsFile.close();
+		}
+		if (resourceUtilizationStatsFile != null) {
+			resourceUtilizationStatsFile.close();
 		}
 		
@@ -813,5 +836,5 @@
 	
 	
-	private ResourceUsageStats gatherResourceLoadStats(ComputingResource resource, Map<String, List<ResStat>> basicStats) {
+	private ResourceUsageStats gatherResourceOccupancyStats(ComputingResource resource, Map<String, List<ResStat>> basicStats) {
 		String usageType = null;
 		if(resource.getResourceCharacteristic().getParameters().get("load-sensor")!= null){
@@ -844,5 +867,5 @@
 		int usedResources = 0;
 		for(ComputingResource compResource: resource.getChildren()){
-			double meanLoad = calculateMeanValue(gatherResourceLoadStats(compResource, basicResStats));
+			double meanLoad = calculateMeanValue(gatherResourceOccupancyStats(compResource, pesStats));
 			if(meanLoad > 0){
 				usedResources++;
@@ -916,4 +939,34 @@
 	}
 	
+	private ResourceUsageStats gatherResourceUtlizationStats(PhysicalResource resource) {
+		
+		String usageType = null;
+		if(resource.getResourceCharacteristic().getParameters().get("load-sensor")!= null){
+			usageType = resource.getResourceCharacteristic().getParameters().get("load-sensor").get(0).getContent();
+		}
+		ResourceUsageStats resUtlization = new ResourceUsageStats(resource.getFullName(), resource.getType(), usageType);
+		Map<Long, Double> usage = resUtlization.getHistory();
+		
+		ExtensionList extensionList = resource.getExtensionList();
+		if(extensionList != null){
+			for (Extension extension : extensionList) {
+				if (extension.getType() == ExtensionType.LOAD_EXTENSION) {
+					LoadExtension le = (LoadExtension)extension;
+					if(le.getLoadProfile() == null)
+						break;
+					List<MeasurementHistory> loadHistory = le.getLoadProfile().getUtilizationHistory();
+					if(loadHistory.size() == 0)
+						break;
+					long endSimulationTime = DateTimeUtilsExt.currentTimeMillis();
+
+					loadHistory.add(new MeasurementHistory(endSimulationTime, le.getLoadProfile().getUtilizationHistory().get(le.getLoadProfile().getUtilizationHistory().size() - 1).getValue()/100));
+					for(MeasurementHistory l:loadHistory){
+						usage.put(l.getTimestamp(), l.getValue()/100);
+					}
+				}
+			}
+		}
+		return resUtlization;
+	}
 	
 	private ResourcePowerStats gatherResourcePowerConsumptionStats(PhysicalResource resource) {
@@ -921,5 +974,5 @@
 		
 		String usageType = null;
-		if(resource.getResourceCharacteristic().getParameters().get("power-sensor")!= null){
+		if(resource.getResourceCharacteristic().getParameters().get("power-sensor") != null){
 			usageType = resource.getResourceCharacteristic().getParameters().get("power-sensor").get(0).getContent();
 		}
@@ -954,9 +1007,8 @@
 	}
 	
-	
 	private ResourceAirFlowStats gatherResourceAirFlowStats(PhysicalResource resource) {
 
 		String usageType = null;
-		if(resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor")!= null){
+		if(resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor") != null){
 			usageType = resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor").get(0).getContent();
 		}
@@ -1016,5 +1068,5 @@
 	}
 	
-	private void createResourceLoadDiagram(ResourceUsageStats resLoadStats) {
+	private void createResourceOccupancyDiagram(ResourceUsageStats resLoadStats) {
 
 		for(Long key: resLoadStats.getHistory().keySet()){
@@ -1026,11 +1078,31 @@
 				startSimulationTime, endSimulationTime);
 
-		List<XYDataset> loadDiagram = resourceLoadDiagrams.get(resLoadStats.getResourceType().getName());
-		if(loadDiagram == null){
-			loadDiagram = new ArrayList<XYDataset>();
-			loadDiagram.add(dataset);
-			resourceLoadDiagrams.put(resLoadStats.getResourceType().getName(), loadDiagram);
+		List<XYDataset> occupancyDiagram = resourceOccupancyDiagrams.get(resLoadStats.getResourceType().getName());
+		if(occupancyDiagram == null){
+			occupancyDiagram = new ArrayList<XYDataset>();
+			occupancyDiagram.add(dataset);
+			resourceOccupancyDiagrams.put(resLoadStats.getResourceType().getName(), occupancyDiagram);
 		} else {
-			loadDiagram.add(dataset);
+			occupancyDiagram.add(dataset);
+		}
+	}
+	
+	private void createResourceUtilizationDiagram(ResourceUsageStats resLoadStats) {
+
+		for(Long key: resLoadStats.getHistory().keySet()){
+			Double value = resLoadStats.getHistory().get(key) * 100;
+			resLoadStats.getHistory().put(key, value);
+		}
+		
+		XYDataset dataset = createResourceChartDataSet(resLoadStats,
+				startSimulationTime, endSimulationTime);
+
+		List<XYDataset> utilizationDiagram = resourceUtilizationDiagrams.get(resLoadStats.getResourceType().getName());
+		if(utilizationDiagram == null){
+			utilizationDiagram = new ArrayList<XYDataset>();
+			utilizationDiagram.add(dataset);
+			resourceUtilizationDiagrams.put(resLoadStats.getResourceType().getName(), utilizationDiagram);
+		} else {
+			utilizationDiagram.add(dataset);
 		}
 	}
@@ -1109,5 +1181,5 @@
 	}
 
-	private boolean saveResourceUsageDiagrams() {
+	private boolean saveResourceDiagrams() {
 
 		if (!generateDiagrams)
@@ -1133,11 +1205,24 @@
 		chartName = "Load diagram for "
 			+ DataCenterWorkloadSimulator.SIMULATOR_NAME;
-		JFreeChart resourceLoadDiagram = null;
+		JFreeChart resourceOccupancyDiagram = null;
+		if (configuration.creatediagrams_resutilization) {
+			String axisName = "OCCUPANCY [%]";
+			for(String resType: resourceOccupancyDiagrams.keySet()){
+				resourceOccupancyDiagram = getResourceDynamicDiagram(resourceOccupancyDiagrams.get(resType), simulationTime, chartName,
+						subtitle, axisName);
+				if (!saveXYPlotChart(resourceOccupancyDiagram, fileName + "ResourcesOccupancy_" + resType))
+					return false;
+			}
+		}
+		
+		chartName = "Utilization diagram for "
+			+ DataCenterWorkloadSimulator.SIMULATOR_NAME;
+		JFreeChart resourceUtilizationDiagram = null;
 		if (configuration.creatediagrams_resutilization) {
 			String axisName = "UTILIZATION [%]";
-			for(String resType: resourceLoadDiagrams.keySet()){
-				resourceLoadDiagram = getResourceDynamicDiagram(resourceLoadDiagrams.get(resType), simulationTime, chartName,
+			for(String resType: resourceUtilizationDiagrams.keySet()){
+				resourceUtilizationDiagram = getResourceDynamicDiagram(resourceUtilizationDiagrams.get(resType), simulationTime, chartName,
 						subtitle, axisName);
-				if (!saveXYPlotChart(resourceLoadDiagram, fileName + "ResourcesLoad_" + resType))
+				if (!saveXYPlotChart(resourceUtilizationDiagram, fileName + "ResourcesUtilization_" + resType))
 					return false;
 			}
@@ -1322,5 +1407,8 @@
 				//double load = calculateMeanValue(resourceUsage);
 				double load = calculateResourceLoad(compRes, basicResLoad);
-				accStats.meanTotalLoad.add(load);
+				accStats.meanTotalOccupancy.add(load);
+
+				ResourceUsageStats resourceUtilization = gatherResourceUtlizationStats(compRes);
+				accStats.meanTotalLoad.add(calculateMeanValue(resourceUtilization));
 				/*ResourceEnergyStats energyUsage = gatherResourceEnergyStats(compRes);
 				energyUsage.setMeanUsage(calculateEnergyLoad(energyUsage));
@@ -1365,5 +1453,5 @@
 
 	
-	private double calculateMeanValue(ResourceDynamicStats resDynamicStats ){
+	private double calculateMeanValue(ResourceDynamicStats resDynamicStats){
 		double meanValue = 0;
 		long time = -1;
@@ -1387,5 +1475,5 @@
 	
 	
-	private double calculateMaxValue(ResourceDynamicStats resDynamicStats ){
+	private double calculateMaxValue(ResourceDynamicStats resDynamicStats){
 		double maxValue = 0;
 
@@ -1414,5 +1502,5 @@
 		try {
 			File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_"
-					+ RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME);
+					+ TASKS_STATISTICS_OUTPUT_FILE_NAME);
 			taskStatsFile = new PrintStream(new FileOutputStream(file));
 		} catch (IOException e) {
@@ -1634,5 +1722,5 @@
 		chartName = "Task waiting times diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME;
 		if (configuration.creatediagrams_taskswaitingtime) {
-			waitingTimeDiagram = getWaitingTimeDiagram(chartName, subtitle, simulationTime);
+			waitingTimeDiagram = getTaskWaitingTimeDiagram(chartName, subtitle, simulationTime);
 			if (!saveCategoryChart(waitingTimeDiagram, fileName + "Waiting_Time", null /* "Task {1} at {0}" */))
 				return false;
@@ -1655,5 +1743,5 @@
 	}
 
-	private JFreeChart getWaitingTimeDiagram(String chartName, Title subtitle, String simulationTime) {
+	private JFreeChart getTaskWaitingTimeDiagram(String chartName, Title subtitle, String simulationTime) {
 		String tasks = "Tasks";
 		boolean urls = false;
@@ -1878,4 +1966,4 @@
 	textTemperature,
 	chartTemperature,
-	textUsefulWorl;
+	textUsefulWork;
 }
Index: DCWoRMS/branches/coolemall/src/simulator/stats/CoolEmAllMetricsCalculator.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/stats/CoolEmAllMetricsCalculator.java	(revision 1299)
+++ DCWoRMS/branches/coolemall/src/simulator/stats/CoolEmAllMetricsCalculator.java	(revision 1299)
@@ -0,0 +1,426 @@
+package simulator.stats;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import simulator.stats.implementation.MetricsStats;
+import example.energy.coolemall.CoolEmAllTestbedMeasurements;
+
+public class CoolEmAllMetricsCalculator extends AbstractMetricsCalculator{
+	
+	public CoolEmAllMetricsCalculator (long startTime, long endTime, long timestamp){
+		super(startTime, endTime, timestamp);
+	}
+	
+	public List<MetricsStats> calulateMetrics(){
+		List<MetricsStats> metrics = new ArrayList<MetricsStats>();
+		/*for(String resourceTypeName: metricsData.keySet()){
+			MetricsStats metric = new MetricsStats(resourceTypeName, "energyUsage", metricsData.get(resourceTypeName).getMax());
+			metrics.add(metric);}
+		}*/
+		metrics.add(calculateITComputingEnergyConsumption());
+		metrics.add(calculateITEnergyConsumption());
+		metrics.add(calculateNodeGroupFansEnergyConsumption());
+		
+		metrics.add(calculateRackEnergyConsumption());
+		metrics.add(calculateDataCenterFansEnergyConsumption());
+		metrics.add(calculateCoolingDeviceEnergyConsumption());
+		metrics.add(calculateOtherDevicesEnergyConsumption());
+		
+		metrics.add(calculateTotalEnergyConsumption());
+		
+		metrics.add(calculateMeanRackPower());
+		metrics.add(calculateMeanPower());
+		metrics.add(calculateMaxRackPower());
+		metrics.add(calculateMaxPower());
+		
+		metrics.add(calculatePUE());
+		metrics.add(calculatePUELevel4());
+		metrics.add(calculateEnergyWasteRate());
+		
+		metrics.add(calculateUsefulWork());
+		metrics.add(calculateProductivity());
+
+		return metrics;
+	}
+
+	private MetricsStats calculateTotalEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Room")){
+				roomPower = roomPower + acc.getSum();
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_energy_consumption", roomPower, timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateITComputingEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double itComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor")){
+				itComputingPower = itComputingPower + acc.getSum();
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_processors_energy_consumption", (itComputingPower), timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_processors_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateITEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double totalSitePower = 0; 
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				totalSitePower = totalSitePower + acc.getSum();
+			}
+			double nodeComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Node")){
+				nodeComputingPower = nodeComputingPower+ acc.getSum();
+			}
+			double itComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor")){
+				itComputingPower = itComputingPower + acc.getSum();
+			}
+			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_IT_energy_consumption", (totalSitePower * CoolEmAllTestbedMeasurements.POWER_SUPPLY_EFFICIENCY - nodeGroupFansPowerConumspion), timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_IT_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateNodeGroupFansEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double nodeComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Node")){
+				nodeComputingPower = nodeComputingPower+ acc.getSum();
+			}
+			double itComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor")){
+				itComputingPower = itComputingPower + acc.getSum();
+			}
+			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_node_group_fans_energy_consumption", nodeGroupFansPowerConumspion, timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_node_group_fans_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculatePUELevel4(){
+		
+		MetricsStats metric;
+		try{
+			
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Room")){
+				roomPower = roomPower + acc.getSum();
+			}
+			
+			double totalSitePower = 0;
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				totalSitePower = totalSitePower + acc.getSum();
+			}
+			
+		
+			double nodeComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Node")){
+				nodeComputingPower = nodeComputingPower+ acc.getSum();
+			}
+			double itComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor")){
+				itComputingPower = itComputingPower + acc.getSum();
+			}
+			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
+
+			metric = new MetricsStats("CoolEmAllTestbed", "PUE_Level_4", roomPower/(totalSitePower * CoolEmAllTestbedMeasurements.POWER_SUPPLY_EFFICIENCY - nodeGroupFansPowerConumspion), timestamp, "");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "PUE_Level_4", -1, timestamp, "");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculatePUE(){
+		
+		MetricsStats metric;
+		try{
+			
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Room")){
+				roomPower = roomPower + acc.getSum();
+			}
+			
+			double totalSitePower = 0;
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				totalSitePower = totalSitePower + acc.getSum();
+			}
+
+
+			metric = new MetricsStats("CoolEmAllTestbed", "PUE", roomPower/totalSitePower, timestamp, "");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "PUE", -1, timestamp, "");
+		}
+		return metric;
+	}
+
+	private MetricsStats calculateUsefulWork(){
+		
+		MetricsStats metric;
+		try{
+			double usefulWork = 0;
+			for(String key: metricsData.keySet()){
+				if(key.contains("/")){
+					for(GSSAccumulator acc: metricsData.get(key)){
+						usefulWork= usefulWork + acc.getSum();
+					}
+				}
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Useful_Work", usefulWork, timestamp, "UW units");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Useful_Work", -1, timestamp, "UW units");
+		}
+		
+		return metric;
+	}
+	
+	private MetricsStats calculateProductivity(){
+		
+		MetricsStats metric;
+		try{
+			double usefulWork = 0;
+			for(String key: metricsData.keySet()){
+				if(key.contains("/")){
+					for(GSSAccumulator acc: metricsData.get(key)){
+						usefulWork= usefulWork + acc.getSum();
+					}
+				}
+			}
+			double totalSitePower = 0; 
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				totalSitePower = totalSitePower + acc.getSum();
+			}
+			
+			metric = new MetricsStats("CoolEmAllTestbed", "Productivity", usefulWork/totalSitePower, timestamp, "UW units/Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Productivity", -1, timestamp, "UW units/Wh");
+		}
+		
+		return metric;
+	}
+	
+	
+	private MetricsStats calculateMaxRackPower(){
+		
+		MetricsStats metric;
+		try{
+			double maxPower = 0;
+			
+			for(GSSAccumulator acc: metricsData.get("Rack_MAX")){
+				maxPower = maxPower + acc.getSum();
+			}
+
+			metric = new MetricsStats("CoolEmAllTestbed", "Max_rack_power", maxPower, timestamp, "W");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Max_rack_power", -1, timestamp, "W");
+		}
+		
+		return metric;
+	}
+	
+	private MetricsStats calculateMaxPower(){
+		
+		MetricsStats metric;
+		try{
+			double maxPower = 0;
+			
+			for(GSSAccumulator acc: metricsData.get("Room_MAX")){
+				maxPower = maxPower + acc.getSum();
+			}
+
+			metric = new MetricsStats("CoolEmAllTestbed", "Max_power", maxPower, timestamp, "W");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Max_power", -1, timestamp, "W");
+		}
+		
+		return metric;
+	}
+	
+	private MetricsStats calculateDataCenterFansEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double inletsPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Inlet")){
+				inletsPower = inletsPower + acc.getSum();
+			}
+			
+			double outletsPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Outlet")){
+				outletsPower = outletsPower + acc.getSum();
+			}
+			
+			double nodeComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Node")){
+				nodeComputingPower = nodeComputingPower+ acc.getSum();
+			}
+			double itComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor")){
+				itComputingPower = itComputingPower + acc.getSum();
+			}
+			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
+			
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_data_center_fans_energy_consumption", (inletsPower + outletsPower - nodeGroupFansPowerConumspion), timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_data_center_fans_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateRackEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				roomPower = roomPower + acc.getSum();
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_rack_energy_consumption", roomPower, timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_rack_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateCoolingDeviceEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double coolingDevicePower = 0;
+			for(GSSAccumulator acc: metricsData.get("CoolingDevice")){
+				coolingDevicePower = coolingDevicePower + acc.getSum();
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_cooling_device_energy_consumption", coolingDevicePower, timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_cooling_device_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateOtherDevicesEnergyConsumption(){
+		
+		MetricsStats metric;
+		try{
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Room")){
+				roomPower = roomPower + acc.getSum();
+			}
+			
+			double totalSitePower = 0;
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				totalSitePower = totalSitePower + acc.getSum();
+			}
+			
+			double coolingDevicePower = 0;
+			for(GSSAccumulator acc: metricsData.get("CoolingDevice")){
+				coolingDevicePower = coolingDevicePower + acc.getSum();
+			}
+			
+			double inletsPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Inlet")){
+				inletsPower = inletsPower + acc.getSum();
+			}
+			
+			double outletsPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Outlet")){
+				outletsPower = outletsPower + acc.getSum();
+			}
+			
+			double nodeComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Node")){
+				nodeComputingPower = nodeComputingPower+ acc.getSum();
+			}
+			double itComputingPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor")){
+				itComputingPower = itComputingPower + acc.getSum();
+			}
+			double nodeGroupFansPowerConumspion = nodeComputingPower - itComputingPower;
+
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_other_devices_energy_consumption", roomPower - (totalSitePower + coolingDevicePower + (inletsPower + outletsPower - nodeGroupFansPowerConumspion)), timestamp, "Wh");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Total_other_devices_energy_consumption", -1, timestamp, "Wh");
+		}
+		return metric;
+	}
+
+	
+	private MetricsStats calculateMeanPower(){
+		
+		MetricsStats metric;
+		try{
+			
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Room")){
+				roomPower = roomPower + acc.getSum();
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Mean_power", roomPower/((this.endTime - this.startTime)/(SEC_IN_HOUR * MILLI_SEC)), timestamp, "W");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Mean_power", -1, timestamp, "W");
+		}
+		return metric;
+	}
+	
+	
+	private MetricsStats calculateMeanRackPower(){
+		
+		MetricsStats metric;
+		try{
+			
+			double roomPower = 0;
+			for(GSSAccumulator acc: metricsData.get("Rack")){
+				roomPower = roomPower + acc.getSum();
+			}
+			metric = new MetricsStats("CoolEmAllTestbed", "Mean_rack_power", roomPower/((this.endTime - this.startTime)/(SEC_IN_HOUR * MILLI_SEC)), timestamp, "W");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Mean_rack_power", -1, timestamp, "W");
+		}
+		return metric;
+	}
+	
+	private MetricsStats calculateEnergyWasteRate(){
+		
+		MetricsStats metric;
+		try{
+			double itComputingEnergy = 0;
+			double otherItComputingEnergy = 0;
+			for(GSSAccumulator acc: metricsData.get("Processor_CALC")){
+				itComputingEnergy = itComputingEnergy + acc.getSum();
+			}
+			for(GSSAccumulator acc: metricsData.get("Rack_CALC")){
+				otherItComputingEnergy = otherItComputingEnergy + acc.getSum();
+			}
+			itComputingEnergy = itComputingEnergy ;//+ otherItComputingEnergy;// + CoolEmAllTestbedMeasurements.OTHER_DEVICES_POWER_CONSUMPTION * (this.endTime - this.startTime)/(SEC_IN_HOUR * MILLI_SEC);
+
+			double itEnergy = calculateITEnergyConsumption().getValue();
+			double processorsEnergy = calculateITComputingEnergyConsumption().getValue();
+
+			metric = new MetricsStats("CoolEmAllTestbed", "Energy_waste_rate", (1 - itComputingEnergy/itEnergy) * 100, timestamp, "%");
+		} catch (Exception e){
+			metric = new MetricsStats("CoolEmAllTestbed", "Energy_waste_rate", -1, timestamp, "%");
+		}
+		
+		return metric;
+	}
+	
+}
Index: DCWoRMS/branches/coolemall/src/simulator/DCWormsUsers.java
===================================================================
--- DCWoRMS/branches/coolemall/src/simulator/DCWormsUsers.java	(revision 1207)
+++ DCWoRMS/branches/coolemall/src/simulator/DCWormsUsers.java	(revision 1299)
@@ -74,5 +74,5 @@
 		sendJobsIds = new HashSet<String>();
 		returnedJobsIds = new HashSet<String>();
-		
+		returnedJobs = new ArrayList<JobInterface<?>>();
 		this.xsltTransformer = new XsltTransformations();
 	}
@@ -80,6 +80,10 @@
 	@Override
 	public void body() {
-		sendJobs();
-		collectJobs();
+		if(workloadLoader != null){
+			sendJobs();
+			collectJobs();	
+		} else {
+			submissionStartTime = 0;
+		}
 
 		//GridSim dependent code for shutting down the simulation
@@ -93,8 +97,7 @@
 	 */
 	protected void collectJobs() {
-		final int FACTOR = Math.min(10, workloadLoader.getTaskCount()); //the refresh rate of the gauge: at most 10 times
+		final int FACTOR = Math.min(100, workloadLoader.getTaskCount() > 0 ? workloadLoader.getTaskCount() : 1); //the refresh rate of the gauge: at most 10 times
 		final int denominator = workloadLoader.getTaskCount() / FACTOR;
 		allTasksAreFinished = true;
-		returnedJobs = new ArrayList<JobInterface<?>>();
 		int counter = 0;
 		int oldRemeinder = 0;
@@ -244,4 +247,6 @@
 	
 	public List<JobDescription> getAllSentJobs() {
+		if (workloadLoader == null)
+			return new ArrayList<JobDescription>();
 		return (List<JobDescription>) workloadLoader.getJobs();
 	}
@@ -349,4 +354,7 @@
 	
 	public boolean isSimStartTimeDefined(){
+		if(workloadLoader == null){
+			return false;
+		}
 		return workloadLoader.isSimStartTimeDefined();
 	}
