summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorDaniel Langesten <daniel.langest@gmail.com>2015-03-19 10:13:26 +0100
committerDaniel Langesten <daniel.langest@gmail.com>2015-03-19 10:13:26 +0100
commit69c12c7cbf4f35074c8daa32cdd6a6281a67eb0f (patch)
treee4edfda748152490deafe88ad405a72e41a2d4ae /main.go
parenta408114f881add945fc74b1bc98e173a8912f772 (diff)
renamed main
Diffstat (limited to 'main.go')
-rw-r--r--main.go78
1 files changed, 0 insertions, 78 deletions
diff --git a/main.go b/main.go
deleted file mode 100644
index 71c1196..0000000
--- a/main.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package main
-
-import (
- "database/sql"
- _ "github.com/go-sql-driver/mysql"
- "log"
- "time"
-)
-
-var (
- logger *log.Logger
-)
-
-func init() {
- logger = log.New(os.Stdout, "[ Main ]", log.LstdFlags)
-}
-
-func main() {
- cfg, err := readConfig()
- if err != nil {
- logger.Println("Could not read config")
- return
- }
-
- switch cfg.DataSource {
- case "stdin":
- processFromStdin(cfg)
- case "mysq":
- processFromDB(cfg)
- default:
- logger.Println("Invalid dataSource in config. Needs to be either 'stdin' or 'mysql'.")
- }
-
- logger.Println("Finished processing, now exiting")
-}
-
-func processFromStdin(cfg *Config) {
- logger.Println("Starting to process from stdin...")
- input := readFromStdin()
- rDatChan := parseRawData(input, cfg)
- cleanFromStdin(rDatChan, cfg)
-}
-
-func processFromDB(cfg *Config) {
- logger.Print("Cleaning data...")
- starttime := time.Now()
- numOfRowsNotCleaned, err := cleanFromDB(cfg)
- if err != nil {
- logger.Println(err)
- logger.Println("Exiting...")
- return
- }
- logger.Println("Done!")
-
- // 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...")
- db, err := sql.Open("mysql", cfg.DBUser+":"+cfg.DBPass+"@"+cfg.DBConn+"/"+cfg.DBName)
- if err != nil {
- logger.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)
- return
- }
-
- err = privatizeCleaned(db, starttime.Add(-2*ival), cfg)
- if err != nil {
- logger.Println("Failed to privatize data:", err)
- }
- logger.Println("Done!")
- }
-}