Class: Iro::Priceitem
- Inherits:
-
Object
- Object
- Iro::Priceitem
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/iro/priceitem.rb
Overview
specifically Option or Stock priceitem?
Class Method Summary collapse
Instance Method Summary collapse
-
#putCall ⇒ Object
PUT, CALL, STOCK.
Class Method Details
.my_find(props = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/iro/priceitem.rb', line 34 def self.my_find props={} lookup = { '$lookup': { 'from': 'iro_price_items', 'localField': 'date', 'foreignField': 'date', 'pipeline': [ { '$sort': { 'value': -1 } }, ], 'as': 'dates', } } lookup_merge = { '$replaceRoot': { 'newRoot': { '$mergeObjects': [ { '$arrayElemAt': [ "$dates", 0 ] }, "$$ROOT" ] } } } match = { '$match': { 'date': { '$gte': props[:begin_on], '$lte': props[:end_on], } } } group = { '$group': { '_id': "$date", 'my_doc': { '$first': "$$ROOT" } } } outs = Iro::Date.collection.aggregate([ match, lookup, lookup_merge, group, { '$replaceRoot': { 'newRoot': "$my_doc" } }, # { '$replaceRoot': { 'newRoot': "$my_doc" } }, { '$project': { '_id': 0, 'date': 1, 'value': 1 } }, { '$sort': { 'date': 1 } }, ]) puts! 'result' pp outs.to_a # puts! outs.to_a, 'result' end |
Instance Method Details
#putCall ⇒ Object
PUT, CALL, STOCK
11 |
# File 'app/models/iro/priceitem.rb', line 11 field :putCall, type: String |