dbplot 0.0.1 → 0.0.2

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.
@@ -6,12 +6,43 @@ h2. Installation
6
6
 
7
7
  <pre><code>sudo gem install dbplot</code></pre>
8
8
 
9
- h2. Example
9
+ h2. Usage
10
10
 
11
- <pre><code>dbplot -d dbplot -u joe -p password -q "plot yvar vs xvar from tablename"</code></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
1
+ 0.0.2
data/bin/dbplot CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+
3
+ $:.unshift(File.instance_eval { expand_path(join(dirname(__FILE__), '..', "lib")) })
4
+
3
5
  require 'dbplot'
4
6
  require 'dbplot/runner'
5
7
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dbplot}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jacob Rothstein"]
@@ -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="localhost");
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})(?: into ([a-z._]+))?/i
61
- @ordinate, @ordinate_alias, @abscissa, @abscissa_alias, @table, @file = $1, $2, $3, $4, $5, $6
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Rothstein