public OperationResult <AccountDayStatistic> GetDayStatistic(long accountId) { return(InvokeOperations.InvokeOperation(() => { Logger.Trace("Get day statistic for account {0}", accountId); var res = statisticRepository.GetLastStatistic(accountId); return res != null ? new AccountDayStatistic(res) : null; })); }
private void UpdateStatistic() { try { lock (calculationLock) { logger.Info("Calculation daily statistic starting..."); var accountsInService = accountService.GetAllAccounts(); if (!accountsInService.IsSuccess) { throw new Exception(accountsInService.Error); } var accounts = accountsInService .Result .Where(x => x.Role != AccountRole.Tournament && x.AccountTypeId != AccountType.BO && x.AccountTypeId != AccountType.BODEMO) .ToArray(); logger.Info("Received {0} accounts for calculate daily statistic", accounts.Length); statisticRepository.ClearStatisticOfDeletedAccounts(accounts.Select(x => x.AccountId).ToArray()); var lastStatistics = statisticRepository .GetLastStatistic() .ToDictionary(x => x.account_id, x => x); CalculateStatisticForAccouts(lastStatistics, accounts); logger.Info("Calculation daily statistic done!"); OnStatisticUpdated(); } } catch (Exception ex) { logger.Error("Error at calculate daily statistic: {0}", ex.ToString()); } }