Add DB.load_schedule_joined(db)

Load the schedule data into a DataFrame that can be explored with Julia
This commit is contained in:
gg1234 2024-04-23 17:45:05 -07:00
parent 2bf95ca33a
commit 9815bc259d
1 changed files with 49 additions and 0 deletions

View File

@ -126,3 +126,52 @@ function cancel_schedule(db, schedule_id, new_caster_id)
return e
end
end
"""
Load the entire schedule into a DataFrame
"""
function load_schedule_joined(db)
sql_select = """
SELECT s.id AS id,
seg.n AS title,
c.n AS caster,
s.video_id AS video_id,
s.view_count AS view_count,
m.val AS mscale,
s.jst AS jst
FROM schedule s
JOIN segment seg ON seg.id = s.segment_id
LEFT JOIN caster c ON c.id = s.caster_id
LEFT JOIN mscale m ON m.jst = s.jst
ORDER BY jst DESC
"""
return DBInterface.execute(db, sql_select) |> DataFrame
end
#=
using WeatherNews
using WeatherNews: API, DB
using DataFrames
using DataFramesMeta
using SQLite
using Statistics
db = SQLite.DB("sql/wn.db")
s = DB.load_schedule_joined(db)
# Try finding the median instead of the average.
rs = @chain s begin
@subset(:title .!= "au PAY")
dropmissing(:view_count)
dropmissing(:caster)
@select(:caster, :view_count)
@groupby(:caster)
@combine begin
:median_views = median(:view_count)
:average_views = mean(:view_count)
end
sort(:median_views, rev=true)
end
=#