Page 1 of 1

Update Time and Variance Calculators

PostPosted: Wed Mar 30, 2016 8:07 pm
by Aurum Rider
Update Tools are primarily used, obviously, at upate to get the approximate time that a region updates. This is exremely useful for invading/liberating forces because they can accurately get all their nations in on time to capture the WA delegate position, but it can also be useful for natives and defending forces to know when their region updates so that they can be on in time to defend their region.

An update tool requires 4 things to work properly at a basic level:

1: A Keyed list of all the regions in the game, along with all the data required for the tool
- The first nation that updates in it
- How many regions come before it (It's index)
- How many nations are in it
2: An index list of all regions in the game.
3: A keyed list of all the nations in the game along with al lthe data required for the tool
- The nation's index
4: An index list of all nations in the game

A basic tool works by calculating the time that a Nation updates by using math to get the time it takes for a nation to update. This is done with the following equation.
TimePerNation = UpdateLengthInSeconds / NumberOfNations

This can be used to calculate the rough time a region will update in the game. You do this using how many nations update before it.
EstimatedUpdateTime = NationsBeforeRegion * TimePerNation

However, this time will be wildly inaccurate because there is an arbitary amount of time added to each nation called Variance. Variance was added because initially raider tools were 100% accurate. Calculating variance can only be done during the update by comparing the time that a nation actually updates to the tool-estimated time using this equation.
Variance = ActualUpdateTime - EstimatedUpdateTime

You can then calculate a more accurate time for your target region using that variance.
AccurateTime = EstimatedUpdateTime + Variance


As of the time of writing, the only way to get the Actual Update time of a nation is to watch the happenings API for influence changes.

http://www.nationstates.net/cgi-bin/api ... ge;limit=5

With this poll, you are looking for either world census rankings, or influence changes. You can safely poll that API call every 0.75 seconds, although you won't gain much accuracy over polling it once per second. Although the delay is 28 seconds, the variance calculation will still put your time within about 2 or 3 seconds of accuracy.

Pseudocode wise, you're looking at this:

Code: Select all
RegionDict = //Dictionary of regions. RegionName:{FirstNation, Index, NumNations}
RegionList = //List of regions Index:RegionName
NationDict = //Dictionary of nations. {Nation:Index}
NationList = //List of Nations Index:Nation

UpdateStartTime = //This is important for later. For the major update, it is 12:00am EST, or 4:00am GMT
SecondsInUpdate = //For our purposes, we will assume the Major Update at 12:00am EST lasts 5600 seconds
NumberOfNations = //NationList.length
SecondsPerNation = SecondsInUpdate/NumberOfNations

PollData = PollAPI() //Language dependent. We will assume it returns a pythonic tuple (NationName, Timestamp)

Target = //Doesn't particularly matter for this example

TargetNationIndex = NationDict[RegionDict[Target][FirstNation]] //This will give us the index of the first nation in the region
TargetEstimate = TargetNationIndex * SecondsPerNation // This is Approximately how many seconds into the update the target will update

VarianceNationIndex = NationDict[PollData[0]] //The index of the nation that updated in our API poll
VarianceNationApproximate = VarianceNationIndex * SecondsPerNation //This will give us how many seconds in we thought the nation would update
VarianceNationActual = PollData[0] - UpdateStartTime //This is how many seconds it took for the nation to actully update
Variance = VarianceNationActual - VarianceNationApproximate //This will give us the variance

AccurateUpdateTime = TargetEstimate + Variance //Tada We have our accurate time!


With this implementation, HTML scraping is not really necessary, although if you're desperate for the one or two second difference it makes, you can scrape the world happenings pages a maximum of 10 times per minutes. I wouldn't advise it.

Happy 20xx everyone, and remember to set your user agents!

PostPosted: Thu Mar 31, 2016 6:06 am
by Ballotonia
Aurum Rider wrote:However, this time will be wildly inaccurate because there is an arbitary amount of time added to each nation called Variance. Variance was added because initially raider tools were 100% accurate. Calculating variance can only be done during the update by comparing the time that a nation actually updates to the tool-estimated time using this equation.
Variance = ActualUpdateTime - EstimatedUpdateTime


Perhaps coincidentally, but you're making the exact same mistake the code of Predator made: what you're correcting for here are the server speed differences, which is due to generic server load variations. The Variance that was added into the update is not corrected for in your math, as that's the several seconds you're still off in either direction of your estimate.

Ballotonia

PostPosted: Thu Mar 31, 2016 9:18 am
by Aurum Rider
Ballotonia wrote: you're making the exact same mistake the code of Predator made: what you're correcting for here are the server speed differences, which is due to generic server load variations. The Variance that was added into the update is not corrected for in your math, as that's the several seconds you're still off in either direction of your estimate.

Ballotonia


It's really the only legal time correction that can be done client side (That I know of. Feel free to correct me :D). Even then the time difference between that, and what's currently updating isn't accounted for because of the 28 second delay. At the moment the tool I'm working on (which I can't be bothered to maintain, as changes are coming) is consistently 30 seconds early.
Life was so much easier when you could use the laws shard and filter one.

20XX Is now!

PostPosted: Fri Apr 01, 2016 11:14 pm
by Aurum Rider
In Lieu of current things happening to the site, I have decided to make 20XX now.

Binary Executable for 20XX, an update tool that can achieve accurate update times.
I recently used it with two updaters to hit
http://www.nationstates.net/region=inte ... ist_states
http://www.nationstates.net/region=alli ... on_fallout

*Regionfinding tools not included

Edit to my edit's edit: Kfixed
20XX Tool (EXTRACT IT FIRST PL0X) PLAY THE GAME

20XX Update Tool source code. Don't mind the comments.
20XX Source.zip Source Code!

*It may crash after downloading region data. Don't panic, that happens. I wrote most of this code at 3 in the morning. Just restart it.

PostPosted: Sat Apr 02, 2016 1:09 am
by Klaus Devestatorie
So in the light of very recent events, can we confirm if this tool is okay to use or not? It appears to work, and it appears to be legal, but it has been published by a deleted nation.

PostPosted: Sat Apr 02, 2016 2:26 am
by Ballotonia
Klaus Devestatorie wrote:So in the light of very recent events, can we confirm if this tool is okay to use or not? It appears to work, and it appears to be legal, but it has been published by a deleted nation.


Aurum Rider is not DOS.
As for the legality of this tool, you checked that yourself before using it, no? I for one haven't had the time yet to check this out, we're sorta busy now...

Ballotonia

PostPosted: Sat Apr 02, 2016 2:42 am
by Klaus Devestatorie
Ballotonia wrote:
Klaus Devestatorie wrote:So in the light of very recent events, can we confirm if this tool is okay to use or not? It appears to work, and it appears to be legal, but it has been published by a deleted nation.


Aurum Rider is not DOS.
As for the legality of this tool, you checked that yourself before using it, no? I for one haven't had the time yet to check this out, we're sorta busy now...

Ballotonia
I can't really read most code, I can only really go off the word of the author and the fact that he's already put his scalp on the line by a; publishing it in this forum and b; stating that he's already used it with specifics on where and when. It's Aurum being deleted that worried me.

No worries on the timeframe. Truth be told, in order to put it to use, I'd need other people to raid with (hint hint, any Incognitans reading this). :v

PostPosted: Sat Apr 02, 2016 3:28 pm
by Zacherie
The tool, to my knowledge, should be 100% script legal. It makes a call to download the regional data dump, which is parses and stores locally, and makes one API call per second to
http://www.nationstates.net/cgi-bin/api ... ge;limit=5
It sets the user agent to a user provided name as well as their external IP Address to make it identifiable, and because I don't know how to do so, it does not do anything to sneakily avoid the rate limit, meaning if it exceeds the limit it is unable to function for 15 minutes.

I will gladly cooperate (within reason) with anyone who wants to go through the code, or is curious what purpose certain blocks of code serve*.

PostPosted: Sat Apr 02, 2016 5:21 pm
by Khronion
Hats off to you for releasing the code.

PostPosted: Sat Apr 02, 2016 6:43 pm
by Zacherie
I released the code as insurance so that it couldn't be called foul for not being Open Source, and so that an Admin can one day take a look at it and tell me that that it's Legal/The comments are hilarious.

PostPosted: Sun Apr 03, 2016 1:56 pm
by Zacherie
For the sake of not having some other disaster like Predator happen, can I request an Admin look at 20XX's source code and verify it's legality?

If necessary, I will recomment the entire solution for ease of reading.

EDIT:
I now have a fancy dancy Github repo for it
https://github.com/doomjaw/ADR-20XX/blo ... ingForm.cs

This is the file that has all the relevant code. It is written in C# using Visual Studio 2015 community.

PostPosted: Sun Apr 03, 2016 7:00 pm
by Eluvatar
I've not reviewed the whole thing, by a long shot, but why in the world are you adding the external IP address to the user agent string when we can see the external IP address as, well, the external IP address in the same logs as the user agent?

PostPosted: Sun Apr 03, 2016 7:04 pm
by Zacherie
Eluvatar wrote:I've not reviewed the whole thing, by a long shot, but why in the world are you adding the external IP address to the user agent string when we can see the external IP address as, well, the external IP address in the same logs as the user agent?


I heard that UAs had to be unique across all instances of a script, so I added something to the UA that would be unique to each user of the tool.

PostPosted: Sun Apr 03, 2016 7:36 pm
by Eluvatar
If this and this are the only two lines which contact nationstates.net, as it appears, and if the functions they are in are never invoked in parallel, then (besides the possible oddness of injecting the IP address) this script is 100% okay.

I am not reviewing the rest of the program to make sure those assumptions are correct.

I would suggest that the program refuse to run if the User field is empty.

PostPosted: Sun Apr 03, 2016 7:42 pm
by Zacherie
Eluvatar wrote:If this and this are the only two lines which contact nationstates.net, as it appears, and if the functions they are in are never invoked in parallel, then (besides the possible oddness of injecting the IP address) this script is 100% okay.

I am not reviewing the rest of the program to make sure those assumptions are correct.

I would suggest that the program refuse to run if the User field is empty.


Sounds good boss. I'll change that ASAP.

EDIT: Would it be possible to delete this thread/Lock it so I can make a proper 20XX thread?

PostPosted: Sun Apr 03, 2016 8:58 pm
by Eluvatar
Locked.