This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Add query arg for delay parameter on lines #2
Open
khwilson
wants to merge
4
commits into
blahblahblah-:master
Choose a base branch
from
khwilson:add-query-arg-for-delay-parameter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
MTA_KEY=<<YOUR API KEY>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,19 @@ import LinePane from "./linePane.jsx"; | |
import StarredPane from "./starredPane.jsx"; | ||
import sampleData from "../data/sampleData.js"; | ||
import { Parallax, Background } from 'react-parallax'; | ||
import qs from 'query-string'; | ||
import * as Cookies from 'es-cookie'; | ||
|
||
const API_URL = '/api/info'; | ||
const TEST_DATA = false; | ||
|
||
function getQueryStringValue (key) { | ||
return decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURIComponent(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")); | ||
} | ||
|
||
// Would write the value of the QueryString-variable called name to the console | ||
console.log(getQueryStringValue("name")); | ||
|
||
class LandingPage extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
@@ -241,9 +249,43 @@ class LandingPage extends React.Component { | |
if (TEST_DATA) { | ||
this.setState({ trains: sampleData.routes, lines: sampleData.lines, loading: false }); | ||
} else { | ||
let params = qs.parse(location.search); | ||
let use_median = params.median && params.median === 'true'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just tiny nitpick, let's keep variable names camelCase. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, don't think we need the first half of the evaluation if we are evaluating with |
||
let bad_service_threshold = parseInt(params.bad_service_threshold) || 2; | ||
|
||
let statusFromLines = function(lines) { | ||
for (let boro in lines) { | ||
for (let line of lines[boro]) { | ||
if (line.status == "Delay") { | ||
// Let delays be handled as in Ruby for now | ||
continue; | ||
} | ||
|
||
let scheduled = use_median ? line.median_scheduled_headway : line.max_scheduled_headway; | ||
let actual = use_median ? line.median_actual_headway : line.max_actual_headway; | ||
if (!scheduled) { | ||
// Just use the default in the Ruby for now | ||
continue; | ||
} | ||
|
||
if (actual - scheduled > bad_service_threshold) { | ||
line.status = "Not Good"; | ||
} else { | ||
line.status = "Good Service"; | ||
} | ||
} | ||
} | ||
return lines; | ||
} | ||
fetch(API_URL) | ||
.then(response => response.json()) | ||
.then(data => this.setState({ trains: data.routes, lines: data.lines, blogPost: data.blog_post, timestamp: data.timestamp, loading: false })) | ||
.then(data => this.setState({ | ||
trains: data.routes, | ||
lines: statusFromLines(data.lines), | ||
blogPost: data.blog_post, | ||
timestamp: data.timestamp, | ||
loading: false | ||
})) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,16 +23,60 @@ def delay | |
|
||
def max_actual_headway | ||
@max_actual_headway if @max_actual_headway | ||
compute_actual_headways | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's revert changes of this file until the feature is implemented for routes as well. |
||
@max_actual_headway | ||
end | ||
|
||
def median_actual_headway | ||
@median_actual_headway if @median_actual_headway | ||
compute_actual_headways | ||
@median_actual_headway | ||
end | ||
|
||
def max_scheduled_headway | ||
@max_scheduled_headway if @max_scheduled_headway | ||
compute_scheduled_headways | ||
@max_scheduled_headway | ||
end | ||
|
||
def median_scheduled_headway | ||
@median_scheduled_headway if @median_scheduled_headway | ||
compute_scheduled_headways | ||
@median_scheduled_headway | ||
end | ||
|
||
def headway_discreprency | ||
return nil if trips.empty? | ||
max_actual_headway - max_scheduled_headway if max_scheduled_headway | ||
end | ||
|
||
private | ||
|
||
attr_accessor :trips, :stop_times, :line_direction, :route_id, :timestamp | ||
|
||
def compute_actual_headways | ||
times = trips.map { |t| | ||
t.upcoming_line_directions[line_direction] | ||
} | ||
times << trips.first.timestamp if times.size == 1 | ||
@max_actual_headway = times.sort.each_cons(2).map { |a,b| (b - a) / 60 }.max | ||
headways = times.sort.each_cons(2).map { |a, b| (b - a) } | ||
len = headways.size | ||
if len == 0 | ||
@max_actual_headway = nil | ||
@median_actual_headway = nil | ||
return | ||
end | ||
@median_actual_headway = ((headways[(len - 1) / 2] + headways[len / 2]) / 2.0) / 60 | ||
@max_actual_headway = headways.max / 60 | ||
end | ||
|
||
def max_scheduled_headway | ||
@max_scheduled_headway if @max_scheduled_headway | ||
return nil if stop_times[line_direction.last_stop].nil? | ||
def compute_scheduled_headways | ||
if stop_times[line_direction.last_stop].nil? | ||
@median_scheduled_headway = nil | ||
@max_scheduled_headway = nil | ||
return nil | ||
end | ||
|
||
st = stop_times[line_direction.last_stop].select { |st| st.trip.route_internal_id == route_id} | ||
if line_direction.kind_of?(ExpressLineDirection) | ||
st.reject! { |st| | ||
|
@@ -41,18 +85,18 @@ def max_scheduled_headway | |
} | ||
} | ||
end | ||
times = st.map(&:departure_time) | ||
@max_scheduled_headway = treat_times(times).sort.each_cons(2).map { |a,b| (b - a) / 60 }.max | ||
end | ||
headways = treat_times(st.map(&:departure_time)).sort.each_cons(2).map { |a, b| (b - a) } | ||
len = headways.size | ||
if len == 0 | ||
@max_scheduled_headway = nil | ||
@median_scheduled_headway = nil | ||
return nil | ||
end | ||
|
||
def headway_discreprency | ||
return nil if trips.empty? | ||
max_actual_headway - max_scheduled_headway if max_scheduled_headway | ||
@max_scheduled_headway = headways.max / 60 | ||
@median_scheduled_headway = ((headways[(len - 1) / 2] + headways[len / 2]) / 2.0) / 60 | ||
end | ||
|
||
private | ||
|
||
attr_accessor :trips, :stop_times, :line_direction, :route_id, :timestamp | ||
|
||
def treat_times(times) | ||
if (timestamp + 60.minutes).to_date == (timestamp.to_date + 1.day) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this if we already import
query-string
?