// Confinement COVID-19 ! // Stephane MOTTELET, UTC // Tue Mar 24 08:55:03 CET 2020 // Modified by TAN Chin Luh // Weds Apr 29 10:36:02 GMT+8 2020 // GUI function function CoronaSim2() // Initial Value handles.t = 0:1:360; handles.N = 6000; handles.bet = 0.23; handles.gam = 0.06; // Initialize model plot y=ode('stiff',[handles.N-1;1;0],0,handles.t,list(sir,handles.bet,handles.gam,handles.N)); plot(handles.t',y'); handles.axis1 = gca(); handles.curves1 = gce(); handles.curves1.tag="curves"; handles.curves1.children.thickness=2; legend("Susceptible","Infected","Recovered",-1) // Initialize actual data plot x = 1:1; plot(x,ones(x),'go'); handles.axis2 = gca(); handles.curves2 = gce(); plot(x,ones(x),'r*'); handles.axis3 = gca(); handles.curves3 = gce(); // GUI Components y_loc = -0.05; handles.country = uicontrol("style","edit",... "string","Malaysia",... "units","normalized",... "Position", [0.82,y_loc + 0.95,0.16,0.05],... "BackgroundColor", [1,1,1],... "Callback","insert_data(handles)","HorizontalAlignment","center"); handles.dates = uicontrol("style","edit",... "string","2/11/20",... "units","normalized",... "Position", [0.62,y_loc + 0.95,0.16,0.05],... "BackgroundColor", [1,1,1],... "Callback","insert_data(handles)","HorizontalAlignment","center"); handles.load = uicontrol("style","pushbutton",... "string","Load Data",... "units","normalized",... "Relief","solid",... "Position", [0.42,y_loc + 0.95,0.16,0.05],... "BackgroundColor", [1,1,1],... "Callback","insert_data(handles)","HorizontalAlignment","center"); handles.editN = uicontrol("style","edit",... "string","6000",... "units","normalized",... "Position", [0.85,y_loc + 0.07,0.1,0.05],... "BackgroundColor", [1,1,1],... "Callback","update_population(handles)","HorizontalAlignment","center"); handles.sb1 = uicontrol("style","slider",... "units","normalized",... "Position", [0.85,y_loc + 0.2,0.05,0.48],... "BackgroundColor", [1,1,1],... "Callback_Type",12,... "sliderstep",[1/1000,1/10],... "min",0.15,"max",0.3,"value",handles.bet,... "Callback","draw(handles)","tag","beta"); handles.txt1 = uicontrol("style","text",... "string","$\beta$",... "units","normalized",... "Position", [0.85,y_loc + 0.125,0.05,0.08],... "BackgroundColor", [1,1,1],... "HorizontalAlignment","center"); handles.txtb = uicontrol("style","text",... "string","0.3",... "units","normalized",... "Position", [0.85,y_loc + 0.68,0.05,0.08],... "BackgroundColor", [1,1,1],... "HorizontalAlignment","center"); handles.sb2 = uicontrol("style","slider",... "units","normalized",... "Position", [0.90,y_loc + 0.2,0.05,0.48],... "BackgroundColor", [1,1,1],... "Callback_Type",12,... "sliderstep",[1/1000,1/10],... "min",0,"max",1/15,"value",handles.gam,... "Callback","draw(handles)","tag","gamma"); handles.txt2 = uicontrol("style","text",... "string","$\gamma$",... "units","normalized",... "Position", [0.9,y_loc + 0.125,0.05,0.08],... "BackgroundColor", [1,1,1],... "HorizontalAlignment","center"); handles.txtg = uicontrol("style","text",... "string","0.067",... "units","normalized",... "Position", [0.9,y_loc + 0.68,0.05,0.08],... "BackgroundColor", [1,1,1],... "HorizontalAlignment","center"); handles = resume(handles); endfunction // SIR Model function dydt=sir(t, y, bet, gam, N) dydt=[-bet/N*y(1)*y(2) bet/N*y(1)*y(2)-gam*y(2) gam*y(2)]; endfunction // Data import function function [data, header] = importdata(filename) header = mgetl(filename, 1); header = csvTextScan(header, ",", ".", "string"); data = csvRead(filename, ",", ".", "string", [], [], [], 1); endfunction // Overlapped real-world data function insert_data(handles) // 3 files downlowded from Covid 19 cases from Johns Hopkins Github [confirmed,dates] = importdata("time_series_covid19_confirmed_global.csv"); death = importdata("time_series_covid19_deaths_global.csv"); recovered = importdata("time_series_covid19_recovered_global.csv"); // Date for the "Wave" starting date_ind = find(dates==handles.dates.string); // Confirmed cases my_conf = confirmed(confirmed(:,2) == handles.country.string,date_ind:$); my_conf = strtod(my_conf); my_conf = sum(my_conf,'r'); // Death cases my_death = death(death(:,2) == handles.country.string,date_ind:$); my_death = strtod(my_death); my_death = sum(my_death,'r'); // Recovered cases my_rec = recovered(recovered(:,2) == handles.country.string,date_ind:$); my_rec = strtod(my_rec); my_rec = sum(my_rec,'r'); // Active cases for SIR model my_active = my_conf - my_death - my_rec; cur_x = 1:size(my_active,'*'); // R in SIR model incoulding death and recover my_R = my_death + my_rec; handles.curves2.children.data=[cur_x' my_active']; handles.curves3.children.data=[cur_x' my_R']; endfunction // Update Initial Susceptible Population function update_population(handles) handles.axis1.data_bounds(2,2) = strtod(handles.editN.string); draw(handles); end // Function to update plot function draw(handles) bet = handles.sb1.value; gam = handles.sb2.value; N = handles.editN.string; N = strtod(N); handles.txtb.string = sprintf("%.3f",bet); handles.txtg.string = sprintf("%.3f",gam); y=ode('stiff',[N-1;1;0],0,handles.t,list(sir,bet,gam,N)); handles.curves1.children(1).data(:,2)=y(3,:); handles.curves1.children(2).data(:,2)=y(2,:); handles.curves1.children(3).data(:,2)=y(1,:); handles = resume(handles); end CoronaSim2