Changeset 11030 for branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers
- Timestamp:
- 06/20/14 16:20:02 (11 years ago)
- Location:
- branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/AdminDataController.cs
r11020 r11030 24 24 } 25 25 26 public JsonResult UserTaskStats(string userName, DateTime start, DateTime end)26 public JsonResult TaskStats(DateTime start, DateTime end, string userName=null) 27 27 { 28 28 using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) … … 31 31 join jobs in db.DimJobs 32 32 on tasks.JobId equals jobs.JobId 33 where jobs.UserName == userName&&34 tasks. StartTime >= start&&35 tasks.EndTime < end33 where tasks.StartTime >= start && 34 tasks.EndTime < end && 35 (string.IsNullOrEmpty(userName) || jobs.UserName == userName) 36 36 select new { tasks.TotalWaitingTime, tasks.TotalTransferTime, tasks.TotalRuntime, tasks.NumCalculationRuns, 37 37 tasks.CoresRequired, tasks.MemoryRequired, tasks.TaskSize, tasks.ResultSize}) … … 51 51 } 52 52 } 53 54 public JsonResult AllTaskStats(DateTime start, DateTime end)55 {56 using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString))57 {58 var taskStats = (from tasks in db.FactTasks59 where tasks.StartTime >= start &&60 tasks.EndTime < end61 select new62 {63 tasks.TotalWaitingTime,64 tasks.TotalTransferTime,65 tasks.TotalRuntime,66 tasks.NumCalculationRuns,67 tasks.CoresRequired,68 tasks.MemoryRequired,69 tasks.TaskSize,70 tasks.ResultSize71 })72 .ToList();73 74 List<double> FullStats = new List<double>();75 FullStats.Add(taskStats.Sum(w => w.TotalWaitingTime));76 FullStats.Add(taskStats.Sum(t => t.TotalTransferTime));77 FullStats.Add(taskStats.Sum(r => r.TotalRuntime));78 FullStats.Add(taskStats.Sum(n => n.NumCalculationRuns));79 FullStats.Add(taskStats.Sum(c => c.CoresRequired));80 FullStats.Add(taskStats.Sum(m => m.MemoryRequired));81 FullStats.Add(taskStats.Sum(ts => ts.TaskSize));82 FullStats.Add(taskStats.Sum(rs => Convert.ToDouble(rs.ResultSize)));83 84 return Json(FullStats, JsonRequestBehavior.AllowGet);85 }86 }87 53 } 88 54 } -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/ChartDataController.cs
r11020 r11030 139 139 } 140 140 141 public JsonResult GetUserTask(string userName, DateTime? start = null, DateTime? end = null) 142 { 143 start = start ?? DateTime.Now - DefaultDuration; 144 end = end ?? DateTime.Now; 145 using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) 146 { 147 var data = 141 public JsonResult NumberPages(string userName, string limit, DateTime? start = null, DateTime? end = null, string jobId = null, string taskState = null) 142 { 143 using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) 144 { 145 TaskState state = GetTaskState(taskState); 146 var numberRecords = 148 147 (from tasks in db.FactTasks 149 join jobs in db.DimJobs 150 on tasks.JobId equals jobs.JobId 151 where jobs.UserName == userName && 152 tasks.StartTime >= start && 153 tasks.EndTime < end 154 select new 155 { 156 TotalWaiting = tasks.TotalWaitingTime, 157 TotalTransfer = tasks.TotalTransferTime, 158 TotalRuntime = tasks.TotalRuntime 159 }).ToList(); 160 161 List<List<double>> overallResult = new List<List<double>>(); 148 join jobs in db.DimJobs 149 on tasks.JobId equals jobs.JobId 150 where jobs.UserName == userName && 151 (!start.HasValue || tasks.StartTime >= start) && 152 (!end.HasValue || tasks.EndTime < end) && 153 (string.IsNullOrEmpty(jobId) || tasks.JobId.ToString() == jobId) && 154 (string.IsNullOrEmpty(taskState) || tasks.TaskState == state) 155 select new 156 { 157 TaskID = tasks.TaskId, 158 TotalWaiting = tasks.TotalWaitingTime, 159 TotalTransfer = tasks.TotalTransferTime, 160 TotalRuntime = tasks.TotalRuntime, 161 StartDate = tasks.StartTime 162 }).OrderByDescending(s => s.StartDate).ToList().Count; 163 164 var numberPages = numberRecords / Convert.ToDecimal(limit); 165 numberPages = Decimal.Truncate(numberPages); 166 numberPages += 1; 167 168 return Json(numberPages, JsonRequestBehavior.AllowGet); 169 } 170 } 171 172 public JsonResult GetUserTask(string userName, string limit, DateTime? start = null, DateTime? end = null, string jobId = null, string taskState=null, string currentPage=null) 173 { 174 using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) 175 { 176 TaskState state = GetTaskState(taskState); 177 var data = 178 (from tasks in db.FactTasks 179 join jobs in db.DimJobs 180 on tasks.JobId equals jobs.JobId 181 where jobs.UserName == userName && 182 (!start.HasValue || tasks.StartTime >= start) && 183 (!end.HasValue || tasks.EndTime < end) && 184 (string.IsNullOrEmpty(jobId) || tasks.JobId.ToString() == jobId) && 185 (string.IsNullOrEmpty(taskState) || tasks.TaskState == state) 186 select new 187 { 188 TaskID = tasks.TaskId, 189 TotalWaiting = tasks.TotalWaitingTime, 190 TotalTransfer = tasks.TotalTransferTime, 191 TotalRuntime = tasks.TotalRuntime, 192 StartDate = tasks.StartTime 193 }).OrderByDescending(s => s.StartDate).ToList(); 194 195 if (currentPage != null) { 196 data.RemoveRange(0, (Convert.ToInt32(currentPage) - 1) * Convert.ToInt32(limit)); 197 if (data.Count > Convert.ToInt32(limit)) { 198 data.RemoveRange(Convert.ToInt32(limit), data.Count - Convert.ToInt32(limit)); 199 } 200 } 201 else if (data.Count > Convert.ToInt32(limit)) 202 { 203 data.RemoveRange(Convert.ToInt32(limit), data.Count - Convert.ToInt32(limit)); 204 } 205 206 List<string> id = new List<string>(); 162 207 List<double> wait = new List<double>(); 163 208 List<double> transfer = new List<double>(); 164 209 List<double> run = new List<double>(); 210 data.ForEach(i => id.Add(i.TaskID.ToString())); 165 211 data.ForEach(w => wait.Add(w.TotalWaiting)); 166 212 data.ForEach(t => transfer.Add(t.TotalTransfer)); 167 213 data.ForEach(r => run.Add(r.TotalRuntime)); 168 overallResult.Add(wait); 169 overallResult.Add(transfer); 170 overallResult.Add(run); 171 172 return Json(overallResult,JsonRequestBehavior.AllowGet); 173 } 214 215 List<List<double>> taskStats = new List<List<double>>(); 216 taskStats.Add(wait); 217 taskStats.Add(transfer); 218 taskStats.Add(run); 219 220 return Json(new KeyValuePair<List<string>, List<List<double>>>(id, taskStats), JsonRequestBehavior.AllowGet); 221 } 222 } 223 224 private static TaskState GetTaskState(string taskState) { 225 TaskState state = TaskState.Finished; 226 switch (taskState) 227 { 228 case "Aborted": 229 state = TaskState.Aborted; 230 break; 231 case "Calculating": 232 state = TaskState.Calculating; 233 break; 234 case "Failed": 235 state = TaskState.Failed; 236 break; 237 case "Finished": 238 state = TaskState.Finished; 239 break; 240 case "Offline": 241 state = TaskState.Offline; 242 break; 243 case "Paused": 244 state = TaskState.Paused; 245 break; 246 case "Transferring": 247 state = TaskState.Transferring; 248 break; 249 case "Waiting": 250 state = TaskState.Waiting; 251 break; 252 } 253 return state; 174 254 } 175 255 -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/Controllers/LoginRequiredController.cs
r11020 r11030 5 5 using System.Web.Mvc; 6 6 using HeuristicLab.Services.Hive.Statistics.Models; 7 using HeuristicLab.Services.Hive.DataAccess; 7 8 8 9 namespace HeuristicLab.Services.Hive.Statistics.Controllers { … … 14 15 UserName = User.Identity.Name 15 16 }; 17 18 //Initialize drop down list values 19 var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 20 ViewBag.JobNames = new SelectList(db.DimJobs, "JobId", "JobName"); 21 var TaskStateList = (from task in db.FactTasks 22 select task.TaskState).Distinct(); 23 ViewBag.TaskStates = new SelectList(TaskStateList); 24 16 25 return View(result); 17 26 } … … 25 34 if (User.IsInRole("Hive Administrator")) { 26 35 result.IsAdmin = true; 36 37 //Initialize drop down list values 38 var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString); 39 ViewBag.JobNames = new SelectList(db.DimJobs, "JobId", "JobName"); 40 var TaskStateList = (from task in db.FactTasks 41 select task.TaskState).Distinct(); 42 ViewBag.TaskStates = new SelectList(TaskStateList); 27 43 } 28 44
Note: See TracChangeset
for help on using the changeset viewer.