NATION

PASSWORD

Update Time and Variance Calculators

Bug reports, general help, ideas for improvements, and questions about how things are meant to work.
User avatar
Aurum Rider
Envoy
 
Posts: 295
Founded: Dec 23, 2013
Ex-Nation

Update Time and Variance Calculators

Postby Aurum Rider » Wed Mar 30, 2016 8:07 pm

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!
Captain in Chief - Danger Zone - Married to Ambroscus Koth
20XX is now!

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds, so waiting an update to raid your enemy's raid is now the only viable strategy.

User avatar
Ballotonia
Site Admin
 
Posts: 5339
Founded: Antiquity
New York Times Democracy

Postby Ballotonia » Thu Mar 31, 2016 6:06 am

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
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Aurum Rider
Envoy
 
Posts: 295
Founded: Dec 23, 2013
Ex-Nation

Postby Aurum Rider » Thu Mar 31, 2016 9:18 am

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.
Last edited by Aurum Rider on Thu Mar 31, 2016 9:20 am, edited 2 times in total.
Captain in Chief - Danger Zone - Married to Ambroscus Koth
20XX is now!

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds, so waiting an update to raid your enemy's raid is now the only viable strategy.

User avatar
Aurum Rider
Envoy
 
Posts: 295
Founded: Dec 23, 2013
Ex-Nation

20XX Is now!

Postby Aurum Rider » Fri Apr 01, 2016 11:14 pm

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.
Last edited by Aurum Rider on Sat Apr 02, 2016 12:17 am, edited 6 times in total.
Captain in Chief - Danger Zone - Married to Ambroscus Koth
20XX is now!

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds, so waiting an update to raid your enemy's raid is now the only viable strategy.

User avatar
Klaus Devestatorie
Minister
 
Posts: 2526
Founded: Aug 28, 2008
Compulsory Consumerist State

Postby Klaus Devestatorie » Sat Apr 02, 2016 1:09 am

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.
The Avengrynkhal Ascendant of Klaus Devestatorie

User avatar
Ballotonia
Site Admin
 
Posts: 5339
Founded: Antiquity
New York Times Democracy

Postby Ballotonia » Sat Apr 02, 2016 2:26 am

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
"Een volk dat voor tirannen zwicht zal meer dan lijf en goed verliezen, dan dooft het licht…" -- H.M. van Randwijk

User avatar
Klaus Devestatorie
Minister
 
Posts: 2526
Founded: Aug 28, 2008
Compulsory Consumerist State

Postby Klaus Devestatorie » Sat Apr 02, 2016 2:42 am

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
Last edited by Klaus Devestatorie on Sat Apr 02, 2016 2:42 am, edited 1 time in total.
The Avengrynkhal Ascendant of Klaus Devestatorie

User avatar
Zacherie
Spokesperson
 
Posts: 138
Founded: Apr 29, 2015
Ex-Nation

Postby Zacherie » Sat Apr 02, 2016 3:28 pm

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*.
Last edited by Zacherie on Sat Apr 02, 2016 3:29 pm, edited 1 time in total.
Advocate of 20XX, Formerly Aurum Rider.
"I will be damned if I let some redtext and a WA ban ruin my game."
Frisbeeteria wrote:This is spam hackery.

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds

User avatar
Khronion
Chargé d'Affaires
 
Posts: 437
Founded: Dec 07, 2013
Inoffensive Centrist Democracy

Postby Khronion » Sat Apr 02, 2016 5:21 pm

Hats off to you for releasing the code.
Spyglass (Timesheet Generator)
If you are using a version older than 1.4.4, upgrade immediately!

User avatar
Zacherie
Spokesperson
 
Posts: 138
Founded: Apr 29, 2015
Ex-Nation

Postby Zacherie » Sat Apr 02, 2016 6:43 pm

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.
Last edited by Zacherie on Sat Apr 02, 2016 6:45 pm, edited 1 time in total.
Advocate of 20XX, Formerly Aurum Rider.
"I will be damned if I let some redtext and a WA ban ruin my game."
Frisbeeteria wrote:This is spam hackery.

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds

User avatar
Zacherie
Spokesperson
 
Posts: 138
Founded: Apr 29, 2015
Ex-Nation

Postby Zacherie » Sun Apr 03, 2016 1:56 pm

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.
Last edited by Zacherie on Sun Apr 03, 2016 2:41 pm, edited 4 times in total.
Advocate of 20XX, Formerly Aurum Rider.
"I will be damned if I let some redtext and a WA ban ruin my game."
Frisbeeteria wrote:This is spam hackery.

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds

User avatar
Eluvatar
Site Admin
 
Posts: 2175
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Sun Apr 03, 2016 7:00 pm

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?
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Zacherie
Spokesperson
 
Posts: 138
Founded: Apr 29, 2015
Ex-Nation

Postby Zacherie » Sun Apr 03, 2016 7:04 pm

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.
Advocate of 20XX, Formerly Aurum Rider.
"I will be damned if I let some redtext and a WA ban ruin my game."
Frisbeeteria wrote:This is spam hackery.

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds

User avatar
Eluvatar
Site Admin
 
Posts: 2175
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Sun Apr 03, 2016 7:36 pm

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.
To Serve and Protect: UDL

Eluvatar - Taijitu member

User avatar
Zacherie
Spokesperson
 
Posts: 138
Founded: Apr 29, 2015
Ex-Nation

Postby Zacherie » Sun Apr 03, 2016 7:42 pm

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?
Last edited by Zacherie on Sun Apr 03, 2016 7:43 pm, edited 1 time in total.
Advocate of 20XX, Formerly Aurum Rider.
"I will be damned if I let some redtext and a WA ban ruin my game."
Frisbeeteria wrote:This is spam hackery.

Aurum Rider wrote:The year is 20xx, everyone has access to a raiding tool that can give them update times accurate within 10 seconds

User avatar
Eluvatar
Site Admin
 
Posts: 2175
Founded: Mar 31, 2006
New York Times Democracy

Postby Eluvatar » Sun Apr 03, 2016 8:58 pm

Locked.
To Serve and Protect: UDL

Eluvatar - Taijitu member


Advertisement

Remove ads

Return to Technical

Who is online

Users browsing this forum: Rio Linda

Advertisement

Remove ads