about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-02-12 23:15:19 +0100
committerEmile <hanemile@protonmail.com>2019-02-12 23:15:19 +0100
commitee709e790d5866b3f5d5ef70b015729c522e63a6 (patch)
treeedaa50050aad9fe193dfb521029a0682d4986674
parent10366e331346dbcce6c9e0fe8651f0dfe9743a8f (diff)
finally finished implementing the updateCenterOfMass handler and because that was so much fun, I also implemented the genForestTreeHandler ...
-rwxr-xr-xinsertcsv.sh2
-rwxr-xr-xinsertdouble.sh6
-rw-r--r--main.go32
3 files changed, 35 insertions, 5 deletions
diff --git a/insertcsv.sh b/insertcsv.sh
index f42c953..8a4fd38 100755
--- a/insertcsv.sh
+++ b/insertcsv.sh
@@ -1,4 +1,4 @@
 curl -X POST http://localhost:8081/deleteStars 
 curl -X POST http://localhost:8081/deleteNodes 
 curl -X POST --data "w=1000" http://localhost:8081/new
-curl -X POST --data "filename=200000.csv" http://localhost:8081/insertList
+curl -X POST --data "filename=100.csv" http://localhost:8081/insertList
diff --git a/insertdouble.sh b/insertdouble.sh
index 0d31f96..843950f 100755
--- a/insertdouble.sh
+++ b/insertdouble.sh
@@ -2,8 +2,8 @@
 curl -X POST http://localhost:8081/deleteStars
 curl -X POST http://localhost:8081/deleteNodes 
 curl -X POST --data "w=1000" http://localhost:8081/new
-curl -X POST --data "x=300&y=300&vx=0.1&vy=0.3&m=100&index=1" http://localhost:8081/insertStar
-curl -X POST --data "x=200&y=200&vx=0.1&vy=0.3&m=100&index=1" http://localhost:8081/insertStar
-curl -X POST --data "x=400&y=400&vx=0.1&vy=0.3&m=100&index=1" http://localhost:8081/insertStar
+curl -X POST --data "x=300&y=300&vx=0.1&vy=0.3&m=1&index=1" http://localhost:8081/insertStar
+curl -X POST --data "x=200&y=200&vx=0.1&vy=0.3&m=2&index=1" http://localhost:8081/insertStar
+curl -X POST --data "x=400&y=400&vx=0.1&vy=0.3&m=4&index=1" http://localhost:8081/insertStar
 curl -X GET http://localhost:8081/starlist/go
 curl -X GET http://localhost:8081/starlist/csv
diff --git a/main.go b/main.go
index 37586a6..07fbc36 100644
--- a/main.go
+++ b/main.go
@@ -147,6 +147,34 @@ func updateTotalMassHandler(w http.ResponseWriter, r *http.Request) {
 	updateTotalMassEndpoint(index)
 }
 
+func updateCenterOfMassHandler(w http.ResponseWriter, r *http.Request) {
+	log.Println("[ ] The updateCenterOfMassHandler was accessed")
+
+	// get the star by parsing http-post parameters
+	errParseForm := r.ParseForm() // parse the POST form
+	if errParseForm != nil {      // handle errors
+		panic(errParseForm)
+	}
+
+	// get the tree into which the star should be inserted into
+	index, _ := strconv.ParseInt(r.Form.Get("index"), 10, 64)
+
+	updateCenterOfMassEndpoint(index)
+}
+
+func genForestTreeHandler(w http.ResponseWriter, r *http.Request) {
+	log.Println("[ ] The genForestTreeHandler was accessed")
+
+	vars := mux.Vars(r)
+	treeindex, parseIntErr := strconv.ParseInt(vars["treeindex"], 10, 64)
+	if parseIntErr != nil {
+		panic(parseIntErr)
+	}
+
+	tree := genForestTreeEndpoint(treeindex)
+	_, _ = fmt.Fprintf(w, "%s", tree)
+}
+
 func main() {
 	router := mux.NewRouter()
 
@@ -161,8 +189,10 @@ func main() {
 	router.HandleFunc("/insertList", insertListHandler).Methods("POST")
 
 	router.HandleFunc("/updatetotalmass", updateTotalMassHandler).Methods("POST")
+	router.HandleFunc("/updatecenterofmass", updateCenterOfMassHandler).Methods("POST")
+
+	router.HandleFunc("/genforesttree/{treeindex}", genForestTreeHandler).Methods("GET")
 
-	//router.HandleFunc("/updatecenterofmass/{treeindex}", updateCenterOfMassHandler).Methods("GET")
 	//router.HandleFunc("/metrics", metricHandler).Methods("GET")
 	//router.HandleFunc("/export/{treeindex}", exportHandler).Methods("POST")
 	//router.HandleFunc("/nrofgalaxies", nrofgalaxiesHandler).Methods("GET")