From 30ee13b7ac72835e4cd8971d68acff2e0719c61c Mon Sep 17 00:00:00 2001 From: Shwetas Dhake Date: Fri, 7 Aug 2026 14:56:32 +0530 Subject: [PATCH] Remove unregistered Elo update endpoint --- backend/controllers/profile_controller.go | 68 ----------------------- backend/routes/profile.go | 4 -- 2 files changed, 72 deletions(-) diff --git a/backend/controllers/profile_controller.go b/backend/controllers/profile_controller.go index 489261a1..471d5b94 100644 --- a/backend/controllers/profile_controller.go +++ b/backend/controllers/profile_controller.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "log" - "math" "net/http" "net/url" "strings" @@ -19,18 +18,6 @@ import ( "go.mongodb.org/mongo-driver/mongo/options" ) -// Calculate new Elo ratings using float64 -func calculateEloRating(ratingA, ratingB float64, scoreA float64) (newRatingA, newRatingB float64) { - const K = 32.0 - expectedA := 1.0 / (1.0 + math.Pow(10, (ratingB-ratingA)/400.0)) - expectedB := 1.0 - expectedA - scoreB := 1.0 - scoreA - - newRatingA = ratingA + K*(scoreA-expectedA) - newRatingB = ratingB + K*(scoreB-expectedB) - return newRatingA, newRatingB -} - func extractNameFromEmail(email string) string { for i, char := range email { if char == '@' { @@ -348,58 +335,3 @@ func UpdateProfile(ctx *gin.Context) { } ctx.JSON(http.StatusOK, gin.H{"message": "Profile updated successfully"}) } - -func UpdateEloAfterDebate(ctx *gin.Context) { - var req struct { - WinnerID string `json:"winnerId"` - LoserID string `json:"loserId"` - Topic string `json:"topic"` - } - if err := ctx.ShouldBindJSON(&req); err != nil { - ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"}) - return - } - - dbCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - winnerID, _ := primitive.ObjectIDFromHex(req.WinnerID) - loserID, _ := primitive.ObjectIDFromHex(req.LoserID) - - var winner, loser models.User - _ = db.MongoDatabase.Collection("users").FindOne(dbCtx, bson.M{"_id": winnerID}).Decode(&winner) - _ = db.MongoDatabase.Collection("users").FindOne(dbCtx, bson.M{"_id": loserID}).Decode(&loser) - - newWinnerElo, newLoserElo := calculateEloRating(winner.Rating, loser.Rating, 1.0) - - winnerChange := newWinnerElo - winner.Rating - loserChange := newLoserElo - loser.Rating - - // Update users - db.MongoDatabase.Collection("users").UpdateOne(dbCtx, bson.M{"_id": winnerID}, bson.M{"$set": bson.M{"rating": newWinnerElo}}) - db.MongoDatabase.Collection("users").UpdateOne(dbCtx, bson.M{"_id": loserID}, bson.M{"$set": bson.M{"rating": newLoserElo}}) - - // Log debates - now := time.Now() - db.MongoDatabase.Collection("debates").InsertOne(dbCtx, bson.M{ - "email": winner.Email, - "topic": req.Topic, - "result": "win", - "eloChange": winnerChange, - "rating": newWinnerElo, - "date": now, - }) - db.MongoDatabase.Collection("debates").InsertOne(dbCtx, bson.M{ - "email": loser.Email, - "topic": req.Topic, - "result": "loss", - "eloChange": loserChange, - "rating": newLoserElo, - "date": now, - }) - - ctx.JSON(http.StatusOK, gin.H{ - "winnerNewElo": int(newWinnerElo), - "loserNewElo": int(newLoserElo), - }) -} diff --git a/backend/routes/profile.go b/backend/routes/profile.go index 59a9d72c..58eba07f 100644 --- a/backend/routes/profile.go +++ b/backend/routes/profile.go @@ -13,7 +13,3 @@ func GetProfileRouteHandler(ctx *gin.Context) { func UpdateProfileRouteHandler(ctx *gin.Context) { controllers.UpdateProfile(ctx) } - -func UpdateEloAfterDebateRouteHandler(ctx *gin.Context) { - controllers.UpdateEloAfterDebate(ctx) -}