public List <EvaluationData> List(int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { using (var context = ContextFactory.CreateReadOnly()) { return(Query(context, gameId, actorId, key, evaluationDataType, start, end).ToList()); } }
// todo scopes for user and group #region Helpers private Evaluation CreateCountEvaluation(string token, ActorType actorType, EvaluationDataType evaluationDataType, CriteriaScope scope, int value) { return(_evaluationController.Create( new Achievement { GameId = Fixture.EvaluationDataGameId, Name = $"{token} Name", Description = $"{token} Description", ActorType = actorType, Token = token, EvaluationCriterias = new List <EvaluationCriteria> { new EvaluationCriteria { EvaluationDataKey = Fixture.GenerateEvaluationDataKey(evaluationDataType), EvaluationDataCategory = EvaluationDataCategory.GameData, EvaluationDataType = evaluationDataType, CriteriaQueryType = CriteriaQueryType.Count, ComparisonType = ComparisonType.GreaterOrEqual, Scope = scope, Value = value.ToString() } } })); }
public void DoestGetInvalidDataByLeaderboardType(EvaluationDataType dataType, LeaderboardType leaderboardType) { var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, GameDataClientTestsLeaderboardKey); var game = Helpers.GetGame(Fixture.SUGARClient.Game, GameDataClientTestsLeaderboardKey); Assert.Throws <ClientHttpException>(() => Fixture.SUGARClient.GameData.GetByLeaderboardType(loggedInAccount.User.Id, game.Id, GameDataClientTestsLeaderboardKey, dataType, leaderboardType)); }
public EvaluationData Get(int gameId, int actorId, string key, EvaluationDataType dataType, LeaderboardType sortType) { if (((int)sortType == 3 && ((int)dataType == 1 || (int)dataType == 2)) || ((int)sortType < 3 && ((int)dataType == 0 || (int)dataType == 3))) { throw new ArgumentException($"Cannot get EvaluationData for LeaderboardType {sortType} and EvaluationDataType {dataType} as it would always return zero results."); } EvaluationData data = null; string value = null; switch (sortType) { case LeaderboardType.Highest: TryGetMax(gameId, actorId, key, out data, dataType); break; case LeaderboardType.Lowest: TryGetMin(gameId, actorId, key, out data, dataType); break; case LeaderboardType.Cumulative: switch (dataType) { case EvaluationDataType.Long: value = SumLong(gameId, actorId, key).ToString(CultureInfo.InvariantCulture); break; case EvaluationDataType.Float: value = SumFloat(gameId, actorId, key).ToString(CultureInfo.InvariantCulture); break; } break; case LeaderboardType.Count: value = CountKeys(gameId, actorId, key, dataType).ToString(CultureInfo.InvariantCulture); break; case LeaderboardType.Earliest: TryGetEarliest(gameId, actorId, key, out data, dataType); break; case LeaderboardType.Latest: TryGetLatest(gameId, actorId, key, out data, dataType); break; } if (data == null) { data = new EvaluationData { ActorId = actorId, GameId = gameId, Category = _category, EvaluationDataType = dataType, Key = key, Value = value }; } return(data); }
public void CanGetCountCompletedProgressForGroupMembers(EvaluationDataType evaluationDataType, int groupIndex) { // Arrange var token = $"{nameof(CanGetCountCompletedProgressForGroupMembers)}_{evaluationDataType}"; var group = Fixture.SortedGroups[groupIndex]; var groupUsers = ControllerLocator.RelationshipController.GetRelatedActors(group.Id, ActorType.User); // Each group user that was seeded using the CoreTestFixture should have // its index in sorted users + 1 as the count of data for a given type. var groupUsersDataCount = groupUsers .Sum(gu => Fixture.SortedUsers .ToList() .FindIndex(su => su.Id == gu.Id) + 1); var evaluation = CreateCountEvaluation( token, group.ActorType, evaluationDataType, CriteriaScope.RelatedUsers, groupUsersDataCount); // Act var result = _evaluationController.EvaluateProgress(evaluation, group.Id); // Assert Assert.Equal(1, result); }
private void Send(string key, string value, EvaluationDataType dataType, Action <bool> onComplete = null) { if (SUGARManager.UserSignedIn) { var data = new EvaluationDataRequest { CreatingActorId = SUGARManager.CurrentUser.Id, GameId = SUGARManager.GameId, Key = key, Value = value, EvaluationDataType = dataType }; SUGARManager.client.GameData.AddAsync(data, response => { Debug.Log("GameData Sending Success: True"); onComplete?.Invoke(true); }, exception => { Debug.LogError($"GameData Sending Success: False. Exception: {exception}"); onComplete?.Invoke(false); }); } else { onComplete?.Invoke(false); } }
public List <EvaluationData> List(int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { var list = _evaluationDataDbController.List(gameId, actorId, key, evaluationDataType, start, end); _logger.LogDebug($"{list?.Count} Values for: GameId: {gameId}, ActorId {actorId}, Key: {key}, EvaluationDataType: {evaluationDataType}, Start: {start}, End: {end}"); return(list); }
public List <int?> GetGameKeyActors(int gameId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { var actorIds = _evaluationDataDbController.GetGameKeyActors(gameId, key, evaluationDataType, start, end); _logger.LogInformation($"{actorIds?.Count} Actors for GameId {gameId} and Key {key}"); return(actorIds); }
public int CountKeys(int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { var count = _evaluationDataDbController.CountKeys(gameId, actorId, key, evaluationDataType, start, end); _logger.LogDebug($"Count: {count} for: GameId: {gameId}, ActorId {actorId}, Key: {key}, EvaluationDataType: {evaluationDataType}, Start: {start}, End: {end}"); return(count); }
public bool KeyExists(int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { var keyExists = _evaluationDataDbController.KeyExists(gameId, actorId, key, evaluationDataType, start, end); _logger.LogDebug( $"Key Exists: {keyExists} for GameId: {gameId}, ActorId: {actorId}, Key: {key}, EvaludationDataCategory: {_category}, Start: {start}, End: {end}"); return(keyExists); }
public void CanGetGameDataByLeaderboardType(EvaluationDataType dataType, LeaderboardType leaderboardType, string expectedValue) { var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, GameDataClientTestsLeaderboardKey); var game = Helpers.GetGame(Fixture.SUGARClient.Game, GameDataClientTestsLeaderboardKey); var get = Fixture.SUGARClient.GameData.GetByLeaderboardType(loggedInAccount.User.Id, game.Id, GameDataClientTestsLeaderboardKey, dataType, leaderboardType); Assert.Equal(expectedValue, get.Value); }
public bool KeyExists(int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start, DateTime?end) { using (var context = ContextFactory.Create()) { return(context.GetCategoryData(_category) .FilterByGameId(gameId) .FilterByActorId(actorId) .FilterByKey(key) .FilterByDataType(evaluationDataType) .FilterByDateTimeRange(start, end) .Any()); } }
public List <int?> GetGameKeyActors(int gameId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { using (var context = ContextFactory.Create()) { return(context.GetCategoryData(_category) .FilterByGameId(gameId) .FilterByKey(key) .FilterByDataType(evaluationDataType) .FilterByDateTimeRange(start, end) .Select(d => d.ActorId) .Distinct() .ToList()); } }
private void CriteriaScopeValidation(EvaluationDataType dataType, CriteriaScope scope, CriteriaQueryType queryType, ActorType actorType) { if (queryType == CriteriaQueryType.Sum && (dataType == EvaluationDataType.Boolean || dataType == EvaluationDataType.String)) { throw new ArgumentException($"Cannot create EvaluationCriteria as DataType {dataType} cannot be summed"); } switch (scope) { case CriteriaScope.Actor: break; case CriteriaScope.RelatedUsers: if (actorType == ActorType.Undefined) { throw new ArgumentException($"Cannot create EvaluationCriteria using CriteriaScope {scope} and ActorType {actorType}"); } if (queryType != CriteriaQueryType.Sum && queryType != CriteriaQueryType.Count) { throw new ArgumentException($"Cannot create EvaluationCriteria as only CriteriaQueryType {CriteriaQueryType.Sum} can be used with CriteriaScope {scope}"); } break; case CriteriaScope.RelatedGroups: if (actorType != ActorType.Group) { throw new ArgumentException($"Cannot create EvaluationCriteria using CriteriaScope {scope} and ActorType {actorType}"); } if (queryType != CriteriaQueryType.Sum && queryType != CriteriaQueryType.Count) { throw new ArgumentException($"Cannot create EvaluationCriteria as only CriteriaQueryType {CriteriaQueryType.Sum} can be used with CriteriaScope {scope}"); } break; case CriteriaScope.RelatedGroupUsers: if (actorType != ActorType.Group) { throw new ArgumentException($"Cannot create EvaluationCriteria using CriteriaScope {scope} and ActorType {actorType}"); } if (queryType != CriteriaQueryType.Sum && queryType != CriteriaQueryType.Count) { throw new ArgumentException($"Cannot create EvaluationCriteria as only CriteriaQueryType {CriteriaQueryType.Sum} can be used with CriteriaScope {scope}"); } break; } }
private void GetByLeaderboardType(string key, EvaluationDataType dataType, LeaderboardType type, Action <EvaluationDataResponse> onComplete) { if (SUGARManager.UserSignedIn) { SUGARManager.client.GameData.GetByLeaderboardTypeAsync(SUGARManager.CurrentUser.Id, SUGARManager.GameId, key, dataType, type, onComplete, exception => { Debug.LogError(exception); onComplete(null); }); } else { onComplete(null); } }
/* todo: fix * [Fact] * public void GetLeaderboardGroupMemberFilterAccuracyTest() * { * // this part of the leaderboard logic doesn't currently work correctly * * Random random = new Random(); * var leaderboard = CreateLeaderboard("GetLeaderboardGroupMemberFilterAccuracyTest", EvaluationDataType.Long, LeaderboardType.Lowest, "GetLeaderboardGroupMemberFilterAccuracyTest"); * * var users = CreateUsers(EvaluationDataFixture.SortedUsers.Count, "GetLeaderboardGroupMemberFilterAccuracyTest"); * CreateEvaluationDataAscending(users, "GetLeaderboardGroupMemberFilterAccuracyTest", EvaluationDataType.Long, leaderboard.GameId, true); * CreateGroupMembership("GetLeaderboardGroupMemberFilterAccuracyTest", users); * * var pageLimit = EvaluationDataFixture.SortedUsers.Count/3; * var actorId = users.ElementAt(random.Next(0, users.Count())).Id; * * var filter = CreateLeaderboardStandingsRequest(leaderboard.Token, leaderboard.GameId, LeaderboardFilterType.GroupMembers, pageLimit, actorId); * * var standings = _leaderboardEvaulationController.GetStandings(leaderboard, filter).ToArray(); * * Assert.Equal(Fixture.SortedUsers.Count, standings.Length); * * for (int i = 0; i < filter.PageLimit; i++) * { * int pageOffset = (filter.ActorId.Value - EvaluationDataFixture.SortedUsers.Count - 1) * filter.PageLimit; * Assert.Equal(pageOffset + i + 1, standings[i].ActorId); * } * }*/ #region Helpers private Leaderboard CreateLeaderboard(string token, EvaluationDataType dataType, LeaderboardType boardType, string overrideDataKey = null) { var leaderboard = new Leaderboard { Name = token, Token = token, EvaluationDataKey = overrideDataKey ?? Fixture.GenerateEvaluationDataKey(dataType), GameId = Fixture.EvaluationDataGameId, ActorType = ActorType.User, EvaluationDataType = dataType, CriteriaScope = CriteriaScope.Actor, LeaderboardType = boardType }; _leaderboardDbController.Create(leaderboard); return(leaderboard); }
private bool DataTypeValueValidation(EvaluationDataType dataType, string value) { switch (dataType) { case EvaluationDataType.String: return(true); case EvaluationDataType.Long: return(long.TryParse(value, out var _)); case EvaluationDataType.Float: return(float.TryParse(value, out var _)); case EvaluationDataType.Boolean: return(bool.TryParse(value, out var _)); default: return(false); } }
public void CanGetCountCompletedProgressForUser(EvaluationDataType evaluationDataType, int userIndex) { // Arrange var token = $"{nameof(CanGetCountCompletedProgressForUser)}_{evaluationDataType}"; var user = Fixture.SortedUsers[userIndex]; var userDataCount = userIndex + 1; var evaluation = CreateCountEvaluation( token, user.ActorType, evaluationDataType, CriteriaScope.Actor, userDataCount); // Act var result = _evaluationController.EvaluateProgress(evaluation, user.Id); // Assert Assert.Equal(1, result); }
private void CreateEvaluationDataAscending(string key, EvaluationDataType type, int gameId, List <Actor> actors) { var data = new List <EvaluationData>(); // Each user will have that user's index + 1 amount of EvaluationData (unless singular is defined) // i.e: // users[0] will have 1 EvaluationData of 1 // users[1] will have 2 EvaluationData of 1 each = 2 // users[2] will have 3 EvaluationData of 1 each = 3 // etc for (var actorIndex = 0; actorIndex < actors.Count; actorIndex++) { for (var actorDataIndex = 0; actorDataIndex < actorIndex + 1; actorDataIndex++) { var gameData = new EvaluationData { ActorId = actors[actorIndex].Id, GameId = gameId, Key = key, Value = (actorDataIndex + 1).ToString(), EvaluationDataType = type }; if (type == EvaluationDataType.Float) { gameData.Value = (actorDataIndex * 0.01f).ToString(CultureInfo.InvariantCulture); } else if (type == EvaluationDataType.Boolean) { gameData.Value = (actorDataIndex % 2 == 0).ToString(); } data.Add(gameData); } } _gameDataController.Add(data); }
public static IQueryable <EvaluationData> FilterByDataType(this IQueryable <EvaluationData> evaluationDataQueryable, EvaluationDataType type) { return(evaluationDataQueryable.Where(data => data.EvaluationDataType == type)); }
public bool TryGetMin(int gameId, int actorId, string key, out EvaluationData value, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { var list = List(gameId, actorId, key, evaluationDataType, start, end); if (list.Count > 0) { value = list.OrderBy(s => Convert.ToDouble(s.Value)).First(); return(true); } value = null; return(false); }
public IQueryable <EvaluationData> Query(SUGARContext context, int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { return(context.GetCategoryData(_category) .FilterByGameId(gameId) .FilterByActorId(actorId) .FilterByKey(key) .FilterByDataType(evaluationDataType) .FilterByDateTimeRange(start, end)); }
/// <summary> /// Get the earliest recorded data for the currently signed in user for the key and dataType provided. /// </summary> /// <param name="key">Name of the GameData key.</param> /// <param name="dataType">EvaluationDataType of the GameData.</param> /// <param name="onComplete">Callback which contains the gathered result.</param> public void GetEarliest(string key, EvaluationDataType dataType, Action <EvaluationDataResponse> onComplete) { GetByLeaderboardType(key, dataType, LeaderboardType.Earliest, onComplete); }
private string CreateMappingKey(int gameId, EvaluationDataType dataType, string evaluationDataKey) { return($"{gameId};{dataType};{evaluationDataKey}"); }
public void GetByLeaderboardTypeAsync(int actorId, int gameId, string key, EvaluationDataType dataType, LeaderboardType leaderboardType, Action <EvaluationDataResponse> onSuccess, Action <Exception> onError) { AsyncRequestController.EnqueueRequest(() => GetByLeaderboardType(actorId, gameId, key, dataType, leaderboardType), onSuccess, onError); }
/// <summary> /// Finds a list of GameData with the highest <param name="dataType"/> for each <param name="key"/> provided that matches the <param name="actorId"/> and <param name="gameId"/>. /// </summary> /// <param name="actorId">ID of a User/Group.</param> /// <param name="gameId">ID of a Game.</param> /// <param name="key">Array of Key names.</param> /// <param name="dataType">Data type of value</param> /// <returns>A list of <see cref="EvaluationDataResponse"/> which match the search criteria.</returns> public EvaluationDataResponse GetByLeaderboardType(int actorId, int gameId, string key, EvaluationDataType dataType, LeaderboardType leaderboardType) { var query = GetUriBuilder(ControllerPrefix + "/leaderboardType/{0}/{1}/{2}/{3}/{4}", actorId, gameId, key, dataType.ToString(), leaderboardType.ToString()).ToString(); return(Get <EvaluationDataResponse>(query)); }
/// <summary> /// Get the cumulative value for the currently signed in user for the key and dataType provided. /// </summary> /// <remarks> /// - EvaluationDataType should be a type that can be added together, eg. Long /// </remarks> /// <param name="key">Name of the GameData key.</param> /// <param name="dataType">EvaluationDataType of the GameData.</param> /// <param name="onComplete">Callback which contains the gathered result.</param> public void GetCumulative(string key, EvaluationDataType dataType, Action <EvaluationDataResponse> onComplete) { GetByLeaderboardType(key, dataType, LeaderboardType.Cumulative, onComplete); }
public bool TryGetEarliest(int gameId, int actorId, string key, out EvaluationData value, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { var list = List(gameId, actorId, key, evaluationDataType, start, end); if (list.Count > 0) { value = list.OrderBy(s => s.DateCreated).First(); return(true); } value = null; return(false); }
public async Task <IActionResult> GetByLeaderboardType([FromRoute] int actorId, [FromRoute] int gameId, [FromRoute] string key, [FromRoute] EvaluationDataType dataType, [FromRoute] LeaderboardType sortType) { if ((await _authorizationService.AuthorizeAsync(User, actorId, HttpContext.ScopeItems(ClaimScope.Group))).Succeeded || (await _authorizationService.AuthorizeAsync(User, actorId, HttpContext.ScopeItems(ClaimScope.User))).Succeeded || (await _authorizationService.AuthorizeAsync(User, gameId, HttpContext.ScopeItems(ClaimScope.Game))).Succeeded) { var data = _gameDataCoreController.Get(gameId, actorId, key, dataType, sortType); var dataContract = data.ToContract(); return(new ObjectResult(dataContract)); } return(Forbid()); }
public int CountKeys(int gameId, int actorId, string key, EvaluationDataType evaluationDataType, DateTime?start = null, DateTime?end = null) { return(List(gameId, actorId, key, evaluationDataType, start, end).Count); }