Преглед на файлове

Correct a few bugs and round wind to 0.1 to ensure 0.1 multiples.

Aurelien преди 5 години
родител
ревизия
724afcf7c1
променени са 1 файла, в които са добавени 20 реда и са изтрити 13 реда
  1. 20 13
      spoptim/production_planner.go

+ 20 - 13
spoptim/production_planner.go

@@ -38,7 +38,7 @@ func ProductionPlanner(payload *models.Payload) []interface{} {
 	wind, _ := fuels["wind(%)"].(json.Number).Float64()
 	for _, plant := range payload.Powerplants {
 		if *plant.Type == "windturbine" {
-			*plant.Pmax = *plant.Pmax * wind / 100
+			*plant.Pmax = math.Round(*plant.Pmax * wind / 10) / 10
 		}
 	}
 	fuels["wind(%)"] = json.Number(0)
@@ -64,17 +64,24 @@ func ProductionPlanner(payload *models.Payload) []interface{} {
 		}
 		fuel, _ := fuels[powerplantFuel[*plant.Type]].(json.Number).Float64()
 		if *plant.Pmin < remainingLoad {
-			usedP := math.Min(remainingLoad, *plant.Pmax)
-			load += usedP
-			cost = append(cost, usedP / *plant.Efficiency * fuel)
-			res = append(res, map[string]interface{}{
-					"name": plant.Name,
-					"p": usedP,
-			})
+			if *plant.Pmax != 0 {
+				usedP := math.Min(remainingLoad, *plant.Pmax)
+				load += usedP
+				cost = append(cost, usedP / *plant.Efficiency * fuel)
+				res = append(res, map[string]interface{}{
+						"name": plant.Name,
+						"p": usedP,
+				})
+			}
 		} else {
-			altRes := make([]interface{}, 0)
-			altCost := make([]float64, 0)
-			copy(altRes, res)
+			altRes := make([]interface{}, len(res))
+			for i, re := range res {
+				altRes[i] = map[string]interface{}{
+					"name": re.(map[string]interface{})["name"],
+					"p": re.(map[string]interface{})["p"],
+				}
+			}
+			altCost := make([]float64, len(cost))
 			copy(altCost, cost)
 			loadToRemove := *plant.Pmin - remainingLoad
 			for loadToRemove > 0 {
@@ -90,9 +97,9 @@ func ProductionPlanner(payload *models.Payload) []interface{} {
 			}
 			altRes = append(altRes, map[string]interface{}{
 					"name": *plant.Name,
-					"p": *plant.Pmax,
+					"p": *plant.Pmin,
 			})
-			altCost = append(altCost, *plant.Pmax / *plant.Efficiency * fuel)
+			altCost = append(altCost, *plant.Pmin / *plant.Efficiency * fuel)
 			resToCompare = append(resToCompare, altRes)
 			costToCompare = append(costToCompare, altCost)
 		}