-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiversity.vb
631 lines (545 loc) · 27 KB
/
diversity.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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
Imports System.Windows.Forms
Public Class diversity
Public LibCalculate As New decalculate.calculate
Private sNotaDiversidade As String = "<p><small>O índice Total de Diversidade apesar de ser calculado, na prática não representa um parâmetro comparável, pois está isolado. Entretanto pode ser útil se for usado para comparação de séries temporais distintas!</small></p>"
Public Sub New()
Main()
End Sub
Public Function ShannonWiener(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 lFi As Double, lLogFi As Double
Dim sLev As String, somaT As Double
Dim sRTF As String = ""
Dim lDivSWTotal As Double
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
iLog = LibLoadConfig.LoadConfig("CONFIG", "LOGBASE", "2")
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
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)
End If
Next iR
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-4 col-lg-4'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Valor N: " & lCT & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Base Logarítmica: " & iLog & "</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>" &
"<th>Valor Fi</th>" &
"<th>Valor Log(Fi)</th>" &
"<th>Valor Fi x Log(Fi)</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
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td>"
lFi = lCel / lCT
If lFi > 0 Then ' 0 Then
sRTF &= "<td>" & Math.Round(lFi, 4) & "</td>"
lLogFi = Math.Log(lFi, iLog)
somaT += (lFi * lLogFi)
sRTF &= "<td class='text-center'>" & Format(lLogFi, "###,###,###,##0.0###") & "</td>"
sRTF &= "<td class='text-center'>" & Format((lFi * lLogFi), "###,###,###,##0.0###") & "</td>"
Else
sRTF &= "<td class='text-center'>0</td>"
sRTF &= "<td class='text-center'>0</td>"
End If
sRTF &= "</tr>"
Next iCelValue
sRTF &= "</tbody><tfooter><tr class='text-right text-info'>"
sRTF &= "<td colspan=5>Índice Diversidade de Shannon-Wiener: " & Format(Math.Abs(somaT), "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
lDivSWTotal += somaT
somaT = 0
Next iC
sRTF &= "<p class='lead text-success'>Índice Diversidade de Shannon-Wiener Total: " & Format(Math.Abs(lDivSWTotal), "###,###,###,##0.0###") & "*</p>"
sRTF &= sNotaDiversidade
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de 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 fDivSW(ByRef oDGV As DataGridView, ByVal iC As Integer) As Double
Dim lcol As Long, lrow As Long
Dim iR As Long
Dim lCT As Long, lCel As Long
Dim iCelValue As Integer
Dim lFi As Double, lLogFi As Double
Dim somaT As Double
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
iLog = LibLoadConfig.LoadConfig("CONFIG", "LOGBASE", "2")
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
End If
End If
lCT = 0
For iR = 0 To lrow - 1 ' Step 1
If oDGV.Rows(iR).Cells(iC).Value <> String.Empty Then _
lCT += oDGV.Rows(iR).Cells(iC).Value
Next iR
For iCelValue = 0 To lrow - 1
If oDGV.Rows(iCelValue).Cells(iC).Value <> String.Empty Then
lCel = oDGV.Rows(iCelValue).Cells(iC).Value
Else
lCel = 0
End If
If lCel > 0 Then
lFi = lCel / lCT
If lFi > 0 Then ' 0 Then
lLogFi = Math.Log(lFi, iLog)
somaT += (lFi * lLogFi)
End If
End If
Next iCelValue
Return Math.Abs(somaT)
Catch ex As Exception
LibError.ErrorView(ex)
Return 0
End Try
End Function
Public Function divSimpson(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 lFi As Double, lDivSim As Double
Dim sLev As String, somaT As Double
Dim lNvsN As Double, lDivSimTotal As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
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><th>n*(n-1)</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>"
lFi += lCel * (lCel - 1)
somaT += lFi
If lFi > 0 Then ' 0 Then
sRTF &= "<td class='text-center'>" & Format(lFi, "###,###,###,##0.0###") & "</td>"
Else
sRTF &= "<td>n*(n-1): 0</td>"
End If
sRTF &= "</tr>"
End If
Next iCelValue
lDivSim = 1 - (lFi / lNvsN)
lDivSimTotal += (lFi / lNvsN)
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td colspan=3>Índice Diversidade de Simpson: " & Format(Math.Abs(lDivSim), "###,###,###,##0.0###") & "</td>"
sRTF &= "</tr></tfooter>"
sRTF &= "</table></div><hr/>"
somaT = 0
lFi = 0
Next iC
sRTF &= "<p class='lead text-success'>Índice Diversidade de Simpson Total: " & Format(Math.Abs(lDivSimTotal), "###,###,###,##0.0###") & "</p>"
sRTF &= sNotaDiversidade
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de 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 fdivSimpson(ByRef oDGV As DataGridView, ByVal ic As Integer)
Dim lcol As Long, lrow As Long
Dim iR As Long
Dim lCT As Long, lCel As Long
Dim iCelValue As Integer
Dim lFi As Double, lDivSim As Double
Dim sLev As String, somaT As Double
Dim lNvsN As Double
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
End If
End If
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
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)
Else
lCel = 0
End If
If lCel > 0 Then
lFi += lCel * (lCel - 1)
somaT += lFi
End If
Next iCelValue
lDivSim = 1 - (lFi / lNvsN)
Return lDivSim
Catch ex As Exception
LibError.ErrorView(ex)
Return 0
End Try
End Function
Public Function divMargalef(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 lDivMargalef As Double, sLev As String
Dim sp As Double, lDivMargalefTotal As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
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-4 col-lg-4'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Valor N: " & lCT & "</div>" &
"<div class='col-xs-4 col-lg-4'>Valor Log10 (N): " & Math.Round(Math.Log10(lCT), 4) & "</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
sp += 1
End If
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
Next iCelValue
lDivMargalef = (sp - 1) / CDbl(Math.Log10(lCT))
lDivMargalefTotal += lDivMargalef
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de Espécies do Levantamento: " & sp & "</td>"
sRTF &= "<td>Índice Diversidade de Margalef (ɑ): " & Format(Math.Abs(lDivMargalef), "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
sp = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de Margalef</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function divGleason(ByRef oDGV As DataGridView)
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 lDivGleason As Double, sLev As String
Dim sp As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
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-4 col-lg-4'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Valor N: " & lCT & "</div>" &
"<div class='col-xs-4 col-lg-4'>Valor Log10 (N): " & Math.Round(Math.Log10(lCT), 4) & "</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
sp += 1
End If
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
Next iCelValue
lDivGleason = sp / CDbl(Math.Log10(lCT))
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de Espécies do Levantamento: " & sp & "</td>"
sRTF &= "<td>Índice Diversidade de Gleason: " & Format(Math.Abs(lDivGleason), "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
sp = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de Gleason</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function divMenhinick(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 lDivMenhinick As Double, sLev As String
Dim sp As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
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-4 col-lg-4'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Valor N: " & lCT & "</div>" &
"<div class='col-xs-4 col-lg-4'>Valor Raiz Quadrada: " & Math.Round(Math.Sqrt(lCT), 4) & "</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
sp += 1
End If
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
Next iCelValue
lDivMenhinick = sp / Math.Sqrt(lCT)
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Número de Espécies do Levantamento: " & sp & "</td>"
sRTF &= "<td>Índice Diversidade de Menhinick: " & Format(Math.Abs(lDivMenhinick), "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
sp = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de Menhinick</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function divMcIntosh(ByRef oDGV As DataGridView)
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 lDivMcIntosh As Double, sLev As String
Dim dU As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
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)
lCel2 += lCel ^ 2
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
Next iCelValue
dU = Math.Sqrt(lCel2)
lDivMcIntosh = (lCT - dU) / (lCT - Math.Sqrt(lCT))
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Valor de U: " & Math.Round(dU, 4) & "</td>"
sRTF &= "<td>Índice Diversidade de McIntosh: " & Format(Math.Abs(lDivMcIntosh), "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
dU = 0
lCel2 = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de McIntosh</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function divBrillouin(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 lDivBrillouin As Double
Dim sLev As String
Dim FactN As Double, Factni As Double, FactRet As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
End If
End If
iLog = LibLoadConfig.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 += oDGV.Rows(iR).Cells(iC).Value
Next iR
FactN = lCT
FactN = Math.Log(LibCalculate.Factorial(FactN), iLog)
sLev = oDGV.Columns(iC).HeaderText.ToString
sRTF &= "<div class='row'><div class='col-xs-4 col-lg-4'>Levantamento: " & sLev & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Valor N: " & lCT & "</div>"
sRTF &= "<div class='col-xs-4 col-lg-4'>Base Logarítmica: " & iLog & "</div></div>"
sRTF &= "<div class='table-responsive'><table class='table table-bordered table-hover'><thead><tr class='info'><th colspan=2>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
FactRet = LibCalculate.Factorial(lCel)
Factni += Math.Log(FactRet, iLog)
sRTF &= "<tr>"
sRTF &= "<td colspan=2>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
End If
Next iCelValue
lDivBrillouin = (FactN - Factni) / (lCT)
If lDivBrillouin = Double.NaN Or IsNumeric(lDivBrillouin) = False Then lDivBrillouin = 0
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Fatorial de Log de N!: " & Math.Round(FactN, 4) & "</td>"
sRTF &= "<td>Somatório do log n!: " & Math.Round(Factni, 4) & "</td>"
sRTF &= "<td>Índice Diversidade de Brillouin: " & Format(lDivBrillouin, "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
Factni = 0
FactN = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de Brillouin</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function divTotal(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 lDivTotal As Double, sLev As String
Dim lFi As Double, lFiMinus As Double, lFixFiMinus As Double, lWi As Double
Dim sRTF As String = ""
lcol = oDGV.ColumnCount
lrow = oDGV.RowCount
Try
If Auditoria(oDGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
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 += 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
lFi = lCel / lCT
lFiMinus = 1 - lFi
lFixFiMinus = lFi * lFiMinus
lWi = 1 / lFi
End If
sRTF &= "<tr>"
sRTF &= "<td>" & oDGV.Rows(iCelValue).HeaderCell.Value & "</td>"
sRTF &= "<td class='text-center'>" & lCel & "</td></tr>"
Next iCelValue
lDivTotal = lWi * lFixFiMinus
sRTF &= "</tbody><tfooter><tr class='text-info'>"
sRTF &= "<td>Valor de Wi: " & Math.Round(lWi, 4) & "</td>"
sRTF &= "<td>Índice Diversidade de Total: " & Format(lDivTotal, "###,###,###,##0.0###") & "</td></tr></tfooter>"
sRTF &= "</table></div><hr/>"
lFi = 0
lFiMinus = 0
lFixFiMinus = 0
Next iC
sResult = sHTMLStart & "<h3 class='alert alert-success'>Relatório da Diversidade de Total</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
End Class