Am Sonntag, 12. Februar 2017 21:22:39 UTC+1 schrieb Borov:
>
> I think I just got your idea. Misunderstood it at first. Sorry to confuse 
> you. 
>
> I see that your magic is happening due to the "grid_to" edge. As per your 
> documentation:
>
>> Besides the hierarchically TimeGraph »Jahr <-->Monat <--> Tag <--> 
>> Stunde« the Vertices are connected horizontally via »grid_to«-Edges. This 
>> enables an easy access to the neighbours.
>
>
> Can you please explain how do you internally connect these dates? Are you 
> simply taking each day and connect it to the next using the "grid_to" edge 
> at the time of building the entire year? Or, is there anything else 
> applied? And if this is how it works, which nodes do you connect a Day -> 
> Next Day or anything else?
>
> I tried to read your rubby logic, but realized that I'd need to first 
> learn ruby. Don't have that much time :)
>
>
>
Its quite simple, though I omitted any metaprogramming. 
1) Start with the given years  (an array or a range) and create a 
Year-Vertex.
2) Then connect via an GRID_OF-Edge to the  Neighbor-Year-Vertex, if 
present.
3) Create Month-Vertices in the same manner
4) repeat it with daily  and hourly vertices
5) Before closing the loop, create vertical edges

The Idea of the timegraph is to connect to an already present grid-element.
Thus the first step is to establish an empty grid. 
After this, you may attach anything you want to the grid and are able to 
fetch it with a customized logic. 

Hope you are now able, to move on.

Greetings
hartmut



TG::Jahr,Monat,Tag,Stunde are vertices,
TG::GRID_OF is the Edge-Class.
 

> (1) years.each do | the_year |
> year_vertex = TG::Jahr.create value: the_year
> (2) TG::GRID_OF.create( from: year_grid , to: year_vertex ) if 
> year_grid.present?
> year_grid =  year_vertex
> (3) month_vertices = ( 1 .. 12 ).map do | the_month |
>  month_vertex= TG::Monat.create value: the_month
>  TG::GRID_OF.create( from: month_grid , to: month_vertex ) if 
> month_grid.present?
>  month_grid =  month_vertex
>  last_month_day =  (Date.new( the_year, the_month+1, 1)-1).day rescue 31 
>  # rescue covers month > 12
> (4)  day_vertices = ( 1 .. last_month_day ).map do | the_day | 
>    day_vertex = TG::Tag.create value: the_day  
>    TG::GRID_OF.create( from: day_grid , to: day_vertex ) if 
> day_grid.present?
>    day_grid =  day_vertex
>    if kind_of_grid == 'hourly'
>      hour_vertices = (0 .. 23).map do |h| 
> hour_vertex =  Stunde.create( value: h)
> (5) TG::GRID_OF.create( from: hour_grid , to: hour_vertex ) if 
> hour_grid.present?
> hour_grid =  hour_vertex
> hour_vertex # return_value
>      end
> (5)      TG::TIME_OF.create from: day_vertex, to: hour_vertices
>    end 
>    day_vertex # return_value
>  end
> (5)  TG::DAY_OF.create from: month_vertex, to: day_vertices
>  month_vertex # return_value
> end
> (5) TG::MONTH_OF.create from: year_vertex, to: month_vertices
>       end
>     end




 

>
> On Wednesday, February 8, 2017 at 11:31:11 PM UTC-8, hartmut bischoff 
> wrote:
>>
>> Hi,
>>
>> the time-graph in the ruby-gem follows the standard approach. Its 
>> documented on github.
>>
>> You are walking horizontally through the grid. Therefor you have to start 
>> at the day-class in order walk to a different day. On the year-level, the 
>> adjacent node is another year.
>>
>>
>> Am Donnerstag, 9. Februar 2017 07:39:50 UTC+1 schrieb Borov:
>>>
>>> Does your time-grid has the same node structure as in my diagram? I like 
>>> the idea of counting number of days in the range and do a traversal, 
>>> however, if I start the traversal from the top (Year) node it will get me 
>>> all months and days for the specified limit.
>>>
>>> How do I start from the specific day and go let say to the right 
>>> (ascending order) to get next days until the counted limit of days reached? 
>>> If I start from a specific day, I would have to traverse to its parent 
>>> (Month) and then to that parent (Year) in order to traverse days 
>>> horizontally, but it's the same as starting from the Year.
>>>
>>> For example, this traversal query get's me the 10 days, but how do I 
>>> start from a specific day and go to the right to get the next day, etc.?
>>>
>>> select from (
>>>   traverse out()
>>>   from #217:6  // Year node
>>>   maxdepth 2
>>>   strategy BREADTH_FIRST
>>> ) 
>>> where $depth >= 2
>>> limit 10
>>>
>>>
>>> Or am I missing something here? Or my graph (per diagrams) is not 
>>> correct?
>>>
>>>
>>>
>>> On Wednesday, February 8, 2017 at 1:40:31 AM UTC-8, hartmut bischoff 
>>> wrote:
>>>>
>>>>
>>>>
>>>> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to