Results 1 to 13 of 13

Thread: Trying to make function for calculating average trip time

  1. #1
    Join Date
    Jul 2007
    Location
    N O R
    Posts
    208
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Trying to make function for calculating average trip time

    Hi, i've been trying to make a function that calculates the amount of time the script has been running, divides that by the amount of trips made, and then you can get the average trip time, but it must then be converted into whatever format you want. I have tried a few differen't ways but none of them have fully worked. You also must convert the decimal to seconds.

    So example would be

    Minutes (20) / Loads (5) = 4 minutes per load

    But if you had:
    Minutes (22) / Loads(6) = 3.67 minutes per load, and .67 must be converted to seconds so it should be: 3 minutes and 40.2 or 40 seconds.
    So I want it to then return (in this example) 3:40

    Here is what I have to make it return (in this example) 3.67

    SCAR Code:
    function CalcAvgTime: string;
    var
      ATime : extended;
      Minutes, Seconds : integer;
    begin
      Seconds := GetTimeRunning / 1000;
      Minutes := Seconds / 60;
      ATime := Minutes / Loads;
      if (ATime > 1) and (ATime < 10) then
      Result := Copy(FloatToStr(ATime), 1, 4);
      if (ATime >= 10) then
      Result := Copy(FloatToStr(ATime), 1, 5);
      if (ATime >= 100) then
      Result := 'More than 100.00';
      if (ATime < 1) then
      Result := 'Less than 1.00';
    end;

    I know there must be a way to do it how I would like it. Any help is appreciated.

    Thanks

    - rostaryms

  2. #2
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    function CalcTripTime(time, trips: Integer): string;
    var
      h, m, s: Integer;
    begin
      Writeln('meow');
      h := Round((time / trips) / 3600000);
      m := ((Round(time / trips) mod 3600000) / 60000);
      s := ((Round(time / trips) mod 60000) / 1000);
      Result := IntToStr(h) + ' hour(s), ' + IntToStr(m) + ' minute(s) and ' + IntToStr(s) + ' second(s)';
    end;
    That turns (time / trips) into hours, minutes and seconds. I can add ms as well if you want, but you should be able to adjust that to what you want - pretty much replace time with GetTimeRunning and trips with player[currentPlayer].Integers[0] or whatever you hold trips made in.
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  3. #3
    Join Date
    Jul 2007
    Location
    N O R
    Posts
    208
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    okay will test that out and get back to you
    p.s. this is probably very noob but what does mod do?

  4. #4
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    Quote Originally Posted by rostaryms View Post
    okay will test that out and get back to you
    p.s. this is probably very noob but what does mod do?
    i never understood mod
    because in the tutorial i saw it said it removes the remainder
    it said
    SCAR Code:
    5 mod 2 = 4
    ?

    ~shut

  5. #5
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Look at TimeRunning in Timing.scar
    Just add /trips

    SCAR Code:
    {*******************************************************************************
    function AvgTripTime(TimeMsecs,TripsDone:integer): String;
    By: Based on Time Running from Phalanx's script/RsN
    Description: Returns Average Time per Trip in Hours Minutes Seconds
    *******************************************************************************}


    function AvgTripTime(TimeMsecs,TripsDone:integer): String;
    var
      RHours, Minutes, Seconds, RMinutes, RSeconds: LongInt;
      Time: string;
    begin
      Seconds := (TimeMsecs/TripsDone) div 1000;
      Minutes := Seconds div 60;
      RHours := Minutes div 60;
      Time := IntToStr(Seconds) + ' Seconds';
      if Minutes <> 0 then
      begin
        RSeconds := Seconds mod (Minutes * 60);
        Time := IntToStr(Minutes) + ' Minutes and ' + IntToStr(RSeconds) +
          ' Seconds';
      end;
      if RHours <> 0 then
      begin
        RMinutes := Minutes mod (RHours * 60);
        RSeconds := Seconds mod (Minutes * 60);
        Time := IntToStr(RHours) + ' Hours, ' + IntToStr(RMinutes) +
          ' Minutes and ' + IntToStr(RSeconds) + ' Seconds';
      end;
      Result := Time;
    end;

    edit:
    5 mod 2 = 1
    9 mod 2 = 1
    28 mod 5 = 3

    How to calculate A mod B
    A/B=C
    Round down C, you get D
    D*B=E
    A-E is the answer

    Example
    9 mod 2
    9/2 = 4.5
    Round down 4.5 to 4
    4*2 is 8
    9-8 is 1.

    Or you can keep subtracting the first number from the second number, until what is left over is less than the second number.
    Example 28 mod 5
    28-5 = 23
    23-5 = 18
    18-5 = 13
    13-5 = 8
    8-5 = 3
    3 is less than 5, so answer is 3.

  6. #6
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    mod returns the remainder - must use with 2 integers.
    It could be seen as remainder := num - Round(num / modNum);
    e.g. 5 mod 2 returns 1 as 2 * 2 = 4, 5 - 4 = 1.
    9 mod 3 returns 0 as 3 * 3 = 9, 9 - 9 = 0.
    4 mod 10 returns 4 as 10 * 0 = 0, 4 - 0 = 4.
    10 mod 4 returns 2 as 4 * 2 = 8, 10 - 8 = 2.
    That should help, if not just say.
    Also, mine is close enough to that Boreas
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  7. #7
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Actually it removes the remainder for me but idk.

    input:
    SCAR Code:
    writeln(inttostr(11 mod 9));

    output
    SCAR Code:
    2

  8. #8
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  9. #9
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by mixster View Post
    Also, mine is close enough to that Boreas
    Not always
    SCAR Code:
    program New;
    const trips=4;
    timerunning=26952000;
    function CalcTripTime(time, trips: Integer): string;
    var
      h, m, s: Integer;
    begin
      Writeln('meow');
      h := Round((time / trips) / 3600000);
      m := ((Round(time / trips) mod 3600000) / 60000);
      s := ((Round(time / trips) mod 60000) / 1000);
      Result := IntToStr(h) + ' hour(s), ' + IntToStr(m) + ' minute(s) and ' + IntToStr(s) + ' second(s)';
    end;

    {*******************************************************************************
    function AvgTripTime(TimeMsecs,TripsDone:integer): String;
    By: Based on Time Running from Phalanx's script/RsN
    Description: Returns Average Time per Trip in Hours Minutes Seconds
    *******************************************************************************}


    function AvgTripTime(TimeMsecs,TripsDone:integer): String;
    var
      RHours, Minutes, Seconds, RMinutes, RSeconds: LongInt;
      Time: string;
    begin
      Seconds := (TimeMsecs/TripsDone) div 1000;
      Minutes := Seconds div 60;
      RHours := Minutes div 60;
      Time := IntToStr(Seconds) + ' Seconds';
      if Minutes <> 0 then
      begin
        RSeconds := Seconds mod (Minutes * 60);
        Time := IntToStr(Minutes) + ' Minutes and ' + IntToStr(RSeconds) +
          ' Seconds';
      end;
      if RHours <> 0 then
      begin
        RMinutes := Minutes mod (RHours * 60);
        RSeconds := Seconds mod (Minutes * 60);
        Time := IntToStr(RHours) + ' Hours, ' + IntToStr(RMinutes) +
          ' Minutes and ' + IntToStr(RSeconds) + ' Seconds';
      end;
      Result := Time;
    end;

    begin

    writeln(AvgTripTime(timerunning,trips));
    writeln(CalcTripTime(timerunning,trips));
    end.

  10. #10
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Put Round() instead of Trunc() /facepalm
    Changing all Round's to Trunc leads to same output though
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  11. #11
    Join Date
    Jul 2007
    Location
    N O R
    Posts
    208
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  12. #12
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by mixster View Post
    Put Round() instead of Trunc() /facepalm
    Changing all Round's to Trunc leads to same output though
    Yup, one of those annoying 'not all the time' bugs. Pun intended

  13. #13
    Join Date
    Jul 2007
    Location
    N O R
    Posts
    208
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The function mixster gave me works perfectly even though i have analyzed it and still don't fully understand it lol. thanks too boreas.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Time to make a script?
    By Adroit707 in forum OSR Help
    Replies: 7
    Last Post: 03-01-2009, 12:07 AM
  2. Replies: 7
    Last Post: 07-13-2007, 06:39 PM
  3. How to make the script show it's running time?
    By PwNZoRNooB in forum OSR Help
    Replies: 4
    Last Post: 05-12-2007, 03:01 PM
  4. requesting good script too make much $$$ in lil time
    By dertykid555 in forum RS3 Outdated / Broken Scripts
    Replies: 2
    Last Post: 03-10-2007, 09:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •