-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUtil_DataFrames.R
230 lines (178 loc) · 9.41 KB
/
Util_DataFrames.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# FOOD POOL DATAFRAMES ----------------------------------------------------
#SERVICE 1 DAY 1 CREATION OF DATAFRAMES ================================================================
if(j==1 && k== 1){
#Fruit-------------------------------------------------------------
if (Sim_Fruit==1){
Fr_Data.Frame<-Fuct_DF_Initial(FoodType = "Fruit")
#Adding Initial Contaminations of fruit Data frame based on initial cont and prevalence CFU/Fruit
if(salmonella==1 && Calculated_Cont_Fr==1){
#Adding Contamination to the Dataframe
Fr_Data.Frame<-func_Cont_cm2(Fr_Data.Frame,Prevalence_Salmonella_Fr,Fr_Contamination_salmonella,Fr_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Fr ==1){
#Adding Contamination to Data Fra
Fr_Data.Frame<-func_Cont_HuNoV_Fr(Fr_Data.Frame)
}
}
# Pss ---------------------------------------------------------------------
if(Sim_PSS==1){
Pss_Data.Frame<-Fuct_DF_Initial(FoodType = "Pss")
#Adding initial contamination based on prevalence and area of the item #CFU/Pss
if(salmonella==1 && Calculated_Cont_Pss==1){
Pss_Data.Frame<-func_Cont_cm2(Pss_Data.Frame,Prevalence_Salmonella_Pss,Pss_Contamination_salmonella,Pss_Mean_area)
#Adding items to know Contaminated Items
} else if (norovirus == 1 && Calculated_Cont_Fr ==1){
Pss_Data.Frame<-func_Cont_cm2(Pss_Data.Frame,Prevalence_Norovirus_Pss,Pss_Contamination_norovirus,Pss_Mean_area)
#Adding items to know Contaminated Items
}
}
# Pre ---------------------------------------------------------------------
if(Sim_PRE==1){
Pre_Data.Frame<-Fuct_DF_Initial(FoodType = "Pre")
#Adding initial spoilge contamination to the Dataframe
Pre_Data.Frame<-Func_Adding_Initial_MilkCont(df = Pre_Data.Frame, mean = Milk_Con_Mean, sd = Milk_Con_SD)
#Adding initial contamination based on prevalence and area of the item #CFU/Pss
if(salmonella==1 && Calculated_Cont_Pss==1){
Pre_Data.Frame<-func_Cont_cm2(Pre_Data.Frame,Prevalence_Salmonella_Pre,Pre_Contamination_salmonella,Pre_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Pss ==1){
Pre_Data.Frame<-func_Cont_cm2(Pre_Data.Frame,Prevalence_Norovirus_Pre,Pre_Contamination_norovirus,Pre_Mean_area)
}
}
} #end of J1
#SERVICE >1 DAY 1 ===============================================================
if(j>1 && k ==1 ){
# Fruit -------------------------------------------------------------------
if (Sim_Fruit==1){
Fr_Data.Frame<-Fuct_DF_Reservice(FoodType = "Fruit")
#Adding Initial Contaminations of fruit
if(salmonella==1 && Calculated_Cont_Fr==1){
#Adding Contaminations to the Data Frames
Fr_Data.Frame<-func_Cont_cm2(Fr_Data.Frame,Prevalence_Salmonella_Fr,Fr_Contamination_salmonella,Fr_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Fr ==1){
#Adding Contamination to the Data Frames
Fr_Data.Frame<-func_Cont_HuNoV_Fr(Fr_Data.Frame)
}
#Adding times that the share table items have been shared
Left_ST_Fr[,colnames(Left_ST_Fr)=="STtimes"]<-(Left_ST_Fr[,colnames(Left_ST_Fr)=="STtimes"])+1
#Binding all the stuff. for next service
Fr_Data.Frame<-rbind(Left_Selection_Fr,Fr_Data.Frame,Left_ST_Fr)
#Reseting Numbers in Data Frames
Fr_Data.Frame$Item.No.<- 1:nrow(Fr_Data.Frame)
row.names(Fr_Data.Frame)<-1:nrow(Fr_Data.Frame)
Fr_Data.Frame$Service<-j
Fr_Data.Frame$Day<-k
}
# Pss ---------------------------------------------------------------------
if(Sim_PSS==1){
Pss_Data.Frame<-Fuct_DF_Reservice(FoodType = "Pss")
#Adding initial contamination based on prevalence and area of the item #CFU/Pss
if(salmonella==1 && Calculated_Cont_Pss==1){
Pss_Data.Frame<-func_Cont_cm2(Pss_Data.Frame,Prevalence_Salmonella_Pss,Pss_Contamination_salmonella,Pss_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Pss ==1){
Pss_Data.Frame<-func_Cont_cm2(Pss_Data.Frame,Prevalence_Norovirus_Pss,Pss_Contamination_norovirus,Pss_Mean_area)
}
#Adding times that the share table items have been shared
Left_ST_Pss[,colnames(Left_ST_Pss)=="STtimes"]<-(Left_ST_Pss[,colnames(Left_ST_Pss)=="STtimes"])+1
#Binding all the stuff. for next service
Pss_Data.Frame<-rbind(Left_Selection_Pss,Pss_Data.Frame,Left_ST_Pss)
#Reseting Numbers in Data Frames
Pss_Data.Frame$Item.No.<- 1:nrow(Pss_Data.Frame)
row.names(Pss_Data.Frame)<-1:nrow(Pss_Data.Frame)
Pss_Data.Frame$Service<-j
Pss_Data.Frame$Day<-k
}
# Pre ---------------------------------------------------------------------
if(Sim_PRE==1){
Pre_Data.Frame<-Fuct_DF_Reservice(FoodType = "Pre")
#Adding initial spoilge contamination to the Datafra,e
Pre_Data.Frame<-Func_Adding_Initial_MilkCont(df = Pre_Data.Frame, mean = Milk_Con_Mean, sd = Milk_Con_SD)
#Adding initial contamination based on prevalence and area of the item #CFU/Pss
if(salmonella==1 && Calculated_Cont_Pre==1){
Pre_Data.Frame<-func_Cont_cm2(Pre_Data.Frame,Prevalence_Salmonella_Pre,Pre_Contamination_salmonella,Pre_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Pre ==1){
Pre_Data.Frame<-func_Cont_cm2(Pre_Data.Frame,Prevalence_Norovirus_Pre,Pre_Contamination_norovirus,Pre_Mean_area)
}
#Adding times that the share table items have been shared
Left_ST_Pre[,colnames(Left_ST_Pre)=="STtimes"]<-(Left_ST_Pre[,colnames(Left_ST_Pre)=="STtimes"])+1
#Binding all the stuff. for next service
Pre_Data.Frame<-rbind(Left_Selection_Pre,Pre_Data.Frame,Left_ST_Pre)
#Reseting Numbers in Data Frames
Pre_Data.Frame$Item.No.<- 1:nrow(Pre_Data.Frame)
row.names(Pre_Data.Frame)<-1:nrow(Pre_Data.Frame)
Pre_Data.Frame$Service<-j
Pre_Data.Frame$Day<-k
}
}#end of j loop
# SERVICES MULTIPLE AND MULTIPLE DAYS ===============================================================
if(j>0 && k>1 ){
# Fruit ----------------------------------------------------------------------
if (Sim_Fruit==1){
Fr_Data.Frame<-Fuct_DF_Reservice(FoodType = "Fruit")
#Adding Initial Contaminations of fruit
if(salmonella==1 && Calculated_Cont_Fr==1){
#Adding Contamination to the Data Frames
Fr_Data.Frame<-func_Cont_cm2(Fr_Data.Frame,Prevalence_Salmonella_Fr,Fr_Contamination_salmonella,Fr_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Fr ==1){
#Adding Contamination to the Data Frames
Fr_Data.Frame<-func_Cont_HuNoV_Fr(Fr_Data.Frame)
}
#Adding times that the share table items have been shared
Left_ST_Fr[,colnames(Left_ST_Fr)=="STtimes"]<-(Left_ST_Fr[,colnames(Left_ST_Fr)=="STtimes"])+1
#Binding all the stuff. for next service
Fr_Data.Frame<-rbind(Left_Selection_Fr,Fr_Data.Frame,Left_ST_Fr)
#Reseting Numbers in Data Frames
Fr_Data.Frame$Item.No.<- 1:nrow(Fr_Data.Frame)
row.names(Fr_Data.Frame)<-1:nrow(Fr_Data.Frame)
Fr_Data.Frame$Service<-j
Fr_Data.Frame$Day<-k
}
# Pss ---------------------------------------------------------------------
if(Sim_PSS==1){
Pss_Data.Frame<-Fuct_DF_Reservice(FoodType = "Pss")
#Adding initial contamination based on prevalence and area of the item #CFU/Pss
if(salmonella==1 && Calculated_Cont_Pss==1){
Pss_Data.Frame<-func_Cont_cm2(Pss_Data.Frame,Prevalence_Salmonella_Pss,Pss_Contamination_salmonella,Pss_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Pss ==1){
Pss_Data.Frame<-func_Cont_cm2(Pss_Data.Frame,Prevalence_Norovirus_Pss,Pss_Contamination_norovirus,Pss_Mean_area)
}
#Adding times that the share table items have been shared
Left_ST_Pss[,colnames(Left_ST_Pss)=="STtimes"]<-(Left_ST_Pss[,colnames(Left_ST_Pss)=="STtimes"])+1
#Binding all the stuff. for next service
Pss_Data.Frame<-rbind(Left_Selection_Pss,Pss_Data.Frame,Left_ST_Pss)
#Reseting Numbers in Data Frames
Pss_Data.Frame$Item.No.<- 1:nrow(Pss_Data.Frame)
row.names(Pss_Data.Frame)<-1:nrow(Pss_Data.Frame)
Pss_Data.Frame$Service<-j
Pss_Data.Frame$Day<-k
}
# Pre ---------------------------------------------------------------------
if(Sim_PRE==1){
Pre_Data.Frame<-Fuct_DF_Reservice(FoodType = "Pre")
#Adding initial spoilge contamination to the Datafra,e
Pre_Data.Frame<-Func_Adding_Initial_MilkCont(df = Pre_Data.Frame, mean = Milk_Con_Mean, sd = Milk_Con_SD)
#Adding initial contamination based on prevalence and area of the item #CFU/Pss
if(salmonella==1 && Calculated_Cont_Pre==1){
Pre_Data.Frame<-func_Cont_cm2(Pre_Data.Frame,Prevalence_Salmonella_Pre,Pre_Contamination_salmonella,Pre_Mean_area)
} else if (norovirus == 1 && Calculated_Cont_Pre ==1){
Pre_Data.Frame<-func_Cont_cm2(Pre_Data.Frame,Prevalence_Norovirus_Pre,Pre_Contamination_norovirus,Pre_Mean_area)
}
#Adding times that the share table items have been shared
Left_ST_Pre[,colnames(Left_ST_Pre)=="STtimes"]<-(Left_ST_Pre[,colnames(Left_ST_Pre)=="STtimes"])+1
#Binding all the stuff. for next service
Pre_Data.Frame<-rbind(Left_Selection_Pre,Pre_Data.Frame,Left_ST_Pre)
#Reseting Numbers in Data Frames
Pre_Data.Frame$Item.No.<- 1:nrow(Pre_Data.Frame)
row.names(Pre_Data.Frame)<-1:nrow(Pre_Data.Frame)
Pre_Data.Frame$Service<-j
Pre_Data.Frame$Day<-k
}
}#end of j loop
# Vectors -----------------------------------------------------------------
if (Sim_Fruit==1){
V_Shared_Fr<-c(0)
}
if(Sim_PSS==1){
V_Shared_Pss<-c(0)
}
if(Sim_PRE==1){
V_Shared_Pre<-c(0)
}