diff options
author | hanemile <hanemile@protonmail.com> | 2019-01-23 20:25:44 +0100 |
---|---|---|
committer | hanemile <hanemile@protonmail.com> | 2019-01-23 20:25:44 +0100 |
commit | 48451fa85af62d28bfb9257ae8c2b05cecea80fe (patch) | |
tree | 907650e33b02281f0d926ec1e696a4bbe39c93b8 /import.go | |
parent | e1ec6a26489b311ca5368fd227b527e6591882ee (diff) |
push before using everything in docker swarm
Diffstat (limited to 'import.go')
-rw-r--r-- | import.go | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/import.go b/import.go index c52090f..c3c1e96 100644 --- a/import.go +++ b/import.go @@ -1,24 +1,29 @@ package main import ( + "encoding/csv" "encoding/json" "fmt" + "io" "io/ioutil" + "log" "net/http" + "strconv" + "strings" "github.com/gorilla/mux" "git.darknebu.la/GalaxySimulator/structs" ) -// fastInsertHandler gets a tree index and a filename and tries to read -func fastInsertHandler(w http.ResponseWriter, r *http.Request) { +// fastInsertHandler gets a tree index and a filename and tries to read insert all the stars from the file into the tree +func fastInsertJSONHandler(w http.ResponseWriter, r *http.Request) { // read the mux variables vars := mux.Vars(r) filename, _ := vars["filename"] // read the content using the given filename - content, readErr := ioutil.ReadFile(filename) + content, readErr := ioutil.ReadFile(fmt.Sprintf("/db/%s", filename)) if readErr != nil { panic(readErr) } @@ -36,3 +41,54 @@ func fastInsertHandler(w http.ResponseWriter, r *http.Request) { // return the treeArray index the tree was inserted into (== the length of the array) _, _ = fmt.Fprintln(w, len(treeArray)) } + +func fastInsertListHandler(w http.ResponseWriter, r *http.Request) { + // read the mux variables + vars := mux.Vars(r) + filename, _ := vars["filename"] + treeindex, _ := strconv.ParseInt(vars["filename"], 10, 64) + + // read the content using the given filename + content, readErr := ioutil.ReadFile(fmt.Sprintf("/home/db/%s", filename)) + if readErr != nil { + panic(readErr) + } + + in := string(content) + reader := csv.NewReader(strings.NewReader(in)) + + for { + record, err := reader.Read() + if err == io.EOF { + break + } + if err != nil { + log.Println("------------------------") + log.Println("error:") + log.Println(record) + log.Println(err) + log.Println("------------------------") + } + fmt.Println(record) + + x, _ := strconv.ParseFloat(record[0], 64) + y, _ := strconv.ParseFloat(record[1], 64) + + fmt.Println("___________________") + fmt.Println(record[1]) + fmt.Println(y) + fmt.Println("___________________") + + star := structs.NewStar2D(structs.Vec2{x, y}, structs.Vec2{0, 0}, 42) + + fmt.Printf("Star: %v", star) + + err = treeArray[treeindex].Insert(star) + if err != nil { + log.Println(err) + errorCount[treeindex] += 1 + } + fmt.Printf("Inserted %v\n", star) + starCount[treeindex] += 1 + } +} |