SRL Archive - OSR Help

Progress report calculations


Total

2012-04-11 04:30:28

So I'm having troubles with my progress report calculations. After a certain amount of time they turn into wild numbers that are obviously incorrect. Here are some examples.

Proggy :

//////TotalNats V1//////
Nats crafted: 7306(5053 Nats/Hour)
Exp gained: 33267 exp(23008 Exp/Hour)
Profit earned: 800007 gp(-271842 GP/Hour) <--- See? negative gp/hr
Essence used: 3653 essence
Pouches repaired: 6
Running for: 01:26:45
///////////////////////////

Code for proggy(I set NatsMade to 0 when I start the script):

procedure Proggy;
begin
Seconds := (GetTimeRunning/1000);
EssUsed := (NatsMade / 2);
EssLoss := (EssUsed * EssPrice);
XPGained := (GetXPBarTotal - StartExp);
XPPerhour :=(3600*(XPGained))/(Seconds);
NatsProfit := (NatsMade * NatsPrice);
TotalProfit := (NatsProfit - EssLoss);
ProfitPerHour := (3600*(TotalProfit))/(Seconds);
NatsPerHour := (3600*(NatsMade))/(Seconds);
ClearDebug;
Writeln('//////TotalNats V' + ToStr(Version) + '//////');
Writeln('Nats crafted: ' + ToStr(NatsMade) + '(' + ToStr(NatsPerHour) + ' Nats/Hour)');
Writeln('Exp gained: ' + ToStr(XPGained) + ' exp' + '(' + ToStr(XPPerHour) + ' Exp/Hour)');
Writeln('Profit earned: ' + ToStr(TotalProfit) + ' gp' + '(' + ToStr(ProfitPerHour) + ' GP/Hour)');
Writeln('Essence used: ' + ToStr(EssUsed) + ' essence');
Writeln('Pouches repaired: ' + ToStr(Repaired));
Writeln('Running for: ' + MsToTime(GetTimeRunning, Time_Bare));
Writeln('///////////////////////////');
end;

Will post more proggies/examples if needed, but I think this will work for now.

YoHoJo

2012-04-11 04:35:49

Maybe try using extendeds or something instead of all integers? (If you are not).

Also if you use GroupDigits you can make it have commahs in the amounts over 1,000 which helps it looks nicer.

Total

2012-04-11 04:38:16

Ah yeah they are all integers now, will try that out. And thanks, didn't know about the GroupDigits function.

YoHoJo

2012-04-11 04:43:02

Actually wait.
Don't use extendeds (well you can if you want decimal Values), just keep them all as integers, but use the Round function instead (when needed) for all nice whole values. :D

Total

2012-04-11 04:46:17

Was about to say I can't use GroupDigits with extended, so I'll try rounding instead. :p.

putonajonny

2012-04-11 04:54:03


Var
Seconds, EssUsed, EssLoss, XPGained, NatsProfit, TotalProfit, NatsPerHour,
NatsMade, EssPrice, GetXPBarTotal_, StartExp, NatsPrice, Repaired : integer;
XPPerHour, ProfitPerHour : extended; //Put profit per hour and xp as an extended

function RoundEx(Number : extended; DecimalPlaces : integer) : extended; //you could use this function that rounds numbers to specific numbers of decimal places
Var
Temp : integer;
begin
Result := Number * Pow(10, DecimalPlaces);
Temp := Round(Result);
Result := Temp / Pow(10, DecimalPlaces);
end;

procedure Proggy;
begin
Seconds := (GetTimeRunning/1000);
Seconds := 500 + Random(500);
EssUsed := (NatsMade / 2);
EssLoss := (EssUsed * EssPrice);
XPGained := (GetXPBarTotal_ - StartExp);
XPPerhour := RoundEx((3.6*(XPGained))/(Seconds), 1);
NatsProfit := (NatsMade * NatsPrice);
TotalProfit := (NatsProfit - EssLoss);
ProfitPerHour := RoundEx((3.6*(TotalProfit))/(Seconds), 1);
NatsPerHour := (3600*(NatsMade))/(Seconds);
ClearDebug;
Writeln('//////TotalNats V' + ToStr(Version) + '//////');
Writeln('Nats crafted: ' + ToStr(NatsMade) + '(' + ToStr(NatsPerHour) + ' Nats/Hour)');
Writeln('Exp gained: ' + ToStr(XPGained) + ' exp' + '(' + ToStr(XPPerHour) + ' K/Hour)');
Writeln('Profit earned: ' + ToStr(TotalProfit) + ' gp' + '(' + ToStr(ProfitPerHour) + ' k/hour)');
Writeln('Essence used: ' + ToStr(EssUsed) + ' essence');
Writeln('Pouches repaired: ' + ToStr(Repaired));
Writeln('Running for: ' + MsToTime(GetTimeRunning, Time_Bare));
Writeln('///////////////////////////');
end;

//////TotalNats V2.04//////
Nats crafted: 250(1130 Nats/Hour)
Exp gained: 1845 exp(8.3 K/Hour)
Profit earned: 38500 gp(174.1 k/hour)
Essence used: 125 essence
Pouches repaired: 5
Running for: 00:00:00
///////////////////////////

Total

2012-04-11 05:03:54

Took me a while to understand exactly how that worked but now I see lol. Will definitely use if simply rounding doesn't work with your permission. :)

Hmmm…using your method this happens


/////////TotalNats V1/////////
Nats crafted: 108(3,085 Nats/Hour)
Exp gained: 549 exp(15.6999999999999k Exp/Hour)
Profit earned: 11,826 gp(337.899999999999k GP/Hour)
Essence used: 54 essence
Pouches repaired: 1
Running for: 00:02:06
///////////////////////////

putonajonny

2012-04-12 11:26:15

From: TotalKillz
Took me a while to understand exactly how that worked but now I see lol. Will definitely use if simply rounding doesn't work with your permission. :)

Hmmm…using your method this happens


/////////TotalNats V1/////////
Nats crafted: 108(3,085 Nats/Hour)
Exp gained: 549 exp(15.6999999999999k Exp/Hour)
Profit earned: 11,826 gp(337.899999999999k GP/Hour)
Essence used: 54 essence
Pouches repaired: 1
Running for: 00:02:06
///////////////////////////


Are you using the RoundEx function?

Total

2012-04-12 11:41:21

Yeah, I went back to rounding normally and it seems to be working now though. I think my problem was I was rounding it in the Writeln so it wasn't working correctly for whatever reason.

Nope…still doesn't work. What the hell. >.<


/////////TotalNats V1/////////
Nats crafted: 18,234(5,204 Nats/Hour)
Exp gained: 82,958 exp(23,679 Exp/Hour)
Profit earned: 1,996,623 gp(-,111,171 GP/Hour)
Essence used: 9,117 essence
Pouches repaired: 14
Running for: 03:30:12
///////////////////////////


procedure Proggy;
begin
Seconds := (GetTimeRunning/1000);
EssUsed := (NatsMade / 2);
EssLoss := (EssUsed * EssPrice);
XPGained := (GetXPBarTotal - StartExp);
XPPerhour := Round(XPGained * 3600)/(Seconds);
NatsProfit := (NatsMade * NatsPrice);
TotalProfit := (NatsProfit - EssLoss);
ProfitPerHour := Round(TotalProfit * 3600)/(Seconds);
NatsPerHour := (3600*(NatsMade))/(Seconds);
if TimeFromMark(CommitTimer) > 300000 then
begin
Commit;
MarkTime(CommitTimer);
end;
Writeln('/////////TotalNats V' + ToStr(Version) + '/////////');
Writeln('Nats crafted: ' + ToStr(GroupDigits(NatsMade, ',')) + '(' + ToStr(GroupDigits(NatsPerHour, ',')) + ' Nats/Hour)');
Writeln('Exp gained: ' + ToStr(GroupDigits(Round(XPGained), ',')) + ' exp' + '(' + ToStr(GroupDigits(XPPerHour, ',')) + ' Exp/Hour)');
Writeln('Profit earned: ' + ToStr(GroupDigits(Round(TotalProfit), ',')) + ' gp' + '(' + ToStr(GroupDigits(ProfitPerHour, ',')) + ' GP/Hour)');
Writeln('Essence used: ' + ToStr(GroupDigits(EssUsed, ',')) + ' essence');
Writeln('Pouches repaired: ' + ToStr(Repaired));
Writeln('Running for: ' + MsToTime(GetTimeRunning, Time_Bare));
Writeln('///////////////////////////');
end;

They are all integers…