]> gitweb.michael.orlitzky.com - charm-bypass.git/blobdiff - index.html.in
index.html.in: add a few more MARC Train zone mappings
[charm-bypass.git] / index.html.in
index c073221bb9eaec2f02c9826117b587f1b1436f8e..f6094fafa999961ba1abeb17c9f80968f1387903 100644 (file)
@@ -4,13 +4,14 @@
     <meta name="viewport" content="width=device-width, initial-scale=1" />
 
     <title>
-      CharmBypass: transit equity whether you like it or not
+      CharmBypass: you're getting transit equity whether you like it
+      or not
     </title>
 
     <style>
       input[type=submit] {
-       margin-top: 1em;
-       margin-bottom: 1em;
+        margin-top: 1em;
+        margin-bottom: 1em;
       }
 
       svg {
       #citycopy {
         /* The city moves faster than the clouds but slower
          * than the trees */
-       animation: citycopyscroll 35s linear infinite;
+        animation: citycopyscroll 35s linear infinite;
       }
     </style>
   </head>
   <body>
     <div id="menu">
       <h1>CharmBypass</h1>
-      <h2>transit equity whether you like it or not</h2>
+      <h2>you're getting transit equity whether you like it or not</h2>
       <form>
         <fieldset>
           <legend>BaltimoreLink (Bus, Light Rail, Metro)</legend>
         }
       }
 
+
+      /*******************************************************/
+      /* Compute the MARC "zone" from its origin/destination */
+      /*******************************************************/
+
+      /* Sorted on the first component, then the second */
+      const zone_map = {
+        BAL_BWE: 2,
+        BAL_BWI: 1,
+        BAL_SEB: 3,
+        BAL_WAS: 4,
+        BAL_WBL: 1,
+        BCA_CPK_: 3,
+        BCA_WAS_: 4,
+        BWI_BWE: 1,
+        BWI_WAS: 3,
+        BWI_WBL: 1
+      };
+
+      /* The default. Obviously wrong for when we don't
+       * have the necessary data. */
+      let zone = 0;
+
+      function compute_marc_zone(src, dest) {
+        /* Forward direction key for zone_map */
+        const fwd = src + "_" +  dest;
+
+        /* Reverse direction key for zone_map. The zone_map only
+         * has them listed in one direction, so we check both
+         * directions here. */
+        const rev = dest + "_" +  src;
+
+        if (zone_map[fwd]) {
+          zone = zone_map[fwd];
+        }
+        else if (zone_map[rev]) {
+          zone = zone_map[rev];
+        }
+
+        /* Convert the number to a string */
+        switch (zone) {
+          case 1:
+            return "One Zone";
+          case 2:
+            return "Two Zone";
+          case 3:
+            return "Three Zone";
+          case 4:
+            return "Four Zone";
+          default:
+            return "??? Zone";
+        }
+      }
+
+      function set_marc_zone() {
+        const params = new URLSearchParams(document.location.search);
+        if (params.get("origin") && params.get("destination")) {
+          const src = params.get("origin");
+          const dest = params.get("destination");
+          const zone = compute_marc_zone(src, dest);
+
+          /* TODO: actually set the zone */
+          alert(zone);
+        }
+      }
+
       /******************************************/
       /* Display the ticket (and hide the menu) */
       /******************************************/
         /* Set the ticket expiration date/time upon page load */
         window.addEventListener("load", set_ticket_expiry);
 
+       /* Set the MARC Train zone, if applicable */
+       window.addEventListener("load", set_marc_zone);
+
         /* Swap colors when the screen is tapped */
         document.body.addEventListener("click", swap_colors);
       }