Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Ex338

livebooks/standings_chart.livemd

Ex338

Mix.install([
  {:kino, "~> 0.13.0"},
  {:kino_vega_lite, "~> 0.1.11"}
])

Section

require Kino.RPC
node = :"phoenix-app@127.0.0.1"
Node.set_cookie(node, String.to_atom(System.fetch_env!("LB_COOKIE")))

data =
  Kino.RPC.eval_string(
    node,
    ~S"""
    alias Ex338.Repo 
    alias Ex338.FantasyLeagues.FantasyLeague

    league = Repo.get!(FantasyLeague, 1) 

    alias Ex338.FantasyTeams 
    FantasyTeams.list_standings_history(league)

    """,
    file: __ENV__.file
  )
VegaLite.new(width: 1000, title: "Info")
|> VegaLite.data_from_values(data, only: ["datetime", "points", "team_name"])
|> VegaLite.mark(:line)
|> VegaLite.encode_field(:x, "datetime", type: :temporal)
|> VegaLite.encode_field(:y, "points", type: :quantitative)
|> VegaLite.encode_field(:color, "team_name", type: :nominal, scale: [scheme: "category20"])
VegaLite.new()
|> VegaLite.data_from_values(data, only: ["datetime", "points"])
|> VegaLite.mark(:point)
|> VegaLite.encode_field(:x, "datetime", type: :temporal)
|> VegaLite.encode_field(:y, "points", type: :quantitative)