Big chunk of work

This commit is contained in:
ronreg-ribdev 2020-06-04 03:57:18 -07:00
parent 701a55ce29
commit e4bd7d3ced
2 changed files with 60 additions and 17 deletions

View File

@ -113,12 +113,14 @@ class RouteSearch extends Component {
constructor(props) {
super(props);
const now = new Date();
const hours = now.getHours();
this.state = {
fromStation: "",
toStation: "",
depart: 'now',
min: now.getMinutes(),
hour: now.getHours(),
hour: hours === 0 ? 12 : hours % 12,
isPM: hours >= 12
};
}
@ -134,7 +136,11 @@ class RouteSearch extends Component {
evt.preventDefault();
api.action("bartinfo", "json", {
from: this.state.fromStation,
to: this.state.toStation});
to: this.state.toStation,
min: this.state.min,
hour: this.state.hour,
isPM: this.state.isPM,
});
}
changeStation(evt) {
@ -155,10 +161,12 @@ class RouteSearch extends Component {
setDepartAt(evt) {
evt.preventDefault();
const now = new Date();
const hours = now.getHours();
this.setState({
depart: "givenTime",
hour: now.getHours(),
min: now.getMinutes(),
hour: hours === 0 ? 12 : hours % 12,
isPM: hours >= 12
});
}
@ -182,13 +190,30 @@ class RouteSearch extends Component {
<div></div>
<div>
</div>
<select name="hour" value={this.state.hour} onChange={(evt) => this.setState({hour: evt.target.value}) } disabled={departNow}>
{ _.map(_.range(0, 24), (hour) => { return <option key={`h-${hour}`} value={hour}>{hour}</option>;}) }
<select
name="hour"
value={this.state.hour}
onChange={(evt) => this.setState({hour: evt.target.value}) } disabled={departNow}
>
{ _.map(_.range(1, 13), (hour) => { return <option key={`h-${hour}`} value={hour}>{hour}</option>;}) }
</select>
<span>:</span>
<select name="min" value={this.state.min} onChange={(evt) => this.setState({min: evt.target.value}) } disabled={departNow}>
<select
name="min"
value={this.state.min}
onChange={(evt) => this.setState({min: evt.target.value}) } disabled={departNow}
>
{ _.map(_.range(0, 60), (min) => { return <option key={`m-${min}`} value={min}>{min}</option>;}) }
</select>
<select
name="isPM"
value={this.state.isPM ? "PM" : "AM"}
disabled={departNow}
onChange={(evt) => this.setState({isPM: evt.target.value === "PM"})}
>
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
</div>
</div>);
}

View File

@ -105,12 +105,19 @@
?> ?=(%o -.value)
=/ update=json (pairs:enjs:format [update+o+p.value ~])
[%give %fact ~[/bartstations] %json !>(update)]~
::
::
[%elevators *]
=/ value=json (parse-elevator-status-response:cc client-response.sign-arvo)
?> ?=(%o -.value)
=/ update=json (pairs:enjs:format [update+o+p.value ~])
[%give %fact ~[/elevators] %json !>(update)]~
::
[%routeplan *]
~& client-response.sign-arvo
=/ value=json (parse-routeplan-response:cc client-response.sign-arvo)
?> ?=(%o -.value)
=/ update=json (pairs:enjs:format [update+o+p.value ~])
[%give %fact ~[/routes] %json !>(update)]~
==
[http-moves this]
?. ?=(%bound +<.sign-arvo)
@ -194,14 +201,20 @@
(with-json-handler response handler)
::
++ bart-api-routeplan
|= [from=tape to=tape]
|= [from=tape to=tape hour=@ min=@ ispm=?]
^- request:http
:: http://api.bart.gov/api/sched.aspx?cmd=depart&orig=ASHB&dest=CIVC&date=now
:: TODO cmd can be 'depart' or 'arrive', also 'fare'
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&key={bart-api-key}&json=y")
=/ meridian ?:(ispm "pm" "am")
=/ time "{<hour>}:{<min>}{meridian}"
=/ url (crip "{bart-api-url-base}/sched.aspx?cmd=depart&orig={from}&dest={to}&time={time}&key={bart-api-key}&json=y")
~& url
=/ headers [['Accept' 'application/json']]~
[%'GET' url headers *(unit octs)]
++ parse-routeplan-response
|= response=client-response:iris
^- json
(with-json-handler response |=(x=json x))
++ poke-handle-json
|= jon=json
^- (list card)
@ -209,15 +222,20 @@
=, format
?. ?=(%o -.jon)
[~]
=/ omso ((om:dejs so:dejs) jon)
=/ from-station=tape (trip (~(gut by omso) 'from' ''))
=/ to-station=tape (trip (~(gut by omso) 'to' ''))
=/ req (bart-api-routeplan from-station to-station)
=/ [hour=@ min=@ ispm=? from-station=tape to-station=tape]
%.
jon
%: ot:dejs
['hour' ni:dejs]
['min' ni:dejs]
['isPM' bo:dejs]
['from' sa:dejs]
['to' sa:dejs]
~
==
=/ req (bart-api-routeplan from-station to-station hour min ispm)
=/ out *outbound-config:iris
=/ output [%pass /routeplan %arvo %i %request req out]
::
=/ update=json *json
[%give %fact ~[/routes] %json !>(update)]~
[[%pass /routeplan %arvo %i %request req out] ~]
::
++ poke-handle-http-request
|= =inbound-request:eyre