So, which making an NPM library to interface with Amtrak's train tracking API, I decided to make it in TS as a little challenge to myself, to learn something new, and to just make everything cleaner. While making types for the trainData, I realized that there were numbers, "arrays", and dates stored as strings, not their actual type.
Good news is that I now plan on having trainDataRaw and trainData, with the first being what I get from the API, and the second is a conversion of the first with the correct data types.
That too, just these seem to be kinda in 8601, just already adjusted to different timezones, without said timezones included in the response. Some times are always eastern, some where the train is, and some where the train originated. Its horrid.
Yup. Go to https://replit.com/@piemadd/amtrak and hit the run button, the output will print out, all 33k lines lmao (note it takes some time to run since its building a nix env and the ts firs)
Looks like they probably migrated to some ORM library that had updated at and created at, which is pretty common now since Ruby on Rails kinda popularised them.
The rest of the fields are probably ancient ones they just keep migrating around, wouldn't doubt this is an almost raw Database schema dump or done for backwards compatibility
This scema has been around for 3 years from when Amtrak introduced the tracking, though I don't doubt it. They definitely tracked all of the trains themselves beforehand.
The snake case smacks of default rails behaviour. They're probably using their own conventions (that include a lot of anxious naming of fields that refer to acronyms) because they've come from some other stack
35
u/ImplosiveTech Sep 06 '21
So, which making an NPM library to interface with Amtrak's train tracking API, I decided to make it in TS as a little challenge to myself, to learn something new, and to just make everything cleaner. While making types for the trainData, I realized that there were numbers, "arrays", and dates stored as strings, not their actual type.
Good news is that I now plan on having trainDataRaw and trainData, with the first being what I get from the API, and the second is a conversion of the first with the correct data types.
13
u/alexanderhameowlton Sep 06 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
7
u/Bit5keptical Sep 07 '21
The line number is giving me anxiety.
3
u/DelusionalPianist Sep 07 '21
I wonder what kind of sophisticated measurements devices they have to determine the speed of a train with that accuracy!
2
u/Sn0wCrack7 Sep 07 '21
Looks like they probably migrated to some ORM library that had updated at and created at, which is pretty common now since Ruby on Rails kinda popularised them.
The rest of the fields are probably ancient ones they just keep migrating around, wouldn't doubt this is an almost raw Database schema dump or done for backwards compatibility
13
u/alago1 Sep 06 '21
Why would I use 4 bytes to represent something that I can represent in 4+4*log(n) bytes???
0
u/[deleted] Sep 06 '21
[deleted] — view deleted comment