Example #1
0
		private static void DoWriteViolations(TextWriter writer, Severity severity, Violations violations, ref int counter)
		{
			foreach (KeyValuePair<Violation, List<Location>> pair in violations)
			{
				if (pair.Key.Severity == severity)
				{
					DoError(writer, counter, pair.Key, pair.Value);
					counter += pair.Value.Count;
				}
			}
		}
Example #2
0
        private void Process()
        {
            NeedsRegularization = false;

            IsHoliday = CheckIfHoliday();
            IsWeekEnd = AppliedPolicy.IsWeekend(Date);
            if (IsHoliday && IsPresent)
            {
                Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.WorkingOnHoliday, AllAccessEvents));
            }
            if (IsWeekEnd && IsPresent)
            {
                Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.WorkingOnWeekend, AllAccessEvents));
            }
            if (IsHoliday || IsWeekEnd)
            {
                return;
            }

            if (IsPresent)
            {
                CalculateTimeSpan_Gym();
                CalculateTimeSpan_Recreation();
                CalculateTimeSpan_OutsidePremises();
                CompensateForApprovedLeave();
                CompensateForBlockRegularization();

                //Calculation of work time should be after all the other calculations
                CalculateTimeSpan_Work();

                AppliedPolicy.Validate(WorkTimeRules.GymnasiumUsageRule);
                AppliedPolicy.Validate(WorkTimeRules.RecreationUsageRule);
                AppliedPolicy.Validate(WorkTimeRules.TotalWorkHoursPerDayRule);
                AppliedPolicy.Validate(WorkTimeRules.WorkStartEndTimingRule);
            }
            else
            {
                if (ApprovedLeave == null)
                {
                    //No leave applied yet and is absent
                    Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.AbsentWithoutLeave));
                }
                if (ApprovedLeave != null && ApprovedLeave.IsHalfDay)
                {
                    //Half day leave applied and is absent
                    Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.AbsentWithHalfDayLeave));
                }
            }
            FlaggedForSevereViolation = Violations.Where(v => v.Level == ViolationLevel.Severe).ToList().Count > 0;
        }
Example #3
0
        public string IsErr(string nameWithoutPrefix)
        {
            var result = string.Empty;

            if (Violations != null)
            {
                var v = Violations.FirstOrDefault(y => y.ControlName == nameWithoutPrefix);
                if (v != null)
                {
                    return(ErrorCssClass);
                }
            }
            return(result);
        }
Example #4
0
        private void CalculateTimeSpan_Work()
        {
            var violationsNeedingRegularizations = Violations.Where(v => v.Level == ViolationLevel.Severe || v.Level == ViolationLevel.Medium).ToList();

            if (violationsNeedingRegularizations.Count > 0)
            {
                NeedsRegularization = true;
            }

            var combinedDurationOfLunchAndRecreation = OutsidePremisesTimeSpan + RecreationTimeSpan;
            var excess = combinedDurationOfLunchAndRecreation - TimeSpan.FromMinutes(45.0);

            if (excess < TimeSpan.FromMinutes(0))
            {
                excess = TimeSpan.FromMinutes(0);
            }
            WorkTime = TotalDuration + LeaveTimeCompensation + BlockRegularizationCompensation - (excess + GymnasiumTimeSpan);
        }
Example #5
0
        public static Violations GetViolations(Error[] errors)
        {
            Violations violations = new Violations(errors.Length);

            foreach (Error error in errors)
            {
                List <Location> locations = null;

                if (!violations.TryGetValue(error.Violation, out locations))
                {
                    locations = new List <Location>();
                    violations.Add(error.Violation, locations);
                }

                locations.Add(error.Location);
            }

            return(violations);
        }
Example #6
0
		public static Violations GetViolations(Error[] errors)
		{
			Violations violations = new Violations(errors.Length);
			
			foreach (Error error in errors)
			{
				List<Location> locations = null;
				
				if (!violations.TryGetValue(error.Violation, out locations))
				{
					locations = new List<Location>();
					violations.Add(error.Violation, locations);
				}
				
				locations.Add(error.Location);
			}
			
			return violations;
		}
Example #7
0
 private void CompensateForApprovedLeave()
 {
     if (ApprovedLeave == null)
     {
         LeaveTimeCompensation = TimeSpan.FromHours(0);
         return;
     }
     if (ApprovedLeave.IsHalfDay)
     {
         LeaveTimeCompensation = TimeSpan.FromHours(4.5);
     }
     else
     {
         LeaveTimeCompensation = TimeSpan.FromHours(9.0);
         if (IsPresent)
         {
             Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.WorkingOnLeaveDay, AllAccessEvents));
         }
     }
 }
Example #8
0
        private void CalculateTimeSpan_Gym()
        {
            var swipes = SwipesAtAccessPoint("Gym").OrderBy(x => x.EventTime).ToList();

            if (swipes.Count % 2 == 1)
            {
                Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.OddAccessEvents_Gymnasium, swipes));
            }
            else
            {
                TimeSpan gymnasiumTime = TimeSpan.FromDays(0);
                for (int i = 1; i < swipes.Count; i += 2)
                {
                    var a = swipes[i].EventTime;
                    var b = swipes[i + 1].EventTime;
                    gymnasiumTime += (b - a);
                }
                GymnasiumTimeSpan = gymnasiumTime;
            }
        }
Example #9
0
        public async Task My_Points()
        {
            var violator = await _mongo.GetCollection <Violator>(Context.Client).GetUserAsync(Context.Guild.Id, Context.User.Id);

            var penalties = await _mongo.GetCollection <Penalty>(Context.Client).GetPenaltiesAsync(Context.Guild.Id);

            violator = await Violations.TryDecreasePoints(Context, violator);

            var nextPenalty = penalties.OrderBy(p => p.RequiredPoints).FirstOrDefault(penalty => penalty.RequiredPoints > violator.Points);

            var until = TimeSpan.Zero;

            if (violator.Points > 0)
            {
                until = violator.LatestViolation.AddHours(_config.PointDecreaseHours) - DateTime.UtcNow;
            }
            await ReplyAsync(
                // ReSharper disable once UseFormatSpecifierInInterpolation
                $"You currently have {violator.Points} points. {(until != TimeSpan.Zero ? $"You will lose one point in {until.ToString(@"hh'h'\:mm'm'\:ss's'")}" : "")}" +
                $"{(nextPenalty != null ? $"\nThe next Penalty*({nextPenalty.PenaltyType})* is at {nextPenalty.RequiredPoints} points" : "")}");
        }
Example #10
0
        private void AddViolation(DateTimeOffset startDateTime, DateTimeOffset endDateTime, Enums.ViolationType violationType, Jurisdiction jurisdiction)
        {
            switch (violationType)
            {
            case Enums.ViolationType.Driving:
                ViolationDurationDrivingSinceLastDailyReset = ViolationDurationDrivingSinceLastDailyReset.Add(endDateTime.Subtract(startDateTime));
                break;

            case Enums.ViolationType.OnDuty:
                ViolationDurationOnDutySinceLastDailyReset = ViolationDurationOnDutySinceLastDailyReset.Add(endDateTime.Subtract(startDateTime));
                break;

            case Enums.ViolationType.Rest:
                ViolationDurationOnDutySinceLastRestBreak = ViolationDurationOnDutySinceLastRestBreak.Add(endDateTime.Subtract(startDateTime));
                break;

            case Enums.ViolationType.Weekly:
                ViolationDurationOnDutySinceLastWeeklyReset = ViolationDurationOnDutySinceLastWeeklyReset.Add(endDateTime.Subtract(startDateTime));
                break;
            }
            Violations.Add(new DutyStatusViolation(startDateTime, endDateTime, violationType, jurisdiction.JurisdictionId));
        }
Example #11
0
        private void CalculateTimeSpan_OutsidePremises()
        {
            var swipes = SwipesAtAccessPoint("Main Entry").OrderBy(x => x.EventTime).ToList();

            if (swipes.Count % 2 == 1)
            {
                Violations.Add(WorkTimeViolation.GetViolation(WorkTimeViolationType.OddAccessEvents_PremisesEntry, swipes));
            }
            else
            {
                TimeSpan outPremisesTime = TimeSpan.FromDays(0);
                if (swipes.Count > 2)
                {
                    for (int i = 1; i < swipes.Count; i += 2)
                    {
                        var a = swipes[i].EventTime;
                        var b = swipes[i + 1].EventTime;
                        outPremisesTime += (b - a);
                    }
                }
                OutsidePremisesTimeSpan = outPremisesTime;
            }
        }
Example #12
0
        /// <summary>
        /// Runs StyleCop+ for specified file.
        /// </summary>
        public void Run(string sourceFile, SpecialRunningParameters specialRunningParameters)
        {
            Violations.Clear();
            Output.Length = 0;

            string basePath = AppDomain.CurrentDomain.BaseDirectory;

            StyleCopConsole console = new StyleCopConsole(
                null,
                false,
                null,
                new List <string>(new[] { basePath }),
                true);

            StyleCopPlusRules styleCopPlus = ExtractStyleCopPlus(console);

            if (styleCopPlus == null)
            {
                throw new InvalidOperationException("StyleCopPlus was not found.");
            }

            styleCopPlus.SpecialRunningParameters = specialRunningParameters;

            CodeProject project = new CodeProject(
                0,
                basePath,
                new Configuration(null));

            console.Core.Environment.AddSourceCode(project, sourceFile, null);

            console.ViolationEncountered += OnViolationEncountered;
            console.OutputGenerated      += OnOutputGenerated;
            console.Start(new[] { project }, true);

            console.OutputGenerated      -= OnOutputGenerated;
            console.ViolationEncountered -= OnViolationEncountered;
        }
 // Count the number of violations at the specified level
 public Int32 CountViolationLevel(ViolationLevel level)
 {
     return(Violations.Count(v => v.m_level == level));
 }
Example #14
0
        public override int GetHashCode()
        {
            unchecked
            {
                // Choose large primes to avoid hashing collisions
                const int HashingBase       = (int)2166136261;
                const int HashingMultiplier = 16777619;

                int hash = HashingBase;
                hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, DriverAge) ? DriverAge.GetHashCode() : 0);
                hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Relationship) ? Relationship.GetHashCode() : 0);
                hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, StudentStatus) ? StudentStatus.GetHashCode() : 0);
                hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Violations) ? Violations.GetHashCode() : 0);
                hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, DriverGPA) ? DriverGPA.GetHashCode() : 0);
                hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, MaritalStatus) ? MaritalStatus.GetHashCode() : 0);
                return(hash);
            }
        }
Example #15
0
 /// <summary>
 /// Handles encountered violations.
 /// </summary>
 private void OnViolationEncountered(object sender, ViolationEventArgs e)
 {
     Violations.Add(e.Violation.Rule.Name);
 }
Example #16
0
        public ActionResult NewOrEdit(Violations model, FormCollection frm)
        {
            try
            {
                var db = DB.Entities;
                model.Date_occurred = CommonFunction.ChangeFormatDate(frm["Date_occurred"]);
                model.Date_resolved = CommonFunction.ChangeFormatDate(frm["Date_resolved"]);
                if (model.ID == 0)
                {
                    // Edit

                    db.Violations.AddObject(model);
                }
                else
                {
                    // Add new
                    db.AttachTo("Violations", model);
                    db.ObjectStateManager.ChangeObjectState(model, System.Data.EntityState.Modified);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                #region SELECT OPTION
                string dataDriver_Info = "<option value=''>--Select Driver_Info--</option>";
                foreach (var item in NationalIT.DB.Entities.Driver_Info)
                {
                    if (model != null && model.Driver == item.ID)
                    {
                        dataDriver_Info += string.Format("<option value='{0}' selected='selected'>{1} {2}</option>", item.ID, item.Last_name, item.First_name);
                    }
                    else
                    {
                        dataDriver_Info += string.Format("<option value='{0}'>{1} {2}</option>", item.ID, item.Last_name, item.First_name);
                    }
                }
                ViewBag.dataDriver_Info = dataDriver_Info;

                string dataEquipment = "<option value=''>--Select Equiment--</option>";
                foreach (var item in NationalIT.DB.Entities.Equipment)
                {
                    if (model != null && model.Equipment == item.ID)
                    {
                        dataEquipment += string.Format("<option value='{0}' selected='selected'>{1} - {2}</option>", item.ID, item.Equipment_number, item.Equipment_Type);
                    }
                    else
                    {
                        dataEquipment += string.Format("<option value='{0}'>{1} - {2}</option>", item.ID, item.Equipment_number, item.Equipment_Type);
                    }
                }
                ViewBag.dataEquipment = dataEquipment;

                string dataDispatcher = "<option value=''>--Select Dispatcher--</option>";
                foreach (var item in NationalIT.DB.Entities.Dispatchers)
                {
                    if (model != null && model.DispatcherID == item.ID)
                    {
                        dataDispatcher += string.Format("<option value='{0}' selected='selected'>{1} {2}</option>", item.ID, item.Last_name, item.First_name);
                    }
                    else
                    {
                        dataDispatcher += string.Format("<option value='{0}'>{1} {2}</option>", item.ID, item.Last_name, item.First_name);
                    }
                }
                ViewBag.dataDispatcher = dataDispatcher;
                #endregion
                return(View(model));
            }
        }