kupkasmale/WebWorldDev
0
1from webworld_lib import *2 3pn.extension("tabulator")4 5ACCENT = "indigo"6 7styles = {8 "box-shadow": "rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px",9 "border-radius": "4px",10 "padding": "10px",11}12 13CSS = """14div.card-margin:nth-child(1) {15 max-height: 280px;16}17}18"""19 20fixed_data = fixed_parameters()21global Nt, SN;22Nt =0.0; Tn = 0.023MS = fixed_data[0]24R = fixed_data[1]25c= fixed_data[2]26ld = fixed_data[3]27Ng = fixed_data[4]28L = fixed_data[5]29K = fixed_data[6]30b = fixed_data[7]31 32Running = False33 34# Parameter Values35t_comp = pn.widgets.FloatSlider(value= c ,start=0.1, 36 end=0.9, step=0.1,37 name='Competition')38t_res = pn.widgets.FloatSlider(value= R ,start=1e4, 39 end=1e6, step=1e4,40 name='Resources')41 42figa = (43 pd.DataFrame([],columns=['SN'])44).hvplot(45 title="Number of Species",46 ylabel="Number of Species",47 xlabel="Evolutionary event",48 #xlim=(0, Ng),49 autorange = "y",50 color=ACCENT,51)52#print(figa)53FW = nx.DiGraph()54figb = hvnx.draw(FW, with_labels=True) 55 56pr1 = pn.pane.Str(57 'Static parameters (K,L):'+str(K)+' '+str(L)58 )59pr2 = pn.pane.Str('Max number of allowed species: '+str(MS))60pr3 = pn.pane.Str('Number of evolutionary steps: '+str(Ng))61pr4 = pn.pane.Str('b: '+str(b))62#pr3 = pn.pane.Str('Ready')63button = pn.widgets.Button(name='\u25b6',description='Run')64#print(button.name)65 66# Display Data67indicators = pn.FlexBox(68 69 70 pn.indicators.Number(71 value=t_res, name="External Resources", 72 format="{value:,.1E}",73 font_size = "5",74 title_size = "6", 75 styles=styles76 ),77 pn.indicators.Number(78 value=t_comp,79 name="Competition parameter",80 format="{value:,.1f}",81 font_size = "5",82 title_size = "6",83 styles=styles,84 ),85 86 pn.indicators.Number(87 value=Tn,88 name="Time",89 format="{value:,.1f}",90 font_size = "5",91 title_size = "6",92 styles=styles,93 ),94 95 96 pn.indicators.Number(97 value=Nt,98 name="Number of Species",99 font_size = "5",100 title_size = "6",101 format="{value:,.1f}",102 styles=styles,103 ), 104)105 106Pt = np.array([MS,t_res.value,t_comp.value,ld,Ng,L,K,b,indicators[3],indicators[2]])107plotns = pn.pane.HoloViews(figa, sizing_mode="stretch_both", name="PlotNS")108plotfw = pn.pane.HoloViews(figb, sizing_mode="stretch_both", name="PlotFW")109 110tabs = pn.Tabs(111 plotns, plotfw, styles=styles, sizing_mode="stretch_width", height=500, margin=10112)113 114 115ly1 = pn.Column(pr1, pr2, pr3, pr4,t_comp,t_res, button, sizing_mode="stretch_both")116ly2 = pn.Column(indicators, tabs, sizing_mode="stretch_both")117 118button.on_click(partial(start_sim,Pt,[t_res,t_comp],button,tabs))119 120pn.template.FastListTemplate(121 title="Webworld Model Demo",122 main=[ly1,ly2],123 main_layout=None,124 accent=ACCENT,125 raw_css=[CSS]126).servable()