![]() deposit, sportsbook bet, etc) and the various attributes of the action. The audience criteria of a promotional campaign can be based on any type of action that we record (ie. For the purposes of this article, only a truncated sample of the SportsbookBetAttributes embedded schema will be shown below as well.ĭefmodule do use Ecto.Schema false embedded_schema do field :amount_cents_wagered, :integer field :amount_cents_payout, :integer field :bet_type, Ecto.Enum, values : field :odds, :integer embeds_many :legs, SportsbookBetLegAttributes end end defmodule do use Ecto.Schema false embedded_schema do field :event_id, :string field :event_type, :string field :market_id, :string field :market_selection_id, :string field :market_type, :string field :in_play, :boolean field :odds, :integer end end Example Criteria to Turn into Database Queries The table which they get stored within has been created with a migration that resembled the code sample below.ĭefmodule Promotions.UserAction do use Ecto.Schema alias alias alias alias schema "user_actions" do field :action_id, :string field :action_type, Ecto.Enum, values : field :occurred_at, :utc_datetime_usec field :region, Ecto.Enum, values : field :user_id, Ecto.UUID embeds_one :casino_wager_attributes, CasinoWagerAttributes, source : :attributes embeds_one :deposit_attributes, DepositAttributes, source : :attributes embeds_one :registration_attributes, RegistrationAttributes, source : :attributes embeds_one :sportsbook_bet_attributes, SportsbookBetAttributes, source : :attributes timestamps () end endĮach of the various embedded schemas to populate the attributes field is represented in a separate Ecto schema of its own. These actions are used for a variety of purposes within our Promotions service, but in this case, we are exploring looking at the past actions of a given user to see if they fulfill the audience criteria of a given promotional campaign. These events are received asynchronously from other internal services, via Kafka, and then stored internally in the Promotions database as a generic "user action". The Promotions service depends on the ability to read past events placed by a patron. For example, when creating a new promotion, we can specify that its audience can only include patrons who have previously deposited a specific amount of money, or placed a specific quantity of bets.ĭisclaimer: The specific scenario, and format of the data shown in the examples throughout, is contrived entirely for the purposes of this article. Each promotional campaign allows us to specify an audience of users who will be available to participate in the campaign, by comparing on past actions that a given user has taken against a set of dynamic rules. , % Friends.The Promotions team at theScore is responsible for enabling dynamic marketing campaigns within theScore Bet app. Below, we’ll get the movie with an ID of 1: iex> alias Friends. ![]() It returns nil if no such record is found. It returns a struct describing the record found, if any. This function requires two arguments: a “queryable” data structure and the ID of a record to retrieve from the database. We can use the Repo.get/3 function to fetch a record from the database given its ID. We can perform simple queries directly against our Friends.Repo with the help of a handful of functions. Recall that a “repository” in Ecto maps to a datastore such as our Postgres database.Īll communication to the database will be done using this repository. In this lesson, we’ll continue building off the Friends app and the movie-cataloguing domain we set up in the previous lesson.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |