1
|
|
|
/* |
2
|
|
|
* |
3
|
|
|
* Copyright 2014, Armenak Grigoryan, and individual contributors as indicated |
4
|
|
|
* by the @authors tag. See the copyright.txt in the distribution for a |
5
|
|
|
* full listing of individual contributors. |
6
|
|
|
* |
7
|
|
|
* This is free software; you can redistribute it and/or modify it |
8
|
|
|
* under the terms of the GNU Lesser General Public License as |
9
|
|
|
* published by the Free Software Foundation; either version 2.1 of |
10
|
|
|
* the License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This software is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15
|
|
|
* Lesser General Public License for more details. |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
package com.strider.datadefender.utils; |
22
|
|
|
|
23
|
|
|
import java.util.ArrayList; |
24
|
|
|
import java.util.List; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This class calculates the risk score for an individual column and for entire data store. |
28
|
|
|
* |
29
|
|
|
* @author Armenak Grigoryan |
30
|
|
|
*/ |
31
|
|
|
public class Score { |
32
|
|
|
private static final int SCORE_LOW = 1; |
33
|
|
|
private static final int SCORE_MEDIUM = 2; |
34
|
|
|
private static final int SCORE_HIGH = 3; |
35
|
|
|
private static final List<Integer> averageScore = new ArrayList<>(); |
36
|
|
|
|
37
|
|
|
public String columnScore(final int rowCount) { |
38
|
|
|
int score = 0; |
39
|
|
|
|
40
|
|
|
if (rowCount == 0) { |
41
|
|
|
score = 0; |
42
|
|
|
} else if ((rowCount > 0) && (rowCount <= 100)) { |
43
|
|
|
score = SCORE_LOW; |
44
|
|
|
} else if ((rowCount > 100) && (rowCount <= 1000)) { |
45
|
|
|
score = SCORE_MEDIUM; |
46
|
|
|
} else { |
47
|
|
|
score = SCORE_HIGH; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
averageScore.add(score); |
51
|
|
|
|
52
|
|
|
return getScoreDefinition(score); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public String dataStoreScore() { |
56
|
|
|
float averageDataStoreScore = 0; |
57
|
|
|
int tmp = 0; |
58
|
|
|
|
59
|
|
|
for (final int score : averageScore) { |
60
|
|
|
tmp += score; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if ((averageScore != null) && (averageScore.size() > 0)) { |
64
|
|
|
averageDataStoreScore = tmp / averageScore.size(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return getScoreDefinition(Math.round(averageDataStoreScore)); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public String getScoreDefinition(final int score) { |
71
|
|
|
String scoreDefinition = ""; |
72
|
|
|
|
73
|
|
|
switch (score) { |
74
|
|
|
case 1: |
75
|
|
|
scoreDefinition = "Low"; |
76
|
|
|
break; |
77
|
|
|
case 2: |
78
|
|
|
scoreDefinition = "Medium"; |
79
|
|
|
break; |
80
|
|
|
case 3: |
81
|
|
|
scoreDefinition = "High"; |
82
|
|
|
break; |
83
|
|
|
default: |
84
|
|
|
scoreDefinition = "Undefined"; |
85
|
|
|
break; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return scoreDefinition; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
//~ Formatted by Jindent --- http://www.jindent.com |
94
|
|
|
|