package org.josast.CubesatSim.influxDB;

import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;

public class DataCubesatSim {

	private Logger log = Logger.getLogger(getClass().getName());

	private double BatteryVoltage;
	private double TotalCurrent;
	private double pXcurrent;
	private double mXcurrent;
	private double pYcurrent;
	private double mYcurrent;
	private double pZcurrent;
	private double mZcurrent;
	private double BaseTemperature;
	private double BatteruCurrent;

	public DataCubesatSim() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @return the batteryVoltage
	 */
	public double getBatteryVoltage() {
		return BatteryVoltage;
	}

	/**
	 * @param batteryVoltage the batteryVoltage to set
	 */
	public void setBatteryVoltage(double batteryVoltage) {
		BatteryVoltage = batteryVoltage;
	}

	/**
	 * @return the totalCurrent
	 */
	public double getTotalCurrent() {
		return TotalCurrent;
	}

	/**
	 * @param totalCurrent the totalCurrent to set
	 */
	public void setTotalCurrent(double totalCurrent) {
		TotalCurrent = totalCurrent;
	}

	/**
	 * @return the pXCurent
	 */
	public double getpXCurent() {
		return pXcurrent;
	}

	/**
	 * @param pXCurent the pXCurent to set
	 */
	public void setpXCurent(double pXcurrent) {
		this.pXcurrent = pXcurrent;
	}

	/**
	 * @return the mXcurrent
	 */
	public double getmXcurrent() {
		return mXcurrent;
	}

	/**
	 * @param mXcurrent the mXcurrent to set
	 */
	public void setmXcurrent(double mXcurrent) {
		this.mXcurrent = mXcurrent;
	}

	/**
	 * @return the pYcurrent
	 */
	public double getpYcurrent() {
		return pYcurrent;
	}

	/**
	 * @param pYcurrent the pYcurrent to set
	 */
	public void setpYcurrent(double pYcurrent) {
		this.pYcurrent = pYcurrent;
	}

	/**
	 * @return the mYcurrent
	 */
	public double getmYcurrent() {
		return mYcurrent;
	}

	/**
	 * @param mYcurrent the mYcurrent to set
	 */
	public void setmYcurrent(double mYcurrent) {
		this.mYcurrent = mYcurrent;
	}

	/**
	 * @return the pZcurrent
	 */
	public double getpZcurrent() {
		return pZcurrent;
	}

	/**
	 * @param pZcurrent the pZcurrent to set
	 */
	public void setpZcurrent(double pZcurrent) {
		this.pZcurrent = pZcurrent;
	}

	/**
	 * @return the mZcurrent
	 */
	public double getmZcurrent() {
		return mZcurrent;
	}

	/**
	 * @param mZcurrent the mZcurrent to set
	 */
	public void setmZcurrent(double mZcurrent) {
		this.mZcurrent = mZcurrent;
	}

	/**
	 * @return the baseTemperature
	 */
	public double getBaseTemperature() {
		return BaseTemperature;
	}

	/**
	 * @param baseTemperature the baseTemperature to set
	 */
	public void setBaseTemperature(double baseTemperature) {
		BaseTemperature = baseTemperature;
	}

	/**
	 * @return the batteruCurrent
	 */
	public double getBatteruCurrent() {
		return BatteruCurrent;
	}

	/**
	 * @param batteruCurrent the batteruCurrent to set
	 */
	public void setBatteruCurrent(double batteruCurrent) {
		BatteruCurrent = batteruCurrent;
	}

	public void writetoInfluxDB(InfluxDBInstance dataBase) {
		BatchPoints batchPoints = BatchPoints.database(dataBase.getDatabasename())
				// .retentionPolicy("defaultPolicy")
				.build();

		Point point1 = Point.measurement("BatteryVoltage").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", BatteryVoltage).build();
		Point point2 = Point.measurement("TotalCurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", TotalCurrent).build();
		Point point3 = Point.measurement("pXcurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", pXcurrent).build();
		Point point4 = Point.measurement("mXcurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", mXcurrent).build();
		Point point5 = Point.measurement("pYcurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", pYcurrent).build();
		Point point6 = Point.measurement("mYcurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", mYcurrent).build();
		Point point7 = Point.measurement("pZcurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", pZcurrent).build();
		Point point8 = Point.measurement("mZcurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", mZcurrent).build();
		Point point9 = Point.measurement("BaseTemperature").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", BaseTemperature).build();
		Point point10 = Point.measurement("BatteruCurrent").time(System.currentTimeMillis(), TimeUnit.MILLISECONDS)
				.addField("value", BatteruCurrent).build();

		batchPoints.point(point1);
		batchPoints.point(point2);
		batchPoints.point(point3);
		batchPoints.point(point4);
		batchPoints.point(point5);
		batchPoints.point(point6);
		batchPoints.point(point7);
		batchPoints.point(point8);
		batchPoints.point(point9);
		batchPoints.point(point10);
		dataBase.write(batchPoints);
		log.info("data write :" + this.toString());

	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */

	@Override
	public String toString() {
		return "dataCubesatSim [BatteryVoltage=" + BatteryVoltage + ", TotalCurrent=" + TotalCurrent + ", pXCurent="
				+ pXcurrent + ", mXcurrent=" + mXcurrent + ", pYcurrent=" + pYcurrent + ", mYcurrent=" + mYcurrent
				+ ", pZcurrent=" + pZcurrent + ", mZcurrent=" + mZcurrent + ", BaseTemperature=" + BaseTemperature
				+ ", BatteruCurrent=" + BatteruCurrent + "]";
	}

}
