AirwaySim
Online Airline Management Simulation
Login
Username
Password
 
or login using:
 
My Account
Username:
E-mail:
Edit account
» Achievements
» Logout
Game Credits
Credit balance: 0 Cr
Buy credits
» Credit history
» Credits FAQ

Author Topic: [-] 7-day flight collapser  (Read 814 times)

Offline LemonButt

  • Members
  • Posts: 1895
[-] 7-day flight collapser
« on: October 05, 2013, 07:49:46 PM »
There have been several requests for a "7-day flight collapser" that cleans up the route timetables as they can get very messy and difficult to read with multi-day scheduling.  I finally got off my butt and wrote some JavaScript to solve this problem.  It was a challenge, but was actually WAY easier than I thought it would be.  JavaScript is a client side language that runs in your web browser, so there is no extra load on the server (just your computer).  Attached are screenshots and the code (sami--I have an annotated js file if you want it--forum won't let me attach js or txt files).

How to use it:

Hopefully sami will incorporate it somehow for all game worlds down the line (there are some issues to work out as to how it executes etc. because it can freeze the browser on large timetables).  Right now it is setup so that the player hovers over the "Route Planning" link on timetables and it will collapse the flights.  AWS players can use this TODAY by doing the following:

1. Go to a timetable page.
2. Copy/paste the below code into the address bar:

Quote
javascript:$(document).ready( function() { $("a[title='Route planning']").parents('td').css('background-color','#CFDBC5').css('color','#FFF'); $("a[title='Route planning']").hover( function() { if ($(this).attr('collapsed')) return false; $(this).attr('collapsed','yes'); var flight = new Array(); var n = 1; flight[n] = $(this).parents('tr').next('tr').next('tr'); while (isNaN($(flight[n++]).next('tr').children('td:first-child').attr('colspan'))) flight[n] = $(flight[n-1]).next('tr'); $.each(flight, function(n, v) { if ($(flight[n]).children('td:nth-child(1)') != "1234567" && n > 0) { if ($(flight[n]).children('td:nth-child(6)').html() == $(flight[n-1]).children('td:nth-child(6)').html() && $(flight[n]).children('td:nth-child(5)').html() == $(flight[n-1]).children('td:nth-child(5)').html() && $(flight[n]).children('td:nth-child(4)').html() == $(flight[n-1]).children('td:nth-child(4)').html() && $(flight[n]).children('td:nth-child(3)').html() == $(flight[n-1]).children('td:nth-child(3)').html()) { $(flight[n]).children('td:nth-child(1)').html($(flight[n-1]).children('td:nth-child(1)').html()+$(flight[n]).children('td:nth-child(1)').html()); $(flight[n]).children('td:nth-child(2)').html($(flight[n-1]).children('td:nth-child(2)').html()+$(flight[n]).children('td:nth-child(2)').html()); var days = $(flight[n]).children('td:nth-child(1)').html(); var dayz = ''; if (days.match(/1/)) dayz = dayz+'1'; else dayz = dayz+'-'; if (days.match(/2/)) dayz = dayz+'2'; else dayz = dayz+'-'; if (days.match(/3/)) dayz = dayz+'3'; else dayz = dayz+'-'; if (days.match(/4/)) dayz = dayz+'4'; else dayz = dayz+'-'; if (days.match(/5/)) dayz = dayz+'5'; else dayz = dayz+'-'; if (days.match(/6/)) dayz = dayz+'6'; else dayz = dayz+'-'; if (days.match(/7/)) dayz = dayz+'7'; else dayz = dayz+'-'; $(flight[n]).children( 'td:nth-child(1)').html(dayz); $(flight[n-1]).hide(); } } }); }); });

3. If you did it successfully, the "Route Planning" links will have a green background.
4. Hover over the green "Route Planning" links to collapse flights.

How it works:

The script creates an event "listener" that triggers when you hover the "Route Planning" link.  When it executes, it searches for the table rows that displays the flights.  When it finds "similar" flights, it collapses them into one table row.  "Similar" is defined as two flights having the same airline, aircraft, and departure time.  You will notice if 7-day scheduling is used with two different aircraft types, even if it is B734 and B735 then it will not collapse the flights into a single row, but will still group flights using the same aircraft model.

I'm sure I violated some sort of AWS Terms of Use or other policy by doing this, but I'm hoping sami will be gentle on me :)
« Last Edit: October 07, 2013, 04:47:55 PM by sami »

Offline Sami

  • Administrator
  • Members
  • Posts: 14535
    • AirwaySim - Are you the next Richard Branson?
Re: 7-day flight collapser
« Reply #1 on: October 05, 2013, 07:58:52 PM »
Yea, you are a huge criminal now  ;D but pls mail the js to sami at airwaysim. I'll check it out too (though not usable directly as I will surely assign unique id's etc for the fields then and so forth, when I eventually build the "real" code)

Offline LemonButt

  • Members
  • Posts: 1895
Re: 7-day flight collapser
« Reply #2 on: October 05, 2013, 08:01:07 PM »
I'm emailing now sami.  I also just realized you can create a bookmarklet for this to run the code.  If you create a new bookmark where the URL is the following, you can run the JavaScript without having to copy/paste all the time and can just click a button when you're on the timetable page:

Quote
javascript:$(document).ready( function() { $("a[title='Route planning']").parents('td').css('background-color','#CFDBC5').css('color','#FFF'); $("a[title='Route planning']").hover( function() { if ($(this).attr('collapsed')) return false; $(this).attr('collapsed','yes'); var flight = new Array(); var n = 1; flight[n] = $(this).parents('tr').next('tr').next('tr'); while (isNaN($(flight[n++]).next('tr').children('td:first-child').attr('colspan'))) flight[n] = $(flight[n-1]).next('tr'); $.each(flight, function(n, v) { if ($(flight[n]).children('td:nth-child(1)') != "1234567" && n > 0) { if ($(flight[n]).children('td:nth-child(6)').html() == $(flight[n-1]).children('td:nth-child(6)').html() && $(flight[n]).children('td:nth-child(5)').html() == $(flight[n-1]).children('td:nth-child(5)').html() && $(flight[n]).children('td:nth-child(4)').html() == $(flight[n-1]).children('td:nth-child(4)').html() && $(flight[n]).children('td:nth-child(3)').html() == $(flight[n-1]).children('td:nth-child(3)').html()) { $(flight[n]).children('td:nth-child(1)').html($(flight[n-1]).children('td:nth-child(1)').html()+$(flight[n]).children('td:nth-child(1)').html()); $(flight[n]).children('td:nth-child(2)').html($(flight[n-1]).children('td:nth-child(2)').html()+$(flight[n]).children('td:nth-child(2)').html()); var days = $(flight[n]).children('td:nth-child(1)').html(); var dayz = ''; if (days.match(/1/)) dayz = dayz+'1'; else dayz = dayz+'-'; if (days.match(/2/)) dayz = dayz+'2'; else dayz = dayz+'-'; if (days.match(/3/)) dayz = dayz+'3'; else dayz = dayz+'-'; if (days.match(/4/)) dayz = dayz+'4'; else dayz = dayz+'-'; if (days.match(/5/)) dayz = dayz+'5'; else dayz = dayz+'-'; if (days.match(/6/)) dayz = dayz+'6'; else dayz = dayz+'-'; if (days.match(/7/)) dayz = dayz+'7'; else dayz = dayz+'-'; $(flight[n]).children( 'td:nth-child(1)').html(dayz); $(flight[n-1]).hide(); } } }); }); });

Also, the script doesn't care if the 7-day scheduling isn't in "order" as shown by the attached screenshots.

BD

  • Former member
Re: 7-day flight collapser
« Reply #3 on: October 05, 2013, 08:34:56 PM »
Nice idea and great model.

How would this work/look if you have to bump the time on a particular day of the week?

I'm assuming the oddball one drops out, but the other six remain in one line - correct?

Also, do the flightids remain "clickable" (i.e. click to open the route - if they are yours)?
« Last Edit: October 05, 2013, 08:37:53 PM by BD »

Offline LemonButt

  • Members
  • Posts: 1895
Re: 7-day flight collapser
« Reply #4 on: October 05, 2013, 08:40:18 PM »
Nice idea and great model.

How would this work/look if you have to bump the time on a particular day of the week?

I'm assuming the oddball one drops out, but the other six remain in one line - correct?

Also, do the flightids remain "clickable" (i.e. click to open the route - if they are yours)?

You can see in the first screenshot that the last flights are 6 days/1 day because they have different times.  I assume that's what you meant when you said "bump the time".

All flight links are preserved (see first screenshot and links remain underlined).

Offline meiru

  • Members
  • Posts: 745
Re: 7-day flight collapser
« Reply #5 on: October 05, 2013, 10:23:40 PM »
Yes, that's one solution, but it can be easier, if he'd drop the restriction, that flight numbers have to be unique... but then I'd also like to see the pages of e.g. the aircraft talking about flights and no longer routes... because, currently I have aircrafts with 3 routes and such with 14 ... but the 14 routes is 14 flights and the 3 is 21... so... I think it needs something more, but no database change, just some small beautification of the UI...

Online JumboShrimp

  • Members
  • Posts: 5991
Re: 7-day flight collapser
« Reply #6 on: October 06, 2013, 12:34:42 AM »
Full solution would be preferable, one where you would see the 7 lets as one flight, so that you could see daily results on one flight...

Route screen would be a lot less crowded as a result.

Offline meiru

  • Members
  • Posts: 745
Re: 7-day flight collapser
« Reply #7 on: October 06, 2013, 11:40:35 AM »
Yes, but that's like in politics... you bether take the small solution than try to get the large and fail. ... I remember, that maybe 2 years ago sami said, that there will never ever be a 7-day scheduling in this game... so, bether getting an improved UI than nothing.

Offline LemonButt

  • Members
  • Posts: 1895
Re: 7-day flight collapser
« Reply #8 on: October 06, 2013, 03:07:56 PM »
Having identical flight numbers for every day of the week in a XXX-D format would require a row in the database to have 7 additional columns to associate aircraft with the flight.  Every time you do an insert statement on the database, it updates the indexes, of which we'd be adding 7 indexes to the flights database alone.  Updating an index is like finding the right spot in a phone book to put a name--it can be very cpu intensive.  This is why there is a small lag when you create and/or delete a flight--the insert/delete statements are updating the indexes.

If you were to do it this way, you'd have to not only update 7 additional indexes, but you'd also have to create a long, complex select statement to check against all 7 indexes and/or run 7 separate select statements to get the data out of the database.  This would effectively create a seven-fold increase on the server, which would slow everything down.  On top of players working the server, there are also cron jobs happening on the server asynchronously to update the database with numbers, such as how many people flew on a flight every day, updating revenue numbers, etc.

So the long story short is unless sami increases computing power sevenfold (it would probably need to be more like fivefold), then it is better to have 7-day flights the way they are.  The most logical solution is to just change how they are displayed to users versus drastically changing the database table structures and rewriting large chunks of game code.  Hope this helps.

Offline meiru

  • Members
  • Posts: 745
Re: 7-day flight collapser
« Reply #9 on: October 06, 2013, 03:54:25 PM »
Correct... if the flight number (what is it? a string?) is indexed and if not an other (maybe artificial) primary key exists... (that's how I would have designed it) ... but... if we don't know that, and if you're right, then it's really the best just to update the output... maybe by only displaying one flight number (the smallest?) after combining the flights for output... something like that should work... and if you don't want extra cpu time on your server, put it into javascript (I don't like the idea, but if computational power is a problem, that's an easy to implement solution for the moment).
Or... even easier... don't use things like SQL servers... since... well, that's going too far and mostly nobody want's to hear it  ;D but it's my job to work with such things.

BD

  • Former member
Re: 7-day flight collapser
« Reply #10 on: October 06, 2013, 04:37:55 PM »
You can see in the first screenshot that the last flights are 6 days/1 day because they have different times.  I assume that's what you meant when you said "bump the time".

All flight links are preserved (see first screenshot and links remain underlined).
Thanks for your reply.  I concentrated too much on the image in the other post.  :P

Looks good to me.

Offline Sami

  • Administrator
  • Members
  • Posts: 14535
    • AirwaySim - Are you the next Richard Branson?
Re: 7-day flight collapser
« Reply #11 on: October 06, 2013, 08:35:40 PM »
As per the other thread of the same subject, this will be done so that flight number does not have to be unique for each flight anymore. In other words you can have up to 7 different individual flights on the same flt number if they are to the same destination, but on different days. Does not have to be the same plane or same schedule, just same destination and different day.

Those flights are then grouped in the airport schedule view but displayed individually in all other views (manage routes, scheduling etc). Doesn't need any database structure changes.

Offline meiru

  • Members
  • Posts: 745
Re: 7-day flight collapser
« Reply #12 on: October 06, 2013, 09:40:21 PM »
Sounds great. Can you also switch from "route count"-numbers to "flight count"-numbers on different pages ? So that we can compare those numbers clearly.

Offline Sami

  • Administrator
  • Members
  • Posts: 14535
    • AirwaySim - Are you the next Richard Branson?
Re: 7-day flight collapser
« Reply #13 on: October 07, 2013, 04:47:50 PM »
http://www.airwaysim.com/forum/index.php/topic,26356.msg277270.html#msg277270

(= pls start using the same flt numbers now on these routes using the 7day method   ... if people still after some months tend to use different number of each flight, then I'll have to make another module to this as per this thread, but I hope these changes made now are sufficient)
« Last Edit: October 07, 2013, 04:57:46 PM by sami »

Offline Cardinal

  • Members
  • Posts: 967
Re: 7-day flight collapser
« Reply #14 on: October 08, 2013, 10:38:22 AM »
(= pls start using the same flt numbers now on these routes using the 7day method   ... if people still after some months tend to use different number of each flight, then I'll have to make another module to this as per this thread, but I hope these changes made now are sufficient)

Is this something I'm going to be forced into at some point? Because unlike most players I'm sure, I micromanage my flight numbers. It is kind of a pain in the beginning but it pays off dividends in route management later on. And with the scheduling screen not showing the day of the week in collapsed view, the flight number method I came up with is a way around that. (First digit of flight # = day of week) I rarely schedule my planes one route at a time because the scheduling screen causes memory leaks in Firefox so I try to minimize reloads (after a certain number of reloads of the scheduling screen I have to restart). Which means I usually create several routes first and then assign them to planes in large groups = fewer reloads.


 

WARNING! This website is not compatible with the old version of Internet Explorer you are using.

If you are using the latest version please turn OFF the compatibility mode.