route_c 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 70e700d59b416b24098c10461c92d971a9e358b0
4
- data.tar.gz: 957594f6be7a1c1d4fc3c62861ce3fc55c46a5ad
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWZkNTUxODU1MjcxM2Y5OGNkZWM3NWE4MGI2ZDRhNjc1NDIxYTljOQ==
5
+ data.tar.gz: !binary |-
6
+ ZThlODk4ZWQ3OWEwOWIzZDM5OTg0NmM3NzZhODM1MDljNWUyNWQ1OA==
5
7
  SHA512:
6
- metadata.gz: 0579a4e7ad1d76d1e7f13b827c363f9ea57050f697b70b71d2a69c3dbef70c1906ba492fe95f11d84219d55154de54f641236d9a2ad6fb29c895867f07becc35
7
- data.tar.gz: 0e7324530d27f69392be3702d8547bd992c053a04607e58272433387605cd2ad4205377e6f90e7c77eac1ba23f7e8dff0b06e9c9b732952c01ae823be1331041
8
+ metadata.gz: !binary |-
9
+ NDQyNjJhOGQxYWZmYTdkOWE0Y2IxZGFjMDM0NmQwZDdmOGQ1ZDVhMjNhMDZj
10
+ YWZhN2EzMjY3N2VjZGUwZGEwMDViN2RhYzc1OWIxMDcwNjQ2Y2I0ZGZjOTc4
11
+ MmNkYjAxNzY5OWVmZjcyZmE4YzgyNjEyMzYwNGVlZmM5MGU0YTk=
12
+ data.tar.gz: !binary |-
13
+ NzdmYmU5ODkzODdjMDZjNjgwMjQ0ZmM0NzcyNDZkNzQyNDgxYTdlYmM2Yzlm
14
+ ZDkzZTJkYzE5MDIzNDRkY2IwNDlhNjgyMDMzYTRhYzlkNDNkZmFmNGFkMzMy
15
+ MDBjNmRmMzAwYjBiN2YwYjFiODhmNWY3YmQxNGQzYWQ3YzdiZjk=
@@ -1,9 +1,24 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.0
4
- - 2.1.5
3
+ - 2.3.0
4
+ - 2.1.5
5
5
  before_install: gem install bundler -v 1.11.2
6
6
  env:
7
7
  global:
8
- - SIR_HANDEL_USERNAME=foo
9
- - SIR_HANDEL_PASSWORD=bar
8
+ - SIR_HANDEL_USERNAME=foo
9
+ - SIR_HANDEL_PASSWORD=bar
10
+ - secure: uXgk++CEZft7nv8Qw3YwWTwJ3pGlnmaVLra3lv1GCwkIFZJZn/B2MSMlVsQbOK4h/ABsLif3gu+L4lvAXzwLOK6n6DfRCkdj3KZ/nEbLZoxTZqxSe/w1g74Dt009Ty4Vcz0881hMgK9WfoycELPc03Oscb31cQpVwgwaZ9imjQzoqqf+b/weF0CWCOKQLcDUjrmpiTwCR7R15FoTuLfbss9lT5FEWnuX4f5VPH2GN7ROL4T8GcatLGG2t0XPqAlfK4sFqBbJn931KX2IM0EY1GmcBkpvoO7y7YCspDm6/PJAFc0t93pKehqVZsUDzC5Jc/9pXZJwOEoBTB1stj0mWZqAWk7E0oEsJrryuu6hcXk/MOOOTQ6iat4EB2rmCnj1pY+2aIRIms9VFWplKjG42CcHKwVYy4LCCwR4UpI982k6EzVt9Heq9FyNj0OsWTtjpTFjSPAFhv16BzF9bUm1Um8Nk61L0OWVnOBJGlqyQegQcRMZ1/wr2r6RVP2GOz/JhFqQCDHlDsJY0Y1jiwzbcqJha0ksAA9TJ01rWES4qPwSUkH7TRo3b8qS+4xc9ZZDBIkZ+RFuB6hmLukbCisBSKqNN9wJmLq/UBClKi78boG6PdlH6X/MfSCwtb1IBk5c2xWCxQcJv6gyqRmSVBL5AiqoBdc0lxmvGrS5ZgQsco4=
11
+ - secure: cesErL4ZY53X15gemEF+7EJmk7XnGhx2ktDpl7wH55UMFLaKee7m1t17qdb+gOLw0H82Z8iDtCU9iCmi542Ns/ZHd7S/UH4G492o8sP5f+a1Ad9vCj1MnYrcvLk+wuexlFAlCal5RVGEDKY7HwYItLUFScbPAqVteO7Xy0GyVLtceUJ9y3jhSH3bUekSZsNQ0vPJzB4p0CdRrp28FnqgvHzOc83xX0D4vg6jpxsXH+X7+PlMJX+00yHFZBizTUXHxv7Os3Uj7toM7iOLEG6ULtebvryqAyovjYHChTiz3dFQIzRO4+MzZFjWGnY+tIyY9lzF66yvYX7VfFf0gB3/EhrFxCo8SZBIIY5n5yf9Q7aq1iBRVII0qvQbz3AoAlSNAvASSD0e8Q/Zvf7boO0iD+Geywvb18/T9/9EYMvhJba+22qTRZtT6sGMLYIsPIb9GM1DQ7+gtpWHFlMTYCwoMJRoVT/2pw0qqUJvCZE8iumD/l/6M/pnW7biHrRRBwZ8zeOj4ovBlj3LxIFDwWKNrLvH2KU3qasJYfQNRBIJUK8bGrZCCWE0riNp+uQB5Z1x6OtPkIAnkgPkWACAhcOy/Jr8nYZPtwmKY0+6/rTfXZFwTshvZD6kw9xPEdoTf9001jdquUnKLqQsHf0vYU0+MeusqJHaGkncAjffMmwvPIk=
12
+ after_success:
13
+ - export GEM_VERSION=`ruby -e "puts Gem::Specification.load(Dir['*.gemspec'].first).version.to_s"`
14
+ - '[ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && curl
15
+ -v -X POST -d ''{"ref":"refs/tags/''$GEM_VERSION''","sha":"''$TRAVIS_COMMIT''"}'' --header
16
+ "Content-Type:application/json" -u $GITHUB_USER:$GITHUB_PASSWORD "https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs"'
17
+ deploy:
18
+ provider: rubygems
19
+ api_key:
20
+ secure: nJWVa1ICOlD46KXaVlSJ9DQWdaaZii42e5tZo2LHutldII1rXouQGh/wNTWnvvBBmqei3OrH/pGkZMTc50POkhWyfRbEbSUZaLNgpttBQjwWnas+t5jgc9ShB20fPvk9OMb+e3CPZyGLj55p3t9/CO5gErSyVPFY0Cur4GQs+FLi95rzp5msTknWVoMGWKdnR6UBERitaIT8mohcBhx1i9ftCwulntk9DAaR0I/kaU9OdFmUvG5dIPbisx98enRDNVscc+k8rg9WhG1VFYTA4XYGTNV9I4t3/HdPZVZz5EBA8p4qSoYWTlfxaniikUm3iq+k9l2kSojLQeacnfpmQDCVrM0IwwZclpdu9y142MB8g9DLUtqtaPGRW8ezxM/3Syo/tBMmoY6ObEOtLxpH8CpGqDQTTwCVKxq1QfSEpczpBY8y4Lkok79+CyIzByM61fWjOHy8nt0ZokTv0mCOVHD/MqER/IFujyq6Ad5+g/yUUU/BRpze3UxkUE7xn6+Mm/cOs01Qg+aPuyeN6aQa1YHe4XU2EXYX8lZXlfsHTIgovuEDlnklridj975tDI5gPxK2pG/44OMqtI0yygOtANKrwUPDe0RttnFpWI3kqdFCgTTg06mnR3TzcruCvgEMkSJkrP0j4AY7B7tgI7xUpJivQQsUvRK1Vj41fKgBe9A=
21
+ gem: route_c
22
+ on:
23
+ tags: true
24
+ repo: TheODI-UD2D/route_c
@@ -0,0 +1,8 @@
1
+ require 'pi_piper'
2
+ include PiPiper
3
+
4
+ after :pin => 21, :goes => :high do
5
+ puts "Button pressed"
6
+ end
7
+
8
+ PiPiper.wait
@@ -1,5 +1,4 @@
1
1
  base_url: http://goingunderground.herokuapp.com/stations/arriving/
2
- lights: 8
3
2
  interval: 0.1
4
3
  pause: 1
5
4
 
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<SIR_HANDEL_USERNAME>:<SIR_HANDEL_PASSWORD>@goingunderground.herokuapp.com/stations/arriving/southbound/euston/2015-09-23T7:48:00.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Cowboy
23
+ Date:
24
+ - Mon, 29 Feb 2016 10:42:55 GMT
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Vary:
30
+ - Accept
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Content-Length:
34
+ - '832'
35
+ Via:
36
+ - 1.1 vegur
37
+ body:
38
+ encoding: UTF-8
39
+ string: '[[{"segment":1193,"number":0,"timeStamp":"2015-09-23T07:11:42.012Z"},{"CAR_A":97.02272727272727,"CAR_B":80.56989247311827,"CAR_C":66.51315789473684,"CAR_D":73.3768115942029}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T23:07:11.575Z"},{"CAR_A":16.650602409638555,"CAR_B":10.929577464788732,"CAR_C":15.414285714285715,"CAR_D":15.185714285714285}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T21:50:17.475Z"},{"CAR_A":27.041666666666668,"CAR_B":21.36,"CAR_C":13.95,"CAR_D":6.521739130434782}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T16:50:48.528Z"},{"CAR_A":41.75,"CAR_B":32.36363636363637,"CAR_C":26.11111111111111,"CAR_D":27.11111111111111}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T15:42:26.012Z"},{"CAR_A":34.05494505494506,"CAR_B":24.7,"CAR_C":14.582089552238806,"CAR_D":6.943661971830986}]]'
40
+ http_version:
41
+ recorded_at: Wed, 23 Sep 2015 06:48:00 GMT
42
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<SIR_HANDEL_USERNAME>:<SIR_HANDEL_PASSWORD>@goingunderground.herokuapp.com/stations/arriving/southbound/euston/2015-09-23T7:48:00.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Cowboy
23
+ Date:
24
+ - Mon, 29 Feb 2016 10:34:50 GMT
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Vary:
30
+ - Accept
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Content-Length:
34
+ - '832'
35
+ Via:
36
+ - 1.1 vegur
37
+ body:
38
+ encoding: UTF-8
39
+ string: '[[{"segment":1193,"number":0,"timeStamp":"2015-09-23T07:11:42.012Z"},{"CAR_A":97.02272727272727,"CAR_B":80.56989247311827,"CAR_C":66.51315789473684,"CAR_D":73.3768115942029}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T23:07:11.575Z"},{"CAR_A":16.650602409638555,"CAR_B":10.929577464788732,"CAR_C":15.414285714285715,"CAR_D":15.185714285714285}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T21:50:17.475Z"},{"CAR_A":27.041666666666668,"CAR_B":21.36,"CAR_C":13.95,"CAR_D":6.521739130434782}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T16:50:48.528Z"},{"CAR_A":41.75,"CAR_B":32.36363636363637,"CAR_C":26.11111111111111,"CAR_D":27.11111111111111}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T15:42:26.012Z"},{"CAR_A":34.05494505494506,"CAR_B":24.7,"CAR_C":14.582089552238806,"CAR_D":6.943661971830986}]]'
40
+ http_version:
41
+ recorded_at: Wed, 23 Sep 2015 06:48:00 GMT
42
+ recorded_with: VCR 3.0.1
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<SIR_HANDEL_USERNAME>:<SIR_HANDEL_PASSWORD>@goingunderground.herokuapp.com/stations/arriving/southbound/euston/2015-09-23T7:48:00.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Cowboy
23
+ Date:
24
+ - Mon, 29 Feb 2016 10:34:50 GMT
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Vary:
30
+ - Accept
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Content-Length:
34
+ - '832'
35
+ Via:
36
+ - 1.1 vegur
37
+ body:
38
+ encoding: UTF-8
39
+ string: '[[{"segment":1193,"number":0,"timeStamp":"2015-09-23T07:11:42.012Z"},{"CAR_A":97.02272727272727,"CAR_B":80.56989247311827,"CAR_C":66.51315789473684,"CAR_D":73.3768115942029}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T23:07:11.575Z"},{"CAR_A":16.650602409638555,"CAR_B":10.929577464788732,"CAR_C":15.414285714285715,"CAR_D":15.185714285714285}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T21:50:17.475Z"},{"CAR_A":27.041666666666668,"CAR_B":21.36,"CAR_C":13.95,"CAR_D":6.521739130434782}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T16:50:48.528Z"},{"CAR_A":41.75,"CAR_B":32.36363636363637,"CAR_C":26.11111111111111,"CAR_D":27.11111111111111}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T15:42:26.012Z"},{"CAR_A":34.05494505494506,"CAR_B":24.7,"CAR_C":14.582089552238806,"CAR_D":6.943661971830986}]]'
40
+ http_version:
41
+ recorded_at: Wed, 23 Sep 2015 06:48:00 GMT
42
+ recorded_with: VCR 3.0.1
@@ -21,7 +21,7 @@ http_interactions:
21
21
  Server:
22
22
  - Cowboy
23
23
  Date:
24
- - Thu, 25 Feb 2016 11:50:27 GMT
24
+ - Mon, 29 Feb 2016 10:34:51 GMT
25
25
  Connection:
26
26
  - keep-alive
27
27
  Content-Type:
@@ -21,7 +21,7 @@ http_interactions:
21
21
  Server:
22
22
  - Cowboy
23
23
  Date:
24
- - Thu, 25 Feb 2016 11:50:27 GMT
24
+ - Mon, 29 Feb 2016 10:34:51 GMT
25
25
  Connection:
26
26
  - keep-alive
27
27
  Content-Type:
@@ -21,7 +21,7 @@ http_interactions:
21
21
  Server:
22
22
  - Cowboy
23
23
  Date:
24
- - Thu, 25 Feb 2016 11:50:27 GMT
24
+ - Mon, 29 Feb 2016 10:34:52 GMT
25
25
  Connection:
26
26
  - keep-alive
27
27
  Content-Type:
@@ -0,0 +1,42 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://<SIR_HANDEL_USERNAME>:<SIR_HANDEL_PASSWORD>@goingunderground.herokuapp.com/stations/arriving/southbound/euston/2015-09-23T16:20:00.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - Cowboy
23
+ Date:
24
+ - Mon, 29 Feb 2016 10:34:51 GMT
25
+ Connection:
26
+ - keep-alive
27
+ Content-Type:
28
+ - application/json
29
+ Vary:
30
+ - Accept
31
+ X-Content-Type-Options:
32
+ - nosniff
33
+ Content-Length:
34
+ - '1728'
35
+ Via:
36
+ - 1.1 vegur
37
+ body:
38
+ encoding: UTF-8
39
+ string: '[[{"segment":1193,"number":0,"timeStamp":"2015-09-23T16:08:39.575Z"},{"CAR_A":29.443181818181817,"CAR_B":17.266666666666666,"CAR_C":12.931506849315069,"CAR_D":13.32857142857143}],[{"segment":1193,"number":0,"timeStamp":"2015-09-23T14:58:45.09Z"},{"CAR_A":27.382022471910112,"CAR_B":23.130434782608695,"CAR_C":11.327272727272728,"CAR_D":6.314814814814815}],[{"segment":1193,"number":0,"timeStamp":"2015-09-23T13:31:52.459Z"},{"CAR_A":30.984848484848484,"CAR_B":31.016666666666666,"CAR_C":17.339622641509433,"CAR_D":24.491525423728813}],[{"segment":1193,"number":0,"timeStamp":"2015-09-23T11:12:05.328Z"},{"CAR_A":25.066666666666666,"CAR_B":17.568627450980394,"CAR_C":16.59090909090909,"CAR_D":7.976744186046512}],[{"segment":1193,"number":0,"timeStamp":"2015-09-23T08:28:09.875Z"},{"CAR_A":76.51546391752578,"CAR_B":68.54166666666667,"CAR_C":66.63013698630137,"CAR_D":61.13636363636363}],[{"segment":1193,"number":0,"timeStamp":"2015-09-23T08:27:35.975Z"},{"CAR_A":82.1938775510204,"CAR_B":74.24489795918367,"CAR_C":68.07246376811594,"CAR_D":64.7127659574468}],[{"segment":1193,"number":0,"timeStamp":"2015-09-23T07:11:42.012Z"},{"CAR_A":97.02272727272727,"CAR_B":80.56989247311827,"CAR_C":66.51315789473684,"CAR_D":73.3768115942029}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T23:07:11.575Z"},{"CAR_A":16.650602409638555,"CAR_B":10.929577464788732,"CAR_C":15.414285714285715,"CAR_D":15.185714285714285}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T21:50:17.475Z"},{"CAR_A":27.041666666666668,"CAR_B":21.36,"CAR_C":13.95,"CAR_D":6.521739130434782}],[{"segment":1193,"number":0,"timeStamp":"2015-09-22T16:50:48.528Z"},{"CAR_A":41.75,"CAR_B":32.36363636363637,"CAR_C":26.11111111111111,"CAR_D":27.11111111111111}]]'
40
+ http_version:
41
+ recorded_at: Fri, 01 Jan 2016 16:20:00 GMT
42
+ recorded_with: VCR 3.0.1
@@ -4,80 +4,9 @@ require 'dotenv'
4
4
  require 'open-uri'
5
5
  require 'pi_piper'
6
6
 
7
- require "route_c/version"
8
- require "route_c/cli"
9
-
10
7
  Dotenv.load
11
8
 
12
- module RouteC
13
- class Query
14
- def initialize(station, direction, datetime = nil)
15
- @station, @direction, @datetime = station, direction, set_datetime(datetime)
16
- end
17
-
18
- def set_datetime(datetime)
19
- if datetime.nil?
20
- hour = Time.now.hour
21
- minute = Time.now.min
22
- "2015-09-23T#{hour}:#{minute}:00"
23
- else
24
- datetime
25
- end
26
- end
27
-
28
- def url
29
- "#{Query.config['base_url']}#{@direction}/#{@station}/#{@datetime}.json"
30
- end
31
-
32
- def self.config
33
- YAML.load_file 'config/config.yaml'
34
- end
35
-
36
- def self.pins
37
- YAML.load_file 'config/pins.yaml'
38
- end
39
-
40
- def json
41
- request = open(url, http_basic_authentication: [
42
- ENV['SIR_HANDEL_USERNAME'],
43
- ENV['SIR_HANDEL_PASSWORD']
44
- ])
45
- JSON.parse request.read
46
- end
47
-
48
- def average_occupancy
49
- loads = json.first.last
50
- average = loads.values.inject{ |sum, el| sum + el }.to_f / loads.size
51
- average.round
52
- end
53
-
54
- def self.num_elements average, elements = Query.config['lights']
55
- (elements * (average / 100.0)).round
56
- end
57
-
58
- def to_a
59
- num = Query.num_elements average_occupancy
60
- Array.new(Query.config['lights']).each_with_index.map { |k,v| v + 1 <= num ? 1 : 0 }
61
- end
62
-
63
- def to_lights
64
- to_a.each_with_index do |b, i|
65
- if b == 1
66
- lights[i].on
67
- sleep Query.config['interval']
68
- end
69
- end
70
-
71
- sleep Query.config['pause']
72
-
73
- lights.reverse.each do |l|
74
- l.off
75
- sleep Query.config['interval']
76
- end
77
- end
78
-
79
- def lights
80
- @lights ||= Query.pins.map { |p| PiPiper::Pin.new(pin: p, direction: :out) }
81
- end
82
- end
83
- end
9
+ require "route_c/version"
10
+ require "route_c/lights"
11
+ require "route_c/query"
12
+ require "route_c/cli"
@@ -1,4 +1,5 @@
1
1
  require 'thor'
2
+ require 'pi_piper'
2
3
 
3
4
  module RouteC
4
5
  class CLI < Thor
@@ -27,5 +28,45 @@ module RouteC
27
28
  routec.to_lights
28
29
  end
29
30
  end
31
+
32
+ desc 'watch', 'wait for a button'
33
+ method_option :daemon,
34
+ type: :boolean,
35
+ default: false,
36
+ desc: 'Creates a file `.pid` with the current process ID'
37
+ def watch
38
+ if options['daemon']
39
+ file = File.new('.pid', 'w+')
40
+ file.write(Process.pid)
41
+ file.rewind
42
+ file.close
43
+ end
44
+
45
+ print 'Waiting for you to push the button... '
46
+ PiPiper.watch pin: 21 do
47
+ watching
48
+ end
49
+
50
+ PiPiper.wait
51
+ end
52
+
53
+ private
54
+
55
+ def watching
56
+ puts 'done'
57
+ print 'Getting data... '
58
+ routec = RouteC::Query.new 'euston', 'southbound'
59
+ puts 'done'
60
+
61
+ print 'Lighting lights... '
62
+ routec.to_lights
63
+ puts 'done'
64
+
65
+ print 'Releasing lights... '
66
+ routec.lights.release
67
+ puts 'done'
68
+
69
+ print 'Waiting for you to push the button... '
70
+ end
30
71
  end
31
72
  end
@@ -0,0 +1,32 @@
1
+ module RouteC
2
+ class Lights
3
+
4
+ def initialize(array)
5
+ @array = array
6
+ end
7
+
8
+ def turn_on
9
+ @array.each_with_index do |b, i|
10
+ if b == 1
11
+ lights[i].on
12
+ sleep Query.config['interval']
13
+ end
14
+ end
15
+ sleep Query.config['pause']
16
+ lights.reverse.each { |l| l.off ; sleep Query.config['interval'] }
17
+ end
18
+
19
+ def lights
20
+ @lights ||= Lights.pins.map { |p| PiPiper::Pin.new(pin: p, direction: :out) }
21
+ end
22
+
23
+ def release
24
+ lights.map { |l| l.release }
25
+ end
26
+
27
+ def self.pins
28
+ YAML.load_file 'config/pins.yaml'
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,56 @@
1
+ module RouteC
2
+ class Query
3
+ def initialize(station, direction, datetime = nil)
4
+ @station, @direction, @datetime = station, direction, set_datetime(datetime)
5
+ end
6
+
7
+ def set_datetime(datetime)
8
+ if datetime.nil?
9
+ hour = Time.now.hour
10
+ minute = Time.now.min
11
+ "2015-09-23T#{hour}:#{minute}:00"
12
+ else
13
+ datetime
14
+ end
15
+ end
16
+
17
+ def url
18
+ "#{Query.config['base_url']}#{@direction}/#{@station}/#{@datetime}.json"
19
+ end
20
+
21
+ def self.config
22
+ YAML.load_file 'config/config.yaml'
23
+ end
24
+
25
+ def json
26
+ request = open(url, http_basic_authentication: [
27
+ ENV['SIR_HANDEL_USERNAME'],
28
+ ENV['SIR_HANDEL_PASSWORD']
29
+ ])
30
+ JSON.parse request.read
31
+ end
32
+
33
+ def average_occupancy
34
+ loads = json.first.last
35
+ average = loads.values.inject{ |sum, el| sum + el }.to_f / loads.size
36
+ average.round
37
+ end
38
+
39
+ def self.num_elements average, elements = Lights.pins.count
40
+ (elements * (average / 100.0)).round
41
+ end
42
+
43
+ def to_a
44
+ num = Query.num_elements average_occupancy
45
+ Array.new(Lights.pins.count).each_with_index.map { |k,v| v + 1 <= num ? 1 : 0 }
46
+ end
47
+
48
+ def to_lights
49
+ lights.turn_on
50
+ end
51
+
52
+ def lights
53
+ @lights ||= Lights.new(to_a)
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module RouteC
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ # /etc/init.d/route_c
3
+
4
+ ### BEGIN INIT INFO
5
+ # Provides: route_c
6
+ # Required-Start: $remote_fs $syslog
7
+ # Required-Stop: $remote_fs $syslog
8
+ # Default-Start: 2 3 4 5
9
+ # Default-Stop: 0 1 6
10
+ # Short-Description: Example initscript
11
+ # Description: This service is used to manage route_c
12
+ ### END INIT INFO
13
+
14
+
15
+ case "$1" in
16
+ start)
17
+ echo "Starting route_c"
18
+ cd /home/pi/route_c && sudo bundle exec routec watch --daemon
19
+ ;;
20
+ stop)
21
+ echo "Stopping route_c"
22
+ PID=`cat /home/pi/route_c/.pid` && sudo kill -15 $PID
23
+ ;;
24
+ restart)
25
+ echo "Stopping route_c"
26
+ PID=`cat /home/pi/route_c/.pid` && sudo kill -15 $PID && cd /home/pi/route_c && sudo bundle exec routec watch --daemon
27
+ ;;
28
+ esac
29
+
30
+ exit 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: route_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -9,160 +9,160 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-02-25 00:00:00.000000000 Z
12
+ date: 2016-02-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dotenv
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: 2.0.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.0.2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thor
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0.19'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0.19'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: pi_piper
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ">="
46
+ - - ! '>='
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ">="
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ~>
61
61
  - !ruby/object:Gem::Version
62
62
  version: '1.11'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ~>
68
68
  - !ruby/object:Gem::Version
69
69
  version: '1.11'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rake
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ~>
75
75
  - !ruby/object:Gem::Version
76
76
  version: '10.0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ~>
82
82
  - !ruby/object:Gem::Version
83
83
  version: '10.0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rspec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ~>
89
89
  - !ruby/object:Gem::Version
90
90
  version: '3.0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ~>
96
96
  - !ruby/object:Gem::Version
97
97
  version: '3.0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: coveralls
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - "~>"
102
+ - - ~>
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0.8'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - "~>"
109
+ - - ~>
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.8'
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: timecop
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - "~>"
116
+ - - ~>
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0.8'
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - "~>"
123
+ - - ~>
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0.8'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: webmock
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - "~>"
130
+ - - ~>
131
131
  - !ruby/object:Gem::Version
132
132
  version: '1.22'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - "~>"
137
+ - - ~>
138
138
  - !ruby/object:Gem::Version
139
139
  version: '1.22'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: vcr
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - "~>"
144
+ - - ~>
145
145
  - !ruby/object:Gem::Version
146
146
  version: '3.0'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - "~>"
151
+ - - ~>
152
152
  - !ruby/object:Gem::Version
153
153
  version: '3.0'
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: pry
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - "~>"
158
+ - - ~>
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0.10'
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - "~>"
165
+ - - ~>
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0.10'
168
168
  description: words
@@ -173,25 +173,33 @@ executables:
173
173
  extensions: []
174
174
  extra_rdoc_files: []
175
175
  files:
176
- - ".gitignore"
177
- - ".rspec"
178
- - ".travis.yml"
176
+ - .gitignore
177
+ - .rspec
178
+ - .travis.yml
179
179
  - Gemfile
180
180
  - LICENSE.md
181
181
  - README.md
182
182
  - Rakefile
183
183
  - bin/console
184
184
  - bin/setup
185
+ - buttons.rb
185
186
  - config/config.yaml
186
187
  - config/pins.yaml
187
188
  - exe/routec
189
+ - fixtures/rspec/vcr/RouteC_CLI/lights_lights_on_button_press.yml
190
+ - fixtures/rspec/vcr/RouteC_CLI/lights_the_lights.yml
191
+ - fixtures/rspec/vcr/RouteC_CLI/returns_an_array.yml
188
192
  - fixtures/rspec/vcr/RouteC_Query/gets_some_json.yml
189
193
  - fixtures/rspec/vcr/RouteC_Query/gets_the_average_occupancy.yml
190
194
  - fixtures/rspec/vcr/RouteC_Query/light_the_elements/as_an_array/returns_an_array_for_an_average_of_18_.yml
195
+ - fixtures/rspec/vcr/RouteC_Query/lights_the_lights.yml
191
196
  - lib/route_c.rb
192
197
  - lib/route_c/cli.rb
198
+ - lib/route_c/lights.rb
199
+ - lib/route_c/query.rb
193
200
  - lib/route_c/version.rb
194
201
  - route_c.gemspec
202
+ - routec.init.d.example
195
203
  homepage: http://github.com
196
204
  licenses:
197
205
  - MIT
@@ -202,17 +210,17 @@ require_paths:
202
210
  - lib
203
211
  required_ruby_version: !ruby/object:Gem::Requirement
204
212
  requirements:
205
- - - ">="
213
+ - - ! '>='
206
214
  - !ruby/object:Gem::Version
207
215
  version: '0'
208
216
  required_rubygems_version: !ruby/object:Gem::Requirement
209
217
  requirements:
210
- - - ">="
218
+ - - ! '>='
211
219
  - !ruby/object:Gem::Version
212
220
  version: '0'
213
221
  requirements: []
214
222
  rubyforge_project:
215
- rubygems_version: 2.5.1
223
+ rubygems_version: 2.4.5
216
224
  signing_key:
217
225
  specification_version: 4
218
226
  summary: words