-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure character birth century #208
Conversation
helpers/date_helper.rb
Outdated
def self.ensure_century(date) | ||
return if date.nil? | ||
|
||
adjustment = (date.year < 1999) ? 2000 : 0 | ||
date + adjustment.years | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only 19xx
date is 1999
, which was retail -- It seems to have been consistently with a century.
Any uploaded birth without a century going forward is assumed to be 20xx
. This means this will be incorrect during the year 3000+. Even if Asheron's Call and Treestats.net live that long, I can confidently say we won't. 😉
def self.parse_birth(birth) | ||
DateTime.strptime("#{birth} EST", "%m/%d/%Y %H:%M:%S %p %Z") | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is unused.
Thanks for taking the initiative on this @jkisor. I will try to take a look at this in the first part of this upcoming week. As a heads up, I think my preferred plan here will be to do a better job parsing squirrely birth values at upload-time and assuming any birth values stored in the db are correct and can be used/displayed without modification. Makes things simpler all around. And I'd want to follow that up with some general cleanup like nulling birth values like |
Sorry for taking longer than I had hoped to look over this @jkisor. As with your other recent PRs, thank you for the diligence in describing the issue and providing solutions and rationale. It helps me dive in more quickly than I otherwise would. I took a look at the database and noticed basically two types of bad values for birth:
I'm not sure what causes the first, but it's clear that some code is catching a null which gets turned into the UNIX epoch datetime. Maybe this has been fixed in emulator updates. For (2), what's really going on is that I screwed up a long time ago before I knew any better and handled dates in a non-culture-invariant way: amoeba/treestats#34. You may be familiar, but it simplifies everyone's life if the plugin just handles dates invariant of culture (locale), I didn't do that, and now we have bad data. Since it's only a few records out of the whole and it's ultimately an issue I can fix from the plugin side, I'm inclined to avoid changes to the site and would rather fix the values directly in the database and fix the plugin. I went ahead and did that in 1c3f242 and things look good again. I effectively followed your Cleanup strategy, just with a slightly modified script. It does look like active players are the cause of some of the odd values for birth so this might crop up again. I'm going to keep an eye on things and work on getting a new version of the plugin out with amoeba/treestats#34. Thanks for taking such an interest and working up these detailed PRs. It really does help the projects, even if I don't merge everything. |
Issue: #193
Root cause
Modern uploads from emulators appear to be uploading some birth dates with no century. For example,
01/01/20
is uploaded instead of01/01/2020
. Treestats.net expects format%m/%d/%Y
seen hereDate.strptime
returns a year of0020
which reproduces the issue.Solutions
There's three parts to the solution:
NOTE: I've solved all three, but you can pair the "Write" and "Cleanup" solutions while omitting the "Read" solution if you like. This will make the diff much smaller.
Points of interest (main branch)
Here's all the locations in the code for reading and writing. Let me know if there I've missed any.
For writing (1) :
treestats.net/routes/upload.rb
Lines 69 to 79 in 4dc8a0f
For reading (4):
treestats.net/helpers/account_helper.rb
Line 42 in 4dc8a0f
treestats.net/helpers/rankings_helper.rb
Line 466 in 4dc8a0f
treestats.net/views/_other_pane.haml
Line 7 in 4dc8a0f
treestats.net/routes/server.rb
Line 65 in 4dc8a0f
Cleanup
Run
bundle exec rake cleanup_birth
Sample output:
The task can be re-run to ensure it finds
0
.