graffable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +7 -0
- data/lib/graffable/app.rb +35 -19
- data/lib/graffable/database.rb +1 -1
- data/lib/graffable/migration_task.rb +6 -1
- data/lib/graffable/seed_task.rb +4 -4
- data/lib/graffable/version.rb +1 -1
- data/lib/graffable/views/report.haml +7 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46adff9ed7f91eaf984f65e4dea871ce51de43df
|
4
|
+
data.tar.gz: 18c69537813f8d22bcceec67793f6377b1937f1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29fd8acb103da34e6674e26d2c0e6f43087de388d46a5dd7d5dac7c99e0eb574ceee77f7bdc6996d1a781b62dcff8be2ba22170a3af1d14018c0e75cde9f2eae
|
7
|
+
data.tar.gz: c690f97cb951290a6380a8a1ae30613617891172c9f6fee5b2828df41bd8658d1f704c183c883a1eedc372bd7e916ba1c7e721b842e0b5e7a41d9dd410689bcc
|
data/CHANGES.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
Graffable Changes
|
3
3
|
=================
|
4
4
|
|
5
|
+
2014-02-06 Graffable v0.0.2
|
6
|
+
---------------------------
|
7
|
+
* `Graffable::Database.connect()` now connects to `ENV['DATABASE_URL']` (was `ENV['GRAFFABLE_DATABASE_URL']`)
|
8
|
+
* Fix bug `Graffable::App#return_csv` when `max` is set
|
9
|
+
* Fix bug `Graffable::App#return_json` when `max` is set
|
10
|
+
|
11
|
+
|
5
12
|
2014-01-29 Graffable v0.0.1
|
6
13
|
---------------------------
|
7
14
|
First release of Sinatra-based data charting application.
|
data/lib/graffable/app.rb
CHANGED
@@ -21,10 +21,11 @@ module Graffable
|
|
21
21
|
|
22
22
|
|
23
23
|
before do
|
24
|
-
@db = Graffable::Database.connect
|
24
|
+
@db = Graffable::Database.connect
|
25
25
|
@groups = @db[:groups].order(:name)
|
26
26
|
end
|
27
27
|
|
28
|
+
|
28
29
|
# /:group/:report/:year/:month.json
|
29
30
|
get %r{/(.+)/(.+)/(\d{4})/(\d{2}).(csv|json)} do |group_name, report_name, year, month, extension|
|
30
31
|
group = assert_group group_name
|
@@ -182,17 +183,24 @@ module Graffable
|
|
182
183
|
defaults = { max: -1 }
|
183
184
|
opts = defaults.merge params
|
184
185
|
|
185
|
-
data
|
186
|
+
data = [ %w( date label value ).to_csv ]
|
187
|
+
values = {}
|
186
188
|
dataset.each do |row|
|
187
|
-
date
|
188
|
-
label
|
189
|
-
value
|
190
|
-
|
189
|
+
date = %i( year month day hour ).collect { |k| row[k] }.compact.join('-')
|
190
|
+
label = row[:label] || ''
|
191
|
+
value = row[:value].to_i
|
192
|
+
|
193
|
+
values[date] ||= {}
|
194
|
+
values[date][label] = value
|
191
195
|
end
|
192
196
|
|
193
|
-
if opts[:max] > -1
|
194
|
-
|
195
|
-
|
197
|
+
values = values.sort.reverse.slice( 0 .. opts[:max] - 1 ).reverse if opts[:max] > - 1
|
198
|
+
values.each do |tuple|
|
199
|
+
date = tuple.first
|
200
|
+
pairs = tuple.last
|
201
|
+
pairs.each_pair do |label, value|
|
202
|
+
data << [ date, label, value ].to_csv
|
203
|
+
end
|
196
204
|
end
|
197
205
|
|
198
206
|
content_type :text
|
@@ -203,22 +211,30 @@ module Graffable
|
|
203
211
|
defaults = { max: -1 }
|
204
212
|
opts = defaults.merge params
|
205
213
|
|
206
|
-
data
|
214
|
+
data = {}
|
215
|
+
date_mapping = {}
|
216
|
+
values = {}
|
207
217
|
dataset.each do |row|
|
208
|
-
date =
|
218
|
+
date = %i( year month day hour ).collect { |k| row[k] }.compact.join('-')
|
209
219
|
label = row[:label] || ''
|
210
220
|
value = row[:value].to_i
|
221
|
+
|
222
|
+
date_mapping[date] = opts[:date_formatter].call row[:year], row[:month], row[:day], row[:hour] unless date_mapping.key?(date)
|
211
223
|
|
212
|
-
|
213
|
-
|
214
|
-
data[label][:label] = label unless label.empty?
|
215
|
-
end
|
216
|
-
data[label][:data].push [ date, value ]
|
224
|
+
values[date] ||= {}
|
225
|
+
values[date][label] = value
|
217
226
|
end
|
218
227
|
|
219
|
-
if opts[:max] > -1
|
220
|
-
|
221
|
-
|
228
|
+
values = values.sort.reverse.slice( 0 .. opts[:max] - 1 ).reverse if opts[:max] > - 1
|
229
|
+
values.each do |tuple|
|
230
|
+
date = date_mapping[ tuple.first ]
|
231
|
+
pairs = tuple.last
|
232
|
+
pairs.each_pair do |label, value|
|
233
|
+
unless data.key?(label)
|
234
|
+
data[label] = { data: [] }
|
235
|
+
data[label][:label] = label unless label.empty?
|
236
|
+
end
|
237
|
+
data[label][:data].push [ date, value ]
|
222
238
|
end
|
223
239
|
end
|
224
240
|
|
data/lib/graffable/database.rb
CHANGED
@@ -8,18 +8,19 @@ module Graffable
|
|
8
8
|
def initialize
|
9
9
|
|
10
10
|
Sequel.extension :migration
|
11
|
-
db = Graffable::Database.connect
|
12
11
|
namespace = 'graffable:migrate'
|
13
12
|
migrations = File.join( File.dirname(__FILE__), '../../db/migrations' )
|
14
13
|
|
15
14
|
desc 'Perform migration down (erase all data)'
|
16
15
|
task "#{namespace}:down" do
|
16
|
+
db = Graffable::Database.connect
|
17
17
|
Sequel::Migrator.run db, migrations, target: 0
|
18
18
|
puts "<= #{namespace}:down executed"
|
19
19
|
end
|
20
20
|
|
21
21
|
desc 'Perform migration reset (full erase and migration up)'
|
22
22
|
task "#{namespace}:reset" do
|
23
|
+
db = Graffable::Database.connect
|
23
24
|
Sequel::Migrator.run db, migrations, target: 0
|
24
25
|
Sequel::Migrator.run db, migrations
|
25
26
|
puts "<= #{namespace}:reset executed"
|
@@ -27,6 +28,7 @@ module Graffable
|
|
27
28
|
|
28
29
|
desc 'Perform migration down (erase all data)'
|
29
30
|
task "#{namespace}:down" do
|
31
|
+
db = Graffable::Database.connect
|
30
32
|
Sequel::Migrator.run db, migrations, target: 0
|
31
33
|
puts "<= #{namespace}:down executed"
|
32
34
|
end
|
@@ -35,12 +37,15 @@ module Graffable
|
|
35
37
|
task "#{namespace}:to" do
|
36
38
|
version = ENV['VERSION'].to_i
|
37
39
|
raise 'No VERSION was provided' if version.nil?
|
40
|
+
|
41
|
+
db = Graffable::Database.connect
|
38
42
|
Sequel::Migrator.run db, migrations, target: version
|
39
43
|
puts "<= #{namespace}:to version=[#{version}] executed"
|
40
44
|
end
|
41
45
|
|
42
46
|
desc 'Perform migration to latest migration available'
|
43
47
|
task "#{namespace}:up" do
|
48
|
+
db = Graffable::Database.connect
|
44
49
|
Sequel::Migrator.run db, migrations
|
45
50
|
puts "<= #{namespace}:up executed"
|
46
51
|
end
|
data/lib/graffable/seed_task.rb
CHANGED
@@ -7,12 +7,12 @@ module Graffable
|
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
|
10
|
-
|
11
|
-
namespace = 'graffable'
|
10
|
+
namespace = 'graffable'
|
12
11
|
|
13
|
-
desc 'Load Graffable seed data from
|
12
|
+
desc 'Load Graffable seed data from SEED_FILE'
|
14
13
|
task "#{namespace}:seed" do
|
15
|
-
|
14
|
+
db = Graffable::Database.connect
|
15
|
+
key = 'SEED_FILE'
|
16
16
|
seed = ENV[key]
|
17
17
|
raise "No #{key} was provided" if seed.nil?
|
18
18
|
load seed
|
data/lib/graffable/version.rb
CHANGED
@@ -8,6 +8,10 @@
|
|
8
8
|
%a{ href: url(@next) }
|
9
9
|
%span.glyphicon.glyphicon-chevron-right
|
10
10
|
|
11
|
+
#content{ style: 'align: center; margin: auto; padding: 1em; width: 95%;' }
|
12
|
+
#placeholder{ style: 'align: center; height: 75%; margin: auto; padding: 1em; width: 95%;' }
|
13
|
+
#legend{ style: 'padding-bottom: 1em;' }
|
14
|
+
|
11
15
|
:javascript
|
12
16
|
data_url = "#{ url(@data_url) }";
|
13
17
|
|
@@ -20,6 +24,9 @@
|
|
20
24
|
grid: {
|
21
25
|
hoverable: true
|
22
26
|
},
|
27
|
+
legend: {
|
28
|
+
container: $('#legend')
|
29
|
+
},
|
23
30
|
points: {
|
24
31
|
show: true
|
25
32
|
},
|
@@ -57,7 +64,4 @@
|
|
57
64
|
|
58
65
|
});
|
59
66
|
|
60
|
-
-# FIXME
|
61
|
-
#content{ style: 'align: center; margin: auto; padding: 1em; width: 95%;' }
|
62
|
-
#placeholder{ style: 'align: center; height: 75%; margin: auto; padding: 1em; width: 95%;' }
|
63
67
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graffable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- blair christensen.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: haml
|