<commit_before>package main // probably need to convert this to a proper go test

import (
	"Inf191BloomFilter/bloomDataGenerator"
	"Inf191BloomFilter/databaseAccessObj"
	"flag"
	"fmt"
	"os"
	"strconv"
)

type UserInputs struct {
	command  string
	numUser  int
	minEmail int
	maxEmail int
}

const dsn = "bloom:test@/unsubscribed"
const schema = `(user_id int(11), email varchar(255), ts timestamp default current_timestamp, primary key (user_id, email));`

func checkErr(err error) {
	// check error from database if any
	if err != nil {
		panic(err)
	}
}

// Grabs the command line argments
// and return a Inputs object containinf the
// values. And a nil if no cli atgements were
// given
func getCommandLineInputs() UserInputs {
	cmdPtr := flag.String("cmd", "", "Possible commands: 'repopulate', 'add', 'del', 'mktbls'")
	userPtr := flag.Int("numUser", 1, "Possible inputs: integers > 0")
	minEmailPtr := flag.Int("minEmail", 1, "Possible inputs: integer > 0")
	maxEmailPtr := flag.Int("maxEmail", 2, "Possible inputs: integer > minEmail")
	flag.Parse()
	return UserInputs{*cmdPtr, *userPtr, *minEmailPtr, *maxEmailPtr}
}

// Given the user inputs, clear existing data and repopulate
// the table with new randomly generated data
func handleRepopulate(numUser, minEmail, maxEmail int) {
	dao := databaseAccessObj.New(dsn)
	dao.Clear()
	dataset := bloomDataGenerator.GenData(numUser, minEmail, maxEmail)
	dao.Insert(dataset)
	dao.CloseConnection()
}

func handleAdd(numUser, minEmail, maxEmail int) {
	dao := databaseAccessObj.New(dsn)
	dataset := bloomDataGenerator.GenData(numUser, minEmail, maxEmail)
	dao.Insert(dataset)
	dao.CloseConnection()
}

func handleDel(numUser, minEmail, maxEmail int) {
	dao := databaseAccessObj.New(dsn)
	// change arguments
	// use a int to determines how many rows to delete
	// need dao to return a subset of random useremail pairs
	// delete those from the db (may need a func in dao for that)
	// return the ones deleted?
	dao.CloseConnection()
}

func handleMkTbl() {
	dao := databaseAccessObj.New(dsn)
	for i := 0; i < 15; i++ {
		tablename := "unsub_" + strconv.Itoa(i)
		dao.MkTbl(tablename, schema)
	}
	dao.CloseConnection()
}

func main() {
	userInputs := getCommandLineInputs()
	if userInputs.command == "" {
		fmt.Fprintf(os.Stderr, "Error: cmd cannot be empty.\n")
		flag.PrintDefaults()
	}
	switch userInputs.command {
	case "mktbls":
		handleMkTbl()
		fmt.Println("Done. Created tables in unsubscribed.")
	case "repopulate":
		handleRepopulate(userInputs.numUser, userInputs.minEmail, userInputs.maxEmail)
		fmt.Printf("Done. \n")
	case "add":
		handleAdd(userInputs.numUser, userInputs.minEmail, userInputs.maxEmail)
		fmt.Printf("Done. \n")
	case "del":
		handleDel(userInputs.numUser, userInputs.minEmail, userInputs.maxEmail)
		fmt.Printf("Done. \n")
	default:
		fmt.Fprintf(os.Stderr, "Error: invalid command.\n")
		flag.PrintDefaults()
	}
}<commit_msg>Updated updateDatabase.go<commit_after>package main // probably need to convert this to a proper go test

import (
	"Inf191BloomFilter/bloomDataGenerator"
	"Inf191BloomFilter/databaseAccessObj"
	"flag"
	"fmt"
	"os"
	"strconv"
)

type UserInputs struct {
	command  string
	numUser  int
	minEmail int
	maxEmail int
}

const dsn = "bloom:test@/unsubscribed"
const schema = `(user_id int(11), email varchar(255), ts timestamp default current_timestamp, primary key (user_id, email));`

func checkErr(err error) {
	// check error from database if any
	if err != nil {
		panic(err)
	}
}

// Grabs the command line argments
// and return a Inputs object containinf the
// values. And a nil if no cli atgements were
// given
func getCommandLineInputs() UserInputs {
	cmdPtr := flag.String("cmd", "", `
	Possible commands: 
	mktbls: Create 15 tables named unsub 0 - 14 in unsubscribed
		(no arguments needed) 
	repopulate: Clear all current values in tables and repopulates it 
		(can optionally specify number of users, mininum and maximum emails per user)
	add: Create new dataset and add it to the database
		(can optionally specify number of users, mininum and maximum emails per user)
	`)
	userPtr := flag.Int("numUser", 1, "Possible inputs: integers > 0")
	minEmailPtr := flag.Int("minEmail", 1, "Possible inputs: integer > 0")
	maxEmailPtr := flag.Int("maxEmail", 2, "Possible inputs: integer > minEmail")
	flag.Parse()
	return UserInputs{*cmdPtr, *userPtr, *minEmailPtr, *maxEmailPtr}
}

// Given the user inputs, clear existing data and repopulate
// the table with new randomly generated data
func handleRepopulate(numUser, minEmail, maxEmail int) {
	dao := databaseAccessObj.New(dsn)
	dao.Clear()
	dataset := bloomDataGenerator.GenData(numUser, minEmail, maxEmail)
	dao.Insert(dataset)
	dao.CloseConnection()
}

func handleAdd(numUser, minEmail, maxEmail int) {
	dao := databaseAccessObj.New(dsn)
	dataset := bloomDataGenerator.GenData(numUser, minEmail, maxEmail)
	dao.Insert(dataset)
	dao.CloseConnection()
}

func handleMkTbl() {
	dao := databaseAccessObj.New(dsn)
	for i := 0; i < 15; i++ {
		tablename := "unsub_" + strconv.Itoa(i)
		dao.MkTbl(tablename, schema)
	}
	dao.CloseConnection()
}

func main() {
	userInputs := getCommandLineInputs()
	if userInputs.command == "" {
		fmt.Fprintf(os.Stderr, "Error: cmd cannot be empty.\n")
		flag.PrintDefaults()
	} else {
		switch userInputs.command {
		case "mktbls":
			handleMkTbl()
			fmt.Println("Done. Created tables in unsubscribed.")
		case "repopulate":
			handleRepopulate(userInputs.numUser, userInputs.minEmail, userInputs.maxEmail)
			fmt.Printf("Done. \n")
		case "add":
			handleAdd(userInputs.numUser, userInputs.minEmail, userInputs.maxEmail)
			fmt.Printf("Done. \n")
		default:
			fmt.Fprintf(os.Stderr, "Error: invalid command.\n")
			flag.PrintDefaults()
		}
	}
}
{'fraction_non_alphanumeric': 0.12182387747998608, 'fraction_numerical': 0.007483466759484859, 'mean_word_length': 4.617790811339199, 'pattern_counts': {'":': 7, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7373896', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1986, 'n_words': 555}