Skip to content

Instantly share code, notes, and snippets.

@rnewman
Created September 19, 2017 18:20
Show Gist options
  • Save rnewman/b7caf764ec82e6b109e64b42f13c4aa9 to your computer and use it in GitHub Desktop.
Save rnewman/b7caf764ec82e6b109e64b42f13c4aa9 to your computer and use it in GitHub Desktop.
Example attribute definitions and data for video
;; Vocabulary:
[
;; Devices.
{:db/ident :device/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The name of the FxA device."}
{:db/ident :device/platform
:db/valueType :db.type/keyword
:db/cardinality :db.cardinality/one
:db/doc "A platform: typically one of :mac, :windows, :android, :linux, :ios."}
{:db/ident :device/fxa-id
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one
:db/valueType :db.type/string
:db/doc "The unique FxA device identifier for this device."}
;; Visits.
{:db/ident :visit/url
:db/valueType :db.type/uri
:db/cardinality :db.cardinality/one
:db/doc "Each visit represents a device's navigation to a single URL."}
{:db/ident :visit/device
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The device that conducted the visit."}
{:db/ident :visit/at
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/doc "The instant in time at which the visit began, corresponding to the end of page load."}
{:db/ident :visit/page
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The top-level page entity that was retrieved during this visit."}
{:db/ident :visit/from
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "An optional referring visit -- the visit from which the user came."}
;; Pages.
{:db/ident :page/title
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The title of the page, typically corresponding to the HTML title element."}
{:db/ident :page/embeds
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/doc "If this page contains iframes, this attribute points to them."}
{:db/ident :page/contains-video
:db/valueType :db.type/uri
:db/cardinality :db.cardinality/many
:db/doc "If this page contains video elements, this attribute points to their srcs"}
{:db/ident :page/canonical
:db/valueType :db.type/uri
:db/doc "The page's optional canonical URL."}
;; Videos.
{:db/ident :video/embed-url
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "A URL by which this video has been embedded in a page."}
{:db/ident :video/canonical
:db/valueType :db.type/uri
:db/unique :db.unique/identity
:db/cardinality :db.cardinality/one
:db/doc "The canonical URL for this video. A video can have only one, and it suffices to identify the video."}
{:db/ident :video/title
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The title of the video. Not necessarily the title of the page retrieved from its canonical URL."}
{:db/ident :video/tag
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/doc "Optional tags for the video."}
{:db/ident :video/director-url
:db/valueType :db.type/uri
:db/cardinality :db.cardinality/many
:db/doc "A URL from which a description of the director can be retrieved."}
;; Plays.
{:db/ident :play/at
:db/valueType :db.type/instant
:db/cardinality :db.cardinality/one
:db/doc "The instant in time at which playback began."}
{:db/ident :play/video
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The video that was played."}
{:db/ident :play/on-page
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "The page on which this video was played."}
{:db/ident :play/element
:db/valueType :db.type/uri
:db/cardinality :db.cardinality/one
:db/doc "The src of the video element that was played on the page."}
]
;; Transactions during example scenario:
---
;; Define the device. Hereafter we'll refer to this by reference to its device ID.
{:device/name "Richard's Mac"
:device/fxa-id "1234"
:device/platform :mac}
---
;; Load Reddit.
---
{:visit/device [:device/fxa-id "1234"]
:visit/url "https://www.reddit.com/r/vimeo/"
:visit/at "2017-09-15T18:40:00Z"
:id "_visitR"
:visit/page {
:id "_pageR"
:page/title "/r/vimeo: The best of Vimeo, here on Reddit"
}
}
---
;; These temporary IDs are given real IDs when we transact the data above.
;; Hold on to the page and visit identifiers so we can later link them
;; to any embedded videos.
let reddit = result.tempid["_pageR"];
let reddit_visit = result.tempid["_visitR"];
;; Load the embedded video.
---
{:visit/device [:device/fxa-id "1234"]
:visit/url "https://player.vimeo.com/video/233322792?referrer=https%3A…"
:visit/at "2017-09-15T18:40:02Z"
:visit/from reddit_visit
:id "_visitE"
:visit/page {
:id "_pageE"
:page/_embeds reddit ; Reverse attribute notation - back pointer.
:page/title "Art of the Moment from Travis Lee Ratcliff on Vimeo"
:page/contains-video "blob:https://player.vimeo.com/7ed1646a-5955-b048-b9d0-1e5b3ce4ee0d"
:page/canonical "https://vimeo.com/233322792"
}
}
---
let embed_visit = result.tempid["_visitE"]
let embed_page = result.tempid["_pageE"]
---
{:video/embed-url "blob:https://player.vimeo.com/7ed1646a-5955-b048-b9d0-1e5b3ce4ee0d"
:video/canonical "https://vimeo.com/233322792"}
---
;; Play the embedded video.
---
{:play/video [:video/canonical "https://vimeo.com/233322792"]
:play/at "2017-09-15T18:41:00Z"
:play/element "blob:https://player.vimeo.com/7ed1646a-5955-b048-b9d0-1e5b3ce4ee0d"
:play/on-page embed_page}
---
;; Click through to Vimeo.
---
{:visit/device [:device/fxa-id "1234"]
:visit/url "https://vimeo.com/233322792"
:visit/at "2017-09-15T18:50:00Z"
:visit/from embed_visit
:id "_visitV"
:visit/page {
:id "_pageE"
:page/title "Art of the Moment on Vimeo"
:page/contains-video "blob:https://vimeo.com/d76a4b51-0b0f-fa4a-9abe-ffa890f7cad4"
:page/canonical "https://vimeo.com/233322792"
}
}
---
;; Record the new known embed URL for the existing video,
;; along with all of the metadata that the canonical page carries.
---
{:video/canonical "https://vimeo.com/233322792"
:video/embed-url "blob:https://vimeo.com/d76a4b51-0b0f-fa4a-9abe-ffa890f7cad4"
:video/title "Art of the Moment"
:video/tag "Manschot Art"
:video/director-url "https://vimeo.com/travisleeratcliff"
}
---
;; Tell me about the videos that the user played since September 15.
;; This will return objects containing title, tags (as an array), etc. etc.
---
[:find (pull ?video "*")
:where
[?play :play/at ?at]
[(< "2017-09-15T00:00:00Z" ?at)]
[?play :play/video ?video]
]
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment