All hail @hhaensel for taking the time to help a noob. This is HIS code not mine, you know this because IT WORKS, it’s got a much better approach and there is lashings of things for noobs to unpack. Just take a look at the random generator, or the manner in which the dataframe is updated. Clearly a man who knows where his towel is.
The fact that, ONCE AGAIN, my inability to read is front and center. I found this code from @hhaensel to be an excellent learning tool.
theakson
#https://github.com/GenieFramework/Stipple.jl/discussions/126
using Stipple
using StippleUI
using StipplePlotly
using CSV, DataFrames, Dates
dash_columns = ["sym","price","sdmove","hv20","hv10","hv5","iv","iv%ile","prc%ile","volume"]
df = DataFrame([col => (col == "sym" ? String : Float64)[] for col in dash_columns])
df_table = Observable(df)
zmq_dash = Dict("LAST" => "price","CLOSE" => "price","OPTION_IMPLIED_VOL" => "iv",
"VOLUME" => "volume","IV" => "iv","IV_PERCENTILE" => "iv%ile" ,"HV20" => "hv20",
"HV10" => "hv10","HV5" => "hv5" ,"PRICE_PERCENTILE" => "prc%ile")
@reactive mutable struct TontineModel <: ReactiveModel
tontine_data::R{DataTable} = DataTable(df_table[])
end
function ui(model::TontineModel)
page(
model, class="container", title="title TONTINE2 ", head_content=Genie.Assets.favicon_support(),
[
heading("heading Tontine2 7/18/22")
row([
cell(class="st-module", [
h5("h5 tontine data")
table(:tontine_data)
])
])
]
)
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()
for _ in 1:10
# generate a random entry
message = join([
["A", "B", "C", "D", "E", "F", "G"][rand(1:7)],
["a", "b", "c", "d", "e", "f", "g"][rand(1:7)],
collect(keys(zmq_dash))[rand(1:length(zmq_dash))],
string(rand())
], "~")
sleep(0.5)
global in_source, sym_in, field_in, value_in = split(message , "~")
global value_fl = parse(Float64, value_in) # convert to Float64
try
global field_out = zmq_dash[field_in] # ie field_in "OPTION_IMPLIED_VOL" => field_out "iv"
println("message to add : $in_source, $sym_in, $field_out, $value_in")
catch e
println("field_in : ", field_in, " not in cols" )
end
sym_in in df_table[][!,:sym] || push!(df_table[], (sym_in, 0.0, 0.0, 0.0 , 0.0, 0.0 , 0.0 , 0.0 , 0.0 , 0.0))
df_table[][findfirst(==(sym_in), df_table[].sym), findfirst(==(field_out), names(df_table[]))] = value_fl
notify(df_table)
end