Skip to content

Commit

Permalink
feat: handling all quasi identifer error
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao-Ma5566 committed Apr 24, 2024
1 parent 3776cb0 commit f62b758
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
24 changes: 17 additions & 7 deletions pkg/sigo/anonymizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package sigo

import (
"fmt"
"os"

"github.com/cgi-fr/jsonline/pkg/cast"
Expand Down Expand Up @@ -206,7 +205,12 @@ func (a CodingAnonymizer) Anonymize(rec Record, clus Cluster, qi, s []string) Re
bottom := q.Q1
top := q.Q3

recVals, _ := rec.QuasiIdentifer()
recVals, err := rec.QuasiIdentifer()
if err != nil {
log.Err(err).Msg("Cannot cast quasi-identifier to float64")
log.Warn().Int("return", 1).Msg("End SIGO")
os.Exit(1)
}

val := recVals[i]

Expand All @@ -233,9 +237,9 @@ func (a NoiseAnonymizer) Anonymize(rec Record, clus Cluster, qi, s []string) Rec
for i, key := range qi {
recVals, err := rec.QuasiIdentifer()
if err != nil {
fmt.Println(err)

break
log.Err(err).Msg("Cannot cast quasi-identifier to float64")
log.Warn().Int("return", 1).Msg("End SIGO")
os.Exit(1)
}

val := recVals[i]
Expand Down Expand Up @@ -465,8 +469,14 @@ func listValues(clus Cluster, qi []string) (mapValues map[string][]float64) {

for _, record := range clus.Records() {
for i, key := range qi {
vals, _ := record.QuasiIdentifer()
val := vals[i]
recVals, err := record.QuasiIdentifer()
if err != nil {
log.Err(err).Msg("Cannot cast quasi-identifier to float64")
log.Warn().Int("return", 1).Msg("End SIGO")
os.Exit(1)
}

val := recVals[i]
mapValues[key] = append(mapValues[key], val)
}
}
Expand Down
9 changes: 8 additions & 1 deletion pkg/sigo/kdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package sigo
import (
"fmt"
"math"
"os"
"sort"
"strings"

Expand Down Expand Up @@ -257,7 +258,13 @@ func (n *node) string(offset int) string {

for _, rec := range n.cluster {
// result += fmt.Sprintf("%v ", rec.QuasiIdentifer()[n.rot])
recValue, _ := rec.QuasiIdentifer()
recValue, err := rec.QuasiIdentifer()
if err != nil {
log.Err(err).Msg("Cannot cast quasi-identifier to float64 in node")
log.Warn().Int("return", 1).Msg("End SIGO")
os.Exit(1)
}

result += fmt.Sprintf("%v ", recValue)
}

Expand Down

0 comments on commit f62b758

Please sign in to comment.