caddie 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bdc2a5e9c25ef5e2dcd4c493cfc3dcbb1d8e7ba
4
- data.tar.gz: 4f3e2dfe992c6372efd9ac22748dbf6c8d8ab1ee
3
+ metadata.gz: 8cde684aa557176c35056c250c5c83aa6d94f9ff
4
+ data.tar.gz: 5eed164762cd4574a8f6334eed84d2494c4cc87d
5
5
  SHA512:
6
- metadata.gz: 79bf09bff7a35246301f19eb7ad4ea4cafc0d09802956bae39848584db6d2e88649bb58917899ee164521700fe32dca847ccb4a3a82e4275d26839adb992a30f
7
- data.tar.gz: 7c3130658d924ea1b7fa68d168ee5634bea345b341c0bed9bfc7ddd7e448cb91d076ac25360fc025cec8b8ce6651f4ecb040f52c222b6ae0ce0d1b5248e994d6
6
+ metadata.gz: 6e0b29ddfcd8346b4c381a0b6bf0707a1c370c708f34524f3077ca3b5eca5645ed5a9687fb06973749e604daa830111c8f54ea59ef6c6719ea8890fc9388d40c
7
+ data.tar.gz: 6b89a77002858571d2a73faa33e27a91b167c5ce31d6c79dd7244b79aeaf84d2efb2ae7f648db8e093a18410b02d4f94af4e1231e9af2be55c0102def1301c6d
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Caddie
2
4
 
3
5
  class CrestPriceHistoryUpdate < ActiveRecord::Base
@@ -19,26 +21,34 @@ module Caddie
19
21
 
20
22
  daily_operations_list.joins( :eve_item, :region ).pluck( :eve_item_id, :region_id, :cpp_eve_item_id, :cpp_region_id ).each do |row|
21
23
 
24
+ # puts "Processing row = #{row}"
25
+
22
26
  eve_item_id, region_id, cpp_eve_item_id, cpp_region_id = row
23
27
  # puts "Requesting : #{cpp_region_id}, #{cpp_eve_item_id}"
24
28
  items, connections_count = get_markets( cpp_region_id, cpp_eve_item_id )
25
29
  total_connections_counts += connections_count
26
30
 
27
31
  ActiveRecord::Base.transaction do
32
+
33
+ # puts 'About to reject already used lines'
34
+ timestamps = CrestPriceHistory.where( region_id: region_id, eve_item_id: eve_item_id ).pluck( :day_timestamp ).to_set
35
+ items.reject! do |item|
36
+ date_info = DateTime.parse( item['date'] )
37
+ date_info_ts = date_info.strftime( '%Y%m%d' )
38
+ timestamps.include?( date_info_ts )
39
+ end
40
+ # puts 'Lines rejected'
41
+
42
+
28
43
  items.each do |item_data|
29
44
 
30
45
  date_info = DateTime.parse( item_data['date'] )
31
46
  date_info_ts = date_info.strftime( '%Y%m%d' )
32
47
 
33
- CrestPriceHistory.where( region_id: region_id, eve_item_id: eve_item_id, day_timestamp: date_info_ts ).first_or_create! do |h|
34
- h.history_date = date_info
35
- h.order_count = item_data['orderCount']
36
- h.volume = item_data['volume']
37
- h.low_price = item_data['lowPrice']
38
- h.avg_price = item_data['avgPrice']
39
- h.high_price = item_data['highPrice']
48
+ CrestPriceHistory.create!( region_id: region_id, eve_item_id: eve_item_id, day_timestamp: date_info_ts,
49
+ history_date: date_info, order_count: item_data['orderCount'], volume: item_data['volume'],
50
+ low_price: item_data['lowPrice'], avg_price: item_data['avgPrice'], high_price: item_data['highPrice'] )
40
51
  total_inserts += 1
41
- end
42
52
  end
43
53
  end
44
54
  end
@@ -48,7 +58,7 @@ module Caddie
48
58
  private
49
59
 
50
60
  def self.daily_operations_list
51
- self.where( next_process_date: Time.now.to_date ).order( :process_queue_priority )
61
+ self.where( next_process_date: Time.now.to_date ).order( :process_queue_priority ).limit( 100 )
52
62
  end
53
63
 
54
64
  end
@@ -0,0 +1,6 @@
1
+ class MThreadedUpdater
2
+
3
+ # TODO : - split the work in database using thread_slice_id (set numbers : 1 .. MAX_THREADS)
4
+ # TODO : Then run N threads each threads get the records associated to it's number
5
+
6
+ end
@@ -36,4 +36,5 @@ WHERE nb_days <= 30 AND nb_days > 7;
36
36
 
37
37
  UPDATE caddie_crest_price_history_updates cphu
38
38
  SET process_queue = 'MONTHLY', next_process_date = date_trunc( 'month', ( current_date + ( interval '1 month' ) ) ), process_queue_priority = 3
39
- WHERE nb_days > 30 OR nb_days IS NULL;
39
+ WHERE nb_days > 30 OR nb_days IS NULL;
40
+
@@ -0,0 +1,5 @@
1
+ class AddThreadSliceIdToCaddieCrestPriceHistoryUpdates < ActiveRecord::Migration
2
+ def change
3
+ add_column :caddie_crest_price_history_updates, :thread_slice_id, :integer, index: true
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Caddie
2
- VERSION = "0.0.2"
2
+ VERSION = '0.0.4'
3
3
  end
@@ -4,7 +4,7 @@ namespace :caddie do
4
4
  task :feed_price_histories => :environment do
5
5
 
6
6
  puts 'About to compute crest_price_history_updates'
7
- Caddie::CrestPriceHistoryUpdate.update
7
+ Caddie::CrestPriceHistoryUpdate.update
8
8
 
9
9
  puts 'About to feed crest_price_histories'
10
10
  total_inserts, total_connections, total_time = Caddie::CrestPriceHistoryUpdate.feed_price_histories
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20160405090537) do
14
+ ActiveRecord::Schema.define(version: 20160527152027) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"
@@ -38,6 +38,24 @@ ActiveRecord::Schema.define(version: 20160405090537) do
38
38
  add_index "blueprints", ["cpp_blueprint_id"], name: "index_blueprints_on_cpp_blueprint_id", using: :btree
39
39
  add_index "blueprints", ["eve_item_id"], name: "index_blueprints_on_eve_item_id", using: :btree
40
40
 
41
+ create_table "caddie_crest_price_history_updates", force: :cascade do |t|
42
+ t.integer "eve_item_id"
43
+ t.integer "region_id"
44
+ t.date "max_update"
45
+ t.date "max_eve_item_create"
46
+ t.date "max_region_create"
47
+ t.date "max_date"
48
+ t.integer "nb_days"
49
+ t.string "process_queue"
50
+ t.integer "process_queue_priority"
51
+ t.date "next_process_date"
52
+ t.datetime "created_at", null: false
53
+ t.datetime "updated_at", null: false
54
+ t.integer "thread_slice_id"
55
+ end
56
+
57
+ add_index "caddie_crest_price_history_updates", ["eve_item_id", "region_id"], name: "index_caddie_cphu_on_eve_item_id_and_region_id", unique: true, using: :btree
58
+
41
59
  create_table "components", force: :cascade do |t|
42
60
  t.integer "cpp_eve_item_id"
43
61
  t.string "name", limit: 255
@@ -336,6 +354,8 @@ ActiveRecord::Schema.define(version: 20160405090537) do
336
354
 
337
355
  add_foreign_key "api_key_errors", "users"
338
356
  add_foreign_key "blueprints", "eve_items"
357
+ add_foreign_key "caddie_crest_price_history_updates", "eve_items"
358
+ add_foreign_key "caddie_crest_price_history_updates", "regions"
339
359
  add_foreign_key "crest_costs", "eve_items"
340
360
  add_foreign_key "crest_price_histories", "eve_items"
341
361
  add_foreign_key "crest_price_histories", "regions"