package gr.uoc.csd.hy439.positioning.fingerprint;

import java.io.IOException;
import java.util.ArrayList;

import android.content.Context;
import android.location.Location;
import android.net.wifi.ScanResult;
import android.util.Log;

/**
 * This algorithm estimates a random location and returns it.
 */
public class RandomAlgorithm extends FingerprintAlgorithm {
	public static final double MIN_LATITUDE = 34.915215;
	public static final double MAX_LATITUDE = 35.429344;
	public static final double MIN_LONGITUDE = 24.705505;
	public static final double MAX_LONGITUDE = 25.466309;

	public RandomAlgorithm(Context context) {
		super(context);
	}
	
	@Override
	protected void onCreate() {
		// do nothing
	}

	@Override
	protected void trainModel(){
		// do nothing
	}

	@Override
	protected void saveModel() throws IOException {
		// save nothing
	}

	@Override
	protected void retrieveModel() throws Exception {
		// store nothing
	}

	/**
	 * Estimates a random location
	 * @param scanResults is ignored
	 * @throws OutOfTrainingAreaException is never thrown
	 */
	@Override
	Location estimateLocation(ArrayList<ScanResult> scanResults) throws OutOfTrainingAreaException {
		Log.d(this.getClass().getName(), "I estimate a new Location");
		double latitude= MIN_LATITUDE + (double) (Math.random() * ((MAX_LATITUDE - MIN_LATITUDE)));
		double longitude= MIN_LONGITUDE + (double) (Math.random() * ((MAX_LONGITUDE - MIN_LONGITUDE)));
		Location location= new Location(FingerprintService.PROVIDER);
		location.setLatitude(latitude);
		location.setLongitude(longitude);
		return location;
	}
	
}
