Skip to content

Commit b7cd7d0

Browse files
Merge pull request #19 from Ashrockzzz2003/main
Use the 'name' field to represent population and generation for frontend to use 1 api call.
2 parents 36ab900 + 998bacd commit b7cd7d0

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

controller/ea.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"os"
11-
"time"
1211
)
1312

1413
func CreateEA(res http.ResponseWriter, req *http.Request) {
@@ -50,11 +49,18 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {
5049
return
5150
}
5251

52+
var description string
53+
if ea.Algorithm == "de" {
54+
description = "Differential Evolution (DE)"
55+
} else {
56+
description = "Evolutionary Algorithm (EA)"
57+
}
58+
5359
row := db.QueryRow(req.Context(), `
5460
INSERT INTO run (name, description, type, command, createdBy)
5561
VALUES ($1, $2, $3, $4, $5)
5662
RETURNING id
57-
`, time.Now().Local().String(), "Traditional EA Without GP", "ea", "python -m scoop code.py", user["id"])
63+
`, fmt.Sprintf("%d-%d", ea.Generations, ea.PopulationSize), description, "ea", "python -m scoop code.py", user["id"])
5864

5965
var runID string
6066
err = row.Scan(&runID)
@@ -126,6 +132,7 @@ func CreateEA(res http.ResponseWriter, req *http.Request) {
126132
return
127133
}
128134

135+
data["runID"] = runID
129136
util.JSONResponse(res, http.StatusOK, "It works! 👍🏻", data)
130137

131138
}

controller/gp.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"os"
11-
"time"
1211
)
1312

1413
func CreateGP(res http.ResponseWriter, req *http.Request) {
@@ -31,13 +30,13 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {
3130
return
3231
}
3332

34-
ea, err := modules.GPFromJSON(data)
33+
gp, err := modules.GPFromJSON(data)
3534
if err != nil {
3635
util.JSONResponse(res, http.StatusBadRequest, err.Error(), nil)
3736
return
3837
}
3938

40-
code, err := ea.Code()
39+
code, err := gp.Code()
4140
if err != nil {
4241
util.JSONResponse(res, http.StatusBadRequest, err.Error(), nil)
4342
return
@@ -54,7 +53,7 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {
5453
INSERT INTO run (name, description, type, command, createdBy)
5554
VALUES ($1, $2, $3, $4, $5)
5655
RETURNING id
57-
`, time.Now().Local().String(), "Genetic Programming (GP)", "gp", "python -m scoop code.py", user["id"])
56+
`, fmt.Sprintf("%d-%d", gp.Generations, gp.PopulationSize), "Genetic Programming (GP)", "gp", "python -m scoop code.py", user["id"])
5857

5958
var runID string
6059
err = row.Scan(&runID)
@@ -126,5 +125,6 @@ func CreateGP(res http.ResponseWriter, req *http.Request) {
126125
return
127126
}
128127

128+
data["runID"] = runID
129129
util.JSONResponse(res, http.StatusOK, "It works! 👍🏻", data)
130130
}

controller/ml.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"os"
11-
"time"
1211
)
1312

1413
func CreateML(res http.ResponseWriter, req *http.Request) {
@@ -54,7 +53,7 @@ func CreateML(res http.ResponseWriter, req *http.Request) {
5453
INSERT INTO run (name, description, type, command, createdBy)
5554
VALUES ($1, $2, $3, $4, $5)
5655
RETURNING id
57-
`, time.Now().Local().String(), "Optimize ML with EA", "ml", "python -m scoop code.py", user["id"])
56+
`, fmt.Sprintf("%d-%d", ml.Generations, ml.PopulationSize), "Optimize ML with EA", "ml", "python -m scoop code.py", user["id"])
5857

5958
var runID string
6059
err = row.Scan(&runID)
@@ -126,5 +125,6 @@ func CreateML(res http.ResponseWriter, req *http.Request) {
126125
return
127126
}
128127

128+
data["runID"] = runID
129129
util.JSONResponse(res, http.StatusOK, "It works! 👍🏻", data)
130130
}

controller/pso.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"os"
11-
"time"
1211
)
1312

1413
func CreatePSO(res http.ResponseWriter, req *http.Request) {
@@ -54,7 +53,7 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {
5453
INSERT INTO run (name, description, type, command, createdBy)
5554
VALUES ($1, $2, $3, $4, $5)
5655
RETURNING id
57-
`, time.Now().Local().String(), "Particle Swarm Optimization", "pso", "python code.py", user["id"])
56+
`, fmt.Sprintf("%d-%d", pso.Generations, pso.PopulationSize), "Particle Swarm Optimization", "pso", "python code.py", user["id"])
5857

5958
var runID string
6059
err = row.Scan(&runID)
@@ -126,5 +125,6 @@ func CreatePSO(res http.ResponseWriter, req *http.Request) {
126125
return
127126
}
128127

128+
data["runID"] = runID
129129
util.JSONResponse(res, http.StatusOK, "It works! 👍🏻", data)
130130
}

0 commit comments

Comments
 (0)