finexclub 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +58 -0
- data/VERSION +1 -0
- data/bin/finexclub_updater +120 -0
- data/config.ru +4 -0
- data/finexclub.gemspec +100 -0
- data/lib/finexclub/app.rb +29 -0
- data/lib/finexclub/chart.rb +42 -0
- data/lib/finexclub/core.rb +36 -0
- data/lib/finexclub/document.rb +116 -0
- data/lib/finexclub/fabrication.rb +60 -0
- data/lib/finexclub/images.rb +38 -0
- data/lib/finexclub/manager.rb +103 -0
- data/lib/finexclub/signal.rb +27 -0
- data/lib/finexclub/signals/alpha.rb +28 -0
- data/lib/finexclub/signals/zeta.rb +26 -0
- data/lib/finexclub.rb +45 -0
- data/samples/egg.png +0 -0
- data/spec/finexclub/alpha_spec.rb +47 -0
- data/spec/finexclub/app_spec.rb +89 -0
- data/spec/finexclub/chart_spec.rb +51 -0
- data/spec/finexclub/core_spec.rb +91 -0
- data/spec/finexclub/document_spec.rb +203 -0
- data/spec/finexclub/images_spec.rb +49 -0
- data/spec/finexclub/manager_spec.rb +99 -0
- data/spec/finexclub/signal_spec.rb +38 -0
- data/spec/finexclub/zeta_spec.rb +52 -0
- data/spec/spec_helper.rb +34 -0
- metadata +185 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alex Levin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "finexclub"
|
8
|
+
gem.summary = %Q{Little helper to maintain Forex signals and screenshots}
|
9
|
+
gem.description = %Q{Finexclub gem stores and retrieves Forex signals and screenshots. It is the heart of the http://trendsonforex.com and http://finexclub.net}
|
10
|
+
gem.email = "clubfinex@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/alexlevin/finexclub"
|
12
|
+
gem.authors = ["Alex Levin"]
|
13
|
+
gem.add_development_dependency "bacon", ">= 1.1.0"
|
14
|
+
gem.add_development_dependency "facon", ">= 0.4.1"
|
15
|
+
gem.add_dependency "mongo", ">= 1.0.8"
|
16
|
+
gem.add_dependency "dragonfly", ">= 0.7.6"
|
17
|
+
gem.add_dependency "sinatra", ">= 1.0.0"
|
18
|
+
gem.add_dependency "awesome_print", ">= 0.2.1"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:spec) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |spec|
|
36
|
+
spec.libs << 'spec'
|
37
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
38
|
+
spec.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
task :spec => :check_dependencies
|
47
|
+
|
48
|
+
task :default => :spec
|
49
|
+
|
50
|
+
require 'rake/rdoctask'
|
51
|
+
Rake::RDocTask.new do |rdoc|
|
52
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
53
|
+
|
54
|
+
rdoc.rdoc_dir = 'rdoc'
|
55
|
+
rdoc.title = "finexclub #{version}"
|
56
|
+
rdoc.rdoc_files.include('README*')
|
57
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
58
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
require "cgi"
|
7
|
+
require File.dirname(__FILE__) + "/../lib/finexclub"
|
8
|
+
require "optparse"
|
9
|
+
|
10
|
+
class GenFactory
|
11
|
+
def self.get(gen)
|
12
|
+
case gen
|
13
|
+
when 'alpha'
|
14
|
+
AlphaGen.new
|
15
|
+
when 'zeta'
|
16
|
+
ZetaGen.new
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class AlphaGen
|
22
|
+
def name
|
23
|
+
'alpha'
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate(options = {})
|
27
|
+
Finexclub::Chart::SYMBOLS.inject([]) do |data, symbol|
|
28
|
+
data << ["alpha[][symbol]", symbol.upcase]
|
29
|
+
data << ["alpha[][index]", rand(100)]
|
30
|
+
data << ["alpha[][direction]", rand > 0.5? 1 : 0]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class ZetaGen
|
36
|
+
def name
|
37
|
+
'zeta'
|
38
|
+
end
|
39
|
+
|
40
|
+
def generate(options = {})
|
41
|
+
symbol = options[:symbol] || raise("ZetaGen :symbol option is missing")
|
42
|
+
data = []
|
43
|
+
data << ["zeta[][symbol]", symbol.upcase]
|
44
|
+
data << ["zeta[][up_support]", rand(10)]
|
45
|
+
data << ["zeta[][up_resist]", rand(10)]
|
46
|
+
data << ["zeta[][down_support]", rand(10)]
|
47
|
+
data << ["zeta[][down_resist]", rand(10)]
|
48
|
+
data << ["zeta[][screenshot_filename]", "#{symbol.upcase}_ZETA.gif"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class FakeUpdater
|
53
|
+
def initialize(host, port)
|
54
|
+
@host = host
|
55
|
+
@port = port
|
56
|
+
end
|
57
|
+
|
58
|
+
def send(generator, options = {})
|
59
|
+
puts "Sending '#{generator.name}' to #{@host}:#{@port}"
|
60
|
+
begin
|
61
|
+
data = join_params(generator.generate(options))
|
62
|
+
http = Net::HTTP.new(@host, @port)
|
63
|
+
response = http.post("/#{generator.name}", data)
|
64
|
+
puts "Done... #{response.value}"
|
65
|
+
rescue Exception => e
|
66
|
+
puts "...Failed!"
|
67
|
+
puts e.message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def join_params(params)
|
72
|
+
params.map {|k,v| "#{CGI::escape(k)}=#{CGI::escape(v.to_s)}"}.join('&')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
options = {}
|
77
|
+
options[:host] = 'localhost'
|
78
|
+
options[:port] = 9292
|
79
|
+
opts = OptionParser.new do |opts|
|
80
|
+
opts.banner = "Usage: fake_updater.rb alpha|zeta|mega_load [options]"
|
81
|
+
|
82
|
+
opts.on("-a", "--address ADDRESS", "Host to send, default is #{options[:host]}") do |h|
|
83
|
+
options[:host] = h
|
84
|
+
end
|
85
|
+
|
86
|
+
opts.on("-p", "--port PORT", "Use port, default is #{options[:port]}") do |p|
|
87
|
+
options[:port] = p
|
88
|
+
end
|
89
|
+
|
90
|
+
opts.on("-s", "--symbol SYMBOL", "Symbol to use (eurusd, audchf...)") do |s|
|
91
|
+
options[:symbol] = s
|
92
|
+
end
|
93
|
+
|
94
|
+
opts.on_tail("-h", "Help") do |s|
|
95
|
+
puts opts
|
96
|
+
exit
|
97
|
+
end
|
98
|
+
|
99
|
+
opts.on_tail("-g GENERATOR", %w/alpha zeta mega_load/, "One of the generators to send (alpha, zeta)") do |g|
|
100
|
+
options[:generator] = g
|
101
|
+
end
|
102
|
+
end
|
103
|
+
opts.parse!
|
104
|
+
|
105
|
+
case options[:generator]
|
106
|
+
when 'alpha', 'zeta'
|
107
|
+
FakeUpdater.new(options[:host], options[:port]).send(GenFactory.get(options[:generator]), options)
|
108
|
+
when 'mega_load'
|
109
|
+
f = FakeUpdater.new(options[:host], options[:port])
|
110
|
+
a = AlphaGen.new
|
111
|
+
z = ZetaGen.new
|
112
|
+
f.send(a)
|
113
|
+
Finexclub::Chart::SYMBOLS.each do |symbol|
|
114
|
+
f.send(z, :symbol => symbol)
|
115
|
+
end
|
116
|
+
else
|
117
|
+
puts opts
|
118
|
+
end
|
119
|
+
|
120
|
+
|
data/config.ru
ADDED
data/finexclub.gemspec
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{finexclub}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex Levin"]
|
12
|
+
s.date = %q{2010-10-06}
|
13
|
+
s.default_executable = %q{finexclub_updater}
|
14
|
+
s.description = %q{Finexclub gem stores and retrieves Forex signals and screenshots. It is the heart of the http://trendsonforex.com and http://finexclub.net}
|
15
|
+
s.email = %q{clubfinex@gmail.com}
|
16
|
+
s.executables = ["finexclub_updater"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/finexclub_updater",
|
29
|
+
"config.ru",
|
30
|
+
"finexclub.gemspec",
|
31
|
+
"lib/finexclub.rb",
|
32
|
+
"lib/finexclub/app.rb",
|
33
|
+
"lib/finexclub/chart.rb",
|
34
|
+
"lib/finexclub/core.rb",
|
35
|
+
"lib/finexclub/document.rb",
|
36
|
+
"lib/finexclub/fabrication.rb",
|
37
|
+
"lib/finexclub/images.rb",
|
38
|
+
"lib/finexclub/manager.rb",
|
39
|
+
"lib/finexclub/signal.rb",
|
40
|
+
"lib/finexclub/signals/alpha.rb",
|
41
|
+
"lib/finexclub/signals/zeta.rb",
|
42
|
+
"samples/egg.png",
|
43
|
+
"spec/finexclub/alpha_spec.rb",
|
44
|
+
"spec/finexclub/app_spec.rb",
|
45
|
+
"spec/finexclub/chart_spec.rb",
|
46
|
+
"spec/finexclub/core_spec.rb",
|
47
|
+
"spec/finexclub/document_spec.rb",
|
48
|
+
"spec/finexclub/images_spec.rb",
|
49
|
+
"spec/finexclub/manager_spec.rb",
|
50
|
+
"spec/finexclub/signal_spec.rb",
|
51
|
+
"spec/finexclub/zeta_spec.rb",
|
52
|
+
"spec/spec_helper.rb"
|
53
|
+
]
|
54
|
+
s.homepage = %q{http://github.com/alexlevin/finexclub}
|
55
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
56
|
+
s.require_paths = ["lib"]
|
57
|
+
s.rubygems_version = %q{1.3.6}
|
58
|
+
s.summary = %q{Little helper to maintain Forex signals and screenshots}
|
59
|
+
s.test_files = [
|
60
|
+
"spec/finexclub/signal_spec.rb",
|
61
|
+
"spec/finexclub/manager_spec.rb",
|
62
|
+
"spec/finexclub/app_spec.rb",
|
63
|
+
"spec/finexclub/alpha_spec.rb",
|
64
|
+
"spec/finexclub/core_spec.rb",
|
65
|
+
"spec/finexclub/images_spec.rb",
|
66
|
+
"spec/finexclub/chart_spec.rb",
|
67
|
+
"spec/finexclub/document_spec.rb",
|
68
|
+
"spec/finexclub/zeta_spec.rb",
|
69
|
+
"spec/spec_helper.rb"
|
70
|
+
]
|
71
|
+
|
72
|
+
if s.respond_to? :specification_version then
|
73
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
74
|
+
s.specification_version = 3
|
75
|
+
|
76
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
77
|
+
s.add_development_dependency(%q<bacon>, [">= 1.1.0"])
|
78
|
+
s.add_development_dependency(%q<facon>, [">= 0.4.1"])
|
79
|
+
s.add_runtime_dependency(%q<mongo>, [">= 1.0.8"])
|
80
|
+
s.add_runtime_dependency(%q<dragonfly>, [">= 0.7.6"])
|
81
|
+
s.add_runtime_dependency(%q<sinatra>, [">= 1.0.0"])
|
82
|
+
s.add_runtime_dependency(%q<awesome_print>, [">= 0.2.1"])
|
83
|
+
else
|
84
|
+
s.add_dependency(%q<bacon>, [">= 1.1.0"])
|
85
|
+
s.add_dependency(%q<facon>, [">= 0.4.1"])
|
86
|
+
s.add_dependency(%q<mongo>, [">= 1.0.8"])
|
87
|
+
s.add_dependency(%q<dragonfly>, [">= 0.7.6"])
|
88
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
89
|
+
s.add_dependency(%q<awesome_print>, [">= 0.2.1"])
|
90
|
+
end
|
91
|
+
else
|
92
|
+
s.add_dependency(%q<bacon>, [">= 1.1.0"])
|
93
|
+
s.add_dependency(%q<facon>, [">= 0.4.1"])
|
94
|
+
s.add_dependency(%q<mongo>, [">= 1.0.8"])
|
95
|
+
s.add_dependency(%q<dragonfly>, [">= 0.7.6"])
|
96
|
+
s.add_dependency(%q<sinatra>, [">= 1.0.0"])
|
97
|
+
s.add_dependency(%q<awesome_print>, [">= 0.2.1"])
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "sinatra/base"
|
2
|
+
require "ap"
|
3
|
+
|
4
|
+
module Finexclub
|
5
|
+
class App < Sinatra::Base
|
6
|
+
|
7
|
+
configure :development do
|
8
|
+
Finexclub.configure do |f|
|
9
|
+
f.signals.db = Mongo::Connection.new.db("finexclub_dev")
|
10
|
+
f.images.screenshot_path = ENV['SCREENSHOT_PATH']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
configure :production do
|
15
|
+
Finexclub.configure do |f|
|
16
|
+
f.signals.db = Mongo::Connection.from_uri(ENV['MONGOHQ_URL']).db(ENV['MONGOHQ_DB'])
|
17
|
+
f.images.screenshot_path = ENV['SCREENSHOT_PATH']
|
18
|
+
f.images.configure_with(:heroku, ENV['S3_BUCKET'])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
post "/:signal" do
|
23
|
+
signal_type = params[:signal].to_sym
|
24
|
+
ap params[signal_type]
|
25
|
+
Finexclub.store(signal_type, params[signal_type])
|
26
|
+
status 200
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Finexclub
|
2
|
+
class Chart
|
3
|
+
SYMBOLS = %w(chfjpy eurchf audusd audcad eurnzd nzdusd gbpchf nzdcad usdcad cadjpy audjpy euraud gbpnzd nzdjpy eurusd usdjpy eurcad cadchf gbpaud gbpusd audchf eurjpy gbpcad usdchf nzdchf audnzd eurgbp gbpjpy)
|
4
|
+
|
5
|
+
include Document
|
6
|
+
|
7
|
+
field :updated, :timestamp
|
8
|
+
field :symbol, :symbol
|
9
|
+
field :date, :string
|
10
|
+
|
11
|
+
attr_reader :core
|
12
|
+
|
13
|
+
def initialize(core)
|
14
|
+
@core = core
|
15
|
+
@signals = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def alpha=(arr)
|
19
|
+
@signals[:alpha]= arr
|
20
|
+
end
|
21
|
+
|
22
|
+
def zeta=(arr)
|
23
|
+
@signals[:zeta]= arr
|
24
|
+
end
|
25
|
+
|
26
|
+
def signals(type)
|
27
|
+
@signals[type]
|
28
|
+
end
|
29
|
+
|
30
|
+
def alpha
|
31
|
+
Signal.build(core, :alpha, signals(:alpha).last)
|
32
|
+
end
|
33
|
+
|
34
|
+
def zeta
|
35
|
+
Signal.build(core, :zeta, signals(:zeta).last)
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_doc
|
39
|
+
{:symbol => symbol, :date => updated_date}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Finexclub
|
4
|
+
class Core
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_reader :images
|
8
|
+
attr_reader :signals
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@images = Images.new(self)
|
12
|
+
@signals = Manager.new(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(&block)
|
16
|
+
yield self
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def store(signal_type, params)
|
21
|
+
params = params.is_a?(Array) ? params : [params]
|
22
|
+
params.each do |s|
|
23
|
+
signals.add_signal(signal_type, s)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def find(symbol, date)
|
28
|
+
if symbol == :all
|
29
|
+
signals.find(:date => date)
|
30
|
+
else
|
31
|
+
signals.find_one(:date => date, :symbol => symbol)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Finexclub
|
2
|
+
module Document
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
include InstanceMethods
|
7
|
+
extend ClassMethods
|
8
|
+
|
9
|
+
def _id=(value)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def define_attr_reader(name)
|
16
|
+
define_method "#{name}" do
|
17
|
+
instance_variable_get("@#{name}")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def define_attr_writer(name, converter = nil)
|
22
|
+
define_method "#{name}=" do |value|
|
23
|
+
value = converter.nil?? value : converter.call(value)
|
24
|
+
instance_variable_set("@#{name}", value)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def define_symbol_fields(name)
|
29
|
+
define_attr_reader(name)
|
30
|
+
define_attr_writer(name, lambda{|x| x.downcase})
|
31
|
+
end
|
32
|
+
|
33
|
+
def define_integer_fields(name)
|
34
|
+
define_attr_reader(name)
|
35
|
+
define_attr_writer(name, lambda{|x| x.to_i})
|
36
|
+
end
|
37
|
+
|
38
|
+
def define_float_fields(name)
|
39
|
+
define_attr_reader(name)
|
40
|
+
define_attr_writer(name, lambda{|x| x.to_f})
|
41
|
+
end
|
42
|
+
|
43
|
+
def define_string_fields(name)
|
44
|
+
define_attr_reader(name)
|
45
|
+
define_attr_writer(name, lambda{|x| x.to_s})
|
46
|
+
end
|
47
|
+
|
48
|
+
def define_timestamp_fields(name)
|
49
|
+
define_attr_reader(name)
|
50
|
+
define_attr_writer(name, lambda{|x| x.to_i})
|
51
|
+
|
52
|
+
define_method "#{name}_at" do
|
53
|
+
timestamp = instance_variable_get("@#{name}")
|
54
|
+
Time.at(timestamp).utc
|
55
|
+
end
|
56
|
+
|
57
|
+
define_method "#{name}_date" do
|
58
|
+
send("#{name}_at").strftime("%Y-%m-%d")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def define_image_fields(name)
|
63
|
+
define_attr_reader(name)
|
64
|
+
define_attr_writer(name)
|
65
|
+
|
66
|
+
define_method "#{name}_filename=" do |filename|
|
67
|
+
image_uid = core.images.store(filename)
|
68
|
+
instance_variable_set("@#{name}", image_uid)
|
69
|
+
end
|
70
|
+
|
71
|
+
define_method "#{name}_image" do
|
72
|
+
image_uid = instance_variable_get("@#{name}")
|
73
|
+
core.images.fetch(image_uid)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def field(name, field_type)
|
78
|
+
meta[name] = field_type
|
79
|
+
send "define_#{field_type}_fields", name
|
80
|
+
end
|
81
|
+
|
82
|
+
def meta
|
83
|
+
@meta ||= {}
|
84
|
+
end
|
85
|
+
|
86
|
+
def export_fields
|
87
|
+
@doc_fields ||= []
|
88
|
+
end
|
89
|
+
|
90
|
+
def doc_fields(*fields)
|
91
|
+
@doc_fields = fields
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
module InstanceMethods
|
96
|
+
def apply_meta(meta)
|
97
|
+
meta.each do |name, field_type|
|
98
|
+
self.class.field(name, field_type)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def build(params)
|
103
|
+
params.each do |key, value|
|
104
|
+
send "#{key}=", value
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def to_doc
|
109
|
+
doc = {}
|
110
|
+
self.class.export_fields.each { |name| doc[name] = send(name) }
|
111
|
+
doc
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Finexclub
|
2
|
+
module Fabrication
|
3
|
+
def raw_alpha_hash(options = {})
|
4
|
+
{"symbol" => "EURUSD", "index"=>"2", "direction"=>"1"}.merge(options)
|
5
|
+
end
|
6
|
+
|
7
|
+
def raw_zeta_hash(options={})
|
8
|
+
{
|
9
|
+
"symbol" => "EURUSD",
|
10
|
+
"up_support" => "1.124",
|
11
|
+
"up_resist" => "1.123",
|
12
|
+
"down_support" => "1.124",
|
13
|
+
"down_resist" => "1.123",
|
14
|
+
"screenshot_filename" => "egg.png"
|
15
|
+
}.merge(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def chart_factory(options = {})
|
19
|
+
date = options.delete(:date) || Time.now
|
20
|
+
{
|
21
|
+
:symbol => "eurusd",
|
22
|
+
:timeframe => "h1",
|
23
|
+
:date => date.respond_to?(:strftime) ? date.strftime('%Y-%m-%d') : date,
|
24
|
+
:alpha => (0..23).map {|h| self.alpha_factory(:time => Time.local(Time.now.year, Time.now.month, Time.now.day, h, 1))},
|
25
|
+
:zeta => (0..23).map {|h| self.zeta_factory(:time => Time.local(Time.now.year, Time.now.month, Time.now.day, h, 1))}
|
26
|
+
}.merge(options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def alpha_factory(options = {})
|
30
|
+
time = options[:time] || Time.now
|
31
|
+
{
|
32
|
+
:direction => 1,
|
33
|
+
:index => 30 + rand(70),
|
34
|
+
:time => time.respond_to?(:strftime) ? time.strftime('%H:%M') : time
|
35
|
+
}.merge(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def zeta_factory(options = {})
|
39
|
+
time = options[:time] || Time.now
|
40
|
+
{
|
41
|
+
:up_support => (1.1 + rand),
|
42
|
+
:up_resist => 1.1 + rand,
|
43
|
+
:down_support => 1.1 + rand,
|
44
|
+
:down_resist => 1.2 + rand,
|
45
|
+
:screenshot_uid => "ololo"
|
46
|
+
}.merge(options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def add_signals
|
50
|
+
Chart::SYMBOLS.each do |symbol|
|
51
|
+
Finexclub.store(:alpha, raw_alpha_hash("symbol"=>symbol.upcase))
|
52
|
+
Finexclub.store(:zeta, raw_zeta_hash("symbol"=>symbol.upcase))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def clear_signals
|
57
|
+
Finexclub.signals.collection.remove
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "dragonfly"
|
2
|
+
|
3
|
+
module Finexclub
|
4
|
+
class Images
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
attr_reader :core
|
8
|
+
attr_reader :app
|
9
|
+
attr_accessor :screenshot_path
|
10
|
+
|
11
|
+
def_delegators :app, :configure, :configure_with, :fetch
|
12
|
+
|
13
|
+
def initialize(core)
|
14
|
+
@core = core
|
15
|
+
@app = Dragonfly[:images]
|
16
|
+
end
|
17
|
+
|
18
|
+
def store(filename)
|
19
|
+
path = File.expand_path(File.join(screenshot_path, filename))
|
20
|
+
app.store(File.new(path))
|
21
|
+
end
|
22
|
+
|
23
|
+
def configure_endpoint(path_prefix = nil)
|
24
|
+
path_prefix ||= "/media"
|
25
|
+
@app.configure_with(:rmagick) do |c|
|
26
|
+
c.url_path_prefix = path_prefix
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Middleware < Dragonfly::Middleware
|
31
|
+
def initialize(app)
|
32
|
+
path_prefix = Dragonfly[:images].url_path_prefix
|
33
|
+
super(app, :images, path_prefix)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|