-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
206 lines (175 loc) · 9.53 KB
/
server.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
library(shiny)#used for displaying everything
library(gdata) #Used for read.xls function
library(emdbook)#lambertW function
library(reshape2)#3d plots
library(ggplot2)#ggplot function
source("main.R")#Source for our reliabilty models
shinyServer(function(input, output) {
#reactive shiny fuction
reliability <- new.env()
Subsystem <- reactive({
#Subsystem1
reliability$sub1$Reliability_Investment <-
seq(0, input$Reliability_Investment_input1, len = 1000) #makes array of 1000 values for the reliability investment
reliability$sub1$MTTF <- #calculates MTTF for subsystem 1 and stores it in this vailable
MTTF_Function( reliability$sub1$Reliability_Investment,input$C01,input$Cost_Increment1,input$Amode_fail_rate1,input$Bmode_fail_rate1,input$Bmode_FEF1 )
reliability$sub1$minunit <- #calculates the number of replacement parts required
repParts(input$Ttime1,reliability$sub1$MTTF)
reliability$sub1$cst <- #calculates cost of subsystem 1
Cost(reliability$sub1$minunit, input$Ci1)
reliability$sub1$Aff <- AFF(input$Ci1, reliability$sub1$cst) #calculates affordability
reliability$sub1$numUnits <- #calculates fleet size based on fixed budget of 1 billion
NumUnits(1000000000,reliability$sub1$Reliability_Investment,reliability$sub1$cst)
#Subsystem2
reliability$sub2$Reliability_Investment <-
seq(0, input$Reliability_Investment_input2, len = 1000)
reliability$sub2$MTTF <-
MTTF_Function(reliability$sub2$Reliability_Investment,input$C02,input$Cost_Increment2,input$Amode_fail_rate2,input$Bmode_fail_rate2,input$Bmode_FEF2)
reliability$sub2$minunit <-
repParts(input$Ttime2,reliability$sub2$MTTF)
reliability$sub2$cst <-
Cost(reliability$sub2$minunit, input$Ci2)
reliability$sub2$Aff <- AFF(input$Ci2, reliability$sub2$cst)
reliability$sub2$numUnits <-
NumUnits(1000000000,reliability$sub2$Reliability_Investment,reliability$sub2$cst)
#Unit
reliability$unitCost <- #calculates cost of both subsystems
UnitCost(reliability$sub1$cst,reliability$sub2$cst)
reliability$unitInvestment <- #calculates total investment from both subsystems
UnitInvestment(
reliability$sub1$Reliability_Investment,reliability$sub2$Reliability_Investment
)
reliability$numUnits <- #calculates the number of units possible based on both subsystems
NumUnits(1000000000,100000000,reliability$unitCost)
#return variable
reliability
})
Reliability <- reactive({ #allows work to be done on the current selected subsystem (probably not the best way of doing this)
reli <- new.env()
switch(input$panelName,
"subsystem 1" = {
reli = Subsystem()$sub1
},
"subsystem 2" = {
reli = Subsystem()$sub2
})
reli
})
#Mean time to falure vs reliability investment
output$MTTF <- renderPlot({
plot_data <-
data.frame(x = Reliability()$Reliability_Investment/1000000,y = Reliability()$MTTF)
p <-
ggplot(data = plot_data, aes(x = x,y = y)) + geom_point(color = "blue") +
xlab("Reliability Investment (millions of $)") + ylab("Mean time to Failure (hrs)") + ggtitle("MTTF")
#axis()
# p <- p + scale_x_discrete(labels=paste(plot_data$x, "MM", sep = ""))
p <- p + theme(title = element_text(size = rel(1.75)),axis.text = element_text(size=rel(1.25)))
p
})
#number of replacement part
output$repParts <- renderPlot({
p <-
qplot(Reliability()$Reliability_Investment,Reliability()$minunit)+ xlab("Reliability Investment ($)") + ylab("Replacement parts") + ggtitle("Replacements")
p <- p + theme(axis.title.y = element_text(angle = 90))+theme(axis.text.y = element_text(size = rel(1.5)))
p <- p + theme(title = element_text(size = rel(2)))
p
})
#cost per subsystem (and total system) vs investment
output$Cost <- renderPlot({
#if(Subsystem()$sub1$Reliability_Investment[length(Subsystem()$sub1$Reliability_Investment)] > Subsystem()$sub2$Reliability_Investment[length(Subsystem()$sub2$Reliability_Investment)]) X <- Subsystem()$sub1$Reliability_Investment else X <- Subsystem()$sub2$Reliability_Investment
X <- Subsystem()$sub1$Reliability_Investment #currently only scaled for subsystem 1, above statement will pick the larger of the two
y1 <- Subsystem()$sub1$cst + X #the reliability investment is added to demonstrate minima on cost
y2 <- Subsystem()$sub2$cst + X
y3 <- y1 + y2 #Subsystem()$numUnits
length(y3) = length(y1) = length(y2) = length(X)
#allowing multiple lines be plotted on one graph
plot_data <-
data.frame(
x = X, "Subsystem 1" = y1, "Subsystem 2" = y2, "System" = y3
)
#plot_data <- data.frame(x = Reliability()$Reliability_Investment, "Subsystem 1" = Subsystem()$sub1$cst, "Subsystem 2" = Subsystem()$sub2$cst)
plot_data_long <- melt(plot_data, id = "x")
p <-
ggplot(data = plot_data_long, aes(x = x, y = value, colour = variable)) + geom_point() +
ylab("Lifecycle Cost ($)") + xlab("Reliability Investment ($)") +ggtitle("Lifecycle Cost")
p <- p + theme(axis.title.y = element_text(size = rel(1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1)))
p <- p + theme(title = element_text(size = rel(2))) + theme(legend.title = element_text(size = rel(.5)))
p
})
#cost per subsystem (and total system) vs investment
output$OSCost <- renderPlot({
if(Subsystem()$sub1$Reliability_Investment[length(Subsystem()$sub1$Reliability_Investment)] > Subsystem()$sub2$Reliability_Investment[length(Subsystem()$sub2$Reliability_Investment)]) X <- Subsystem()$sub1$Reliability_Investment else X <- Subsystem()$sub2$Reliability_Investment
# X <- Subsystem()$sub1$Reliability_Investment #currently only scaled for subsystem 1, above statement will pick the larger of the two
y1 <- Subsystem()$sub1$cst
y2 <- Subsystem()$sub2$cst
y3 <- y1 + y2 #Subsystem()$numUnits
length(y3) = length(y1) = length(y2) = length(X)
#allowing multiple lines be plotted on one graph
plot_data <-
data.frame(
x = X, "Subsystem 1" = y1, "Subsystem 2" = y2, "System" = y3
)
#plot_data <- data.frame(x = Reliability()$Reliability_Investment, "Subsystem 1" = Subsystem()$sub1$cst, "Subsystem 2" = Subsystem()$sub2$cst)
plot_data_long <- melt(plot_data, id = "x")
p <-
ggplot(data = plot_data_long, aes(x = x, y = value, colour = variable)) + geom_point() +
ylab("O&S Cost ($)") + xlab("Reliability Investment ($)") +ggtitle("O&S Cost")
p <- p + theme(axis.title.y = element_text(size = rel(1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1)))
p <- p + theme(title = element_text(size = rel(2))) + theme(legend.title = element_text(size = rel(.5)))
p
})
#total fleet size
output$fleetSize <- renderPlot({
if (Subsystem()$sub1$Reliability_Investment[length(Subsystem()$sub1$Reliability_Investment)] > Subsystem()$sub2$Reliability_Investment[length(Subsystem()$sub2$Reliability_Investment)])
X <- Subsystem()$sub1$Reliability_Investment
else
X <- Subsystem()$sub2$Reliability_Investment
y1 <- Subsystem()$sub1$numUnits
y2 <- Subsystem()$sub2$numUnits
y3 <- Subsystem()$numUnits
length(y3) = length(y1) = length(y2) = length(X)
plot_data <-
data.frame(
x = X, "Subsystem 1" = y1, "Subsystem 2" = y2, "System" = y3
)
plot_data_long <- melt(plot_data, id = "x")
p <-
ggplot(data = plot_data_long, aes(x = x, y = value, colour = variable)) + geom_point() +
ylab("Units") + xlab("Reliability Investment ($)") + ggtitle("Fleet size")
p <- p + theme(axis.title.y = element_text(size = rel(1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1), angle = 00))
p <- p + theme(title = element_text(size = rel(2), angle = 00))+ theme(legend.title = element_text(size = rel(.5)))
p
})
#affordability plot
output$Aff <- renderPlot({
p <- qplot(Reliability()$Reliability_Investment,Reliability()$Aff) + xlab("Reliability Investment ($)") + ylab("Affordability") + ggtitle("Affordability")
p <- p + theme(axis.title.y = element_text(size = rel(1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1), angle = 00))
p <- p + theme(title = element_text(size = rel(2), angle = 00))
p
})
#this is an example plot. currently plots the contours of a volcano
output$TA <- renderPlot({
p <- ggplot(melt(volcano), aes(x = Var1, y = Var2, fill = value)) + geom_tile() +
scale_fill_gradient("Desirability",low = "red",high = "blue") + xlab("Reliability Investment ($)") +
ylab("Cost") + ggtitle("Desirability")
p <- p + theme(axis.title.y = element_text(size = rel(1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1), angle = 00))
p <- p + theme(title = element_text(size = rel(2), angle = 00))
p
})
#displays text, not currently used
output$MTTF_Output <- renderText({
Reliability()$numUnits
})
#availability plot
output$ava <- renderPlot({
plot_data <-
data.frame(x = Reliability()$Reliability_Investment,y = (Reliability()$MTTF / input$Ttime1) )
p <-
ggplot(data = plot_data, aes(x = x,y = y)) + geom_point(color = "black") + xlab("Reliability Investment ($)") +
ylab("System Availability") + ggtitle("Availability")
p <- p + theme(axis.title.y = element_text(size = rel(1), angle = 90)) + theme(axis.title.x = element_text(size = rel(1), angle = 00))
p <- p + theme(title = element_text(size = rel(2), angle = 00))
p
})
})