Fix 0 weights

This commit is contained in:
2024-11-06 04:04:29 +04:00
parent d8449237bb
commit 62346bd3d4

View File

@@ -196,9 +196,11 @@ func (h *IMDbHandler) HandlerGetRecommendations(w http.ResponseWriter, r *http.R
RespondWithJSON(w, ErrorResponse{Error: "year_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest) RespondWithJSON(w, ErrorResponse{Error: "year_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest)
return return
} }
weight.Year = uint32(yearWeight) if yearWeight > 0 {
totalSum += yearWeight weight.Year = uint32(yearWeight)
features = append(features, "year") totalSum += yearWeight
features = append(features, "year")
}
} }
if ratingWeightQ != "" { if ratingWeightQ != "" {
ratingWeight, err := strconv.Atoi(ratingWeightQ) ratingWeight, err := strconv.Atoi(ratingWeightQ)
@@ -210,9 +212,11 @@ func (h *IMDbHandler) HandlerGetRecommendations(w http.ResponseWriter, r *http.R
RespondWithJSON(w, ErrorResponse{Error: "rating_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest) RespondWithJSON(w, ErrorResponse{Error: "rating_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest)
return return
} }
weight.Rating = uint32(ratingWeight) if ratingWeight > 0 {
totalSum += ratingWeight weight.Rating = uint32(ratingWeight)
features = append(features, "rating") totalSum += ratingWeight
features = append(features, "rating")
}
} }
if genresWeightQ != "" { if genresWeightQ != "" {
genresWeight, err := strconv.Atoi(genresWeightQ) genresWeight, err := strconv.Atoi(genresWeightQ)
@@ -224,9 +228,11 @@ func (h *IMDbHandler) HandlerGetRecommendations(w http.ResponseWriter, r *http.R
RespondWithJSON(w, ErrorResponse{Error: "genres_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest) RespondWithJSON(w, ErrorResponse{Error: "genres_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest)
return return
} }
weight.Genres = uint32(genresWeight) if genresWeight > 0 {
totalSum += genresWeight weight.Genres = uint32(genresWeight)
features = append(features, "genres") totalSum += genresWeight
features = append(features, "genres")
}
} }
if nconstsWeightQ != "" { if nconstsWeightQ != "" {
nconstsWeight, err := strconv.Atoi(nconstsWeightQ) nconstsWeight, err := strconv.Atoi(nconstsWeightQ)
@@ -238,9 +244,11 @@ func (h *IMDbHandler) HandlerGetRecommendations(w http.ResponseWriter, r *http.R
RespondWithJSON(w, ErrorResponse{Error: "nconsts_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest) RespondWithJSON(w, ErrorResponse{Error: "nconsts_weight should be greater than or equal to 0 and less than or equal to 400"}, http.StatusBadRequest)
return return
} }
weight.Nconsts = uint32(nconstsWeight) if nconstsWeight > 0 {
totalSum += nconstsWeight weight.Nconsts = uint32(nconstsWeight)
features = append(features, "nconsts") totalSum += nconstsWeight
features = append(features, "nconsts")
}
} }
featuresLen := len(features) featuresLen := len(features)