package com.qiyou.mb.android.beans.basic;

import com.qiyou.mb.android.utils.log.QLog;


public class StatTrack {
	public static String TAG ="com.qiyou.beans.StatTrack";
    public static String dTAG ="com.qiyou";
	public StatTrack() {
		// TODO Auto-generated constructor stub
	}
	//max values begin...
	private float dist =0.0f;
	private float upDistE =0.0f;   //累积上升
//	private float eDownDist =0.0f; //累积下降
	private float topSpeed =0.0f;  
	private long pause=0  ; 
	private int type; //0,1,2...(bike,walk,car)
	private long sportTime =0; 
	private long offTime =0; //no gps time 
	private long totalTime=0 ;
	private float maxR =0;//max radius 
	private float avSpeed=0;
	private float tavSpeed=0;
	private float burn=0;
	private float upDist;
	private float downDist;
	private float maxEle;
	private float minEle;
	private long kmTime=0 ;
	//average values.begin...
	private float sumDist =0.0f;
	private float sumBurn =0.0f;   //累积消耗卡路里
	private float sumEup =0.0f;   //累积上升
	private float sumEdown =0.0f; //累积下降
	private float sumTopSpeed =0.0f;  
	private long sumPause=0  ;	 
	private long sumSportTime =0;
	private long sumOff =0; //no gps time 
	private long sumTotalTime=0 ;
	private float sumMaxR =0;//max radius 
	private float sumAvSpeed=0;  
	private float sumtAvSpeed=0;  
	private float sumUpDist;
	private long sumKmTime;
	
	public float getSumTopSpeed() {
		return sumTopSpeed;
	}

	public float getSumMaxR() {
		return sumMaxR;
	}

	public float getSumAvSpeed() {
		return sumAvSpeed;
	}

	public float getSumtAvSpeed() {
		return sumtAvSpeed;
	}

	public long getSumKmTime() {
		return sumKmTime;
	}

	public float getSumMaxEle() {
		return sumMaxEle;
	}

	public float getSumMinEle() {
		return sumMinEle;
	}
	private float sumDownDist;
	private float sumMaxEle;
	private float sumMinEle;
	private long start=System.currentTimeMillis();
	private long end =0;
	
	private int cnt=0;
	protected boolean isAVcnt=true;
	public boolean getIsAVcnt() {
		return isAVcnt;
	}

	public void setIsAVcnt(boolean isAVcnt) {
		this.isAVcnt = isAVcnt;
	}
	private long minKmTime; 
	
	public float getAvdist() {
		return cnt>0? sumDist/cnt:0;
	}
 
	public float getAveUpDist() {
		return cnt>0? sumEup/cnt:0;
	 
	}
	public long getAvKmTime() {
		return cnt>0? sumKmTime/cnt:0;
	 
	}
	public float getAveDownDist() {
		 
		return cnt>0? sumEdown/cnt:0;
	}
	public float getAvtopSpeed() {
		 
		return cnt>0? sumTopSpeed/cnt:0;
//		return topSpeed;
	}
	public long getAvpause() {
	 
		return cnt>0? sumPause/cnt:0;
	}
	public long getAvsportTime() {
		return cnt>0? sumSportTime/cnt:0;
		 
	}
	public long getAvoffTime() {
	 
		return cnt>0? sumOff/cnt:0;
	}
	public long getAvtotalTime() {
	    return cnt>0? sumTotalTime/cnt:0;
		 
	}
	public float getAvmaxR() { 
		 return cnt>0? sumMaxR/cnt:0; 
	}
	public float getAvavSpeed() { 
		 return cnt>0? sumAvSpeed/cnt:0;
	}
	public float getAvTavSpeed() { 
		 return cnt>0? sumtAvSpeed/cnt:0;
	}
	public float getAvBurn() { 
		 return cnt>0? sumBurn/cnt:0; 
	}
	
	public float getAvUpDist() {
		return cnt>0? sumUpDist/cnt:0;
	 
	}
	public float getAvDownDist() {
		 
		return cnt>0? sumDownDist/cnt:0;
	}
	public float getAvMaxEle() {
		return cnt>0? sumMaxEle/cnt:0;
	 
	}
	public float getAvMinEle() {
		 
		return cnt>0?Math.abs(sumMinEle)>cnt?sumMinEle/cnt:0:0;
	}
	
	
	
	public float getUpDist() {
		return upDist ;
	 
	}
	public float getDownDist() {
		 
		return downDist;
	}
	public float getMaxEle() {
		return maxEle;
	 
	}
	public float getMinEle() {
		 
		return minEle;
	}
	
 
	public void setUpDist(float upDist) {
		if(Float.isInfinite(upDist) ||Float.isNaN(upDist) ||upDist<=0)return;
		sumUpDist+=upDist;
		if(upDist >this.upDist)
		this.upDist = upDist;
	}
	
	 
	public void setDownDist(float downDist) {
		if(Float.isInfinite(downDist) ||Float.isNaN(downDist) ||downDist<=0)return;
		sumDownDist+=downDist;
		if(downDist >this.downDist)
		this.downDist = downDist;
	}
	
 
	public void setMaxEle(float maxEle) {
		if(Float.isInfinite(maxEle) ||Float.isNaN(maxEle) ||maxEle<-1000 )return;
		sumMaxEle+=maxEle;
		if(maxEle >this.maxEle)
		this.maxEle = maxEle;
	}
	

	public void setMinTimeKm(long minKmTime) {
	 if(minKmTime<=0)return;
		sumKmTime+=minKmTime;
		if(this.minKmTime==0 ||  this.minKmTime >minKmTime)
		this.minKmTime = minKmTime;
//		QLog.getLogger().d(dTAG, "sumKmTime is "+ sumKmTime +", minKmTime is " +this.minKmTime +", current KmTime is " + minKmTime);
//		QLog.getLogger().d(dTAG,  "current KmTime is " + minKmTime);
	}
	
	 
	public void setMinEle(float minEle) {
		if(Float.isInfinite(minEle) ||Float.isNaN(minEle) )return;
		sumMinEle+=minEle;
		if(minEle < this.minEle)
		this.minEle = minEle;
	}
	
	
	public float getDist() {
		return dist;
	}
	public void setDist(float dist) {
		if(Float.isInfinite(dist) ||Float.isNaN(dist) ||dist<=0)return;
		if(isAVcnt){
			cnt++;
		}	
		sumDist+=dist;
		if(dist >this.dist)
		this.dist = dist;
	}
	/*public boolean isAVcnt() {
		return isAVcnt;
	}
	public void setAVcnt(boolean isAVcnt) {
		this.isAVcnt = isAVcnt;
	}*/
	public float getUpDistE() {		
		return upDistE;
	}
	public void setUpDistE(float upDistE) {
		if(Float.isInfinite(upDistE)||Float.isNaN(upDistE))return;
		sumEup+=upDistE;
		if(upDistE >this.upDistE)
			this.upDistE = upDistE;
	}
//	public float geteDownDist() {
//		return eDownDist;
//	}
//	public void seteDownDist(float eDownDist) {
//		if(Float.isInfinite(eDownDist)||Float.isNaN(eDownDist))return;
//		sumDownDist+=eDownDist;
//		if(Math.abs(eDownDist) >this.eDownDist)
//		this.eDownDist = Math.abs(eDownDist);
//	}
	public float getTopSpeed() {
		return topSpeed;
	}
	public void setTopSpeed(float topSpeed) {
		if(Float.isInfinite(topSpeed)||Float.isNaN(topSpeed) ||topSpeed<0)return;
		sumTopSpeed+=topSpeed;
		if(topSpeed >this.topSpeed)
		this.topSpeed = topSpeed;
	}
	public long getPause() {
		return pause;
	}
	public void setPause(long pause) {
		if(Float.isInfinite(pause)|| Float.isNaN(pause)||pause<0 )return;
		sumPause+=pause;
		if(pause >this.pause)
		this.pause = pause;
	}
	public int getType() {
		return type;
	}
	public void setType(int type) {
		
		this.type = type;
	}
	public long getSportTime() {
		return sportTime;
	}
	public void setSportTime(long sportTime) {
		if(Float.isInfinite(sportTime)||Float.isNaN(sportTime)||sportTime<0)return;
		sumSportTime+=sportTime;
		if(sportTime >this.sportTime)
		this.sportTime = sportTime;
	}
	public long getOffTime() {
		return offTime;
	}
	public void setOffTime(long offTime) {
		if(Float.isInfinite(offTime)||Float.isNaN(offTime)||offTime<0)return;
		sumOff+=offTime;
		if(offTime >this.offTime)
		this.offTime = offTime;
	}
	public float getMaxR() {
		return maxR;
	}
	public void setMaxR(float maxR) {
		if(Float.isInfinite(maxR)||Float.isNaN(maxR) ||maxR<0)return;
		sumMaxR+=maxR;
		if(maxR >this.maxR)
		this.maxR = maxR;
	}
	
	public void setBurn(float burn) {
		if(Float.isInfinite(burn)||Float.isNaN(burn) ||burn<0)return;
		sumBurn+=burn;
		if(burn >this.burn)
		this.burn = burn;
	}
	
	public float getBurn(){
		return burn;
	}
	
	public float getAvSpeed() {
		return avSpeed;
	}
	
	public long getMinKmTime() {
		return this.minKmTime;
	}
	
	public float getTavSpeed() {
		return tavSpeed;
	}
	
	public void setAvSpeed(float avSpeed) {
//		if(avSpeed == Float.NaN)return;
		if(Float.isInfinite(avSpeed)||Float.isNaN(avSpeed)|| !(avSpeed>0) )return;		
//		Log.e("com.qiyou", "statTrack set avspeed:"+ avSpeed);
		sumAvSpeed+=avSpeed;
		if(avSpeed >this.avSpeed)
		this.avSpeed = avSpeed;
	}
	
	public void setTavSpeed(float tavSpeed) {
//		if(avSpeed == Float.NaN)return;
		if(Float.isInfinite(avSpeed)||Float.isNaN(avSpeed)|| !(avSpeed>0) )return;		
//		Log.e("com.qiyou", "statTrack set avspeed:"+ avSpeed);
		sumtAvSpeed+=tavSpeed;
		if(tavSpeed >this.tavSpeed)
		this.tavSpeed = tavSpeed;
	}
	
	
	public long getTotalTime() {
		return totalTime;
	}
	public void setTotalTime(long totalTime) {
		if(Float.isInfinite(totalTime)||Float.isNaN(totalTime) ||totalTime<0)return;
		sumTotalTime+=totalTime;
		if(totalTime >this.totalTime)
			this.totalTime = totalTime;
	}
	
	/*public void mergeTrack(Track tr){	
		
		QLog.getLogger().d(dTAG, TAG+"   MergeTrack: begin to merge track:" +tr.getTrackBean().getTrackId());
		
		if(tr==null || tr.getTrackBean()==null) return;		
		
		isAVcnt=false;
		Track_bean tb =tr.getTrackBean();
//		isAVcnt = !mergedTracks.contains(tb.getTrackId());
		isAVcnt = mergedTracks.get(Integer.valueOf(tb.getTrackId()))==null;
		Track_bean tb0=  mergedTracks.get(Integer.valueOf(tb.getTrackId()));
		isAVcnt = tb0==null;	
		
		QLog.getLogger().d(dTAG,  TAG+"   MergeTrack: track alread exist?" + isAVcnt);
		
		QLog.getLogger().d(dTAG,  TAG+"   MergeTrack: Last merge distance:?" + tb0.getDistance());
		QLog.getLogger().d(dTAG,  TAG+"   MergeTrack: Current merge distance:?" + tb.getDistance());
		
		QLog.getLogger().d(dTAG,  TAG+"   MergeTrack: Last   merge  totalTime:?" + (tb0.getSportTime()+tb0.getPauseTime()));
		QLog.getLogger().d(dTAG,  TAG+"   MergeTrack: Current merge totalTime:?" + (tb.getSportTime()+tb.getPauseTime()));
		
//		if(tb.getDistance() -tb0.getDistance()<=0)return;
		if( (tb.getSportTime()+tb.getPauseTime()) - (tb0.getSportTime()+tb0.getPauseTime()) <=0)return;
		this.setAvSpeed(tb.getAvs() - tb0.getAvs());
		this.setDist(tb.getDistance()-tb.getDistance() );
		this.seteDownDist(tb.geteDownDist() -tb0.geteDownDist());
		this.seteUpDist(tb.geteUpDist() - tb0.geteUpDist()); 
		this.setMaxR(tb.getRdist() - tb0.getRdist());
		this.setOffTime(tb.getOffTime() - tb0.getOffTime());
		this.setPause(tb.getPauseTime() -tb0.getPauseTime());
		this.setSportTime(tb.getSportTime()-tb0.getSportTime());
		this.setTopSpeed(tb.getTopSpeed() -tb0.getTopSpeed());
		this.setTotalTime((tb.getSportTime()+tb.getPauseTime()) - (tb0.getSportTime()+tb0.getPauseTime()));
		this.setCost(tb.getCost() -tb0.getCost());
		mergedTracks.put(tb.getTrackId(),tb);
		isAVcnt=true;
		QLog.getLogger().d(dTAG,  TAG+"   MergeTrack: DONE.");
	}
//	ArrayList<Integer> mergedTracks =new ArrayList<Integer>(); 
	HashMap<Integer,Track_bean> mergedTracks =new HashMap<Integer,Track_bean>();
	*/
	
	

	public int getCnt(){
		return cnt;
	}
	
	public float getSumDist(){
		return this.sumDist;
	}
	
	public long getSumTotalTime(){
		return this.sumTotalTime;
	}
	
	public long getSumSportTime(){
		return this.sumSportTime;
	}
	
	public float getSumEup(){
		return this.sumEup;
	}
	
	public float getSumEdown(){
		return this.sumEdown;
	}
	
	public float getSumBurn(){
		return this.sumBurn;
	}
	
	public long getSumPause(){
		return this.sumPause;
	}
	
	public long getSumOff(){
		return this.sumOff;
	}
	 
	public float getSumUpDist() {
		return sumUpDist;
	}
 
	public float getSumDownDist() {
		return sumDownDist;
	}

	public long getStart() {
		return start;
	}

	public void setStart(long start) {
		if(start<this.start)
			this.start = start;
	}

	public long getEnd() {
		return end;
	}

	public void setEnd(long end) {
		if(end>this.end)
			this.end = end;
	}

	public long getKmTime() {
		return kmTime;
	}

	public void setKmTime(long kmTime) {
		this.kmTime = kmTime;
	}
 
	
	
	
}
