dbplot 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +33 -2
- data/VERSION +1 -1
- data/bin/dbplot +3 -1
- data/dbplot.gemspec +1 -1
- data/lib/dbplot.rb +20 -5
- metadata +1 -1
data/README.textile
CHANGED
@@ -6,12 +6,43 @@ h2. Installation
|
|
6
6
|
|
7
7
|
<pre><code>sudo gem install dbplot</code></pre>
|
8
8
|
|
9
|
-
h2.
|
9
|
+
h2. Usage
|
10
10
|
|
11
|
-
<pre
|
11
|
+
<pre>
|
12
|
+
Usage: dbplot [options]
|
13
|
+
--help This message
|
14
|
+
-v, --verbose Run verbosely
|
15
|
+
-h, --host HOST MySQL Host
|
16
|
+
-u, --user USER MySQL User
|
17
|
+
-p, --password PASSWORD MySQL Password
|
18
|
+
-d, --database DATABASE MySQL Database
|
19
|
+
-q, --query QUERY dbplot query
|
20
|
+
--version Print version info and exit
|
21
|
+
--dry-run Print but do not execute. Implies -v.
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
h3. Non-interactive
|
25
|
+
|
26
|
+
<pre><code>dbplot -d database -u username -p password -q "plot yvar vs xvar from tablename"</code></pre>
|
12
27
|
|
13
28
|
This would generate and execute a MySQL query (@select yvar, xvar from tablename@), pass it to R, and use ggplot2 to generate the appropriate plot (@qplot(xvar, yvar, data=data.from.mysql)@) and save it to a pdf (by default, out.pdf).
|
14
29
|
|
30
|
+
h3. Interactive
|
31
|
+
|
32
|
+
If you skip the @-q@ flag, you'll land on a dbplot prompt, which lets you execute multiple dbplot commands.
|
33
|
+
dbplot commands can be multiple lines and will not evaluate until a line ends with a semicolon (much like the mysql command).
|
34
|
+
Type "exit" or "quit" to get out.
|
35
|
+
|
36
|
+
h2. Syntax
|
37
|
+
|
38
|
+
<pre><code>
|
39
|
+
PLOT y_variable [AS y_variable_alias] VS x_variable [AS x_variable_alias] FROM table_name
|
40
|
+
[COLOR BY color_variable [AS color_variable_alias]]
|
41
|
+
[FACET BY facet_variable [AS facet_variable_alias]]
|
42
|
+
[INTO output_filename.pdf]
|
43
|
+
</code></pre>
|
44
|
+
|
45
|
+
|
15
46
|
h2. Project Goals:
|
16
47
|
|
17
48
|
Support as much of common interactions between a database and ggplot2, including joins, faceting, grouping, coloring, summarization, different geoms, etc.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/bin/dbplot
CHANGED
data/dbplot.gemspec
CHANGED
data/lib/dbplot.rb
CHANGED
@@ -38,7 +38,7 @@ class DbPlot
|
|
38
38
|
|
39
39
|
con <- dbConnect(MySQL(), user="#{settings[:username]}",
|
40
40
|
password="#{settings[:password]}", dbname="#{settings[:database]}",
|
41
|
-
host="
|
41
|
+
host="#{settings[:host]}");
|
42
42
|
|
43
43
|
data <- dbGetQuery(con, "#{@query}")
|
44
44
|
|
@@ -57,11 +57,11 @@ class DbPlot
|
|
57
57
|
def parse
|
58
58
|
name_regex = /[a-z_]+/
|
59
59
|
|
60
|
-
if string =~ /plot (#{name_regex})(?: as (#{name_regex}))? vs (#{name_regex})(?: as (#{name_regex}))? from (#{name_regex})
|
61
|
-
@ordinate, @ordinate_alias, @abscissa, @abscissa_alias, @table
|
62
|
-
|
63
|
-
@file ||= "out.pdf"
|
60
|
+
if string =~ /plot (#{name_regex})(?: as (#{name_regex}))? vs (#{name_regex})(?: as (#{name_regex}))? from (#{name_regex})/i
|
61
|
+
@ordinate, @ordinate_alias, @abscissa, @abscissa_alias, @table = $1, $2, $3, $4, $5
|
64
62
|
|
63
|
+
@file = "out.pdf"
|
64
|
+
|
65
65
|
@needed_columns = {@ordinate => @ordinate_alias, @abscissa => @abscissa_alias}
|
66
66
|
|
67
67
|
@qplot = [
|
@@ -69,10 +69,25 @@ class DbPlot
|
|
69
69
|
@ordinate_alias || @ordinate
|
70
70
|
]
|
71
71
|
|
72
|
+
if string =~ /into ([a-z._]+.pdf)/
|
73
|
+
@file = $1
|
74
|
+
end
|
75
|
+
|
72
76
|
if string =~ /color by (#{name_regex})(?: as (#{name_regex}))?/i
|
73
77
|
@needed_columns[$1] = $2
|
74
78
|
@qplot << "colour = #{$2 || $1}"
|
75
79
|
end
|
80
|
+
|
81
|
+
if string =~ /facet by (#{name_regex})(?: as (#{name_regex}))?(?: vs (#{name_regex})(?: as (#{name_regex}))?)?/i
|
82
|
+
@needed_columns[$1] = $2
|
83
|
+
if $3
|
84
|
+
@needed_columns[$3] = $4
|
85
|
+
@qplot << "facets = #{$2 || $1}~#{$4 || $3}"
|
86
|
+
else
|
87
|
+
@qplot << "facets = ~#{$2 || $1}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
76
91
|
else
|
77
92
|
puts "\ncould not parse: \"#{string}\"\n\n"
|
78
93
|
@string = nil
|