plotrobber 0.0.2 → 0.0.3
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.
- data/README.md +9 -0
 - data/lib/plotrobber/version.rb +1 -1
 - data/lib/plotrobber.rb +41 -12
 - metadata +2 -2
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -39,6 +39,15 @@ Do write this: 
     | 
|
| 
       39 
39 
     | 
    
         
             
                  }
         
     | 
| 
       40 
40 
     | 
    
         
             
                }
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
      
 42 
     | 
    
         
            +
            Even more convenient:
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                plot('Fit some data') {
         
     | 
| 
      
 45 
     | 
    
         
            +
                  fn = fit SOME_DATA, [1,3] # Find linear fit using columns 1 and 3.
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                  show fn                   # Plots the line of best fit
         
     | 
| 
      
 48 
     | 
    
         
            +
                  candlesticks SOME_DATA    # Plots candlesticks using 1:3:2:6:5 
         
     | 
| 
      
 49 
     | 
    
         
            +
                }
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       42 
51 
     | 
    
         
             
            ## Installation
         
     | 
| 
       43 
52 
     | 
    
         | 
| 
       44 
53 
     | 
    
         
             
            The usual:
         
     | 
    
        data/lib/plotrobber/version.rb
    CHANGED
    
    
    
        data/lib/plotrobber.rb
    CHANGED
    
    | 
         @@ -22,6 +22,32 @@ class Gnuplot::Plot 
     | 
|
| 
       22 
22 
     | 
    
         
             
                arbitrary_lines << s
         
     | 
| 
       23 
23 
     | 
    
         
             
              end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
      
 25 
     | 
    
         
            +
              def store(data)
         
     | 
| 
      
 26 
     | 
    
         
            +
                (@store ||= {})[data] ||= begin
         
     | 
| 
      
 27 
     | 
    
         
            +
                  file = Tempfile.new(['plotrobber.','.dat'])
         
     | 
| 
      
 28 
     | 
    
         
            +
                  file.write data.map{|x|x.join("\t")}.join("\n")
         
     | 
| 
      
 29 
     | 
    
         
            +
                  file.write "\n"
         
     | 
| 
      
 30 
     | 
    
         
            +
                  file.rewind
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  file
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              def source_name(what)
         
     | 
| 
      
 37 
     | 
    
         
            +
                name = case what
         
     | 
| 
      
 38 
     | 
    
         
            +
                  when String         then what
         
     | 
| 
      
 39 
     | 
    
         
            +
                  when Array          then store(what).path
         
     | 
| 
      
 40 
     | 
    
         
            +
                  when Tempfile, File then what.path
         
     | 
| 
      
 41 
     | 
    
         
            +
                  else                     what.to_s
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                unless name.start_with?("'") or name['(']
         
     | 
| 
      
 45 
     | 
    
         
            +
                  name = "'#{name}'"
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
                
         
     | 
| 
      
 48 
     | 
    
         
            +
                name
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       25 
51 
     | 
    
         
             
              def candlesticks(name, extra_opts = {})
         
     | 
| 
       26 
52 
     | 
    
         
             
                with_opt = case extra_opts[:with]
         
     | 
| 
       27 
53 
     | 
    
         
             
                  when Hash, Array then 'candlesticks ' + extra_opts[:with].to_a.join(' ')
         
     | 
| 
         @@ -34,21 +60,24 @@ class Gnuplot::Plot 
     | 
|
| 
       34 
60 
     | 
    
         
             
                show name, options
         
     | 
| 
       35 
61 
     | 
    
         
             
              end
         
     | 
| 
       36 
62 
     | 
    
         | 
| 
       37 
     | 
    
         
            -
              def  
     | 
| 
       38 
     | 
    
         
            -
                 
     | 
| 
       39 
     | 
    
         
            -
                  file = Tempfile.new(['plotrobber.','.dat'])
         
     | 
| 
       40 
     | 
    
         
            -
                  file.write name.map{|x|x.join("\t")}.join("\n")
         
     | 
| 
       41 
     | 
    
         
            -
                  file.close
         
     | 
| 
      
 63 
     | 
    
         
            +
              def fit(what, using, use_b = true)
         
     | 
| 
      
 64 
     | 
    
         
            +
                name = source_name what
         
     | 
| 
       42 
65 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
      
 66 
     | 
    
         
            +
                @next_fn ||= 0
         
     | 
| 
      
 67 
     | 
    
         
            +
                @next_fn += 1
         
     | 
| 
       45 
68 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                 
     | 
| 
      
 69 
     | 
    
         
            +
                f, m, b = %w[f m b].map {|x| "#{x}#{@next_fn}" }
         
     | 
| 
      
 70 
     | 
    
         
            +
                using_str = using.join(':')
         
     | 
| 
      
 71 
     | 
    
         
            +
                via_str = use_b ? "#{m}, #{b}" : m
         
     | 
| 
       48 
72 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
      
 73 
     | 
    
         
            +
                please '%s(x) = %s*x + %s' % [f, m, use_b ? b : 0]
         
     | 
| 
      
 74 
     | 
    
         
            +
                please 'fit %s(x) %s using %s via %s' % [f, name, using_str, via_str]
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                "#{f}(x)"
         
     | 
| 
      
 77 
     | 
    
         
            +
              end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
              def show(what, *args)
         
     | 
| 
      
 80 
     | 
    
         
            +
                name = source_name what
         
     | 
| 
       52 
81 
     | 
    
         | 
| 
       53 
82 
     | 
    
         
             
                self.data << Gnuplot::DataSet.new(name) do |ds|
         
     | 
| 
       54 
83 
     | 
    
         
             
                  for arg in args
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: plotrobber
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.3
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -9,7 +9,7 @@ authors: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       10 
10 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       11 
11 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       12 
     | 
    
         
            -
            date: 2013-03- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-03-14 00:00:00.000000000 Z
         
     | 
| 
       13 
13 
     | 
    
         
             
            dependencies:
         
     | 
| 
       14 
14 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       15 
15 
     | 
    
         
             
              name: gnuplot
         
     |