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