Last active
August 29, 2015 14:10
-
-
Save zobalogh/b38b8fca5b6614033644 to your computer and use it in GitHub Desktop.
Transport uber flow
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
[{"id":"ecd5e4e2.132a18","type":"tfl underground","line":"Piccadilly","name":"Check Piccadilly line status","x":404,"y":485,"z":"86fba54d.790458","wires":[["c11f5737.3ee0a8"]]},{"id":"dc21420b.23dec","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":55,"y":337,"z":"86fba54d.790458","wires":[["7653e6b2.89ac18"]]},{"id":"5df6386.fa209c8","type":"openweathermap","name":"London weather","lon":"","lat":"","city":"London","country":"England","x":346,"y":140,"z":"86fba54d.790458","wires":[["d18ecefa.2e713"]]},{"id":"c11f5737.3ee0a8","type":"function","name":"Is the Piccadilly line to Action Town OK?","func":"var stations = [\"Hyde Park Corner\", \"Knightsbridge\", \"South Kensington\", \"Earl's Court\", \"Hammersmith\", \"Turnham Green\", \"Acton Town\"];\nvar lineok = true;\nvar minordelays = false;\n\nif (msg.payload.goodservice) {\n // minor delays are reported as good service but sometimes have a info about delay\n\tif (msg.payload.description === \"Minor Delays\") {\n\t minordelays = true;\n\t if (msg.payload.branchdisruptions.length > 0) {\n\t for (var l = 0; l < msg.payload.branchdisruptions.length; l++) {\n\t \n\t\t \tvar disruption = msg.payload.branchdisruptions[l];\n\t\t \tvar stationFrom = disruption.StationFrom[0].$.Name;\n\t \t\tvar index = -1;\n\t \t\tfor (var j = 0; j < stations.length; j++) {\n\t \t\t\tif(stations[j] === stationFrom) {\n\t \t \t\tindex = j;\n\t \t\t\t}\n\t \t\t}\n\t \t\tif ((index !== -1) && (index !== (stations.length - 1))) {\n\t \t\t\tvar stationTo = disruption.StationTo[0].$.Name;\n\t \t\t\tfor (var k = index; k < stations.length; j++) {\n\t \t \t\t\tif(stations[k] === stationTo) {\n\t \t\t\tlineok = false;\n\t \t\t\t}\n\t \t\t\t}\n\t \t\t}\n\t\t\t}\n\t\t}\t\t\t\n\t}\n} else {\n\tlineok = false;\n}\nmsg.payload = {};\nmsg.topic = \"underground\";\nmsg.payload = false;\n\nif (lineok) {\n\tmsg.payload = true;\n}\nreturn msg;","outputs":1,"x":790,"y":442,"z":"86fba54d.790458","wires":[["66c8d1cd.99373"]]},{"id":"66c8d1cd.99373","type":"function","name":"Make decision","func":"if(!context.global.travelData) {\n\tcontext.global.travelData = {};\n}\n\nif(msg.topic === \"weather\") {\n\tcontext.global.travelData.weatherOK = msg.payload;\n}\n\nif(msg.topic === \"underground\") {\n\tcontext.global.travelData.piccadillyOK = msg.payload;\n}\n\nif(msg.topic === \"bus\") {\n\tcontext.global.travelData.busOK = msg.payload;\n\t\n}\n\nif(msg.topic === \"bike\") {\n\tcontext.global.travelData.bikeOK = msg.payload;\n}\n\n// done set up\nif( (typeof context.global.travelData.piccadillyOK !== 'undefined' ) && (typeof context.global.travelData.busOK !== 'undefined' ) && (typeof context.global.travelData.weatherOK !== 'undefined' ) && (typeof context.global.travelData.bikeOK !== 'undefined' )) {\n\tif(context.global.travelData.weatherOK === false) {\n\t\tif(context.global.travelData.piccadillyOK === true) {\n\t\t\tmsg.payload = \"You should use the underground as the weather's bad.\";\n\t\t} else if(context.global.travelData.busOK === true) {\n\t\t\tmsg.payload = \"You should use the bus as the weather's bad and the underground has problems.\";\n\t\t} else {\n\t\t\tmsg.payload = \"The weather is bad and the underground and the bus are broken. Hire a taxi or stay at home.\";\n\t\t}\n\t} else { // weather's good\n\t\tif(context.global.travelData.bikeOK === true) {\n\t\t\tmsg.payload = \"There are bikes available and the weather is good, enjoy the ride.\";\n\t\t} else if(context.global.travelData.busOK === true) {\n\t\t\tmsg.payload = \"The weather is good but there are no bikes left, take the bus please.\";\n\t\t} else if(context.global.travelData.piccadillyOK === true) {\n\t\t\tmsg.payload = \"You should use the underground as that's the only available transport method.\";\n\t\t} else {\n\t\t\tmsg.payload = \"You're unlucky today. Take a taxi, walk or stay at home.\";\n\t\t}\n\t}\n\treturn msg;\n}","outputs":1,"x":986,"y":269,"z":"86fba54d.790458","wires":[["f702b857.08fd48"]]},{"id":"667f262.f9980d8","type":"function","name":"Is my bus arriving within 10 mins?","func":"msg.topic = \"bus\";\nmsg.topic.busOK = true;\nvar estimatedBusArrival = msg.payload.EstimatedTime;\n\nif(estimatedBusArrival) {\n\tvar tenMinutesMillis = 600000;\n\tvar currentTimeMillis = new Date().getTime();\n\tvar timeDifference = (estimatedBusArrival.getTime()) - currentTimeMillis; // assuming that the bus arrival is in the future\n\tif(timeDifference <= tenMinutesMillis) {\n\t\tmsg.payload = true;\n\t} else {\n\t\tmsg.payload = false;\n\t}\n} else {\n\t\tmsg.payload = false;\n}\n\nreturn msg;","outputs":1,"x":674,"y":332,"z":"86fba54d.790458","wires":[["66c8d1cd.99373"]]},{"id":"f702b857.08fd48","type":"debug","name":"","active":true,"console":"false","complete":"payload","x":1148,"y":183,"z":"86fba54d.790458","wires":[]},{"id":"383f13d1.c7c0ec","type":"tfl-bus","lat":"51.507268","lon":"-0.16573","radius":"600","stopCode1":"71003","lineID":"94","stopName":"Hyde Park Street towards Lancaster Gate or Notting Hill","lineName":"94 to Acton Green","name":"Bus arrival towards Acton Green","x":448,"y":260,"z":"86fba54d.790458","wires":[["667f262.f9980d8"]]},{"id":"7653e6b2.89ac18","type":"function","name":"Clear context","func":"context.global.travelData = {};\nreturn msg;","outputs":1,"x":206,"y":332,"z":"86fba54d.790458","wires":[["383f13d1.c7c0ec","ecd5e4e2.132a18","5df6386.fa209c8","dfaa2e4a.2055d"]]},{"id":"dfaa2e4a.2055d","type":"cyclehire","name":"Hyde Park Corner bike hire","station":"Hyde Park Corner, Hyde Park","lon":"","lat":"","x":340,"y":603,"z":"86fba54d.790458","wires":[["3490722e.cb6f8e"]]},{"id":"3490722e.cb6f8e","type":"function","name":"Have we got at least 3 bikes available?","func":"msg.topic = \"bike\";\nif(msg.payload.bikes >=3) {\n\tmsg.payload = {};\n\tmsg.payload = true;\n} else {\n\tmsg.payload = {};\n\tmsg.payload = false;\n}\n\nreturn msg;","outputs":1,"x":806,"y":604,"z":"86fba54d.790458","wires":[["66c8d1cd.99373"]]},{"id":"d18ecefa.2e713","type":"function","name":"Is the weather Good for cycling?","func":"msg.topic = \"weather\";\nif(msg.payload.weather && (msg.payload.weather === \"Rain\" || msg.payload.weather === \"Snow\" || msg.payload.weather === \"Thunderstorm\" || msg.payload.weather === \"Drizzle\")) {\n\tmsg.payload = false;\n} else {\n\tmsg.payload = true;\n}\nreturn msg;","outputs":1,"x":751,"y":139,"z":"86fba54d.790458","wires":[["66c8d1cd.99373"]]}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment