Skip to content

Commit 96f59c6

Browse files
committed
Merge branch 'release/v1.0.2'
2 parents 85a1039 + 479170a commit 96f59c6

File tree

12 files changed

+230
-14
lines changed

12 files changed

+230
-14
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
${{ secrets.DOCKERHUB_USERNAME }}/veritas-assessment-tool:latest
7070
${{ secrets.DOCKERHUB_USERNAME }}/veritas-assessment-tool:v1
7171
${{ secrets.DOCKERHUB_USERNAME }}/veritas-assessment-tool:v1.0
72-
${{ secrets.DOCKERHUB_USERNAME }}/veritas-assessment-tool:v1.0.1
72+
${{ secrets.DOCKERHUB_USERNAME }}/veritas-assessment-tool:v1.0.2
7373
7474
7575
- name: Move cache

bin/install.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ cd py || exit
55

66
pip3 install virtualenv
77

8+
if [[ -d venv ]]; then
9+
rm -rf venv
10+
fi
11+
# create virtual environment
812
virtualenv venv -p python3
9-
13+
# using virtual environment
1014
source venv/bin/activate
11-
15+
# install python module
1216
pip3 install --no-cache-dir -r requirements.txt

bin/start.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ if [[ -f py/venv/bin/activate ]]; then
66
source py/venv/bin/activate
77
fi
88

9-
nohup java -jar $(pwd)/jar/veritas-assessment-tool.jar 1>>log/stdout.log 2>&1 &
9+
JVM_OPT='-Dlog4j2.formatMsgNoLookups=true'
10+
11+
nohup java ${JVM_OPT} -jar $(pwd)/jar/veritas-assessment-tool.jar 1>>log/stdout.log 2>&1 &

bin/tool.sh

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/bin/bash
2+
3+
POSITIONAL=()
4+
5+
6+
function check_user() {
7+
local l_user="$1"
8+
local l_user_count=`sqlite3 $SQLITE_FILE <<EOF
9+
select count(id) from vat_user where username = "$l_user";
10+
EOF
11+
`
12+
if [[ $l_user_count -eq 0 ]]; then
13+
echo "Not found user: $l_user"
14+
exit 1;
15+
fi
16+
}
17+
18+
function unlock() {
19+
if [[ $# -eq 0 ]]; then
20+
echo "use command: '$0 unlock -u USERNAME'"
21+
exit 1;
22+
fi
23+
local l_user="$1"
24+
check_user l_user
25+
sqlite3 $SQLITE_FILE <<EOF
26+
update vat_user set locked=0 where username = "$l_user";
27+
EOF
28+
clear_cache
29+
}
30+
31+
function reset_password() {
32+
if [[ $# -eq 0 ]]; then
33+
echo "use command: '$0 reset_password -u USERNAME'"
34+
exit 1;
35+
fi
36+
local l_user="$1"
37+
check_user l_user
38+
local l_password='$2a$10$XRz2ew7AX.StHRF.XptumuXSSSHiF4ylTCC5uDBO1l2z51maRnE82'
39+
sqlite3 $SQLITE_FILE <<EOF
40+
update vat_user set should_change_password=1, password="$l_password" where username = "$l_user";
41+
EOF
42+
clear_cache
43+
}
44+
45+
function user_list() {
46+
sqlite3 $SQLITE_FILE <<EOF
47+
select id, username from vat_user order by id;
48+
EOF
49+
}
50+
51+
function print_help() {
52+
echo "
53+
help: print this help info.
54+
list: list all user.
55+
unlock: unlock user
56+
flag: -u USERNAME
57+
reset_password: reset user's password
58+
flag: -u USERNAME
59+
"
60+
}
61+
62+
function clear_cache() {
63+
touch 'file/db/.clear_cache'
64+
}
65+
66+
cd "$(dirname $0)" || exit
67+
cd .. || exit
68+
69+
SQLITE_FILE='file/db/sqlite.db'
70+
71+
if [[ $# -eq 0 ]]; then
72+
print_help;
73+
exit 1;
74+
elif [[ $# -gt 0 ]]; then
75+
COMMAND="$1"
76+
shift
77+
fi
78+
79+
80+
while [[ $# -gt 0 ]]; do
81+
key="$1"
82+
83+
case $key in
84+
-u|--user)
85+
G_USER="$2"
86+
shift # past argument
87+
shift # past value
88+
;;
89+
*) # unknown option
90+
POSITIONAL+=("$1") # save it in an array for later
91+
shift # past argument
92+
;;
93+
esac
94+
done
95+
96+
case $COMMAND in
97+
list)
98+
user_list
99+
;;
100+
unlock)
101+
unlock $G_USER
102+
;;
103+
reset_password)
104+
reset_password $G_USER
105+
;;
106+
help)
107+
print_help;
108+
;;
109+
*)
110+
echo "'$COMMAND' is not a legal command.";
111+
echo "see '$0 help'"
112+
exit 1
113+
;;
114+
esac

doc/system_maintenance_manual.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,33 @@ You should change the default password after first login.
105105

106106
You can create some normal users as needed.
107107

108+
109+
### Tool command
110+
111+
We provide a tool script for resetting user passwords and unlocking users in the background.
112+
113+
Unlock user
114+
```bash
115+
bin/tool.sh unlock -u USERNAME
116+
```
117+
118+
Reset password for user
119+
```bash
120+
bin/tool.sh reset_password -u USERNAME
121+
```
122+
123+
Help
124+
```bash
125+
bin/tool.sh help
126+
127+
help: print this help info.
128+
list: list all user.
129+
unlock: unlock user
130+
flag: -u USERNAME
131+
reset_password: reset user's password
132+
flag: -u USERNAME
133+
```
134+
108135
## FAQ
109136
110137
### Why use python

docker/docker-run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ fi
1212
if [[ -f py/venv/bin/activate ]]; then
1313
source py/venv/bin/activate
1414
fi
15-
16-
exec java -jar $(pwd)/jar/veritas-assessment-tool.jar
15+
JVM_OPT='-Dlog4j2.formatMsgNoLookups=true'
16+
exec java ${JVM_OPT} -jar $(pwd)/jar/veritas-assessment-tool.jar

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>org.veritas</groupId>
1212
<artifactId>assessment-tool</artifactId>
13-
<version>1.0.1</version>
13+
<version>1.0.2</version>
1414
<name>assessment</name>
1515
<description>Assessment tool of veritas.</description>
1616
<properties>
@@ -19,6 +19,7 @@
1919
<openhtml.version>1.0.10</openhtml.version>
2020
<springdoc.version>1.5.11</springdoc.version>
2121
<spring-boot.version>2.4.10</spring-boot.version>
22+
<log4j2.version>2.15.0</log4j2.version>
2223

2324
<config.directory>config</config.directory>
2425
</properties>

py/plot.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def plot_calibration(bin_true_prob, bin_pred_prob, zf_name):
6464
ax1.plot(bin_pred_prob, bin_true_prob, "s-", color='#02124D',
6565
label="model")
6666

67-
ax1.set_ylabel("Fraction of loans that resolve", fontsize=14)
67+
ax1.set_ylabel("Fraction of Positives", fontsize=14)
6868
ax1.set_ylim([-0.05, 1.05])
6969
ax1.legend(loc="lower right", fontsize=12)
7070
ax1.set_title('Model Calibration (reliability curve)', fontsize=16)
@@ -78,6 +78,7 @@ def plot_calibration(bin_true_prob, bin_pred_prob, zf_name):
7878

7979
# plot heatmap
8080
def plot_heatmap(corr_values, feature_names, zf_name):
81+
plt.figure(figsize=(9, 8))
8182
ax = sns.heatmap(
8283
corr_values,
8384
vmin=-1, vmax=1, center=0,
@@ -86,7 +87,7 @@ def plot_heatmap(corr_values, feature_names, zf_name):
8687
)
8788
ax.set_xticklabels(
8889
feature_names,
89-
rotation=25,
90+
rotation=45,
9091
horizontalalignment='right'
9192
)
9293
ax.set_yticklabels(
@@ -127,11 +128,11 @@ def plot_weighted_confusion_matrix(values, name1, name2, zf_name):
127128

128129

129130
# Plot contour
130-
def plot_contour(zf_name, key):
131+
def plot_contour(zf_name, key, fair_metric_name, perf_metric_name):
131132
plt.figure(figsize=(9, 8))
132133
# plt.title('Fairness vs. Performance Tradeoffs', fontsize=18)
133-
plt.xlabel('Lending Threshold Privileged', fontsize=16)
134-
plt.ylabel('Lending Threshold Unprivileged', fontsize=16)
134+
plt.xlabel(key+' Threshold Privileged', fontsize=16)
135+
plt.ylabel(key+' Threshold Unprivileged', fontsize=16)
135136
plt.xlim(np.min(th_a), np.max(th_a))
136137
plt.ylim(np.min(th_b), np.max(th_b))
137138

@@ -208,7 +209,7 @@ def plot_contour(zf_name, key):
208209
perf_dynamic = data['perf_dynamic']
209210

210211
# plot weighted_confusion_matrix
211-
plot_weighted_confusion_matrix(weighted_confusion_matrix_list, ['Default', 'Repay'], ['Default', 'Repay'], zf_name)
212+
plot_weighted_confusion_matrix(weighted_confusion_matrix_list, ['Negative', 'Positive'], ['Negative', 'Positive'], zf_name)
212213

213214
# plot class distribution
214215
plot_piechart(class_distribution_list, class_distribution_label, zf_name, '')
@@ -222,6 +223,10 @@ def plot_contour(zf_name, key):
222223
# plot perf dynamic
223224
plot_perf_dynamic(perf_dynamic['threshold'], perf_dynamic['perf'], perf_dynamic['selection_rate'], zf_name)
224225
for key in features_dict:
226+
fair_metric_name = features_dict[key]['tradeoff']['fair_metric_name']
227+
perf_metric_name = features_dict[key]['tradeoff']['perf_metric_name']
228+
fair_metric_name = re.sub('_', ' ', fair_metric_name)
229+
perf_metric_name = re.sub('_', ' ', perf_metric_name)
225230
th_a = features_dict[key]['tradeoff']['th_x']
226231
th_b = features_dict[key]['tradeoff']['th_y']
227232
perf = np.array(features_dict[key]['tradeoff']['perf'])
@@ -235,6 +240,6 @@ def plot_contour(zf_name, key):
235240
# plot feature_distribution
236241
plot_piechart(feature_distribution_list, feature_distribution_label, zf_name, key)
237242
# plot contour
238-
plot_contour(zf_name, key)
243+
plot_contour(zf_name, key, fair_metric_name, perf_metric_name)
239244

240245
print(json.dumps(image_file_list))

src/main/java/org/veritas/assessment/AssessmentApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import org.springframework.boot.autoconfigure.SpringBootApplication;
2222
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2323
import org.springframework.cache.annotation.EnableCaching;
24+
import org.springframework.scheduling.annotation.EnableScheduling;
2425
import org.veritas.assessment.system.config.VeritasProperties;
2526

2627
@SpringBootApplication
2728
@MapperScan(basePackages = {"org.veritas.assessment.system.mapper", "org.veritas.assessment.biz.mapper"})
2829
@EnableCaching
30+
@EnableScheduling
2931
@EnableConfigurationProperties(VeritasProperties.class)
3032
public class AssessmentApplication {
3133

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.veritas.assessment.biz.scheduled;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.apache.commons.io.FileUtils;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.cache.Cache;
7+
import org.springframework.cache.CacheManager;
8+
import org.springframework.scheduling.annotation.Scheduled;
9+
import org.springframework.stereotype.Component;
10+
11+
import java.io.File;
12+
13+
@Component
14+
@Slf4j
15+
public class CacheScheduledTask {
16+
@Autowired
17+
private CacheManager cacheManager;
18+
19+
@Scheduled(fixedRate = 5 * 1000)
20+
public void clearCacheSchedule() {
21+
if (!needCleanCache()) {
22+
return;
23+
}
24+
log.info("clear cache start...");
25+
for (String name : cacheManager.getCacheNames()) {
26+
Cache cache = cacheManager.getCache(name);
27+
if (cache != null) {
28+
cache.clear();
29+
}
30+
}
31+
log.info("clear cache has finished.");
32+
33+
}
34+
35+
private boolean needCleanCache() {
36+
File file = new File("file/db/.clear_cache");
37+
boolean result = file.exists();
38+
if (result) {
39+
FileUtils.deleteQuietly(file);
40+
}
41+
if (log.isTraceEnabled()) {
42+
if (result) {
43+
log.trace("need to clear cache.");
44+
} else {
45+
log.trace("not need to clear cache.");
46+
}
47+
}
48+
return result;
49+
}
50+
}

0 commit comments

Comments
 (0)