Esempio n. 1
0
 public Notification(Computer comp, Lab lab, string departmentName, Constant.NotificationType type, int days)
 {
     DepartmentName   = departmentName;
     Building         = lab.Building;
     RoomNumber       = lab.RoomNumber;
     ComputerName     = comp.ComputerName;
     LabId            = lab.LabId;
     NotificationType = type;
     Days             = days;
 }
Esempio n. 2
0
        public int NumberOfAvilableComputers(Lab lab)
        {
            List <int> freeComp = new List <int>();

            if (IsLabOccupied(lab))
            {
                return(0);
            }
            List <Task> tasks = new List <Task>();
            List <int>  ids   = lab.Computers.Select(e => e.ComputerId).ToList();

            foreach (int id in ids)
            {
                tasks.Add(Task.Run(() => IsComputerAvilable(id, freeComp)));
                //IsComputerAvilable(id, freeComp);
            }
            Task.WaitAll(tasks.ToArray());
            return(freeComp.Count());
        }
Esempio n. 3
0
        public LabOccupancyReport CreateOccupancyLabReport(DateTime startDate, DateTime endDate, DateTime startHour, DateTime endHour, Lab lab, bool weekends)
        {
            LabOccupancyReport labReport = new LabOccupancyReport(lab);

            TimeSpan labTotalActiveTime = TimeSpan.Zero;

            List <ComputerLab> cL           = getComputerInLab(lab, startDate, endDate);
            List <int>         hoursToCheck = new List <int>();
            Dictionary <int, LabHourOccupancyReport> hourReports = new Dictionary <int, LabHourOccupancyReport>();

            for (int start = startHour.Hour; start < endHour.Hour; start++)
            {
                hoursToCheck.Add(start);
                hourReports.Add(start, new LabHourOccupancyReport(start));
            }
            Dictionary <DayOfWeek, LabDayOfWeekReport> weekDayReports = new Dictionary <DayOfWeek, LabDayOfWeekReport>();

            for (int i = 0; i < 7; i++)
            {
                if (!weekends && isWeekend((DayOfWeek)i))
                {
                    continue;
                }
                weekDayReports.Add((DayOfWeek)i, new LabDayOfWeekReport((DayOfWeek)i));
            }

            //for each day
            for (DateTime date = startDate.Date; date < endDate.Date; date = date.AddDays(1))
            {
                //skip the weekends dates if weekends unincluded
                if (!weekends && isWeekend(date.DayOfWeek))
                {
                    continue;
                }
                double maxCompNum = 0;
                double minCompNum = int.MaxValue;
                double sum        = 0;
                //for each hour check how many computers were on
                foreach (var hour in hoursToCheck.ToList())
                {
                    int    computerCount = 0;
                    int    computers     = 0;
                    double occPrecent    = 0;
                    foreach (var item in cL.ToList())
                    {
                        //if the computer were in the lab in this specific day
                        if (date >= item.Entrance.Date && (!item.Exit.HasValue || date <= item.Exit.Value.Date))
                        {
                            if (IsComputerActive(date, hour, item.ComputerId))
                            {
                                computerCount++;
                            }
                            computers++;
                        }
                    }
                    if (computers > 0)
                    {
                        occPrecent = (double)computerCount / computers;
                    }
                    maxCompNum = Math.Max(maxCompNum, occPrecent);
                    minCompNum = Math.Min(minCompNum, occPrecent);
                    sum       += occPrecent;
                    hourReports[hour].AddDay(occPrecent);
                }
                weekDayReports[date.DayOfWeek].AddDay(maxCompNum, minCompNum, sum / hoursToCheck.Count);
            }

            foreach (var item in weekDayReports)
            {
                labReport.AddByDayReport(item.Value);
            }
            foreach (var item in hourReports)
            {
                labReport.AddByHourReport(item.Value);
            }
            return(labReport);
        }
Esempio n. 4
0
        public LabOccupancyReport CreateOccupancyLabReport(DateTime startDate, DateTime endDate, DateTime startHour, DateTime endHour, int id, bool weekends)
        {
            Lab lab = _lController.GetLab(id);

            return(CreateOccupancyLabReport(startDate, endDate, startHour, endHour, lab, weekends));
        }
Esempio n. 5
0
 /// <summary>
 /// get all computers that were in the lab during that time or part of it
 /// </summary>
 /// <param name="lab"></param>
 /// <param name="startDate"></param>
 /// <param name="endDate"></param>
 /// <returns></returns>
 private List <ComputerLab> getComputerInLab(Lab lab, DateTime startDate, DateTime endDate)
 {
     return(lab.ComputerLabs.Where(e => (!((e.Entrance > endDate) || (e.Exit < startDate)))).ToList());
 }
Esempio n. 6
0
        public LabReport CreateLabReport(DateTime startDate, DateTime endDate, DateTime startHour, DateTime endHour, Lab lab, bool weekends)
        {
            LabReport          labReport = new LabReport(lab);
            List <Task>        tasks     = new List <Task>();
            List <ComputerLab> cL        = getComputerInLab(lab, startDate, endDate);

            foreach (var item in cL)
            {
                //  Task t = Task.Factory.StartNew(() =>
                //  {
                ComputerReport cR = CreateComputerInLabReport(startDate, endDate, startHour, endHour, item, weekends);

                //add data to labreport
                lock (reportLock)
                {
                    labReport.ComputersReport.Add(cR);
                    labReport.AddToLabTotalActivityTime(cR.GetComputerTotalActiveTime());
                    labReport.AddToLabTotalActivityTimeWithClasses(cR.GetComputerTotalActiveTimeWithClasses());
                    labReport.AddToLabTotalHours(cR.GetComputerTotalTime());
                }
                //  });
                //  tasks.Add(t);
            }
            Task.WaitAll(tasks.ToArray());

            return(labReport);
        }
Esempio n. 7
0
 public LabDetailsViewModel(Lab lab, LabsController labsController)
 {
     this.Lab          = lab;
     this._lController = labsController;
     this.domain       = Lab.Department.Domain;
 }
Esempio n. 8
0
 public LabReport(Lab lab)
 {
     Lab                = lab;
     ComputersReport    = new List <ComputerReport>();
     labTotalActiveTime = TimeSpan.Zero;
 }
Esempio n. 9
0
 public LabOccupancyReport(Lab lab)
 {
     Lab     = lab;
     ByHours = new List <LabHourOccupancyReport>();
     ByDay   = new List <LabDayOfWeekReport>();
 }