Skip to content

Commit 6bdaf7b

Browse files
committed
Fixed a bug that caused a crash if the PersistentData folder didn't exist at startup. Added a hardcoded endpoint for EQI when using any method other than EnVisen's.
1 parent 8908dd7 commit 6bdaf7b

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/Eqi.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"github.com/polyverse/ropoly/lib/eqi"
66
"github.com/polyverse/ropoly/lib/types"
7+
"math"
78
"net/url"
89
)
910

@@ -12,6 +13,8 @@ func DirectEqi(f1 types.Fingerprint, f2 types.Fingerprint, eqiFunc string, form
1213
return eqi.OriginalEnvisenEqi(f1, f2), nil
1314
}
1415

16+
normalized := form.Get("normalized") == "true"
17+
1518
function := directEqiFuncs[eqiFunc]
1619
if function == nil {
1720
return types.EntropyQualityIndex(0), errors.New("EQI function not recognized.")
@@ -21,7 +24,7 @@ func DirectEqi(f1 types.Fingerprint, f2 types.Fingerprint, eqiFunc string, form
2124
if err != nil {
2225
return types.EntropyQualityIndex(0), err
2326
}
24-
return normalizeEqi(eqi), nil
27+
return normalizeEqi(eqi, eqiFunc, normalized), nil
2528
}
2629

2730
type directEqiFunc func(types.Fingerprint, types.Fingerprint, url.Values) (float64, error)
@@ -33,6 +36,10 @@ var directEqiFuncs = map[string]directEqiFunc {
3336
"highest-offset-count": eqi.HighestOffsetCountEqi,
3437
}
3538

36-
func normalizeEqi(eqi float64) types.EntropyQualityIndex {
37-
return types.EntropyQualityIndex(100.0 * (1.0 - eqi))
39+
func normalizeEqi(eqi float64, eqiFunc string, normalized bool) types.EntropyQualityIndex {
40+
ret := 100.0 * (1.0 - eqi)
41+
if normalized {
42+
ret = 1.7626080809865 * (math.Pow(1.04139221012755, ret) - 1)
43+
}
44+
return types.EntropyQualityIndex(ret)
3845
}

lib/Filepaths.go

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func EnsureDirectory(path string) error {
1818

1919
// https://stackoverflow.com/questions/10510691/how-to-check-whether-a-file-or-directory-exists/10510718
2020
func Exists(path string) (bool, error) {
21+
if path == "" {
22+
return true, nil
23+
}
2124
_, err := os.Stat(path)
2225
if err == nil {
2326
return true, nil
@@ -52,6 +55,9 @@ func windDirectoryStack(stack *[]string) error {
5255
}
5356
if !exists {
5457
lastSlashIndex := strings.LastIndex(peek(stack), "/")
58+
if lastSlashIndex == -1 {
59+
lastSlashIndex = 0
60+
}
5561
push(stack, peek(stack)[:lastSlashIndex])
5662
}
5763
}

0 commit comments

Comments
 (0)