summaryrefslogtreecommitdiff
path: root/flow-cleaner.go
diff options
context:
space:
mode:
Diffstat (limited to 'flow-cleaner.go')
-rw-r--r--flow-cleaner.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/flow-cleaner.go b/flow-cleaner.go
index e840c41..f40f1c3 100644
--- a/flow-cleaner.go
+++ b/flow-cleaner.go
@@ -4,21 +4,22 @@ import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"log"
+ "os"
"time"
)
var (
- logger *log.Logger
+ flogger *log.Logger
)
func init() {
- logger = log.New(os.Stdout, "[ Main ]", log.LstdFlags)
+ flogger = log.New(os.Stdout, "[ Flow-cleaner ]", log.LstdFlags)
}
func main() {
cfg, err := readConfig()
if err != nil {
- logger.Println("Could not read config")
+ flogger.Println("Could not read config")
return
}
@@ -28,52 +29,52 @@ func main() {
case "mysq":
processFromDB(cfg)
default:
- logger.Println("Invalid dataSource in config. Needs to be either 'stdin' or 'mysql'.")
+ flogger.Println("Invalid dataSource in config. Needs to be either 'stdin' or 'mysql'.")
}
- logger.Println("Finished processing, now exiting")
+ flogger.Println("Finished processing, now exiting")
}
func processFromStdin(cfg *Config) {
- logger.Println("Starting to process from stdin...")
+ flogger.Println("Starting to process from stdin...")
input := readFromStdin()
rDatChan := parseRawData(input, cfg)
cleanFromStdin(rDatChan, cfg)
- logger.Println("Finished processing from stdin!")
+ flogger.Println("Finished processing from stdin!")
}
func processFromDB(cfg *Config) {
- logger.Print("Starting to process from db...")
+ flogger.Print("Starting to process from db...")
starttime := time.Now()
numOfRowsNotCleaned, err := cleanFromDB(cfg)
if err != nil {
- logger.Println(err)
- logger.Println("Exiting...")
+ flogger.Println(err)
+ flogger.Println("Exiting...")
return
}
- logger.Println("Finished processing from db!")
+ flogger.Println("Finished processing from db!")
// If either all rows are processed or if there is no limit for the processing
// we can safely add noise to the cleaned data
if (numOfRowsNotCleaned == 0 || cfg.Limit == 0) && cfg.Epsilon >= 0 {
- logger.Println("Adding differential privacy noise to processed data...")
+ flogger.Println("Adding differential privacy noise to processed data...")
db, err := sql.Open("mysql", cfg.DBUser+":"+cfg.DBPass+"@"+cfg.DBConn+"/"+cfg.DBName)
if err != nil {
- logger.Println("Failed to connect to db:", err)
+ flogger.Println("Failed to connect to db:", err)
return
}
defer db.Close()
ival, err := cfg.getInterval()
if err != nil {
- logger.Println("erronous interval in conf prevents the privatization of data:", err)
+ flogger.Println("erronous interval in conf prevents the privatization of data:", err)
return
}
err = privatizeCleaned(db, starttime.Add(-2*ival), cfg)
if err != nil {
- logger.Println("Failed to privatize data:", err)
+ flogger.Println("Failed to privatize data:", err)
}
- logger.Println("Done!")
+ flogger.Println("Done!")
}
}