FileDocCategorySizeDatePackage
PingSourceStats.javaAPI DocAzureus 3.0.3.44758Fri Jul 06 16:35:40 BST 2007com.aelitis.azureus.core.speedmanager.impl.v2

PingSourceStats

public class PingSourceStats extends Object
Keeps the ping time stats for a single source. Should calculate averages for the data.

Fields Summary
final com.aelitis.azureus.core.speedmanager.SpeedManagerPingSource
source
double
currPing
com.aelitis.azureus.core.util.average.Average
shortTerm
com.aelitis.azureus.core.util.average.Average
medTerm
com.aelitis.azureus.core.util.average.Average
longTerm
com.aelitis.azureus.core.util.average.Average
forChecks
Constructors Summary
public PingSourceStats(com.aelitis.azureus.core.speedmanager.SpeedManagerPingSource _source)


      
        source = _source;
    
Methods Summary
public voidaddPingTime(int ping)

        currPing = (double) ping;
        shortTerm.update( (double)ping );
        medTerm.update( (double)ping );
        longTerm.update( (double)ping );
    
public com.aelitis.azureus.core.util.average.AveragegetHistory()
Get the average that should be used for checking ping times.

return
- ping time of history.

        return forChecks;
    
public com.aelitis.azureus.core.util.average.AveragegetLongTermAve()
Get the long-term average.

return
Average - longTerm

        return longTerm;
    
public intgetTrend()
Speculative method to see if it can determine a trend. The larger the number the stronger the trend.

return
current - interger. A positive number is an increasing trend. A negative number is a decreasing trend.


        int retVal = 0;

        //based on current ping values.
        if(currPing<0.0){
            retVal--;
        }else{
            if( currPing < shortTerm.getAverage() ){
                retVal++;
            }else{
                retVal--;
            }

            if( currPing < medTerm.getAverage() ){
                retVal++;
            }else{
                retVal--;
            }

            if( currPing < longTerm.getAverage() ){
                retVal++;
            }else{
                retVal--;
            }
        }

        //compare shortTerm and medium term averages.
        if(shortTerm.getAverage() < medTerm.getAverage() ){
            retVal++;
        }else{
            retVal--;
        }

        //compare short-term with long term.
        if(shortTerm.getAverage() < longTerm.getAverage() ){
            retVal++;
        }else{
            retVal--;
        }

        //compare medium-term with long-term.
        if(medTerm.getAverage() < longTerm.getAverage() ){
            retVal++;
        }else{
            retVal--;
        }

        //modify results based on absolute ping values.
        final int ABSOLUTE_GOOD_PING_VALUE = 30;
        if(currPing<ABSOLUTE_GOOD_PING_VALUE){
            retVal++;
        }
        if(shortTerm.getAverage()<ABSOLUTE_GOOD_PING_VALUE){
            retVal++;
        }
        if(medTerm.getAverage()<ABSOLUTE_GOOD_PING_VALUE){
            retVal++;
        }
        if(longTerm.getAverage()<ABSOLUTE_GOOD_PING_VALUE){
            retVal++;
        }

        //modify results based on absolute ping values that are too long.
        final int ABSOLUTE_BAD_PING_VALUE = 300;
        if(currPing>ABSOLUTE_BAD_PING_VALUE){
            retVal--;
        }
        if(shortTerm.getAverage()>ABSOLUTE_BAD_PING_VALUE){
            retVal--;
        }
        if(medTerm.getAverage()>ABSOLUTE_BAD_PING_VALUE){
            retVal--;
        }
        if(longTerm.getAverage()>ABSOLUTE_BAD_PING_VALUE){
            retVal--;
        }

        return retVal;
    
public voidmadeChange()

        //want to make all the values NAN until it is ready to compare again.