package clustering.kmeans;
public class DataPoint {
	static final int MINUTES_OF_A_DAY =  60*24;
	private int mSensorId;
	private int[] mBatteryLevel;
	private Cluster mCluster; // Current cluster of this data point
	private double mEuDt;

	public DataPoint(int mSensorId, int[] mBatteryLevel) {
		this.mSensorId = mSensorId;
		this.mBatteryLevel = mBatteryLevel;
		// at first there's no cluster for it.
		this.mCluster = null;
	}

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

	public void calcEuclideanDistance() {
		// called when DP is added to a cluster or when a Centroid is
		// recalculated.
		double temp = 0;
		// Total of all differences squared from every one minutes
		for (int m = 0; m < MINUTES_OF_A_DAY; m++) {
			temp += Math.pow(this.mBatteryLevel[m]
					- this.mCluster.getCentroid().getBatteryLevel()[m], 2);
		}
		mEuDt = Math.sqrt(temp);
	}

	public double testEuclideanDistance(Centroid c) {
		double temp = 0;
		// Total of all differences squared from every one minutes
		for (int m = 0; m < MINUTES_OF_A_DAY; m++) {
			temp += Math.pow(this.mBatteryLevel[m] - c.getBatteryLevel()[m], 2);
		}
		return Math.sqrt(temp);
	}

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

	public Cluster getCluster() {
		return mCluster;
	}

	public double getCurrentEuDt() {
		return mEuDt;
	}

	public int getSensorId() {
		return this.mSensorId;
	}
}
