Database Reference
In-Depth Information
for r in result:
setattr(r, "timestampAsStr",
datetime.fromtimestamp(int(r.timestamp)).strftime('%m/%d/%Y') + " at " +
datetime.fromtimestamp(int(r.timestamp)).strftime('%I:%M %p')
)
return result
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 prepopulated 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 9-35).
Listing 9-35. Consumption Route to Show a List of Products and the Product Trail of the Current User
# show products and products VIEWED by user
@route('/consumption', method='GET')
def consumption():
products = Product().get_products(graph_db, 0)
next = True
nextPageUrl = "/consumption/10"
productTrail = Product().get_product_trail(graph_db, request.cookies[graphstoryUserAuthKey])
return template('public/templates/graphs/consumption/index.html',
layout=applayout, products=products,
productTrail=productTrail, next=next, nextPageUrl=nextPageUrl,
title="Consumption")
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, you are creating a
timestamp with a date and string value of the timestamp. The query, provided in Listing 9-36, checks to see if a VIEWED
relationship already exists between the user and the product using MERGE .
In the MERGE section of the query, if the result of the MERGE is zero matches, then a relationship is created with key
value pairs on the new relationship, specifically dateAsStr and timestamp. Finally, the query uses MATCH to return the
existing product views.
 
Search WWH ::




Custom Search