Database Reference
In-Depth Information
#convert the timestamp to readable date and time
e.merge!("timestampAsStr" => Time.at(e["timestamp"]).strftime("%m/%d/%Y") +
" at " +
Time.at(e["timestamp"]).strftime("%l:%M %p"))
end
r
end
Consumption Graph Model
This section examines a few techniques to capture and use patterns of consumption generated implicitly by a user
or users. For the purposes of your application, you will use the pre-populated set of products provided in the sample
graph. The code required for the console will reinforce the standard persistence operations, this section focuses on
the operations that take advantage of this model type, including:
Capturing consumption
Filtering consumption for users
Filtering consumption for messaging
Capturing Consumption
The process above for creating code that directly captures consumption for a user could also be done by creating
a graph-backed service to consume the webserver logs in real time, or by creating another data store to create
the relationships. The result would be the same in any event: a process that connects nodes to reveal a pattern of
consumption (Listing 10-38).
Listing 10-38. Consumption route to show a list of products and the product trail of the current user
# add a product via VIEWED relationship and return VIEWED products
get '/consumption' do
@title="Consumption"
@products=get_products(neo,0)
@next = true
@nextPageUrl="/consumption/1"
@productTrail = get_product_trail(neo,request.cookies[graphstoryUserAuthKey])
mustache :"graphs/consumption/index"
end
The sample application used the create_user_view_and_return_views method in the Product class to first find
the product being viewed and then create an explicit relationship type called VIEWED . As you may have noticed, this
is the first relationship type in the application that also contains properties. In this case, we are creating a timestamp
with a date and string value of the timestamp. The query, shown in Listing 10-39, will check to see if a VIEWED
relationship already exists between the user and the product using MERGE .
 
Search WWH ::




Custom Search