- Timestamp:
- 06/03/13 15:18:12 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
r9561 r9571 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Linq; 3 4 using System.Transactions; … … 128 129 from s in db.Resources.OfType<Slave>() 129 130 where !db.DimClients.Select(x => x.ResourceId).Contains(s.ResourceId) 130 || modifiedClients.Select(x => x.Slave.ResourceId).Contains(s.ResourceId)131 || modifiedClients.Select(x => x.Slave.ResourceId).Contains(s.ResourceId) 131 132 select new { 132 133 Slave = s, … … 222 223 223 224 private void UpdateTaskFacts(DimTime newTime, HiveDataContext db) { 225 var time = newTime.Time; 226 224 227 var lastFacts = 225 228 from fact in db.FactTasks … … 231 234 join lastFact in lastFacts on task.TaskId equals lastFact.TaskId into lastFactsPerTask 232 235 from lastFact in lastFactsPerTask.DefaultIfEmpty() 233 let newStateLogs = task.StateLogs.Where(stateLog => (lastFact == null || stateLog.DateTime > lastFact.EndTime) && stateLog.DateTime < newTime.Time) 236 let newStateLogs = task.StateLogs.Where(stateLog => (lastFact == null || stateLog.DateTime > lastFact.EndTime) && stateLog.DateTime < time) 237 let lastStateLog = lastFact == null ? null : (task.StateLogs.Where(stateLog => stateLog.DateTime < lastFact.EndTime).OrderByDescending(stateLog => stateLog.DateTime).First()) 234 238 let lastSlaveId = newStateLogs.OrderByDescending(stateLog => stateLog.DateTime).First(stateLog => stateLog.SlaveId != null).SlaveId 235 239 join client in db.DimClients.Where(client => client.ExpirationTime == null) on lastSlaveId equals client.ResourceId into clientPerTask 236 240 from client in clientPerTask.DefaultIfEmpty() 241 where newStateLogs.Any() 237 242 select new { 238 243 Task = task, … … 240 245 LastFact = lastFact, 241 246 StateLogs = newStateLogs.OrderBy(stateLog => stateLog.DateTime), 247 LastStateLog = lastStateLog, 242 248 LastClientId = client != null ? client.Id : default(Guid?) 243 249 }; … … 245 251 var newTaskFacts = 246 252 from t in lastFactAndStateLogsAndLastClientPerTask.ToList() 253 let stateLogsLinkedList = t.LastStateLog == null ? new LinkedList<StateLog>(t.StateLogs) : new LinkedList<StateLog>(t.StateLogs).AddFirst(t.LastStateLog).List 247 254 select new FactTask { 248 255 TaskId = t.Task.TaskId, … … 256 263 TaskSize = t.LastFact != null ? t.LastFact.TaskSize : t.TaskDataSize, 257 264 ResultSize = t.Task.State == TaskState.Finished ? t.TaskDataSize : default(long?), 258 NumCalculationRuns = (t.LastFact != null ? t.LastFact.NumCalculationRuns : 0) + t.StateLogs.Count(x => x.State == TaskState.Calculating), 259 NumFails = (t.LastFact != null ? t.LastFact.NumFails : 0) + t.StateLogs.Count(x => x.State == TaskState.Failed || !string.IsNullOrEmpty(x.Exception)), 260 TotalWaitingTime = 0, //ToDo 261 TotalRuntime = 0, //ToDo 262 TotalTransferTime = 0 //ToDo 265 NumCalculationRuns = 266 (t.LastFact != null ? t.LastFact.NumCalculationRuns : 0) + 267 t.StateLogs.Count(x => x.State == TaskState.Calculating), 268 NumRetries = 269 (t.LastFact != null ? t.LastFact.NumRetries : 0) + 270 stateLogsLinkedList.EnumerateNodes().Count(sl => sl.Value.State == TaskState.Calculating && sl.Next != null && !sl.NextIs(nsl => nsl.State == TaskState.Transferring)), //TotalWaitingTime = SumTotalWaitingTime(t.LastFact, stateLogsLinkedList), 271 TotalWaitingTime = SumTotalTime(t.LastFact, fact => fact.TotalWaitingTime, stateLogsLinkedList, stateLog => stateLog.Value.State == TaskState.Waiting), 272 TotalRuntime = SumTotalTime(t.LastFact, fact => fact.TotalRuntime, stateLogsLinkedList, stateLog => stateLog.Value.State == TaskState.Calculating && stateLog.NextIs(x => x.State == TaskState.Transferring)), 273 TotalTransferTime = SumTotalTime(t.LastFact, fact => fact.TotalTransferTime, stateLogsLinkedList, stateLog => stateLog.Value.State == TaskState.Transferring) 263 274 }; 264 275 265 276 db.FactTasks.InsertAllOnSubmit(newTaskFacts); 277 } 278 279 private double SumTotalTime(FactTask lastFact, Func<FactTask, double> lastValue, LinkedList<StateLog> stateLogs, Predicate<LinkedListNode<StateLog>> predicate) { 280 double sum = lastFact != null ? lastValue(lastFact) : 0.0; 281 282 sum += stateLogs.EnumerateNodes() 283 .Where(sl => predicate(sl)) 284 .Sum(stateLog => stateLog.Next != null ? (stateLog.Next.Value.DateTime - stateLog.Value.DateTime).TotalMinutes : 0); 285 return sum; 286 } 287 } 288 289 public static class LinkedListNodeExtensions { 290 public static IEnumerable<LinkedListNode<T>> EnumerateNodes<T>(this LinkedList<T> list) { 291 var node = list.First; 292 while (node != null) { 293 yield return node; 294 node = node.Next; 295 } 296 } 297 298 public static bool NextIs<T>(this LinkedListNode<T> node, Predicate<T> predicate) { 299 return node.Next != null && predicate(node.Next.Value); 266 300 } 267 301 }
Note: See TracChangeset
for help on using the changeset viewer.