@Override
	public void addKPIs(String inst_id, double maxPower, double avgPower, double energy, double cost, double co2) {
		boolean first = false;
		
		String tableName;
		String tick_tableName;
		String id;
		
		if(inst_id.equalsIgnoreCase(AGGR)) {
			id = AGGR;
			tableName = COL_AGGRKPIS;
			tick_tableName = COL_AGGRRESULTS;
		} else {
			id = inst_id;
			tableName = COL_INSTKPIS;
			tick_tableName = COL_INSTRESULTS;
		}
				
		double[] data = getKPIData(tableName, "inst_id", id);
		
		double newMaxPower = maxPower;
		double newAvgPower = avgPower;
		double newEnergy = energy;
		double newCost = cost;
		double newCo2 = co2;
		if(data == null) 
			first = true;
		else {
			newMaxPower += data[0];
			newAvgPower += data[1];
			newEnergy += data[2];
			newCost +=data[3];
			newCo2 += data[4];
		}
		
		double maxavgValue = newAvgPower;
		
		String maxQuery = "SELECT MAX(P) AS maxp FROM " + tick_tableName;
		if(!inst_id.equalsIgnoreCase(AGGR))
			maxQuery += " WHERE inst_id='" + inst_id +"'";
		ResultSet maxavg = executeSelectQuery(maxQuery);
		if(maxavg != null)
			try {
				while (maxavg.next())
					maxavgValue = maxavg.getDouble("maxp");
			} catch (SQLException e) {
				System.out.println(" . . . exception thrown:");
				errorPrint(e);
			}
		
		String psQuery = "";
		if(first) 
			psQuery = "insert into " + tableName + " values('" + id + "'," + maxavgValue + ", " + newMaxPower + ", " + newAvgPower + ", " + newEnergy + ", " + newCost + ", " + newCo2+ ")";
		else 
			psQuery = "update " + tableName + " set AVGPEAK=" + maxavgValue +", MAXPOWER=" + newMaxPower + ", AVGPOWER=" + newAvgPower 
					+ ", ENERGY=" + newEnergy + ", COST=" + newCost + ", CO2=" + newCo2 + " where inst_id='" + id + "'";
		executeUpdateQuery(psQuery);
	
	}