package clustering.kmeans;

public class Centroid {
	static final int MINUTES_OF_A_DAY = 60*24;
	private double[] mBatteryLevel;

	private Cluster mCluster;

	public Centroid(double[] mBatteryLevel) {
		this.mBatteryLevel = mBatteryLevel;
	}

	public void calcCentroid() { // only called by CAInstance
		int numDP = mCluster.getNumDataPoints();
		double[] tempBatteryLevel = new double[MINUTES_OF_A_DAY];
		for (int m = 0; m < MINUTES_OF_A_DAY; m++) {
			tempBatteryLevel[m] = 0;
		}
		int i;
		// calculating the new Centroid
		for (i = 0; i < numDP; i++) {
			// total for battery level
			for (int m = 0; m < MINUTES_OF_A_DAY; m++) {
				tempBatteryLevel[m] = tempBatteryLevel[m]
						+ mCluster.getDataPoint(i).getBatteryLevel()[m];
			}

		}
		for (int m = 0; m < MINUTES_OF_A_DAY; m++) {
			this.mBatteryLevel[m] = tempBatteryLevel[m] / numDP;
		}
		// calculating the new Euclidean Distance for each Data Point
		
		//tempBatteryLevel = null;

		for (i = 0; i < numDP; i++) {
			mCluster.getDataPoint(i).calcEuclideanDistance();
		}
		// calculate the new Sum of Squares for the Cluster
		mCluster.calcSumOfSquares();
	}

	public void setCluster(Cluster c) {
		this.mCluster = c;
	}

	public Cluster getCluster() {
		return mCluster;
	}



	public double[] getBatteryLevel() {
		return this.mBatteryLevel;
	}

	public String print() {
		return ("(" + this.getBatteryLevel()[0] + ")");
	}

}
