Changeset 27 for trunk/UDriveScan.pas


Ignore:
Timestamp:
Apr 6, 2016, 7:45:46 AM (8 years ago)
Author:
chronos
Message:
  • Modified: Improved average value in speed measurement.
  • Added: Show Min and Max values with different colors in speed chart.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDriveScan.pas

    r25 r27  
    5050
    5151  TSpeedValue = record
     52  public
    5253    Null: Boolean;
    5354    Max: Int64;
    5455    Average: Int64;
     56    Values: array of Int64;
    5557    Min: Int64;
    5658    procedure Reset;
     
    132134
    133135procedure TSpeedValue.UpdateValue(Value: Int64);
     136var
     137  Sum: Double;
     138  I: Integer;
    134139begin
    135140  if Null then begin
    136141    Min := High(Int64);
    137142    Max := Low(Int64);
    138     Average := 0;
     143    SetLength(Values, 0);
    139144  end;
    140145  Null := False;
    141146  if Value > Max then Max := Value;
    142147  // TODO: Computer average
    143   Average := Value;
     148  SetLength(Values, Length(Values) + 1);
     149  Values[Length(Values) - 1] := Value;
     150  Sum := 0;
     151  for I := 0 to Length(Values) - 1 do
     152    Sum := Sum + Values[I];
     153  Average := Trunc(Sum / Length(Values));
    144154  if Value < Min then Min := Value;
    145155end;
     
    344354  SpeedTimeCurrent: TDateTime;
    345355  Index: Integer;
     356  Value: Int64;
    346357begin
    347358  SpeedTimeCurrent := Now;
    348359  Index := Trunc(SectorCurrent / SectorCount * SpeedStepsCount);
    349360  if Index >= Length(SpeedSteps) then Index := Length(SpeedSteps) - 1;
    350   SpeedSteps[Index].UpdateValue(
    351     Trunc((SectorCurrent - SectorLast) * SectorSize / ((SpeedTimeCurrent - SpeedTimeLast) / OneSecond)));
     361  Value := Trunc((SectorCurrent - SectorLast) * SectorSize / ((SpeedTimeCurrent - SpeedTimeLast) / OneSecond));
     362  if Value < 0 then Value := 0;
     363  SpeedSteps[Index].UpdateValue(Value);
    352364  SpeedTimeLast := SpeedTimeCurrent;
    353365  SectorLast := SectorCurrent;
     
    389401  SpeedTimer.Enabled := False;
    390402  SpeedTimer.OnTimer := SpeedTimerExecute;
    391   SpeedStepsCount := 1000;
     403  SpeedStepsCount := 500;
    392404  SectorSize := 4096;
    393405  Terminated := True;
Note: See TracChangeset for help on using the changeset viewer.