Hi there
making “some” progress with julia but every now and again I hit something that I am misunderstanding. To fix this I use the REPL but right now I am having NO luck. To illustrate this I am trying to understand how to test a flag model.isready using the code provided by the splendid @hhaensel. BUT I clearly am misunderstanding the whole Reactive model approach.
timeout = 10 # or whatever your startup process needs
t0 = now()
while ! model.isready[] && now() - t0 < timeout
sleep(200)
end
now() - t0 < timeout && model.df[] = my_brand_new_dataframe
or just do
model.isready[] && model.df[] = my_brand_new_dataframe
the code block used in the REPL looks like this
sing Stipple
using StippleUI
using StipplePlotly
using CSV, DataFrames, Dates , Logging
dash_columns = ["sym","close","price","sdmove","hv20","hv10","hv5","iv","iv%ile","prc%ile","ern_days"]
df = DataFrame([col => (col == "sym" ? String : Float64)[] for col in dash_columns])
df_table = Observable(df)
zmq_dash = Dict("LAST" => "price","CLOSE" => "close","OPTION_IMPLIED_VOL" => "iv","OPTION_HISTORICAL_VOL" => "iv",
"VOLUME" => "volume","IV" => "iv","IV_PERCENTILE" => "iv%ile" ,"HV20" => "hv20",
"HV10" => "hv10","HV5" => "hv5" ,"PRICE_PERCENTILE" => "prc%ile","EARNDAYS" => "ern_days")
@reactive mutable struct TontineModel <: ReactiveModel
tontine_data::R{DataTable} = DataTable(df_table[])
tontine_data_pagination::DataTablePagination = DataTablePagination(rows_per_page=100) #9/9/22
end
function ui(model::TontineModel)
page(
model, class="container", title="title TONTINE2 ", head_content=Genie.Assets.favicon_support(),
[
heading("heading Tontine2 9/6/22")
row([
cell(class="st-module", [
h5("h5 tontine data")
table(:tontine_data;
style="height: 2500px;",
pagination=:tontine_data_pagination) # 9/9/22 added pagination
])
])
]
)
end
function handlers(model)
on(df_table) do _
notify(model.tontine_data)
end
model
end
route("/") do
TontineModel |> init |> handlers |> ui |> html
end
# up(9000; async = true, server = Stipple.bootstrap())
up()
Could someone take a look at my thrashing around in the REPL to tell me:
How I could examine the flag model.isready[]
give me some REPL model debugging tips that I can use to get to grips with this.
julia> using Stipple
julia> using StippleUI
julia> using StipplePlotly
julia> using CSV, DataFrames, Dates , Logging
julia> using ZMQ
julia> # 9/6/22 OLD WAY io = open("/home/dave/tontine_2022/data/logs/logfile.log", "w+")
log_date = Dates.format(now(),"yyyy_mm_dd_HH_MM")
"2022_09_10_08_46"
julia> log_name = "/home/dave/tontine_2022/data/logs/tontine2_log_" * log_date * ".log"
"/home/dave/tontine_2022/data/logs/tontine2_log_2022_09_10_08_46.log"
julia> io = open( log_name, "w+")
IOStream(<file /home/dave/tontine_2022/data/logs/tontine2_log_2022_09_10_08_46.log>)
julia> logger = SimpleLogger(io)
Base.CoreLogging.SimpleLogger(IOStream(<file /home/dave/tontine_2022/data/logs/tontine2_log_2022_09_10_08_46.log>), Info, Dict{Any, Int64}())
julia> global_logger(logger)
ConsoleLogger(IOBuffer(data=UInt8[...], readable=false, writable=false, seekable=false, append=false, size=0, maxsize=0, ptr=1, mark=-1), Info, Logging.default_metafmt, true, 0, Dict{Any, Int64}())
julia> dash_columns = ["sym","close","price","sdmove","hv20","hv10","hv5","iv","iv%ile","prc%ile","ern_days"]
11-element Vector{String}:
"sym"
"close"
"price"
"sdmove"
"hv20"
"hv10"
"hv5"
"iv"
"iv%ile"
"prc%ile"
"ern_days"
julia> df = DataFrame([col => (col == "sym" ? String : Float64)[] for col in dash_columns])
0×11 DataFrame
julia> df_table = Observable(df)
Observable{DataFrame} with 0 listeners. Value:
0×11 DataFrame
julia> zmq_dash = Dict("LAST" => "price","CLOSE" => "close","OPTION_IMPLIED_VOL" => "iv","OPTION_HISTORICAL_VOL" => "iv",
"VOLUME" => "volume","IV" => "iv","IV_PERCENTILE" => "iv%ile" ,"HV20" => "hv20",
"HV10" => "hv10","HV5" => "hv5" ,"PRICE_PERCENTILE" => "prc%ile","EARNDAYS" => "ern_days")
Dict{String, String} with 12 entries:
"EARNDAYS" => "ern_days"
"VOLUME" => "volume"
"HV20" => "hv20"
"LAST" => "price"
"IV" => "iv"
"CLOSE" => "close"
"HV5" => "hv5"
"HV10" => "hv10"
"OPTION_HISTORICAL_VOL" => "iv"
"PRICE_PERCENTILE" => "prc%ile"
"OPTION_IMPLIED_VOL" => "iv"
"IV_PERCENTILE" => "iv%ile"
julia> @reactive mutable struct TontineModel <: ReactiveModel
tontine_data::R{DataTable} = DataTable(df_table[])
tontine_data_pagination::DataTablePagination = DataTablePagination(rows_per_page=100) #9/9/22
end
TontineModel
julia> function ui(model::TontineModel)
page(
model, class="container", title="title TONTINE2 ", head_content=Genie.Assets.favicon_support(),
[
heading("heading Tontine2 9/6/22")
row([
cell(class="st-module", [
h5("h5 tontine data")
table(:tontine_data;
style="height: 2500px;",
pagination=:tontine_data_pagination) # 9/9/22 added pagination
])
])
]
)
end
ui (generic function with 1 method)
julia> function handlers(model)
on(df_table) do _
notify(model.tontine_data)
end
model
end
handlers (generic function with 1 method)
julia> model
ERROR: UndefVarError: model not defined
julia> df_table
Observable{DataFrame} with 0 listeners. Value:
0×11 DataFrame
julia> route("/") do
TontineModel |> init |> handlers |> ui |> html
end
[GET] / => #8 | :get
julia> up()
Genie.AppServer.ServersCollection(Task (runnable) @0x00007f6848424740, nothing)
julia> model
ERROR: UndefVarError: model not defined
julia> To
Toggles TontineModel Toolbars Tooltips
julia> TontineModel
TontineModel
julia> TontineModel.
flags hash instance layout name parameters size super types
julia> TontineModel.flags
0x72
julia> TontineModel.instance
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] getproperty(x::Type, f::Symbol)
@ Base ./Base.jl:33
[2] top-level scope
@ REPL[25]:1
julia> TontineModel.layout
Ptr{Nothing} @0x00007f6851774318
julia> TontineModel.name
typename(TontineModel)
julia> TontineModel.parameters
svec()
julia> TontineModel.types
svec(WARNING: both HttpCommon and Genie export "Headers"; uses of it in module Html must be qualified
WARNING: both Html and Base export "div"; uses of it in module Stipple must be qualified
WARNING: both Html and Base export "mark"; uses of it in module Stipple must be qualified
WARNING: both Html and Base export "summary"; uses of it in module Stipple must be qualified
WARNING: both Html and Base export "time"; uses of it in module Stipple must be qualified
WARNING: both Html and Base export "view"; uses of it in module Stipple must be qualified
Reactive{DataTable}, DataTablePagination, String, Reactive{Bool}, Reactive{Bool})
julia> TontineModel.s
size super
julia> TontineModel.s
size super
julia> TontineModel.size
40
julia> TontineModel.super
ReactiveModel
julia>