Originally Posted by
benandtina
Speeding up algorithms is fun
Any way I could help?
Is the script's runtime n^2 (so comparing each cache to each other cache)? If so, maybe you can try out SQL to speed it up? I don't know how familiar you are with SQL or if that was what you already had in mind, but I have some ideas that I THINK would let you get that data with a single SQL query rather than nesting loops. The query will use a cross product, so all records will still be compared to each other, but my guess would be that it will likely be a little bit quicker than the nested loops. Let me know if you'd like to hear out those ideas
The macro I use for the stats created an SQL database, and a good portion of the stats is calculated from the resulting SQL.
However, for this I just made a macro using GSAK's GetNear function. It cycles through each cache and enters the coordinates into the GetNear function and the result is a delimited string which includes the distance to the 2 nearest caches (the first nearest is the cache I am checking the distance to). This is the simple macro:
Code:
GOTO position=top
WHILE NOT($_EOL)
$Data = getnear($d_latitude + " " + $d_Longitude, "M", 2)
$Distance = Extract($Data, ";", 7)
$d_User2 = $Distance
GOTO position=next
ENDWHILE
MsgOK msg="Finished!"
ENDSUB
I might try using my stats SQL database at a later time, I knew this would work and it was quick to write. GSAK is migrating to a full SQL database in the near future which will make a lot of this much easier.
The hardest part I have about using SQL is efficiently getting the distances to the nearest caches using only the coordinates. In order to do this you currently have to calculate the distances from each cache 4534 times (the number of available caches in the state in my DB). That is over 2 million distance calculations! But I am open to any ideas!
While we're talking math, if you or anyone else can come up with a better formula for me to predict the "Future Milestone Date Predictions" section of my stats I'd be all ears. I know little about how to calculate predictions, my 10 second lame formula is
Code:
$PredictedCachesPerDay = (($TotalCaches/(DateDiff($DateFirst,$DateToday))) + ($LastYearTotal/(DateDiff($OneYearAgo,$DateToday))*2))/3
I'm not even sure I remember what that code does! But IIRC it puts more emphasis on the average number of caches placed per day in the last year than it does the average for all time.
I then take and calculate at what date at the calculated rate per day will occur.