Am Mittwoch, 8. Februar 2017 09:55:43 UTC+1 schrieb hartmut bischoff: > > In the ruby-gem I realized it in a different way. > If you populated a time-grid correctly, you got exact one object per > time-frame (ie. one per day). The days are connected via nodes. > Thus - if you count the time-frames (days) between start and end of your > time-range, you know the count of nodes to traverse. > > This is the ruby-method to get these elements: > > 85 def environment previous_items = 10, next_items = nil > 86 next_items = previous_items if next_items.nil? # default : > symmetric fetching > 87 > 88 my_query = -> (count) { dir = count <0 ? 'in' : 'out'; db.execute > { "select from ( traverse #{dir}(\"grid_of\") from #{rrid} while > $depth <= #{count.abs}) where $depth >=1 " } } # don't fetch self > 89 > 90 prev_result = previous_items.zero? ? [] : my_query[ -previous_items > ] > 91 next_result = next_items.zero? ? [] : my_query[ next_items ] > 92 > 93 prev_result.reverse << self | next_result > 94 end > > > From the documentation: > >> Get the nearest horizontal neighbors >> >> Takes one or two parameters. >> >> (TG::TimeBase.instance).environment: count_of_previous_nodes, >> count_of_future_nodes >> >> Default: return the previous and next 10 items >> >> "22.4.1967".to_tg.environment.datum >> => ["12.4.1967", "13.4.1967", "14.4.1967", "15.4.1967", "16.4.1967", >> "17.4.1967", "18.4.1967", "19.4.1967", …"20.4.1967", "21.4.1967", >> "22.4.1967", "23.4.1967", "24.4.1967", "25.4.1967", "26.4.1967", >> "27.4.1967", "28.4. …1967", "29.4.1967", "30.4.1967", "1.5.1967", >> "2.5.1967"] >> > > > I am sure you can easily adapt to java >
I just checked 2.4.0 :017 > t1 = Date.new 2015, 10, 15 # 10/15/2015 - 02/05/2017 => Thu, 15 Oct 2015 2.4.0 :018 > t2 = Date.new 2017, 5, 2 => Tue, 02 May 2017 2.4.0 :019 > date_range = t1.to_tg.environment(t2-t1) (...) 2.4.0 :020 > date_range.first ## inspect ruby-object => #<TG::Tag:0x00000001d90188 @metadata={"type"=>"d", "class"=>"tag", "version"=>4, "fieldTypes"=>"in_grid_of=g,out_grid_of=g,in_day_of=g", "cluster"=>26, "record"=>10431, "edges"=>{"in"=>["grid_of", "day_of"], "out"=>["grid_of"]}}, @d=nil, @attributes={"value"=>29, "in_grid_of"=>["#49:10802"], "out_grid_of"=>["#50:10802"], "in_day_of"=>["#42:10431"], "created_at"=>Wed, 08 Feb 2017 10:30:39 +0100}> 2.4.0 :021 > date_range.last => #<TG::Tag:0x000000044c4f88 @metadata={"type"=>"d", "class"=>"tag", "version"=>4, "fieldTypes"=>"in_grid_of=g,out_grid_of=g,in_day_of=g", "cluster"=>28, "record"=>10713, "edges"=>{"in"=>["grid_of", "day_of"], "out"=>["grid_of"]}}, @d=nil, @attributes={"value"=>2, "in_grid_of"=>["#52:11094"], "out_grid_of"=>["#49:11095"], "in_day_of"=>["#44:10713"], "created_at"=>Wed, 08 Feb 2017 10:30:40 +0100}> 2.4.0 :022 > date_range.last.datum ## datum is a method of TG::Tag => "2.5.2017" 2.4.0 :024 > date_range.size => 1131 seems it works as proposed -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.