-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathequitability.vb
More file actions
319 lines (291 loc) · 14.8 KB
/
Copy pathequitability.vb
File metadata and controls
319 lines (291 loc) · 14.8 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
Imports System.Windows.Forms
Public Class equitability
Dim dSimp As New diversity
Dim dSW As New diversity
Public ValueLog As Double
Public Sub New()
Main()
End Sub
Public Function EqJ(ByRef oDGV As DataGridView) As String
Dim lcol As Long, lrow As Long
Dim iR As Long, iC As Integer
Dim lCT As Long, lCel As Long
Dim iCelValue As Integer
Dim lSP As Double, lEJ As Double
Dim sLev As String, lHMax As Double, lSW As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iC = 0 To lcol - 1 Step 1
lCT = 0
For iR = 0 To lrow - 1 Step 1
If oDGV.Rows(iR).Cells(iC).Value <> String.Empty Then _
lCT += CDbl(oDGV.Rows(iR).Cells(iC).Value)
Next iR
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-6 col-lg-6'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-6 col-lg-6'>Valor N: " & lCT & "</div></div>"
sRTF &= "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr class='info'><th>Espécie</th><th>Número de Indivíduos</th></tr></thead><tbody>"
For iCelValue = 0 To lrow - 1
If oDGV.Rows(iCelValue).Cells(iC).Value <> String.Empty Then
lCel = CDbl(oDGV.Rows(iCelValue).Cells(iC).Value)
Else
lCel = 0
End If
If lCel > 0 Then
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
If lCel <> 0 Then
lSP += 1
End If
End If
Next iCelValue
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de espécies: " & lSP & "</td>"
lHMax = Math.Log10(lSP)
sRTF &= "<td>Diversidade Máxima para o Índice de Shannon (H<sub>max</sub>): " & Math.Round(lHMax, 4) & "</td></tr>"
lSW = dSW.fDivSW(oDGV, iC)
sRTF &= "<tr class='text-info'><td>Índice Diversidade de Shannon-Wiener: " & Math.Round(lSW, 4) & "</td>"
lEJ = lSW / lHMax
sRTF &= "<td>Índice Equidade de J (Shannon-Wiener): " & Format(Math.Abs(lEJ), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter></table></div><hr/>"
lHMax = 0
lSP = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Equidade J (Shannon-Wiener)</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function EqD(ByRef oDGV As DataGridView) As String
Dim lcol As Long, lrow As Long
Dim iR As Long, iC As Integer
Dim lCT As Long, lCel As Long
Dim iCelValue As Integer
Dim lSP As Double, lED As Double
Dim sLev As String, lDMax As Double, lSimp As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iC = 0 To lcol - 1 Step 1
lCT = 0
For iR = 0 To lrow - 1 Step 1
If oDGV.Rows(iR).Cells(iC).Value <> String.Empty Then _
lCT += CDbl(oDGV.Rows(iR).Cells(iC).Value)
Next iR
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-6 col-lg-6'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-6 col-lg-6'>Valor N: " & lCT & "</div></div>"
sRTF &= "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr class='info'><th>Espécie</th><th>Número de Indivíduos</th></tr></thead><tbody>"
For iCelValue = 0 To lrow - 1
If oDGV.Rows(iCelValue).Cells(iC).Value <> String.Empty Then
lCel = CDbl(oDGV.Rows(iCelValue).Cells(iC).Value)
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
If lCel > 0 Then lSP += 1
End If
Next iCelValue
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de espécies: " & lSP & "</td>"
lDMax = ((lSP - 1) / lSP) * (lCT / (lCT - 1))
sRTF &= "<td>Diversidade Máxima para o Índice de Simpson (D<sub>max</sub>): " & Math.Round(lDMax, 4) & "</td></tr>"
lSimp = dSimp.fdivSimpson(oDGV, iC)
sRTF &= "<tr class='text-info'><td>Índice Diversidade de Simpson: " & Math.Round(lSimp, 4) & "</td>"
lED = lSimp / lDMax
sRTF &= "<td>Índice Equidade de ED (Simpson): " & Format(Math.Abs(lED), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter></table></div><hr/>"
lDMax = 0
lSP = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Equidade ED (Simpson)</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function EHill(ByRef oDGV As DataGridView) As String
Dim lcol As Long, lrow As Long
Dim iR As Long, iC As Integer
Dim lCT As Long, lCel As Long
Dim iCelValue As Integer
Dim lSP As Double, lEHill As Double
Dim sLev As String, lDs As Double, lSW As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iC = 0 To lcol - 1 Step 1
lCT = 0
For iR = 0 To lrow - 1 Step 1
If oDGV.Rows(iR).Cells(iC).Value <> String.Empty Then _
lCT += CDbl(oDGV.Rows(iR).Cells(iC).Value)
Next iR
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-6 col-lg-6'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-6 col-lg-6'>Valor N: " & lCT & "</div></div>"
sRTF &= "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr class='info'><th>Espécie</th><th>Número de Indivíduos</th></tr></thead><tbody>"
For iCelValue = 0 To lrow - 1
If oDGV.Rows(iCelValue).Cells(iC).Value <> String.Empty Then
lCel = CDbl(oDGV.Rows(iCelValue).Cells(iC).Value)
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
If lCel <> 0 Then lSP += 1
End If
Next iCelValue
lDs = dSimp.fdivSimpson(oDGV, iC)
lSW = dSW.fDivSW(oDGV, iC)
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Índice de Diversidade de Shannon-Wiener (H'): " & Math.Round(lSW, 4) & "</td>"
sRTF &= "<td>Índice de Diversidade de Simpson (Ds): " & Math.Round(lDs, 4) & "</td></tr>"
sRTF &= "<tr class='text-info'><td>(1/Ds) - 1 : " & Math.Round((1 / lDs) - 1, 4) & "</td>"
sRTF &= "<td>e<sup>H'</sup>: " & Math.Round((Math.E ^ lSW), 4) & "</td></tr>"
lEHill = ((1 / lDs) - 1) / ((Math.E ^ lSW) - 1)
sRTF &= "<tr class='text-info'><td colspan=2>Índice Equidade de Hill Modificado (EH): " & Format(Math.Abs(lEHill), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter></table></div><hr/>"
lEHill = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Equidade de Hill (Modificado)</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function EqE(ByRef oDGV As DataGridView) As String
Dim lcol As Long, lrow As Long
Dim iR As Integer, iC As Integer
Dim lCT As Long, lCel As Long
Dim iCelValue As Integer
Dim sLev As String, lEqE As Double
Dim sRTF As String = ""
Dim lSp As Integer, lSW As Double
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iC = 0 To lcol - 1 Step 1
lCT = 0
For iR = 0 To lrow - 1 Step 1
'numero total de indivíduos
If oDGV.Rows(iR).Cells(iC).Value <> String.Empty Then _
lCT += CDbl(oDGV.Rows(iR).Cells(iC).Value)
Next iR
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-6 col-lg-6'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-6 col-lg-6'>Valor N: " & lCT & "</div></div>"
sRTF &= "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr class='info'><th>Espécie</th><th>Número de Indivíduos</th></tr></thead><tbody>"
For iCelValue = 0 To lrow - 1
If oDGV.Rows(iCelValue).Cells(iC).Value <> String.Empty Then
lCel = CDbl(oDGV.Rows(iCelValue).Cells(iC).Value)
If lCel <> 0 Then lSp += 1
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
End If
Next iCelValue
lSW = dSW.fDivSW(oDGV, iC)
lEqE = (Math.E ^ lSW) / lSp
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de espécies (S): " & lSp & "</td>"
sRTF &= "<td>Diversidade de Espécie H' (Shannon-Wiener): " & Math.Round(lSW, 4) & "</td></tr>"
sRTF &= "<tr class='text-info'><td colspan=2>Valor da Equidade (E): " & Math.Round(lEqE, 4) & "</td></tr>"
sRTF &= "</table></div><hr/>"
lSW = 0
lEqE = 0
lSp = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Equidade E</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function EqU(ByRef oDGV As DataGridView) As String
Dim lcol As Long, lrow As Long
Dim iR As Long, iC As Integer
Dim lCT As Long, lCel As Long
Dim lCel2 As Double
Dim iCelValue As Integer
Dim EqUValue As Double, sLev As String
Dim dU As Double, lSp As Integer
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iC = 0 To lcol - 1 Step 1
lCT = 0
For iR = 0 To lrow - 1 Step 1
If oDGV.Rows(iR).Cells(iC).Value <> String.Empty Then _
lCT += CDbl(oDGV.Rows(iR).Cells(iC).Value)
Next iR
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-6 col-lg-6'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-6 col-lg-6'>Valor N: " & lCT & "</div></div>"
sRTF &= "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr class='info'><th>Espécie</th><th>Número de Indivíduos</th></tr></thead><tbody>"
For iCelValue = 0 To lrow - 1
If oDGV.Rows(iCelValue).Cells(iC).Value <> String.Empty Then
lCel = CDbl(oDGV.Rows(iCelValue).Cells(iC).Value)
If lCel <> 0 Then lSp += 1
lCel2 += lCel ^ 2
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
End If
Next iCelValue
dU = Math.Sqrt(lCel2)
EqUValue = (lCT - dU) / (lCT - (lCT / (Math.Sqrt(lSp))))
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de Espécie: " & lSp & "</td>"
sRTF &= "<td>Valor de U: " & Math.Round(dU, 4) & "</td></tr>"
sRTF &= "<tr class='text-info'><td colspan=2>Índice Equidade de McIntosh (EqU): " & Format(Math.Abs(EqUValue), "###,###,###,##0.0###") & "</td></tr>"
sRTF &= "</table></div><hr/>"
dU = 0
lCel2 = 0
lSp = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Equidade de McIntosh</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
End Class