Skip to content

Commit

Permalink
Merge pull request #77 from ezraroi/76-add-best-user-for-each-categor…
Browse files Browse the repository at this point in the history
…y-in-stats

added
  • Loading branch information
ezraroi authored Jul 8, 2024
2 parents 9ec6eaa + 6aa6c75 commit 4102556
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Mundialito/Client/src/Users/UserProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
<thead>
<th><i class="fa-solid fa-list"></i> Category</th>
<th class="text-center"><i class="fa-solid fa-people-group"></i> Overall</th>
<th class="text-center"><i class="fa-solid fa-medal"></i> Best</th>
<th class="text-center"><i class="fa-solid fa-trophy"></i> Leader</th>
<th class="text-center" ng-if="!isLoggedUserProfile()"><i class="fa-solid fa-user"></i> {{::profileUser.Name}}</th>
<th class="text-center" ng-if="isLoggedUserProfile()"><i class="fa-solid fa-users"></i> Followees</th>
Expand All @@ -82,6 +83,7 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
<tr ng-repeat="(key,value) in performance">
<td>{{::value.Category}}</td>
<td class="text-center"><span class="label label-default">{{::value.Overall}}</span></td>
<td><span class="label label-default">{{::value.BestResult.Value}}</span> <small>({{::value.BestResult.Name}})</small></td>
<td class="text-center"><span class="label label-default">{{::value.Leader}}</span></td>
<td class="text-center" ng-if="!isLoggedUserProfile()"><span ng-class="{'label-danger': value.User < value.Overall, 'label-warning': value.User >= value.Overall && value.User < value.Leader, 'label-success': value.User >= value.Leader}" class="label">{{::value.User}}</span></td>
<td class="text-center" ng-if="isLoggedUserProfile()"><span ng-class="{'label-danger': value.Followees < value.Overall, 'label-warning': value.Followees >= value.Overall && value.Followees < value.Leader, 'label-success': value.Followees >= value.Leader}" class="label">{{::value.Followees}}</span></td>
Expand All @@ -98,6 +100,9 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
<span class="list-group-item">
<i class="fa-solid fa-people-group"></i> Overall<span class="label label-default pull-right">{{::value.Overall}}</span>
</span>
<span class="list-group-item">
<i class="fa-solid fa-medal"></i> Best<span class="label label-default pull-right">{{::value.BestResult.Value}}</span><small>({{::value.BestResult.Name}})</small>
</span>
<span class="list-group-item">
<i class="fa-solid fa-trophy"></i> Leader<span class="label label-default pull-right">{{::value.Leader}}</span>
</span>
Expand Down
32 changes: 31 additions & 1 deletion Mundialito/Controllers/StatsController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.ComponentModel;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -97,12 +96,17 @@ private PerGameModel getPointsPerMatch(float games, float users, List<Bet> bets,
Leader = getSafe(leaderPoints, games),
Overall = getSafe(getSafe(allPoins, users), games),
Followees = getSafe(getSafe(followeesPoints, followees.Count()), games),
BestResult = new BestResult {
Name = leader.FirstName + " " + leader.LastName,
Value = getSafe(leaderPoints, games),
},
Category = "Points per Match"
};
}

private PerGameModel getCornersPointsPerMatch(float games, float users, List<Bet> bets, MundialitoUser user, MundialitoUser loggedUser, MundialitoUser leader, IEnumerable<MundialitoUser> followees)
{
var best = bets.GroupBy((bet) => bet.User.FirstName + " " + bet.User.LastName).ToDictionary(g => g.Key, g => g.Where((bet) => bet.CornersWin).Count()).OrderByDescending(x => x.Value).FirstOrDefault();
var requestedCorners = bets.Where((bet) => bet.User.UserName == user.UserName).Where((bet) => bet.CornersWin).Count();
var followeesCorners = bets.Where((bet) => followees.Where((fol) => fol.UserName == bet.User.UserName).Any()).Where((bet) => bet.CornersWin).Count();
var loggedCorners = bets.Where((bet) => bet.User.UserName == loggedUser.UserName).Where((bet) => bet.CornersWin).Count();
Expand All @@ -115,12 +119,17 @@ private PerGameModel getCornersPointsPerMatch(float games, float users, List<Bet
Leader = getSafe(leaderCorners, games),
Overall = getSafe(getSafe(allCorners, users), games),
Followees = getSafe(getSafe(followeesCorners, followees.Count()), games),
BestResult = new BestResult{
Value = getSafe(best.Value, games),
Name = best.Key,
},
Category = "Corners points per Match (out of 1 point)"
};
}

private PerGameModel getCardsPointsPerMatch(float games, float users, List<Bet> bets, MundialitoUser user, MundialitoUser loggedUser, MundialitoUser leader, IEnumerable<MundialitoUser> followees)
{
var best = bets.GroupBy((bet) => bet.User.FirstName + " " + bet.User.LastName).ToDictionary(g => g.Key, g => g.Where((bet) => bet.CardsWin).Count()).OrderByDescending(x => x.Value).FirstOrDefault();
var requestedCards = bets.Where((bet) => bet.User.UserName == user.UserName).Where((bet) => bet.CardsWin).Count();
var followeesCards = bets.Where((bet) => followees.Where((fol) => fol.UserName == bet.User.UserName).Any()).Where((bet) => bet.CardsWin).Count();
var loggedCards = bets.Where((bet) => bet.User.UserName == loggedUser.UserName).Where((bet) => bet.CardsWin).Count();
Expand All @@ -133,12 +142,17 @@ private PerGameModel getCardsPointsPerMatch(float games, float users, List<Bet>
Leader = getSafe(leaderCards, games),
Overall = getSafe(getSafe(allCards, users), games),
Followees = getSafe(getSafe(followeesCards, followees.Count()), games),
BestResult = new BestResult{
Value = getSafe(best.Value, games),
Name = best.Key,
},
Category = "Cards points per Match (out of 1 point)"
};
}

private PerGameModel getMarkPerMatch(float games, float users, List<Bet> bets, MundialitoUser user, MundialitoUser loggedUser, MundialitoUser leader, IEnumerable<MundialitoUser> followees)
{
var best = bets.GroupBy((bet) => bet.User.FirstName + " " + bet.User.LastName).ToDictionary(g => g.Key, g => g.Where((bet) => bet.GameMarkWin).Count()).OrderByDescending(x => x.Value).FirstOrDefault();
var requested = bets.Where((bet) => bet.User.UserName == user.UserName).Where((bet) => bet.GameMarkWin).Count();
var followeesMarks = bets.Where((bet) => followees.Where((fol) => fol.UserName == bet.User.UserName).Any()).Where((bet) => bet.GameMarkWin).Count();
var logged = bets.Where((bet) => bet.User.UserName == loggedUser.UserName).Where((bet) => bet.GameMarkWin).Count();
Expand All @@ -151,12 +165,17 @@ private PerGameModel getMarkPerMatch(float games, float users, List<Bet> bets, M
Leader = getSafe(leaderMarks, games),
Overall = getSafe(getSafe(all, users), games),
Followees = getSafe(getSafe(followeesMarks, followees.Count()), games),
BestResult = new BestResult{
Value = getSafe(best.Value, games),
Name = best.Key,
},
Category = "Match mark win probability"
};
}

private PerGameModel getResultProbability(float games, float users, List<Bet> bets, MundialitoUser user, MundialitoUser loggedUser, MundialitoUser leader, IEnumerable<MundialitoUser> followees)
{
var best = bets.GroupBy((bet) => bet.User.FirstName + " " + bet.User.LastName).ToDictionary(g => g.Key, g => g.Where((bet) => bet.ResultWin).Count()).OrderByDescending(x => x.Value).FirstOrDefault();
var requested = bets.Where((bet) => bet.User.UserName == user.UserName).Where((bet) => bet.ResultWin).Count();
var followeesRes = bets.Where((bet) => followees.Where((fol) => fol.UserName == bet.User.UserName).Any()).Where((bet) => bet.ResultWin).Count();
var logged = bets.Where((bet) => bet.User.UserName == loggedUser.UserName).Where((bet) => bet.ResultWin).Count();
Expand All @@ -169,13 +188,19 @@ private PerGameModel getResultProbability(float games, float users, List<Bet> be
Leader = getSafe(leaderRes, games),
Overall = getSafe(getSafe(all, users), games),
Followees = getSafe(getSafe(followeesRes, followees.Count()), games),
BestResult = new BestResult{
Value = getSafe(best.Value, games),
Name = best.Key,
},
Category = "Match result win probability"
};
}

private PerGameModel getNumOfBingo(float games, float users, List<Bet> bets, MundialitoUser user, MundialitoUser loggedUser, MundialitoUser leader, IEnumerable<MundialitoUser> followees)
{
var best = bets.GroupBy((bet) => bet.User.FirstName + " " + bet.User.LastName).ToDictionary(g => g.Key, g => g.Where((bet) => bet.Points == 7).Count()).OrderByDescending(x => x.Value).FirstOrDefault();
var requested = bets.Where((bet) => bet.User.UserName == user.UserName).Where((bet) => bet.Points == 7).Count();
var followeesRes = bets.Where((bet) => followees.Where((fol) => fol.UserName == bet.User.UserName).Any()).Where((bet) => bet.Points == 7).Count();
var logged = bets.Where((bet) => bet.User.UserName == loggedUser.UserName).Where((bet) => bet.Points == 7).Count();
var leaderBingo = bets.Where((bet) => bet.User.UserName == leader.UserName).Where((bet) => bet.Points == 7).Count();
var all = bets.Where((bet) => bet.Points == 7).Count();
Expand All @@ -185,6 +210,11 @@ private PerGameModel getNumOfBingo(float games, float users, List<Bet> bets, Mun
User = requested,
Leader = leaderBingo,
Overall = getSafe(all, users),
Followees = getSafe(followeesRes, followees.Count()),
BestResult = new BestResult{
Value = best.Value,
Name = best.Key,
},
Category = "Total Bingos"
};
}
Expand Down
12 changes: 12 additions & 0 deletions Mundialito/Models/StatsModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ public class PerGameModel {

[JsonPropertyName("Followees")]
public float Followees { get; set; }

[JsonPropertyName("BestResult")]
public BestResult BestResult { get; set; }

Check warning on line 48 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Non-nullable property 'BestResult' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 48 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'BestResult' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 48 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'BestResult' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}

public class BestResult {

[JsonPropertyName("Name")]
public string Name { get; set;}

Check warning on line 54 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 54 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build-and-deploy

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 54 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 54 in Mundialito/Models/StatsModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[JsonPropertyName("Value")]
public float Value { get; set; }
}
5 changes: 5 additions & 0 deletions Mundialito/wwwroot/App/Users/UserProfile.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
<thead>
<th><i class="fa-solid fa-list"></i> Category</th>
<th class="text-center"><i class="fa-solid fa-people-group"></i> Overall</th>
<th class="text-center"><i class="fa-solid fa-medal"></i> Best</th>
<th class="text-center"><i class="fa-solid fa-trophy"></i> Leader</th>
<th class="text-center" ng-if="!isLoggedUserProfile()"><i class="fa-solid fa-user"></i> {{::profileUser.Name}}</th>
<th class="text-center" ng-if="isLoggedUserProfile()"><i class="fa-solid fa-users"></i> Followees</th>
Expand All @@ -82,6 +83,7 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
<tr ng-repeat="(key,value) in performance">
<td>{{::value.Category}}</td>
<td class="text-center"><span class="label label-default">{{::value.Overall}}</span></td>
<td><span class="label label-default">{{::value.BestResult.Value}}</span> <small>({{::value.BestResult.Name}})</small></td>
<td class="text-center"><span class="label label-default">{{::value.Leader}}</span></td>
<td class="text-center" ng-if="!isLoggedUserProfile()"><span ng-class="{'label-danger': value.User < value.Overall, 'label-warning': value.User >= value.Overall && value.User < value.Leader, 'label-success': value.User >= value.Leader}" class="label">{{::value.User}}</span></td>
<td class="text-center" ng-if="isLoggedUserProfile()"><span ng-class="{'label-danger': value.Followees < value.Overall, 'label-warning': value.Followees >= value.Overall && value.Followees < value.Leader, 'label-success': value.Followees >= value.Leader}" class="label">{{::value.Followees}}</span></td>
Expand All @@ -98,6 +100,9 @@ <h4><i class="fa fa-user"></i> {{profileUser.Name}} Profile</h4>
<span class="list-group-item">
<i class="fa-solid fa-people-group"></i> Overall<span class="label label-default pull-right">{{::value.Overall}}</span>
</span>
<span class="list-group-item">
<i class="fa-solid fa-medal"></i> Best<span class="label label-default pull-right">{{::value.BestResult.Value}}</span><small>({{::value.BestResult.Name}})</small>
</span>
<span class="list-group-item">
<i class="fa-solid fa-trophy"></i> Leader<span class="label label-default pull-right">{{::value.Leader}}</span>
</span>
Expand Down

0 comments on commit 4102556

Please sign in to comment.