Ignore:
Timestamp:
07/16/15 15:09:12 (6 years ago)
Author:
dglaser
Message:

#2388:

HeuristicLab.Services.Hive.DataAccess-3.3:

  • Removed old statistics tables
  • Updated SQL Scripts

HeuristicLab.Services.WebApp-3.3:
HeuristicLab.Services.WebApp.Status-3.3:
HeuristicLab.Services.WebApp.Statistics-3.3:

  • Minor changes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs

    r12584 r12768  
    827827    #endregion
    828828
    829     #region Statistics Methods
    830     public DT.Statistics GetStatistic(Guid id) {
    831       using (var db = CreateContext()) {
    832         return DT.Convert.ToDto(db.Statistics.SingleOrDefault(x => x.StatisticsId == id));
    833       }
    834     }
    835 
    836     public IEnumerable<DT.Statistics> GetStatistics(Expression<Func<Statistics, bool>> predicate) {
    837       using (var db = CreateContext()) {
    838         return db.Statistics.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray();
    839       }
    840     }
    841 
    842     public Guid AddStatistics(DT.Statistics dto) {
    843       using (var db = CreateContext()) {
    844         var entity = DT.Convert.ToEntity(dto);
    845         db.Statistics.InsertOnSubmit(entity);
    846         db.SubmitChanges();
    847         foreach (var slaveStat in dto.SlaveStatistics) {
    848           slaveStat.Id = entity.StatisticsId;
    849           db.SlaveStatistics.InsertOnSubmit(DT.Convert.ToEntity(slaveStat));
    850         }
    851         if (dto.UserStatistics != null) {
    852           foreach (var userStat in dto.UserStatistics) {
    853             userStat.Id = entity.StatisticsId;
    854             db.UserStatistics.InsertOnSubmit(DT.Convert.ToEntity(userStat));
    855           }
    856         }
    857         db.SubmitChanges();
    858         return entity.StatisticsId;
    859       }
    860     }
    861 
    862     public void DeleteStatistics(Guid id) {
    863       using (var db = CreateContext()) {
    864         var entity = db.Statistics.FirstOrDefault(x => x.StatisticsId == id);
    865         if (entity != null) db.Statistics.DeleteOnSubmit(entity);
    866         db.SubmitChanges();
    867       }
    868     }
    869 
    870     public Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds) {
    871       using (var db = CreateContext()) {
    872         var waitingTasksByUser = from task in db.Tasks
    873                                  where task.State == TaskState.Waiting && task.AssignedResources.Any(x => resourceIds.Contains(x.ResourceId))
    874                                  group task by task.Job.OwnerUserId into g
    875                                  select new { UserId = g.Key, UsedCores = g.Count() };
    876         return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
    877       }
    878     }
    879 
    880     public Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds) {
    881       using (var db = CreateContext()) {
    882         var calculatingTasksByUser = from task in db.Tasks
    883                                      where task.State == TaskState.Calculating && task.AssignedResources.Any(x => resourceIds.Contains(x.ResourceId))
    884                                      group task by task.Job.OwnerUserId into g
    885                                      select new { UserId = g.Key, UsedCores = g.Count() };
    886         return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
    887       }
    888     }
    889 
    890     public List<DT.UserStatistics> GetUserStatistics() {
    891       using (var db = CreateContext()) {
    892         var userStats = new Dictionary<Guid, DT.UserStatistics>();
    893 
    894         var usedCoresByUser = from job in db.Tasks
    895                               where job.State == TaskState.Calculating
    896                               group job by job.Job.OwnerUserId into g
    897                               select new { UserId = g.Key, UsedCores = g.Count() };
    898 
    899         foreach (var item in usedCoresByUser) {
    900           if (!userStats.ContainsKey(item.UserId)) {
    901             userStats.Add(item.UserId, new DT.UserStatistics() { UserId = item.UserId });
    902           }
    903           userStats[item.UserId].UsedCores += item.UsedCores;
    904         }
    905 
    906         var executionTimesByUser = from task in db.Tasks
    907                                    group task by task.Job.OwnerUserId into g
    908                                    select new { UserId = g.Key, ExecutionTime = TimeSpan.FromMilliseconds(g.Select(x => x.ExecutionTimeMs).Sum()) };
    909         foreach (var item in executionTimesByUser) {
    910           if (!userStats.ContainsKey(item.UserId)) {
    911             userStats.Add(item.UserId, new DT.UserStatistics() { UserId = item.UserId });
    912           }
    913           userStats[item.UserId].ExecutionTime += item.ExecutionTime;
    914         }
    915 
    916         // execution times only of finished task - necessary to compute efficieny
    917         var executionTimesFinishedJobs = from job in db.Tasks
    918                                          where job.State == TaskState.Finished
    919                                          group job by job.Job.OwnerUserId into g
    920                                          select new { UserId = g.Key, ExecutionTimeFinishedJobs = TimeSpan.FromMilliseconds(g.Select(x => x.ExecutionTimeMs).Sum()) };
    921 
    922         foreach (var item in executionTimesFinishedJobs) {
    923           if (!userStats.ContainsKey(item.UserId)) {
    924             userStats.Add(item.UserId, new DT.UserStatistics() { UserId = item.UserId });
    925           }
    926           userStats[item.UserId].ExecutionTimeFinishedJobs += item.ExecutionTimeFinishedJobs;
    927         }
    928 
    929         // start to end times only of finished task - necessary to compute efficiency
    930         var startToEndTimesFinishedJobs = from job in db.Tasks
    931                                           where job.State == TaskState.Finished
    932                                           group job by job.Job.OwnerUserId into g
    933                                           select new {
    934                                             UserId = g.Key,
    935                                             StartToEndTime = new TimeSpan(g.Select(x => x.StateLogs.OrderByDescending(sl => sl.DateTime).First().DateTime - x.StateLogs.OrderBy(sl => sl.DateTime).First().DateTime).Sum(ts => ts.Ticks))
    936                                           };
    937         foreach (var item in startToEndTimesFinishedJobs) {
    938           if (!userStats.ContainsKey(item.UserId)) {
    939             userStats.Add(item.UserId, new DT.UserStatistics() { UserId = item.UserId });
    940           }
    941           userStats[item.UserId].StartToEndTime += item.StartToEndTime;
    942         }
    943 
    944         // also consider executiontimes of DeletedJobStats
    945         var deletedJobsExecutionTimesByUsers = from del in db.DeletedJobStatistics
    946                                                group del by del.UserId into g
    947                                                select new {
    948                                                  UserId = g.Key,
    949                                                  ExecutionTime = TimeSpan.FromSeconds(g.Select(x => x.ExecutionTimeS).Sum()),
    950                                                  ExecutionTimeFinishedJobs = TimeSpan.FromSeconds(g.Select(x => x.ExecutionTimeSFinishedJobs).Sum()),
    951                                                  StartToEndTime = TimeSpan.FromSeconds(g.Select(x => x.StartToEndTimeS).Sum())
    952                                                };
    953         foreach (var item in deletedJobsExecutionTimesByUsers) {
    954           if (!userStats.ContainsKey(item.UserId)) {
    955             userStats.Add(item.UserId, new DT.UserStatistics() { UserId = item.UserId });
    956           }
    957           userStats[item.UserId].ExecutionTime += item.ExecutionTime;
    958           userStats[item.UserId].ExecutionTimeFinishedJobs += item.ExecutionTimeFinishedJobs;
    959           userStats[item.UserId].StartToEndTime += item.StartToEndTime;
    960         }
    961 
    962         return userStats.Values.ToList();
    963       }
    964     }
    965     #endregion
    966 
    967829    #region UserPriority Methods
    968830    public IEnumerable<DT.UserPriority> GetUserPriorities(Expression<Func<UserPriority, bool>> predicate) {
Note: See TracChangeset for help on using the changeset viewer.