-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevenness.vb
284 lines (248 loc) · 12.5 KB
/
evenness.vb
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
Imports System.Windows.Forms
Public Class evenness
Private libCalculate As New calculate
Sub New()
Main()
End Sub
Public Function Dmax(ByVal 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 lFi As Double
Dim sLev As String, somaT As Double
Dim lNvsN As Double, dDivMax As Double
Dim sRTF As String = ""
Dim nSp 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
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>"
lNvsN = lCT * (lCT - 1)
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>"
sRTF &= "</tr>"
End If
If lCel > 0 Then
nSp += 1
End If
Next iCelValue
dDivMax = ((nSp - 1) / (nSp)) * (lCT / (lCT - 1))
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td colspan=2>Regularidade D<sub>max</sub>: " & Format(Math.Abs(dDivMax), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter>"
sRTF &= "</table></div><hr/>"
somaT = 0
lFi = 0
nSp = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Regularidade D<sub>max</sub></h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
MessageBox.Show("Erro: " & ex.Message & vbNewLine & vbNewLine & "Local de Origem: " & ex.StackTrace, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function dminusmax(ByVal 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 lFi As Double
Dim sLev As String, somaT As Double
Dim lNvsN As Double, dDivMinusMax As Double
Dim sRTF As String = ""
Dim nSp 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
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>"
lNvsN = lCT * (lCT - 1)
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>"
sRTF &= "</tr>"
End If
If lCel > 0 Then
nSp += 1
End If
Next iCelValue
dDivMinusMax = nSp * ((lCT - 1) / (lCT - nSp))
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td colspan=2>Regularidade <em>d<sub>max</sub></em>: " & Format(Math.Abs(dDivMinusMax), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter>"
sRTF &= "</table></div><hr/>"
somaT = 0
lFi = 0
nSp = 0
Next iC
'sRTF &= "Índice Diversidade de Simpson Total: " & Format(Math.Abs(lDivSimTotal), "###,###,###,##0.0###") & vbNewLin
sResult = sHTMLStart & "<h3 class='alert alert-success'>Regularidade <em>d<sub>max</sub></em></h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
MessageBox.Show("Erro: " & ex.Message & vbNewLine & vbNewLine & "Local de Origem: " & ex.StackTrace, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function deltamax(ByVal 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 lFi As Double
Dim sLev As String, somaT As Double
Dim lNvsN As Double, dDeltaMax As Double
Dim sRTF As String = ""
Dim nSp 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
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>"
lNvsN = lCT * (lCT - 1)
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>"
sRTF &= "</tr>"
End If
If lCel > 0 Then
nSp += 1
End If
Next iCelValue
dDeltaMax = 1 - (1 / nSp)
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td colspan=2>Regularidade Δ<sub>max</sub>: " & Format(Math.Abs(dDeltaMax), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter>"
sRTF &= "</table></div><hr/>"
somaT = 0
lFi = 0
nSp = 0
Next iC
'sRTF &= "Índice Diversidade de Simpson Total: " & Format(Math.Abs(lDivSimTotal), "###,###,###,##0.0###") & vbNewLin
sResult = sHTMLStart & "<h3 class='alert alert-success'>Regularidade Δ<sub>max</sub></h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
MessageBox.Show("Erro: " & ex.Message & vbNewLine & vbNewLine & "Local de Origem: " & ex.StackTrace, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function Hmax(ByVal 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 lFi As Double, dRemainde As Double, iCValue As Integer, dLogNFact As Double, dLogCplus1 As Double, dlogC As Double
Dim sLev As String, somaT As Double
Dim lNvsN As Double, dHMax As Double
Dim sRTF As String = ""
Dim nSp 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
iLog = LibConfig.LoadConfig("CONFIG", "LOGBASE", "2")
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>"
lNvsN = lCT * (lCT - 1)
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>"
sRTF &= "</tr>"
End If
If lCel > 0 Then
nSp += 1
End If
Next iCelValue
dRemainde = lCT Mod nSp
iCValue = Math.Abs(lCT / nSp)
dLogNFact = Math.Log(libCalculate.Factorial(lCT), iLog)
dlogC = Math.Log(iCValue, iLog)
dLogCplus1 = Math.Log(libCalculate.Factorial(iCValue + 1), iLog)
dHMax = (dLogNFact - (nSp - dRemainde) * (dlogC - dRemainde * dLogCplus1)) / lCT
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td colspan=2>Regularidade H<sub>max</sub>: " & Format(Math.Abs(dHMax), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter>"
sRTF &= "</table></div><hr/>"
somaT = 0
lFi = 0
nSp = 0
Next iC
'sRTF &= "Índice Diversidade de Simpson Total: " & Format(Math.Abs(lDivSimTotal), "###,###,###,##0.0###") & vbNewLin
sResult = sHTMLStart & "<h3 class='alert alert-success'>Regularidade H<sub>max</sub></h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
MessageBox.Show("Erro: " & ex.Message & vbNewLine & vbNewLine & "Local de Origem: " & ex.StackTrace, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
End Class