Example #1
0
        public static bool IsActiveDaycare(Household home)
        {
            if (Household.ActiveHousehold == null)
            {
                return(false);
            }

            foreach (SimDescription actor in Households.All(Household.ActiveHousehold))
            {
                Daycare dayCare = actor.Occupation as Daycare;
                if (dayCare == null)
                {
                    continue;
                }

                foreach (SimDescription sim in Households.All(home))
                {
                    if (dayCare.IsDaycareChild(sim))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        public async Task <IActionResult> PutDaycare(int id, Daycare daycare)
        {
            if (id != daycare.ID)
            {
                return(BadRequest());
            }

            _context.Entry(daycare).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DaycareExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Daycare> > PostDaycare(Daycare daycare)
        {
            _context.Daycare.Add(daycare);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDaycare", new { id = daycare.ID }, daycare));
        }
Example #4
0
        private List <Wish> ConvertDTOToWish(List <DataTransfer.DTOWish> dtoWishes, Daycare dc)
        {
            var list = new List <Wish>();

            dtoWishes.ForEach(w => list.Add(new Wish(dc.Employees.Find(e => e.Id == w.EmpId), w.Shift, w.Day)));
            return(list);
        }
Example #5
0
 public async Task ThrowsArgumentExceptionOnCrossTeamDuplicateWish()
 {
     var dc     = new Daycare();
     var rc     = new RotationCalculator();
     var wishes = new List <Wish>()
     {
         new Wish(dc.Employees.Find(e => e.Id == 2), 10, 1),
         new Wish(dc.Employees.Find(e => e.Id == 10), 10, 1)
     };
     await rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 0);
 }
Example #6
0
 public async Task ThrowsExceptionOnSimilarWishesWithinTeam()
 {
     var dc     = new Daycare();
     var rc     = new RotationCalculator();
     var wishes = new List <Wish>()
     {
         new Wish(dc.Employees.Find(e => e.Id == 2), 10, 1),
         new Wish(dc.Employees.Find(e => e.Id == 1), 11, 1)
     };
     await rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 0);
 }
Example #7
0
        private static List <Sim> GetDayCareChoices()
        {
            List <Sim> actives = new List <Sim>();
            List <Sim> sims    = new List <Sim>();

            foreach (Sim sim in LotManager.Actors)
            {
                Daycare career = sim.Occupation as Daycare;
                if (career == null)
                {
                    continue;
                }

                if (sim.LotCurrent != sim.LotHome)
                {
                    continue;
                }

                if (sim.Household == Household.ActiveHousehold)
                {
                    if (!GoHere.Settings.mAllowActiveDayCare)
                    {
                        continue;
                    }

                    if (career.IsWorkHour(SimClock.CurrentTime()))
                    {
                        actives.Add(sim);
                    }
                }
                else
                {
                    sims.Add(sim);
                }
            }

            if (actives.Count > 0)
            {
                return(actives);
            }
            else
            {
                return(sims);
            }
        }
Example #8
0
        public void EmployeeRotation()
        {
            var dc = new Daycare();

            dc.RotateTeamsOneWeek();
            var expected = new List <StatusEnum>()
            {
                StatusEnum.Teacher, StatusEnum.Nurse, StatusEnum.Teacher,
                StatusEnum.Nurse, StatusEnum.Nurse, StatusEnum.Teacher,
                StatusEnum.Teacher, StatusEnum.Nurse, StatusEnum.Teacher,
                StatusEnum.Nurse, StatusEnum.Nurse, StatusEnum.Teacher
            };
            var actual = new List <StatusEnum>();

            dc.Teams.ForEach(t => t.TeamEmp.ForEach(e => actual.Add(e.Status)));

            CollectionAssert.AreEqual(expected, actual);
        }
Example #9
0
        public void TeamGeneratedCorrectlyWithFalseInput()
        {
            var teams = new List <Team>()
            {
                new Team(5, 2),
                new Team(2, 1),
                new Team(6)
            };

            var dc = new Daycare(teams);

            Assert.AreEqual(0, dc.Teams[0].TeamNumber);
            Assert.AreEqual(1, dc.Teams[1].TeamNumber);
            Assert.AreEqual(2, dc.Teams[2].TeamNumber);

            var teachers = dc.Teams[2].TeamEmp.Where(e => e.Status == StatusEnum.Teacher).Count();

            Assert.AreEqual(1, teachers);
        }
Example #10
0
        public void CalculatesCorrectShiftsForSmallDaycare()
        {
            var teams = new List <Team>()
            {
                new Team(0, 1),
                new Team(1, 2)
            };
            var dc     = new Daycare(teams);
            var rc     = new RotationCalculator();
            var wishes = new List <Wish>();

            rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 1);
            var emp0Shifts = dc.Teams[0].TeamEmp[0].Shifts;
            var emp1Shifts = dc.Teams[0].TeamEmp[1].Shifts;
            var emp2Shifts = dc.Teams[0].TeamEmp[2].Shifts;
            var emp3Shifts = dc.Teams[1].TeamEmp[0].Shifts;
            var emp4Shifts = dc.Teams[1].TeamEmp[1].Shifts;
            var emp5Shifts = dc.Teams[1].TeamEmp[2].Shifts;

            var expShifts1 = new List <WorkShift>()
            {
                new WorkShift(0),
                new WorkShift(2),
                new WorkShift(4),
                new WorkShift(1, true),
                new WorkShift(2),

                new WorkShift(5),
                new WorkShift(1),
                new WorkShift(3),
                new WorkShift(4, true),
                new WorkShift(0),

                new WorkShift(2),
                new WorkShift(4),
                new WorkShift(0),
                new WorkShift(2),
                new WorkShift(5)
            };

            CollectionAssert.AreEqual(expShifts1, emp1Shifts);
        }
Example #11
0
        public void SwitchWorksCorrectly()
        {
            var dc     = new Daycare();
            var rc     = new RotationCalculator();
            var wishes = new List <Wish>()
            {
                new Wish(dc.Employees.Find(e => e.Id == 1), 1, 1),
                new Wish(dc.Employees.Find(e => e.Id == 9), 10, 1)
            };

            rc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 1);
            var actual = dc.Employees.Select(e => (int)e.Shifts[1].Shift).ToList();

            var expected = new List <int>()
            {
                8, 4, 1, 0, 5, 9, 2, 6, 11, 3, 10, 7
            };

            CollectionAssert.AreEqual(expected, actual);
        }
Example #12
0
        static void Main(string[] args)
        {
            var dc = new Daycare();

            var calc = new RotationCalculator();

            try
            {
                var wishes = new List <Wish>()
                {
                    new Wish(dc.Employees.Find(e => e.Id == 1), 10, 4),
                    //new Wish(dc.Employees.Find(e => e.Id == 6), 10, 4),
                    new Wish(dc.Employees.Find(e => e.Id == 10), 6, 1)
                };
                calc.DaycareShiftsOfThreeWeeks(dc, 0, wishes, 0);

                foreach (var team in dc.Teams)
                {
                    foreach (var emp in team.TeamEmp)
                    {
                        var shifts = emp.Id.ToString() + " " + emp.Status.ToString() + ": ";
                        foreach (var shift in emp.Shifts)
                        {
                            var num = Convert.ToInt32(shift.Shift);
                            shifts += num + ((num > 9) ? " " : "  ");
                        }
                        Console.WriteLine(shifts);
                    }
                    Console.WriteLine("\n");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #13
0
            public void ReturnChildren()
            {
                Lot lot = LotManager.GetLot(mLot);

                if (lot.Household == null)
                {
                    return;
                }

                foreach (KeyValuePair <ulong, DateAndTime> pair in mOfflotChildren)
                {
                    SimDescription simDesc = lot.Household.FindMember(pair.Key);
                    if (simDesc == null)
                    {
                        continue;
                    }

                    try
                    {
                        DaycareWorkdaySituation situation = null;

                        foreach (Situation sit in Situation.sAllSituations)
                        {
                            situation = sit as DaycareWorkdaySituation;
                            if (situation == null)
                            {
                                continue;
                            }

                            if (situation.mChildMonitors.ContainsKey(pair.Key))
                            {
                                break;
                            }

                            situation = null;
                        }

                        if (situation != null)
                        {
                            Daycare career = situation.Daycare;
                            if (career != null)
                            {
                                DateAndTime duration = SimClock.CurrentTime() - pair.Value;

                                float hours = SimClock.ConvertFromTicks(duration.Ticks, TimeUnit.Hours);

                                float careerLength = (career.FinishTime - career.StartTime);

                                float ratio = hours / careerLength;

                                string debuggingLog;

                                float xp = 0;

                                DaycareWorkdaySituation priorSituation = career.mDaycareSituation;
                                try
                                {
                                    if (career.mDaycareSituation == null)
                                    {
                                        career.mDaycareSituation = situation;
                                    }

                                    xp = career.GetExperience(pair.Key, Rating.Neutral, out debuggingLog);
                                }
                                finally
                                {
                                    career.mDaycareSituation = priorSituation;
                                }

                                xp *= ratio;

                                career.UpdateXp(xp);

                                int amount = career.GetMoney(pair.Key, Rating.Neutral, out debuggingLog);

                                amount = (int)(amount * ratio);

                                career.PayOwnerSim(amount, GotPaidEvent.PayType.kCareerBonus);

                                if (simDesc.Household != null)
                                {
                                    simDesc.ModifyFunds(-amount);
                                }
                            }

                            if ((situation.mChildMonitors != null) && (situation.mChildMonitors.Count == 1) && (situation.mChildMonitors.ContainsKey(simDesc.SimDescriptionId)))
                            {
                                for (int i = situation.mSimDescIds.Count - 1; i >= 0; i--)
                                {
                                    if (!situation.mChildMonitors.ContainsKey(situation.mSimDescIds[i]))
                                    {
                                        situation.mSimDescIds.RemoveAt(i);
                                    }
                                }
                            }

                            DaycareWorkdaySituation.ScoringRecord oldRecord;
                            if (!situation.ScoringRecords.TryGetValue(simDesc.SimDescriptionId, out oldRecord))
                            {
                                oldRecord = null;
                            }

                            // ScoringRecord will be added by RemovePerson() so remove it now
                            situation.ScoringRecords.Remove(simDesc.SimDescriptionId);

                            situation.RemovePerson(simDesc.CreatedSim);

                            if (oldRecord != null)
                            {
                                DaycareWorkdaySituation.ScoringRecord newRecord;
                                if (situation.ScoringRecords.TryGetValue(simDesc.SimDescriptionId, out newRecord))
                                {
                                    newRecord.Score            += oldRecord.Score;
                                    newRecord.ScoreDebugString += Common.NewLine + oldRecord.ScoreDebugString;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Common.Exception(simDesc, e);
                    }

                    Common.DebugNotify("Remove:" + Common.NewLine + simDesc.FullName);

                    if (simDesc.CreatedSim != null)
                    {
                        simDesc.CreatedSim.InteractionQueue.CancelAllInteractions();

                        /*
                         * while (simDesc.CreatedSim.InteractionQueue.GetCurrentInteraction() != null)
                         * {
                         *  Common.Sleep(5);
                         * }
                         */

                        GoHereEx.Teleport.Perform(simDesc.CreatedSim, simDesc.LotHome, false);
                    }
                }

                mOfflotChildren.Clear();

                GoHere.Settings.mCaregivers.Remove(mLot);
            }
Example #14
0
            public bool AddChild(Sim sim, Sim watcher)
            {
                DaycareWorkdaySituation situation = DaycareWorkdaySituation.GetDaycareWorkdaySituationForLot(sim.LotCurrent);

                if (situation != null)
                {
                    if (situation.mChildMonitors.ContainsKey(sim.SimDescription.SimDescriptionId))
                    {
                        return(true);
                    }
                }

                Daycare career = watcher.Occupation as Daycare;

                situation = DaycareWorkdaySituation.GetDaycareWorkdaySituationForLot(watcher.LotHome);
                if (situation == null)
                {
                    if (career != null)
                    {
                        situation = DaycareWorkdaySituation.CreateSituation(career);
                    }
                }

                if (situation == null)
                {
                    return(false);
                }

                if (!GoHereEx.Teleport.Perform(sim, watcher.LotHome, false))
                {
                    return(false);
                }

                // Allows toddlers to enter the house if deposited on the front porch
                sim.GreetSimOnLot(watcher.LotHome);

                if (!mOfflotChildren.ContainsKey(sim.SimDescription.SimDescriptionId))
                {
                    mOfflotChildren.Add(sim.SimDescription.SimDescriptionId, SimClock.CurrentTime());
                }

                if (!career.mDaycareChildManagers.ContainsKey(sim.SimDescription.SimDescriptionId))
                {
                    career.mDaycareChildManagers.Add(sim.SimDescription.SimDescriptionId, new DaycareChildManager(sim.SimDescription, career));
                }

                //DaycareToddlerDropoffSituation.CreateSituation(situation.Daycare, sim.SimDescription);

                CASAgeGenderFlags age     = sim.SimDescription.Age;
                float             ageDays = sim.SimDescription.AgingYearsSinceLastAgeTransition;

                try
                {
                    if (sim.SimDescription.Baby)
                    {
                        sim.SimDescription.Age = CASAgeGenderFlags.Toddler;

                        Relationship relation = Relationship.Get(sim, watcher, true);
                        if (relation != null)
                        {
                            // Required in order to pick up a baby
                            if (relation.CurrentLTRLiking < 30)
                            {
                                relation.LTR.UpdateLiking(30);
                            }
                        }
                    }

                    if (situation.mChildMonitors != null)
                    {
                        situation.mChildMonitors.Remove(sim.SimDescription.SimDescriptionId);
                    }

                    if (Common.kDebugging)
                    {
                        Common.DebugNotify("Added:" + Common.NewLine + sim.FullName + Common.NewLine + watcher.FullName);
                    }

                    situation.AddPerson(sim);
                }
                catch (Exception e)
                {
                    Common.Exception(sim, e);
                }
                finally
                {
                    if (sim.SimDescription.Age != age)
                    {
                        sim.SimDescription.Age = age;
                        sim.SimDescription.AgingYearsSinceLastAgeTransition = ageDays;
                    }
                }

                return(true);
            }
Example #15
0
        public void ReversedGivesCorrectShifts()
        {
            var dc     = new Daycare();
            var rc     = new RotationCalculator();
            var actual = new List <WorkShift>();

            dc.Teams.ForEach(d => actual.AddRange(rc.TeamShiftsOfWeek(d, 0, dc.Teams.Count, false)));
            var expected = new List <WorkShift>()
            {
                new WorkShift(0),
                new WorkShift(8),
                new WorkShift(4),
                new WorkShift(0),
                new WorkShift(8),

                new WorkShift(8),
                new WorkShift(4),
                new WorkShift(0),
                new WorkShift(8),
                new WorkShift(4),

                new WorkShift(4),
                new WorkShift(0),
                new WorkShift(8),
                new WorkShift(4),
                new WorkShift(0),

                new WorkShift(1),
                new WorkShift(9),
                new WorkShift(5),
                new WorkShift(1),
                new WorkShift(9),

                new WorkShift(9),
                new WorkShift(5),
                new WorkShift(1),
                new WorkShift(9),
                new WorkShift(5),

                new WorkShift(5),
                new WorkShift(1),
                new WorkShift(9),
                new WorkShift(5),
                new WorkShift(1),

                new WorkShift(2),
                new WorkShift(10),
                new WorkShift(6),
                new WorkShift(2),
                new WorkShift(10),

                new WorkShift(10),
                new WorkShift(6),
                new WorkShift(2),
                new WorkShift(10),
                new WorkShift(6),

                new WorkShift(6),
                new WorkShift(2),
                new WorkShift(10),
                new WorkShift(6),
                new WorkShift(2),

                new WorkShift(3),
                new WorkShift(11),
                new WorkShift(7),
                new WorkShift(3),
                new WorkShift(11),

                new WorkShift(11),
                new WorkShift(7),
                new WorkShift(3),
                new WorkShift(11),
                new WorkShift(7),

                new WorkShift(7),
                new WorkShift(3),
                new WorkShift(11),
                new WorkShift(7),
                new WorkShift(3)
            };

            CollectionAssert.AreEqual(expected, actual);
        }
Example #16
0
 private async Task Tick()
 {
     TickStart?.Invoke(null, new TickEventArgs(TickCounter));
     await Daycare.OnTick(tickCounter, Date);
 }