Coding of Virus Spread

From CSclasswiki
Jump to: navigation, search

Think and Code

Simulation of 2400 students' schedule

  • Generate 2400 students in the `student state` table, which includes the information of students' ID, their room ID, their current state, and whether they are vaccinated
    • there are five possible states for student: (0) healthy -> (1)infected but not contagious -> (2) contagious -> (3) not contagious but not recovered -> (4) recovered
    • the first 400 students are assigned into single rooms and 2000 students are assigned into double rooms
  • Generate the calendar for all the places at Smith
    • there would be 14 time slots in MWF, 10 time slots in TT, and 7 time slots on the weekend
    • there are 100 classroom with(30 cap. for each slot)
    • 17 library and cc floor (50 cap.)
    • 10 conference room for study group(10 cap.)
    • 400 singles(1 cap.), 1000 doubles(2 cap.) and
    • 11 dinning halls(220 cap.) for 7 days a week
    • there are also 2 event places (60 capacity) in the evening of the weekend and 1 event place (60 capacity) in the afternoon of the weekend
  • Generate schedule for 2400 students
    • there would be 14 time slots in MWF, 10 time slots in TT, and 7 time slots on the weekend
    • after 9:30pm or 10, everyone will go back to their rooms
  • Randomly generate students' schedule
    • each students will have 5 classes or lab in a week. Each student has half-half chance to have 3 classes on MWF and 2 classes on TT, or 2 classes on MWF and 3 classes on TT. All the classes happen before 5:30
    • In the lunch and dinner time, students will randomly go to one of the dinning hall
    • In other time slots, students will go to libraries, conference rooms, or their rooms. Once they choose a place to stay, they will stay there until classes, meal time, or the time they need to be back to their room
    • on the weekend, there are 20 classrooms open for TA hour or small group meeting. Also students can join one of the free big event.


Run the Simulation of Virus Spread

  • For one simulation
  • Randomly pick one student as the contagious student and change student's state to 1. At the meantime, insert events 1, 2, 3
    • event 1: change state from 1 to 2 after certain days (10 days for Measles)
    • event 1: change state from 2 to 3 after certain days (18 days for Measles)
    • event 1: change state from 3 to 4 after certain days (21 days for Measles)
  • Enter the time for loop which loops over 98days(one semester) day by day
    • Check in the event queue to see if any event should happen today.
    • Identify what day the day is?(MWF? TT? SS?)
    • Find all the contagious students today
      • For each contagious student, look into all the locations they go to today
        • find the all students who is in contact with that contagious student and each of the students have probability p to get infected
          • if a student get infected, insert event 1, 2, 3
    • count the number of students in the 5 possible states and record in the database
    • update all the student state back to 0 and ready for next simulation
  • Go to this page to see the code of Spread Simulation.


Data Visualization

  • Translate the table in database to csv file


  • Translate the locationID to GPS locations


  • Dynamic Heat Map with HTML, CSS, jQuery, and Google Heat Map API

HeatmapOfVirusSpread.png


  • Graph making with R
    • Graph for number of infected students and recovered students

InfectedandRecover.png

---
title: "plot"
author: "Lujun Jian"
date: "April 7, 2015"
output: html_document
---


Infected Student Plot. Read the csv file which have the data
```{r}
ds <- read.csv("Desktop/dataSample300_s1.csv")
head(ds)
```

```{r}
require(mosaic)
ds <- mutate(ds, haveBeenInfected = 2400 - healthyNum)
a <- xyplot(haveBeenInfected ~ time, 
            groups=stimulationNum,
            data=filter(ds, time < 70), 
            col=c("pink"),type=c( "l"),
            main = "Simulated Measles Outbreak at Smith College", 
            xlab = "Day(s)", 
            ylab = "Number of Students",
            )
```

Recover Plot
```{r}
require(mosaic)
b <- xyplot(recoverNum ~ time, groups=stimulationNum, data=filter(ds, time < 70),col=c("grey") ,type=c( "l"))
```

mean Infect & recover - csv file which have the mean data
```{r}
mds <- read.csv("Desktop/dataMean.csv")
head(mds)
```

```{r}
require(mosaic)
c <- xyplot(meanInfect ~ time,  data=filter(mds, time < 70),col=c("red") ,lwd = 4,type=c( "l"))
```

```{r}
require(mosaic)
d <- xyplot(meanRe ~ time,  data=filter(mds, time < 70),col=c("grey2") ,lwd = 4,type=c( "l"))
```

test two in one
```{r}
a + as.layer(b)+ as.layer(c)+as.layer(d)
```


Average by time
```{r}
mu <- mean(haveBeenInfected ~ time, data=ds)
mu
mr <- mean(recoverNum ~ time, data=ds)
mr
```




    • Graph for probability of infection of the disease

DifferentPofInfection.png

---
title: "plot"
author: "Lujun Jian"
date: "April 10, 2015"
output: html_document
---


Infected Student Plot
```{r}
ds01 <- read.csv("Desktop/dataP01.csv")
head(ds)
ds005 <- read.csv("Desktop/dataP005.csv")
head(ds)
ds001 <- read.csv("Desktop/dataP001.csv")
head(ds)
dataMeanP <- read.csv("Desktop/dataMeanP.csv")
head(dataMeanP)
```

```{r}
require(mosaic)
ds01 <- mutate(ds01, haveBeenInfected = 2400 - healthyNum)
e <- xyplot(haveBeenInfected ~ time, 
            groups=stimulationNum,
            data=filter(ds01, time < 98), 
            col=c("plum"),type=c( "l"),
            main = "Simulated Measles Outbreak at Smith College", 
            xlab = "Day(s)", 
            ylab = "Number of Students",
            )
```

```{r}
require(mosaic)
ds005 <- mutate(ds005, haveBeenInfected = 2400 - healthyNum)
f <- xyplot(haveBeenInfected ~ time, 
            groups=stimulationNum,
            data=filter(ds005, time < 98), 
            col=c("aquamarine2"),type=c( "l"),
            main = "Simulated Measles Outbreak at Smith College", 
            xlab = "Day(s)", 
            ylab = "Number of Students",
            )
```

```{r}
require(mosaic)
ds001 <- mutate(ds001, haveBeenInfected = 2400 - healthyNum)
g <- xyplot(haveBeenInfected ~ time, 
            groups=stimulationNum,
            data=filter(ds001, time < 98), 
            col=c("chartreuse1"),type=c( "l"),
            main = "Simulated Measles Outbreak at Smith College", 
            xlab = "Day(s)", 
            ylab = "Number of Students",
            )
```

```{r}
require(mosaic)
h <- xyplot(mean01 ~ time,  data=filter(dataMeanP, time < 98),col=c("blueviolet") ,lwd = 6,type=c( "l"))
```

```{r}
require(mosaic)
i <- xyplot(mean005 ~ time,  data=filter(dataMeanP, time < 98),col=c("blue") ,lwd = 6,type=c( "l"))
```

```{r}
require(mosaic)
j <- xyplot(mean001 ~ time,  data=filter(dataMeanP, time < 98),col=c("springgreen4") ,lwd = 6,type=c( "l"))
```

```{r}
e + as.layer(f)+ as.layer(g)+as.layer(h)+as.layer(i)+as.layer(j)
```

```{r}
m01 <- mean(haveBeenInfected ~ time, data=ds01)
m01
m005 <- mean(haveBeenInfected ~ time, data=ds005)
m005
m001 <- mean(haveBeenInfected ~ time, data=ds001)
m001
```




    • Graph for different Incubation Period of the disease

DifferentIncubationPeriod.png

---
title: "plot"
author: "Lujun Jian"
date: "April 10, 2015"
output: html_document
---


Infected Student Plot
```{r}
dsIn1 <- read.csv("Desktop/dataP01.csv")
head(dsIn1)
dsIn2 <- read.csv("Desktop/StimulationIn.csv")
head(dsIn2)
dataMeanI <- read.csv("Desktop/dataMeanI.csv")
head(dataMeanI)

```

```{r}
require(mosaic)
dsIn1 <- mutate(dsIn1, haveBeenInfected = 2400 - healthyNum)
k <- xyplot(haveBeenInfected ~ time, 
            groups=stimulationNum,
            data=filter(dsIn1, time < 60), 
            col=c("lightskyblue"),type=c( "l"),
            main = "Simulated Measles Outbreak at Smith College", 
            xlab = "Day(s)", 
            ylab = "Number of Students",
            )
```

```{r}
require(mosaic)
dsIn2 <- mutate(dsIn2, haveBeenInfected = 2400 - healthyNum)
l <- xyplot(haveBeenInfected ~ time, 
            groups=stimulationNum,
            data=filter(dsIn2, time < 60), 
            col=c("lightpink"),type=c( "l"),
            main = "Simulated Measles Outbreak at Smith College", 
            xlab = "Day(s)", 
            ylab = "Number of Students",
            )
```

```{r}
require(mosaic)
m <- xyplot(mean14 ~ time,  data=filter(dataMeanI, time < 60),col=c("blue") ,lwd = 5,type=c( "l"))
```

```{r}
require(mosaic)
n <- xyplot(mean21 ~ time,  data=filter(dataMeanI, time < 60),col=c("maroon1") ,lwd = 5,type=c( "l"))
```

test two in one
```{r}
k + as.layer(l) + as.layer(m) + as.layer(n)
```
m14 <- mean(haveBeenInfected ~ time, data=dsIn1)
m14
m21 <- mean(haveBeenInfected ~ time, data=dsIn2)
m21

Improvement in the Future

  • Include more disease parameters
  • Change the placeID into real GPS coordinates so that we don't need to assign and translate the location later
  • Link between and heat map and the database (Use SQL in the HTML file)
  • Link between the graphs and database (Use SQL in R )
  • Integrate the data from registration office
  • Improve the speed