Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /* Main function for processing the transport plans accepts a group of
  3.    patrons and returns an array of cars */
  4. function runTransportAlgorithm(patrons, nearbySetsList){
  5.     var driversThere = new Array();
  6.     var driversBack = new Array();
  7.     var passengersThere = new Array();
  8.     var passengersBack = new Array();
  9.  
  10.     var carsThere = new Array();
  11.     var carsBack = new Array();
  12.     var walkingThere = new Array();
  13.     var walkingBack = new Array();
  14.  
  15.     processSuburbMappings(patrons);
  16.  
  17.     console.log(patrons);
  18.  
  19.     for(var i = 0; i < patrons.length; i++){
  20.         if(patrons[i].carthere == "driving"){
  21.             driversThere.push(patrons[i]);
  22.         } else {
  23.             if(patrons[i].carthere != "none" && patrons[i].carthere != "staying"){
  24.                 passengersThere.push(patrons[i]);
  25.             }
  26.            
  27.         }
  28.         if(patrons[i].carback == "driving"){
  29.             driversBack.push(patrons[i]);
  30.         } else {
  31.             if(patrons[i].carback != "none" && patrons[i].carback != "staying"){
  32.                 passengersBack.push(patrons[i]);
  33.             }
  34.         }
  35.     }
  36.  
  37.     /* Place the drivers in their cars. The cars are arrays with the driver in the
  38.     first position */
  39.     for(var i = 0; i < driversThere.length; i++){
  40.         carsThere.push(new Array(driversThere[i]));
  41.     }
  42.     for(var i = 0; i < driversBack.length; i++){
  43.         carsBack.push(new Array(driversBack[i]));
  44.     }
  45.  
  46.     /* Process preferences */
  47.     /*for(var i = 0; i < passengersThere.length; i++){
  48.         if(passengersThere[i].carthere == "none" || passengersThere[i].carthere == "staying"){
  49.             passengersThere.splice(i, 1);
  50.         }
  51.     }
  52.  
  53.     for(var i = 0; i < passengersBack.length; i++){
  54.         if(passengersBack[i].carback == "none" || passengersBack[i].carback == "staying"){
  55.             passengersBack.splice(i, 1);
  56.         }
  57.     }*/
  58.  
  59.     for(var i = 0; i < passengersThere.length; i++){
  60.         if(passengersThere[i].carthere != "none" && passengersThere[i].carthere != "driving" &&
  61.             passengersThere[i].carthere != "staying"  && passengersThere[i].carthere != "any"){
  62.             if(driverIDIndexInCarList(carsThere, passengersThere[i].carthere) != -1){
  63.                 if(carsThere[driverIDIndexInCarList(carsThere, passengersThere[i].carthere)].length < 5){
  64.                     carsThere[driverIDIndexInCarList(carsThere, passengersThere[i].carthere)].push(passengersThere[i]);
  65.                 }
  66.             }
  67.         }
  68.     }
  69.  
  70.     removeProcessedPassengers(passengersThere, carsThere);
  71.  
  72.     for(var i = 0; i < passengersBack.length; i++){
  73.         if(passengersBack[i].carback != "none" && passengersBack[i].carback != "driving" &&
  74.             passengersBack[i].carback != "staying"  && passengersBack[i].carback != "any"){
  75.             if(driverIDIndexInCarList(carsBack, passengersBack[i].carback) != -1){
  76.                 if(carsBack[driverIDIndexInCarList(carsBack, passengersBack[i].carback)].length < 5){
  77.                     carsBack[driverIDIndexInCarList(carsBack, passengersBack[i].carback)].push(passengersBack[i]);
  78.                 }
  79.             }
  80.         }
  81.     }
  82.  
  83.     removeProcessedPassengers(passengersBack, carsBack);
  84.  
  85.     if(carsThere.length != 0){
  86.         processPlan(patrons, carsThere, walkingThere, passengersThere, nearbySetsList, "there");
  87.     }
  88.  
  89.     if(carsBack.length != 0){
  90.         processPlan(patrons, carsBack, walkingBack, passengersBack, nearbySetsList, "back");
  91.     }
  92.  
  93.     return new Array(carsThere, carsBack, walkingThere, walkingBack);
  94. }
  95.  
  96.  
  97.  
  98. function processPlan(patronsList, carsList, walkingList, passengersList, nearbySetsList, direction){
  99.     /* Remove the nearby sets that are not relevant to the current transport plan
  100.     this means that there are not at least two patrons of the nearby set that are attending the event. */
  101.     var tempPassengersList = new Array();
  102.     for(var i = 0; i < passengersList.length; i++){
  103.         tempPassengersList.push(passengersList[i])
  104.     }
  105.  
  106.     for(var i = 0; i < carsList.length; i++){
  107.         for(var j = 0; j < carsList[i].length; j++){
  108.             tempPassengersList.push(carsList[i][j]);
  109.         }
  110.     }
  111.  
  112.     var relevantNearbySets =
  113.         processNearbySetsFromPassengerList(nearbySetsList, tempPassengersList);
  114.  
  115.     /* Sort relevantNearbySets by length */
  116.     //var b = list[y];
  117.     //list[y] = list[x];
  118.     //list[x] = b;
  119.     for(var k = 0; k < 5; k++){
  120.         for(var i = 0; i < relevantNearbySets.length; i++){
  121.             if(!(i+1 >= relevantNearbySets.length)){
  122.                 if(relevantNearbySets[i].length < relevantNearbySets[i+1].length){
  123.                     var tempNBSet = relevantNearbySets[i];
  124.                     relevantNearbySets[i] = relevantNearbySets[i+1];
  125.                     relevantNearbySets[i+1] = tempNBSet;
  126.                 }
  127.             }
  128.         }
  129.     }
  130.  
  131.     /* Process the nearby sets into their cars */
  132.  
  133.     /* Process nearby sets with three passengers */
  134.     for(var i = 0; i < relevantNearbySets.length; i++){
  135.         if(relevantNearbySets[i].length == 3){
  136.             /* Find a car that has two people in it if the driver or the first passenger share the same suburb as the nearby set then add the nearby set to this car */
  137.             var tempBestCarIndex = "false";
  138.             for(var j = 0; j < carsList.length; j++){
  139.                 /*if(carsList[j].length == 1){
  140.                     if(carsList[j][0].suburb == relevantNearbySets[i][0].suburb){
  141.                         tempBestCarIndex = j;
  142.                     }
  143.                 }*/
  144.                 if(carsList[j].length == 2){
  145.                     /* If the suburb of either the driver or the first passenger is the same as the nearby set of three */
  146.                     if(carsList[j][1].suburb == relevantNearbySets[i][0].suburb || carsList[j][0].suburb == relevantNearbySets[i][0].suburb){
  147.                         tempBestCarIndex = j;
  148.                     }
  149.                     /* If the suburb of both the driver or the first passenger is the same as the nearby set of three, then push immediately */
  150.                     if(carsList[j][i].suburb == relevantNearbySets[i][0].suburb && carsList[j][0].suburb == relevantNearbySets[i][0].suburb){
  151.                         tempBestCarIndex = j;
  152.                         //addToPlan(carsList, walkingList, relevantNearbySets[i][j], driverIDIndexInCarList(carsList, bestDriver.patron_id), direction);
  153.                         break;
  154.                     }
  155.                 }
  156.             }
  157.  
  158.             /* If there is no car that has the driver or first passenger suburb the same as the suburb for the nearby set of three, then if there is no other
  159.             passenger of the same suburb as the nearby set then add the nearby set to a car with only three spaces. Otherwise leave it how it is (tempBestCarIndex = false)
  160.             and the nearby set of three will be placed in an empty car (a car with four spaces). */
  161.             if(tempBestCarIndex == "false"){
  162.                 for(var k = 0; k < passengersList.length; k++){
  163.                     if(passengersList[k].suburb == relevantNearbySets[i][0].suburb
  164.                         && passengersList[k].patron_id != relevantNearbySets[i][0].patron_id
  165.                         && passengersList[k].patron_id != relevantNearbySets[i][1].patron_id
  166.                         && passengersList[k].patron_id != relevantNearbySets[i][2].patron_id){
  167.                         tempBestCarIndex = "place in empty car";
  168.                        
  169.                     }
  170.                 }
  171.             }
  172.  
  173.             if(tempBestCarIndex != "place in empty car"){
  174.                 for(var m = 0; m < carsList.length; m++){
  175.                     if(carsList[m].length == 2){
  176.                         tempBestCarIndex = m;
  177.                         break;
  178.                     }
  179.                 }
  180.             }
  181.  
  182.             if(tempBestCarIndex == "place in empty car"){
  183.                 tempBestCarIndex = "false";
  184.             }
  185.  
  186.             if(tempBestCarIndex != "false"){
  187.                 for(var k = 0; k < relevantNearbySets[i].length; k++){
  188.                     addToPlan(carsList, walkingList, relevantNearbySets[i][k], tempBestCarIndex, direction);
  189.                 }
  190.             }
  191.         }
  192.     }
  193.  
  194.     /* Process nearby set where one of the passengers of the nearby set were processed as a preference */
  195.     for(var i = 0; i < relevantNearbySets.length; i++){
  196.         for(var j = 0; j < relevantNearbySets[i].length; j++){    
  197.             if(carIndexOfPassenger(carsList, walkingList, relevantNearbySets[i][j]) != -1){
  198.                 for(var k = 0; k < relevantNearbySets[i].length; k++){
  199.                     addToPlan(carsList, walkingList, relevantNearbySets[i][k], carIndexOfPassenger(carsList, walkingList, relevantNearbySets[i][j]), direction);
  200.                 }
  201.             }        
  202.         }
  203.     }
  204.  
  205.     /* Process the rest of the nearby sets by the closest driver to the nearby set */
  206.     for(var i = 0; i < relevantNearbySets.length; i++){
  207.         var bestDriver = calculateBestDriver(carsList, relevantNearbySets[i][0], relevantNearbySets[i].length);
  208.         for(var j = 0; j < relevantNearbySets[i].length; j++){
  209.             if(!isDriver(carsList, relevantNearbySets[i][j])){
  210.                 addToPlan(carsList, walkingList, relevantNearbySets[i][j], driverIDIndexInCarList(carsList, bestDriver.patron_id), direction);
  211.             }
  212.         }  
  213.     }
  214.  
  215.     removeProcessedPassengers(passengersList, carsList);
  216.  
  217.     /* Separate passengers into new arrays */
  218.     suburbSeparatedPassengersList = new Array();
  219.     for(var i = 0; i < passengersList.length; i++){
  220.         var processed = false;
  221.         for(var j = 0; j < suburbSeparatedPassengersList.length; j++){
  222.             if(suburbSeparatedPassengersList.length > 0){
  223.                 if(suburbSeparatedPassengersList[j][0].suburb == passengersList[i].suburb){
  224.                     suburbSeparatedPassengersList[j].push(passengersList[i]);
  225.                     processed = true;
  226.                 }  
  227.             } else {
  228.                 suburbSeparatedPassengersList.push(new Array(passengersList[i]));
  229.             }
  230.         }
  231.         if(!processed){
  232.             suburbSeparatedPassengersList.push(new Array(passengersList[i]));
  233.         }
  234.     }
  235.  
  236.     removeProcessedPassengers(passengersList, carsList);
  237.  
  238.     /*Process passengers who share a suburb with one of the suburbs that a driver is already intending to visit*/
  239.     for(var i = 0; i < passengersList.length; i++){
  240.         for(var j = 0; j < carsList.length; j++){
  241.             for(var k = 0; k < carsList[j].length; k++){
  242.                 if(passengersList[i].suburb == carsList[j][k].suburb){
  243.                     addToPlan(carsList, walkingList, passengersList[i], j, direction);
  244.                 }
  245.             }
  246.         }
  247.     }
  248.  
  249.     /* Process passengers which share the same suburb as a driver */
  250.     for(var i = 0; i < suburbSeparatedPassengersList.length; i++){
  251.         for(var j = 0; j < suburbSeparatedPassengersList[i].length; j++){
  252.             for(var k = 0; k < carsList.length; k++){
  253.                 var thisthing = suburbs[String(suburbSeparatedPassengersList[i][j].suburb).concat(carsList[k][0].suburb)];
  254.                 var sub1 = suburbSeparatedPassengersList[i][j].suburb;
  255.                 var sub2 = carsList[k][0].suburb;
  256.                 if(suburbs[String(suburbSeparatedPassengersList[i][j].suburb).concat(carsList[k][0].suburb)] == 1){
  257.                     if(carsList[k].length < 5){
  258.                         addToPlan(carsList, walkingList, suburbSeparatedPassengersList[i][j], k, direction);
  259.                         break;
  260.                     }
  261.                 }
  262.             }  
  263.         }
  264.     }
  265.  
  266.     removeProcessedPassengers(passengersList, carsList);
  267.  
  268.     for(var currentDistantRank = 0; currentDistantRank < 12; currentDistantRank++){
  269.         for(var i = 0; i < passengersList.length; i++){
  270.             var bestDriver = calculateBestDriver(carsList, passengersList[i], 1);
  271.             if(suburbs[String(bestDriver.suburb).concat(passengersList[i].suburb)] == currentDistantRank){
  272.                
  273.                 var bestCarIndex = driverIDIndexInCarList(carsList, bestDriver.patron_id);
  274.  
  275.                 /* If the car of bestdriver has length equal to four and carsList does not contain the patron's suburb in
  276.                 any of the non-full cars, and there exists a near empty (length one or two including driver). Then add to
  277.                 the near empty car */
  278.                 if(carsList[bestCarIndex].length == 4){
  279.                     /* cars list does not contain the patron's suburb in any of the non-empty cars */
  280.                     var suburbContains = false;
  281.                     for(var m = 0; m < carsList.length; m++){
  282.                         if(carsList[m].length != 5){
  283.                             for(var n = 0; n < carsList[m].length; n++){
  284.                                 if(carsList[m][n].suburb == passengersList[i].subrub){
  285.                                     suburbContains = true;
  286.                                 }
  287.                             }
  288.                         }
  289.                     }
  290.                    
  291.                     /* cars list contains a near empty car */
  292.                     var nearEmptyExists = false;
  293.                     var nearEmptyCarIndex = -1;
  294.                     for(var m = 0; m < carsList.length; m++){
  295.                         if(carsList[m].length == 1 || carsList[m].length == 2){
  296.                             nearEmptyExists = true;
  297.                             nearEmptyCarIndex = m;
  298.                         }
  299.                     }
  300.                     if(!suburbContains && nearEmptyExists){
  301.                         addToPlan(carsList, walkingList, passengersList[i], nearEmptyCarIndex, direction);
  302.                     }
  303.                 }
  304.  
  305.                 /* If the car of the bestDriver has a length of 4 and there exists more than one person with the current suburb,
  306.                 and there exists a car that can fit persons sharing the suburb then add it to that car*/
  307.                 addToPlan(carsList, walkingList, passengersList[i], driverIDIndexInCarList(carsList, bestDriver.patron_id), direction);
  308.  
  309.                 /*Process passengers who share a suburb with one of the suburbs that a driver is already intending to visit*/
  310.                
  311.                 for(var m = 0; m < passengersList.length; m++){
  312.                     for(var n = 0; n < carsList.length; n++){
  313.                         for(var o = 0; o < carsList[n].length; o++){
  314.                             if(passengersList[m].suburb == carsList[n][o].suburb){
  315.                                 addToPlan(carsList, walkingList, passengersList[m], n, direction);
  316.                             }
  317.                         }
  318.                     }
  319.                 }
  320.  
  321.             }
  322.         }
  323.     }
  324.  
  325.     removeProcessedPassengers(passengersList, carsList);
  326.  
  327.     for(var i = 0; i < passengersList.length; i++){
  328.         var bestDriver = calculateBestDriver(carsList, passengersList[i], 1);
  329.         addToPlan(carsList, walkingList, passengersList[i], driverIDIndexInCarList(carsList, bestDriver.patron_id), direction);
  330.     }
  331.  
  332.     removeProcessedPassengers(passengersList, carsList);
  333. }
  334.  
  335. function visitingSuburbs(car){
  336.     var suburbVisits = new Array();
  337.     for(var i = 0; i < car.length; i++){
  338.         suburbVisits.push(car[i].suburb);
  339.     }
  340.     return suburbVisits;
  341. }
  342.  
  343. /* Takes a set of cars and a passenger, returns the best driver for the
  344. passenger. If the most efficient driver has a full car, then the next most efficient
  345. driver that does not have a full car is the best driver. */
  346. function calculateBestDriver(cars, patron, numPatrons){
  347.     var i = 0;
  348.     var bestDriver = cars[i][0];
  349.     var currentSuburbPairRank = suburbs[String(patron.suburb).concat(cars[i][0].suburb)];
  350.     var bestCarIndex = 0;
  351.     var carSummations = new Array();
  352.     var currentAvgDistance = 99999999;
  353.     while(cars[i].length > 4 - (numPatrons - 1)){
  354.         i++;
  355.         if(i >= cars.length){
  356.             return -1;
  357.         }
  358.         bestDriver = cars[i][0];
  359.         bestCarIndex = i;
  360.         currentSuburbPairRank = suburbs[String(patron.suburb).concat(cars[i][0].suburb)];
  361.         currentAvgDistance = avgDistance(cars[i], patron);
  362.     }
  363.     /*for(; i < cars.length; i++){
  364.         if(suburbs[String(patron.suburb).concat(cars[i][0].suburb)] < currentSuburbPairRank
  365.             && cars[i].length < 5 - (numPatrons - 1)){
  366.             currentSuburbPairRank = suburbs[String(patron.suburb).concat(cars[i][0].suburb)];
  367.             bestDriver = cars[i][0];
  368.             bestCarIndex = i;
  369.         }
  370.     }*/
  371.     for(; i < cars.length; i++){
  372.         if(avgDistance(cars[i], patron) < currentAvgDistance
  373.             && cars[i].length < 5 - (numPatrons - 1)){
  374.             bestDriver = cars[i][0];
  375.             currentAvgDistance = avgDistance(cars[i], patron);
  376.             bestCarIndex = i;
  377.         }
  378.     }
  379.  
  380.    
  381.  
  382.     /* Make the best driver the driver with the least passengers but with the same suburb as the current best driver */
  383.     if(bestDriver.suburb != patron.suburb && numPatrons > 1){
  384.         for(var i = 0; i < cars.length; i++){
  385.             if(cars[bestCarIndex].length > cars[i].length &&
  386.                 cars[bestCarIndex].suburb == cars[i].suburb){
  387.                 bestDriver = cars[i][0];
  388.                 bestCarIndex = i;
  389.             }
  390.         }
  391.     }
  392.     return bestDriver;
  393. }
  394.  
  395. function avgDistance(car, patron){
  396.     var tempSum = 0;
  397.     for(var i = 0; i < car.length; i++){
  398.         tempSum = tempSum + suburbs[String(patron.suburb).concat(car[i].suburb)];
  399.     }
  400.     return tempSum/(car.length);
  401. }
  402.  
  403. function isDriver(cars, patron){
  404.     for(var i = 0; i < cars.length; i++){
  405.         if(cars[i][0].patron_id == patron.patron_id){
  406.             return true;
  407.         }
  408.     }
  409.     return false;
  410. }
  411.  
  412. function seatsRemaining(cars){
  413.     var sumOfSeats = 0;
  414.     for(var i = 0; i < cars.length; i++){
  415.         sumOfSeats = sumOfSeats + cars[i].length;
  416.     }
  417.     if(sumOfSeats >= (cars.length * 5)){
  418.         return false;
  419.     }
  420.     return true;
  421. }
  422.  
  423. function numOfSeatsRemaining(cars){
  424.     var sumOfSeats = 0;
  425.     for(var i = 0; i < cars.length; i++){
  426.         sumOfSeats = sumOfSeats + cars[i].length;
  427.     }
  428.     return (cars.length * 5) - sumOfSeats;
  429. }
  430.  
  431. function addToPlan(cars, walking, passenger, carIndex, direction){
  432.     if(seatsRemaining(cars)){
  433.         if(carIndex != -1 && cars[carIndex].length != 5){
  434.             if(!planContains(cars, walking, passenger)){
  435.                 if((direction == "there" && passenger.carthere != "none")
  436.                     || (direction == "back" && passenger.carback != "none")){
  437.                     cars[carIndex].push(passenger);
  438.                 }
  439.             }
  440.             return false;
  441.         }
  442.     } else {
  443.         if(!planContains(cars, walking, passenger)){
  444.             if((direction == "there" && passenger.carthere != "none")
  445.                 || (direction == "back" && passenger.carback != "none")){
  446.                 walking.push(passenger);
  447.             }
  448.         }
  449.         return false;
  450.         //walking.push(passenger);
  451.     }
  452. }
  453.  
  454. function planContains(cars, walking, passenger){
  455.     for(var i = 0; i < cars.length; i++){
  456.         for(var j = 0; j < cars[i].length; j++){
  457.             if(cars[i][j].patron_id == passenger.patron_id){
  458.                 return true;
  459.             }
  460.         }
  461.     }
  462.     for(var i = 0; i < walking.length; i++){
  463.         if(walking[i].patron_id == passenger.patron_id){
  464.             return true;
  465.         }
  466.     }
  467.     return false;
  468. }
  469.  
  470. function carIndexOfPassenger(cars, walking, passenger){
  471.     for(var i = 0; i < cars.length; i++){
  472.         for(var j = 0; j < cars[i].length; j++){
  473.             if(cars[i][j].patron_id == passenger.patron_id){
  474.                 return i;
  475.             }
  476.         }
  477.     }
  478.     for(var i = 0; i < walking.length; i++){
  479.         if(walking[i].patron_id == passenger.patron_id){
  480.             return -1;
  481.         }
  482.     }
  483.     return -1;
  484. }
  485.  
  486. function removeProcessedPassengers(passengersList, carsList){
  487.     for(var i = 0; i < carsList.length; i++){
  488.         for(var j = 0; j < carsList[i].length; j++){
  489.             for(var k = 0; k < passengersList.length; k++){
  490.                 if(carsList[i][j].patron_id == passengersList[k].patron_id){
  491.                     passengersList.splice(k, 1);
  492.                 }
  493.             }
  494.         }
  495.     }
  496. }
  497.  
  498. function processNearbySetsFromPassengerList(nearbySetsList, passengersList){
  499.     relevantNearbySetsList = new Array();
  500.     for(var i = 0; i < nearbySetsList.length; i++){
  501.         var tempNearbySet = new Array();
  502.         for(var j = 0; j < nearbySetsList[i].length; j++){
  503.             for(var k = 0; k < passengersList.length; k++){
  504.                 if(nearbySetsList[i][j] == passengersList[k].patron_id){
  505.                     tempNearbySet.push(nearbySetsList[i][j]);
  506.                 }
  507.             }  
  508.         }
  509.         if(tempNearbySet.length > 1){
  510.             relevantNearbySetsList.push(tempNearbySet);
  511.         }
  512.     }
  513.  
  514.     transformedNearbySetsList = new Array();
  515.     for(var i = 0; i < relevantNearbySetsList.length; i++){
  516.         var tempNearbySet = new Array();
  517.         for(var j = 0; j < relevantNearbySetsList[i].length; j++){
  518.             tempNearbySet.push(
  519.                 matchPatronIDToPatronFromList(passengersList, relevantNearbySetsList[i][j]));
  520.         }
  521.         transformedNearbySetsList.push(tempNearbySet);
  522.     }
  523.     return transformedNearbySetsList;
  524. }
  525.  
  526. /*Give a list of patrons and a patron ID then return the patron which from
  527. the patron list which matches the patron ID.*/
  528. function matchPatronIDToPatronFromList(patronList, patronId){
  529.     for(var i = 0; i < patronList.length; i++){
  530.         if(patronList[i].patron_id == patronId){
  531.             return patronList[i];
  532.         }
  533.     }
  534.  
  535. }
  536.  
  537. function getPatronIndexFromPatronList(patronsList, patronId){
  538.     contains = false;
  539.     for(var k = 0; k < patronsList.length; k++){
  540.         if(patronsList[k].patron_id == patronId){
  541.             return k;
  542.         }
  543.     }
  544.     return -1;
  545. }
  546.  
  547. function patronsListContainsPatronID(patronsList, patronId){
  548.     contains = false;
  549.     for(var k = 0; k < patronsList.length; k++){
  550.         if(patronsList[k].patron_id == patronId){
  551.             contains = true;
  552.         }
  553.     }
  554.     return contains;
  555. }
  556.  
  557. /* returns the index of a driver from a list of cars */
  558. function driverIDIndexInCarList(cars, driverId){
  559.     for(var i = 0; i < cars.length; i++){
  560.         if(cars[i][0].patron_id == driverId){
  561.             return i;
  562.         }
  563.     }
  564.     return -1;
  565. }
  566.  
  567.  
  568.  
  569. /* takes a patron and modifies the suburb field so that is useable by
  570. the algorithm */
  571. function processSuburbMappings(patrons){
  572.     for(var i = 0; i < patrons.length; i++){
  573.         if(patrons[i].suburb == "stlucia"){
  574.             patrons[i].suburb = "SL";
  575.         } else if(patrons[i].suburb == "toowong"){
  576.             patrons[i].suburb = "TW";
  577.         } else if(patrons[i].suburb == "taringa"){
  578.             patrons[i].suburb = "TR";
  579.         } else if(patrons[i].suburb == "auchenflower"){
  580.             patrons[i].suburb = "AU";
  581.         } else if(patrons[i].suburb == "indooroopilly"){
  582.             patrons[i].suburb = "IN";
  583.         } else if(patrons[i].suburb == "chapelhill"){
  584.             patrons[i].suburb = "CA";
  585.         } else if(patrons[i].suburb == "kelvingrove"){
  586.             patrons[i].suburb = "KA";
  587.         } else if(patrons[i].suburb == "woolongabba" || patrons[i].suburb == "duttonpark"
  588.             || patrons[i].suburb == "fairfield" || patrons[i].suburb == "annerley"){
  589.             patrons[i].suburb = "WA";
  590.         } else if(patrons[i].suburb == "oxley" || patrons[i].suburb == "sherwood"
  591.             || patrons[i].suburb == "corinda"){
  592.             patrons[i].suburb = "OA";
  593.         } else if(patrons[i].suburb == "sunnybank" || patrons[i].suburb == "willawong"
  594.             || patrons[i].suburb == "logan"){
  595.             patrons[i].suburb = "WA";
  596.         }
  597.     }
  598. }
  599.  
  600. // setTimeout(function(){
  601. //    window.location.reload(1);
  602. // }, 120000);
  603.  
  604. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement