File size: 6,799 Bytes
d3bcaa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{% extends 'base.html' %}
{% block title %}Interactive Map{% endblock title %}
{% block custom %}
    <style>
        .app {
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            height: 100%;
        }
        #map-container {
            height: 60vh;
            width: 100%;
            margin: 20px;
            background-color: white;
            position: relative;
            overflow: hidden;
        }
        #map {
            height: 100%;
            width: 100%;
        }
    </style>
{% endblock custom %}
{% block content %}
    <div class="app container-fluid bg-dark">
        <!-- Map placeholder -->
        <div id="map-container" class="mb-4 position-relative">
            <div id="map">
                {% if map %}
                    {{ map|safe}}
                {% endif %}
            </div>
        </div>

        
        <div class="col-md-4">
            <!-- Description underneath the map -->
            <div class="text-light mt-3">
                <p>Map Legend:</p>
                <ul>
                    <li style="color: red;">Red Stops = Average delay time is longer than one minute.</li>
                    <li style="color: rgb(57, 189, 4);">Green Stops = Average delay time is less than one minute.</li>
                    <li style="color: rgb(0, 204, 255);">Blue Stops = Average delay time is less than 0 seconds (the train usually arrives early).</li>
                </ul>
            </div>
        </div>


        <!-- Dropdown for selecting train line -->
        <form action="/map" method="POST">
            <div class="controls-container mb-3">
                <!-- choice for selecting between race or income map  -->
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="map_type" id="raceMap" value="race" {% if default_map == 'race' %} checked {% endif %}>
                            <label class="form-check-label text-bg-dark" for="raceMap">Race Map</label>
                        </div>
                        <div class="form-check form-check-inline">
                            <input class="form-check-input" type="radio" name="map_type" id="incomeMap" value="income" {% if default_map == 'income' %} checked {% endif %}>
                            <label class="form-check-label text-bg-dark" for="incomeMap">Income Map</label>
                        </div>
                    </div>
                    <!-- Dropdown for selecting train line -->
                    <div class="col-md-4 mb-3">
                        <select name="train_line" id="trainline-dropdown" class="form-select-lg">
                            <option selected value="Select Train Line">Select Train Line</option>
                            {% for train_line in train_lines %}
                                <option value="{{ train_line }}" {% if train_line == selected_train_line %}selected{% endif %}>{{ train_line }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="col-md-4 m-5">
                        <input type="submit" value="Show on Map" class="btn btn-primary">
                    </div>
                </div>
        </form>

        <div>
            <!-- Button to display the delay list -->
            <button type="button" onclick="displayDelayList()" class="btn btn-secondary">Display Delay List</button>
        
            <!-- Button to display the performance list -->
            <button type="button" onclick="displayPerformanceList()" class="btn btn-secondary">Display Performance List</button>
        </div>
        
        <!-- Placeholder for the sorted list data -->
        <div id="sortedList">
            
        </div>
    </div>
{% endblock content %}
{% block scripts %}
    
    <!-- Custom JavaScript for interactions and data loading -->
    <script>
        function displayDelayList() {
            fetch('/delay_list')
                .then(response => response.json())
                .then(data => {
                    // Update the HTML to display the delay list data
                    document.getElementById('sortedList').innerHTML = `
                        <h2 class="text-bg-dark">Total Delays (2018)</h2>
                        <table class="table">
                            <thead>
                                <tr class="table-dark">
                                    <th scope="col">Train Line</th>
                                    <th scope="col">Total Delay Time</th>
                                </tr>
                            </thead>
                            <tbody>
                                ${Object.keys(data).map(train => `
                                    <tr class="table-dark">
                                        <td>${train}</td>
                                        <td>${data[train]}</td>
                                    </tr>
                                `).join('')}
                            </tbody>
                        </table>
                    `;
                });
        }

        function displayPerformanceList() {
            fetch('/performance_list')
                .then(response => response.json())
                .then(data => {
                    // Update the HTML to display the performance list data
                    // Similar to the delay list display
                    document.getElementById('sortedList').innerHTML = `
                        <h2 class="text-bg-dark" >On-Time Performance: 2014-2023</h2>
                        <table class="table">
                            <thead>
                                <tr class="table-dark">
                                    <th scope="col">Train Line</th>
                                    <th scope="col">Average Terminal On-Time Performance</th>
                                </tr>
                            </thead>
                            <tbody>
                                ${Object.keys(data).map(train => `
                                    <tr class="table-dark">
                                        <td>${train}</td>
                                        <td>${data[train]}</td>
                                    </tr>
                                `).join('')}
                            </tbody>
                        </table>
                    `;
                });
        }

        // call the function to display the delay list by default
        displayDelayList();
    </script>
{% endblock scripts %}