Fix 0 weights

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

View File

@ -196,10 +196,12 @@ 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)
return
}
if yearWeight > 0 {
weight.Year = uint32(yearWeight)
totalSum += yearWeight
features = append(features, "year")
}
}
if ratingWeightQ != "" {
ratingWeight, err := strconv.Atoi(ratingWeightQ)
if err != nil {
@ -210,10 +212,12 @@ 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)
return
}
if ratingWeight > 0 {
weight.Rating = uint32(ratingWeight)
totalSum += ratingWeight
features = append(features, "rating")
}
}
if genresWeightQ != "" {
genresWeight, err := strconv.Atoi(genresWeightQ)
if err != nil {
@ -224,10 +228,12 @@ 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)
return
}
if genresWeight > 0 {
weight.Genres = uint32(genresWeight)
totalSum += genresWeight
features = append(features, "genres")
}
}
if nconstsWeightQ != "" {
nconstsWeight, err := strconv.Atoi(nconstsWeightQ)
if err != nil {
@ -238,10 +244,12 @@ 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)
return
}
if nconstsWeight > 0 {
weight.Nconsts = uint32(nconstsWeight)
totalSum += nconstsWeight
features = append(features, "nconsts")
}
}
featuresLen := len(features)
if featuresLen < 1 {