ITZRYLYS5H5XV3R2OZOCER2AEQ2QWG7BWRKGDQ5LOKARCJ2GQYAQC
Takes an up to date FiordlandPacks.csv and produces some metrics.
"""
function metrics_plot()
if Sys.isapple()
file = "/Users/david/julia/FiordlandPacks/images_and_tables/FiordlandPacks.csv"
else
file = "/media/david/SSD1/FiordlandPacks/images_and_tables/FiordlandPacks.csv"
end
df = DataFrame(CSV.File(file))
transform!(df, [:Shopify_Sales, :Invoice_Sales] => (a, b) -> a .+ b)
select!(df, :Week, :Contact_Submit, :Pack_Builder_Clicks, :Checkouts_Created, :Customer_Actions,
:Shopify_Sales, :Invoice_Sales, :Shopify_Sales_Invoice_Sales_function => "Sales", :Google_Spend)
table = pretty_table(last(df, 12); title="Metrics",
header=["Week", "Contact", "Builder", "Checkout", "ACTIONS", "Shopify", "Invoice", "Sales", "Google"],
display_size=(30, 300))
df2 = Base.stack(df, [:Customer_Actions, :Sales, :Google_Spend])
transform!(df2, :Week => ByRow(x -> Dates.format(x, "yyyy-mm-dd")))
rename!(df2, :variable => "Metric", :value => "Number")
df2 |>
@vlplot(
:line,
x = :Week,
y = :Number,
color = :Metric,
title = "Metrics Plot",
width = 400,
height = 400
) |>
if Sys.isapple()
save("/Users/david/julia/FiordlandPacks/images_and_tables/metrics_fiordland_packs.png")
else
save("/media/david/SSD1/FiordlandPacks/images_and_tables/metrics_fiordland_packs.png")
end
return table
end
c = (x -> (x -> (x -> round.(x, digits=1))(last(x, days)))(Indicators.sma(x; n=7)))(
get_traffic(current, days)[!, 2]
)
p = (x -> (x -> (x -> round.(x, digits=1))(last(x, days)))(Indicators.sma(x; n=7)))(
get_traffic(last_year, days)[!, 2]
)
c = get_traffic(current, days)[!, 2] |> x -> Indicators.sma(x, n=7) |> x -> last(x, days) |> x -> round.(x, digits=1)
p = get_traffic(last_year, days)[!, 2] |> x -> Indicators.sma(x, n=7) |> x -> last(x, days) |> x -> round.(x, digits=1)
plt = lineplot(
collect((-days):-1),
[c p];
color=[:blue :yellow],
title="Unique Visitors: 7 day moving average",
name=["Last $days Days", "Last Year"],
xlabel="Day",
ylabel="Visitors",
canvas=DotCanvas,
border=:ascii,
)
plt = lineplot(collect(-days:-1), [c p], color=[:blue :yellow], title="Unique Visitors: 7 day moving average", name=["Last $days Days", "Last Year"], xlabel="Day", ylabel="Visitors", canvas=DotCanvas, border=:ascii)
vcat(DataFrame("Days" => collect(-days:-1), "Visits" => c, "Period" => "Last $days Days"), DataFrame("Days" => collect(-days:-1), "Visits" => p, "Period" => "Previous Year")) |>
@vlplot(
:line,
x = :Days,
y = :Visits,
color = :Period,
title = "Unique Visitors: 7 Day Moving Average",
width = 400,
height = 400
) |>
save(
"/media/david/SSD1/FiordlandPacks/images_and_tables/visits_fiordland_packs.png"
)
end(
@vlplot(
:line,
x = :Days,
y = :Visits,
color = :Period,
title = "Unique Visitors: 7 Day Moving Average",
width = 400,
height = 400
)(
vcat(
DataFrame(
"Days" => collect((-days):-1),
"Visits" => c,
"Period" => "Last $days Days",
),
DataFrame(
"Days" => collect((-days):-1),
"Visits" => p,
"Period" => "Previous Year",
),
),
),
)
save("/media/david/SSD1/FiordlandPacks/images_and_tables/visits_fiordland_packs.png")
end
# Takes a date in string form yy-mm-dd.
# Returns a pretty table of top 10 pages for 7, 30, 365 days.
"""
build_page_rank_table(date::String)
Takes a date in string form yy-mm-dd.
Returns a pretty table of top 10 pages for 7, 30, 365 days.
Make sure repl window is wide enough
"""
function get_custom_events(
end_date::Dates.Date, event::String, days::Int=7, SITE_ID::String="fiordlandpacks.nz"
)::@NamedTuple{Event::String, Number::Int64}
function get_custom_events(end_date::Dates.Date, event::String, days::Int=7, SITE_ID::String="fiordlandpacks.nz")::@NamedTuple{Event::String, Number::Int64}
e = (x -> titlecase(x))(replace(event, "+" => " "))
if isempty(df)
(return (Event=e, Number=0))
else
(return (Event=e, Number=first(df.visitors)))
end
e = replace(event, "+" => " ") |> x -> titlecase(x)
isempty(df) ? (return (Event=e, Number=0)) : (return (Event=e, Number=first(df.visitors)))
function get_pageview_events(
end_date::Dates.Date, event::String, days::Int=7, SITE_ID::String="fiordlandpacks.nz"
)::@NamedTuple{Event::String, Number::Int64}
function get_pageview_events(end_date::Dates.Date, event::String, days::Int=7, SITE_ID::String="fiordlandpacks.nz")::@NamedTuple{Event::String, Number::Int64}
e = (x -> titlecase(x))(replace(event, "_" => " "))
if isempty(df)
(return (Event=e, Number=0))
else
(return (Event=e, Number=first(df.visitors)))
end
e = replace(event, "_" => " ") |> x -> titlecase(x)
isempty(df) ? (return (Event=e, Number=0)) : (return (Event=e, Number=first(df.visitors)))