Index
Metro Schedule App
Once again, it started bored in class, just a year later. This class is the worst bythe way, they gave us a group of 10 people to make the work that would take 3 or 4 people. Besides that, the expectations the teacher has for us are about as high as a kindergarden. Take note that I say "in class" as a very vague term, I have a really stupid habit. I hate arriving just in time, so I like to get to class a little early....... 2 hours. I wake up at 7am so I can be in the classroom alone for almost 2 hours. In that time I get most of my ideas though.
Here in Portugal we have an app for the buses where you choose a stop and it will tell you the next buses that will arrive over the next hour or so. However, for the metros, there is no such thing, so I usually keep the pdf with the timetables tabbed on my phone, and it's a pain to use on a tiny screen. Arriving to "class" one day I remembered that I had gotten a bunch of experience with .json files the previous semester because of a project (I don't think it's serious enough to note it in here, I just did the coding for a "choose your own adventure" site).
So I went to the site of Metro do Porto (Is it really doxxing myself when my country only has 2 populated
cities?) and looked for any download links that would have the metro schedules. I was fully expecting to
having to exatract the numbers from the pdf to an excel spreadsheet. But, to my surprise, they actually had
the schedules on a GTFS format. Do you know what that is? I shure as hell didn't, but it turns
out to be the standart way to format shedules for google services. In the GTFS format, you have a
zip folder with various txt documents organized like:
BU0,6:01:00,6:01:00,5708,0,,,,
.
My first instinct was to find which one of these files had the times (it was calendar.txt) and I could probably do this entire project with little more than awk.
So instead, I spent the first entire day trying to find a way to convert GTFS to json.
And of the second I gave up and make a script with awk to convert those files to a giant json with only the information I cared about....
And then I decided to use linux's built-in jq command instead of actualy JavaScript......
...
Now that I type this I see how stupid it trully was............
At the moment of writting, it is still a work-in-progress, but I can give some insigth to the problems I faced. I had to divide the task in many micro problems and solve them 1 by 1, so I think I can just decribe some of them.
With the giant Json made, I had to figure out what I wanted to show the user. The easiest part by far. Get the date to figure out if I needed the schedule for Saturday, Sunday or Weekdays. Secondly, asking the user to say what station they were in and printing a list of all metros that go there in that schedule. But that caused me a really stupid problem. There are multiples files inside the zip folder that I downloaded, and my script to turn them into json files only worked for one at a time, and the file with the metro times was different than the one with the station names so it only used ids. So I had to run a new file throught the script and make the programme take the inpute station name and look for the correspondent station id. And with that, I could finally dig for times.
Listen, this is not my finest coding moment.
After that, made the user specify the exact metro line so that I can look for the perfect trip ids to print out. Then I realised I had a new problem where I have no way of looking for every single metro line looking for metros. Instead I can only see one line at time, and, sure, that is usefull for 80% of the metro users, but still not ideal. And I am currently working on it.... whenever I feel like.
Lastly, there's directions. Which were not that hard to implement, just counter intuitive. The trip ids for each combination of line and schedule go up to 99, 0..49 for direction 1 and 50..99 for direction 2. So I just threw it in a for loop and called it a day.
Maps
As you can probably tell by now, whenever I get bored in class, I seem to go deeper into the spectrum.
There are a few projects that have started from my boredom, but most of them aren't big enough for me to document, that's why I'm making thes page. Here are some of the weird dumb projects I do to pass the time.
I take pictures of maps and try to make them look realistic
I know this sounds like the most utterly specific hobbie ever thought of......There's no "but", that's it.
Here are the ones I have so far
I don't know why I do this, but it is quite fun.