-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,18 @@ tasks: | |
# docker pull docker.linkos.org/library/debian:bullseye-20240701-slim | ||
# docker pull docker.linkos.org/library/postgres | ||
|
||
## Livebook cluster testing | ||
# Attach on notebook's runtime with: [email protected] and hello cookie | ||
lv-hello1: iex --name [email protected] --cookie hello --erl "-kernel shell_history enabled" -S mix phx.server | ||
# below not work in livebook? | ||
# lv-hello11: iex --sname hello-phx1 --cookie hello --erl "-kernel shell_history enabled" -S mix | ||
lv-start: livebook server {{.CLI_ARGS}} | ||
lv-data: task lv-start -- notebooks/explore-data.livemd | ||
lv-help: task lv-start -- --help | ||
lv-install: mix archive.install hex livebook | ||
# https://fly.io/docs/elixir/advanced-guides/clustering-from-home-to-your-app-in-fly/ | ||
lv-fly-remote: ./cluster-with-remote.sh | ||
|
||
## DB Setup | ||
pgcli: pgcli postgresql://postgres:postgres@localhost:5433 | ||
# db: sudo -u postgres pgcli hello_phx_dev | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Play livebook | ||
|
||
https://github.com/livebook-dev/livebook?tab=readme-ov-file#environment-variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Explore HelloPhx Data attaching | ||
|
||
```elixir | ||
alias VegaLite, as: Vl | ||
alias HelloPhx.Catalog.Product | ||
alias HelloPhx.Repo | ||
import Ecto.Query | ||
``` | ||
|
||
## Explore | ||
|
||
```elixir | ||
query = from(p in Product, | ||
group_by: p.views, | ||
select: {p.views, count(p.id)} | ||
) | ||
|
||
views_counts = query | ||
|> Repo.all | ||
|> Enum.into(%{}) | ||
|
||
# Convert the raw data into a Pie Chart friendly format | ||
data = | ||
Enum.map(views_counts, fn {views, count} -> | ||
%{"views" => "views#{views}", "value" => count} | ||
end) | ||
|
||
Vl.new() | ||
|> Vl.data_from_values(data) | ||
|> Vl.mark(:arc) | ||
|> Vl.encode_field(:theta, "value", type: :quantitative) | ||
|> Vl.encode_field(:color, "views", type: :nominal) | ||
|> Vl.config(view: [stroke: nil]) | ||
``` | ||
|
||
```elixir | ||
# Convert the raw data into a Bar Chart friendly format | ||
data2 = | ||
Enum.map(views_counts, fn {views, count} -> | ||
%{"Views" => "views#{views}", "Views Count" => count} | ||
end) | ||
|
||
# Sort the data by counts to order the results | ||
data2 = Enum.sort_by(data, & &1["Views Count"], :desc) | ||
|> Kino.inspect() | ||
|
||
Vl.new(width: 600, height: 600) | ||
|> Vl.data_from_values(data2) | ||
|> Vl.mark(:bar) | ||
|> Vl.encode_field(:x, "Views", | ||
type: :nominal, | ||
axis: [label_angle: 0], | ||
sort: [field: "Views Count", order: "descendingsr"] | ||
) | ||
|> Vl.encode_field(:y, "Views Count", type: :quantitative) | ||
``` |