public AvatarPicker(ImageList avatarImageList, PersonSetting personSetting) { _imageService = new ImageService(); _okToClose = true; _avatarImageList = avatarImageList; _personSetting = personSetting; InitializeComponent(); emailTextbox.Text = personSetting.Email; if (personSetting.Email != null) { _gravatar.SetImage(personSetting, avatarImageList); tabControl1.SelectedIndex = 1; } if (personSetting.AvatarImageName != null) { _croppedCustom.ImageLocation = Path.Combine(SirenOfShameSettings.GetAvatarsFolder(), personSetting.AvatarImageName); tabControl1.SelectedIndex = 2; } int avatarCount = SirenOfShameSettings.AVATAR_COUNT; for (int i = 0; i < avatarCount; i++) { Avatar avatar = new Avatar(); avatar.SetImage(i, avatarImageList); avatar.Click += AvatarOnClick; flowLayoutPanel1.Controls.Add(avatar); } }
public static double? CalculateLowestBuildRatioAfter50Builds(PersonSetting personSetting, IEnumerable<BuildStatus> allActiveBuildDefinitionsOrderedChronoligically) { int totalBuilds = 0; int unsuccessfulBuilds = 0; double lowestRatio = 0.0; List<BuildStatus> buildStatuses = allActiveBuildDefinitionsOrderedChronoligically .Where(i => i.RequestedBy == personSetting.RawName) .ToList(); if (buildStatuses.Count < 50) return null; double currentRatio = 0; DateTime? lowestRatioAchieved = null; foreach (var buildStatus in buildStatuses) { totalBuilds++; if (buildStatus.BuildStatusEnum == BuildStatusEnum.Broken) unsuccessfulBuilds++; currentRatio = (double)unsuccessfulBuilds / totalBuilds; if (totalBuilds == 50) { lowestRatio = currentRatio; lowestRatioAchieved = buildStatus.StartedTime; } if (totalBuilds > 50) { var oldLowestRatio = lowestRatio; lowestRatio = Math.Min(currentRatio, lowestRatio); if (Math.Abs(oldLowestRatio - lowestRatio) > .001) { lowestRatioAchieved = buildStatus.StartedTime; } } } _log.Debug(string.Format("{0}'s lowest build ratio is {1:p}. They achieved it on {3:d}. Their current ratio is {2:p}", personSetting.RawName, lowestRatio, currentRatio, lowestRatioAchieved)); return lowestRatio; }
public static int HowManyTimesHasPerformedBackToBackBuildsForABuild(PersonSetting activePerson, IEnumerable<BuildStatus> currentBuildDefinitionOrderedChronoligically) { BuildStatus lastBuild = null; int backToBack = 0; foreach (var buildStatus in currentBuildDefinitionOrderedChronoligically) { bool lastBuildWasByActivePerson = lastBuild != null && lastBuild.RequestedBy == activePerson.RawName; bool currentBuildIsByActivePerson = buildStatus.RequestedBy == activePerson.RawName; if (lastBuildWasByActivePerson && currentBuildIsByActivePerson) { bool lastBuildPassed = lastBuild.BuildStatusEnum == BuildStatusEnum.Working; bool currentBuildPassed = buildStatus.BuildStatusEnum == BuildStatusEnum.Working; bool wereBackToBack = lastBuild.IsBackToBackWithNextBuild(buildStatus); if (lastBuildPassed && currentBuildPassed && wereBackToBack) { backToBack++; } } lastBuild = buildStatus; } _log.Debug(activePerson.RawName + " has achieved back to back successful builds " + backToBack + " times"); return backToBack; }
public PersonSetting FindAddPerson(string requestedBy, int avatarCount = AVATAR_COUNT) { if (string.IsNullOrEmpty(requestedBy)) { _log.Warn("Tried to add a person with a null RawName"); return(null); } var person = FindPersonByRawName(requestedBy); if (person != null) { return(person); } person = new PersonSetting { DisplayName = requestedBy, RawName = requestedBy, FailedBuilds = 0, TotalBuilds = 0, AvatarId = People.Count % avatarCount }; People.Add(person); Save(); return(person); }
public static int HowManyTimesHasPerformedBackToBackBuildsAcrossBuilds(PersonSetting activePerson, IEnumerable<BuildStatus> allActiveBuildDefinitionsOrderedChronoligically) { return allActiveBuildDefinitionsOrderedChronoligically .GroupBy(i => i.BuildDefinitionId) .Select(i => HowManyTimesHasPerformedBackToBackBuildsForABuild(activePerson, i)) .Aggregate(0, (i, j) => i + j); }
public static double CalculateCurrentBuildRatio(PersonSetting personSetting, IEnumerable<BuildStatus> allActiveBuildDefinitionsOrderedChronoligically) { var currentUserBuilds = allActiveBuildDefinitionsOrderedChronoligically.Where(i => i.RequestedBy == personSetting.RawName).ToList(); var totalBuilds = currentUserBuilds.Count; var unsuccessfulBuilds = currentUserBuilds.Count(i => i.BuildStatusEnum == BuildStatusEnum.Broken); return totalBuilds == 0 ? 0 : (double)unsuccessfulBuilds/totalBuilds; }
public void OnlyOnePersonOnProject() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser", TotalBuilds = 110, FailedBuilds = 0 }; var people = new List<PersonSetting> { personSetting, }; Assert.IsFalse(new Napoleon(personSetting, people).HasJustAchieved()); }
public static int CalculateSuccessInARow(PersonSetting personSetting, IEnumerable<BuildStatus> allActiveBuildDefinitionsOrderedChronoligically) { return allActiveBuildDefinitionsOrderedChronoligically .Reverse() .Where(i => i.RequestedBy == personSetting.RawName) .TakeWhile(i => i.BuildStatusEnum != BuildStatusEnum.Broken) .Count(); }
public void WasJustLikeLightning_ZeroBuilds() { var fakePersonSetting = new PersonSetting { RawName = "currentUser" }; var builds = new List<BuildStatus> { }; Assert.AreEqual(false, new LikeLightning(fakePersonSetting, builds).HasJustAchieved()); }
public bool IsMeOrDefault(PersonSetting person, bool defaultValue) { if (string.IsNullOrEmpty(MyRawName)) { return(defaultValue); } return(person.RawName == MyRawName); }
public void RefreshStats(PersonSetting person) { _reputation.Text = person.GetReputation().ToString(CultureInfo.InvariantCulture); _achievements.Text = person.Achievements.Count.ToString(CultureInfo.InvariantCulture); _failPercent.Text = string.Format("{0:p1}", person.CurrentBuildRatio).Replace(" ", ""); _successfulBuildsInARow.Text = string.Format("{0}", person.CurrentSuccessInARow); _fixedSomeoneElsesBuild.Text = string.Format("{0}", person.NumberOfTimesFixedSomeoneElsesBuild); _totalBuilds.Text = string.Format("{0}", person.TotalBuilds); }
public void OnlyOneBuild() { PersonSetting personSetting = new PersonSetting {RawName = "currentUser"}; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { RequestedBy = "currentUser", StartedTime = new DateTime(2010, 1, 1, 1, 1, 59), BuildStatusEnum = BuildStatusEnum.Working }, }; Assert.IsFalse(new AndGotAwayWithIt(personSetting, builds).HasJustAchieved()); }
public void GetBothDisplayAndRawNames_RawNameNoDisplayName_OnlyShowsRawName() { var personSetting = new PersonSetting { RawName = "dev\\lrichard", DisplayName = "dev\\lrichard" }; Assert.AreEqual("dev\\lrichard", personSetting.GetBothDisplayAndRawNames()); }
public void GetBothDisplayAndRawNames_DisplayNameAndRawName_DisplaysBoth() { var personSetting = new PersonSetting { RawName = "dev\\lrichard", DisplayName = "Lee Richardson" }; Assert.AreEqual("Lee Richardson (dev\\lrichard)", personSetting.GetBothDisplayAndRawNames()); }
public void SirenNeverBeenConnected() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser" }; SirenOfShameSettings settings = new SirenOfShameSettings(false) { SirenEverConnected = false, MyRawName = "currentUser" }; Assert.AreEqual(false, new ShamePusher(personSetting, settings).HasJustAchieved()); }
public void BrokenThenFixed_BothByCurrentUser_ButWithin60Seconds_() { PersonSetting personSetting = new PersonSetting {RawName = "currentUser"}; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { RequestedBy = "currentUser", FinishedTime = new DateTime(2010, 1, 1, 1, 1, 1), BuildStatusEnum = BuildStatusEnum.Broken }, new BuildStatus { RequestedBy = "currentUser", StartedTime = new DateTime(2010, 1, 1, 1, 2, 1), BuildStatusEnum = BuildStatusEnum.Working }, }; Assert.IsFalse(new AndGotAwayWithIt(personSetting, builds).HasJustAchieved()); }
public void NullStartAndEndTimes() { PersonSetting personSetting = new PersonSetting {RawName = "currentUser"}; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Broken }, new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Working }, }; Assert.IsFalse(new AndGotAwayWithIt(personSetting, builds).HasJustAchieved()); }
public void BackToBackOnce() { var fakePersonSetting = new PersonSetting { RawName = "currentUser" }; var builds = new List<BuildStatus> { new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 2, 2), FinishedTime = new DateTime(2010, 2, 2, 2, 3, 2)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 3, 3), FinishedTime = new DateTime(2010, 2, 2, 2, 4, 3)}, }; Assert.AreEqual(1, BackToBackBuilds.HowManyTimesHasPerformedBackToBackBuildsForABuild(fakePersonSetting, builds)); }
public void SirenHasBeenConnectedButDifferentUserCheckedIn() { PersonSetting personSetting = new PersonSetting {RawName = "someoneElse"}; SirenOfShameSettings settings = new SirenOfShameSettings(false) { SirenEverConnected = true, MyRawName = "currentUser" }; Assert.AreEqual(false, new ShamePusher(personSetting, settings).HasJustAchieved()); }
public void TwoBuildsWithin59Seconds_BrokenThenFixed_ButByDifferentUsers() { PersonSetting personSetting = new PersonSetting {RawName = "currentUser"}; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { RequestedBy = "someoneElse", FinishedTime = new DateTime(2010, 1, 1, 1, 1, 1), BuildStatusEnum = BuildStatusEnum.Broken }, new BuildStatus { RequestedBy = "currentUser", StartedTime = new DateTime(2010, 1, 1, 1, 1, 59), BuildStatusEnum = BuildStatusEnum.Working }, }; Assert.IsFalse(new AndGotAwayWithIt(personSetting, builds).HasJustAchieved()); }
public void CurrentUserHas99MorePointsThanAnyoneElse() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser", TotalBuilds = 110, FailedBuilds = 0 }; var people = new List<PersonSetting> { personSetting, new PersonSetting { RawName = "someoneElse", TotalBuilds = 11, FailedBuilds = 0 }, new PersonSetting { RawName = "someoneElseElse", TotalBuilds = 5, FailedBuilds = 0 }, }; Assert.IsFalse(new Napoleon(personSetting, people).HasJustAchieved()); }
public void ExcludesNullDates() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser" }; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { RequestedBy = "currentUser", StartedTime = null}, }; var max = MaxBuildsInOneDay.GetMaxBuildsInOneDay(personSetting, builds); Assert.AreEqual(0, max); }
public void IgnoreNullStartOrEndTimes() { PersonSetting person = new PersonSetting {RawName = "CurrentUser"}; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { StartedTime = new DateTime(2010, 1, 1, 1, 1, 0), FinishedTime = null, BuildStatusEnum = BuildStatusEnum.Working}, new BuildStatus { StartedTime = new DateTime(2010, 1, 1, 2, 1, 0), FinishedTime = new DateTime(2010, 1, 1, 2, 2, 29), BuildStatusEnum = BuildStatusEnum.Working}, }; Assert.IsFalse(new Macgyver(person, builds).HasJustAchieved()); }
public void AcrossBuilds_BackToBackWithinBuildDoesCount() { var fakePersonSetting = new PersonSetting { RawName = "currentUser" }; var builds = new List<BuildStatus> { new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, BuildDefinitionId = "1", RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 2, 2), FinishedTime = new DateTime(2010, 2, 2, 2, 3, 2)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, BuildDefinitionId = "1", RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 3, 3), FinishedTime = new DateTime(2010, 2, 2, 2, 4, 3)}, }; Assert.AreEqual(1, BackToBackBuilds.HowManyTimesHasPerformedBackToBackBuildsAcrossBuilds(fakePersonSetting, builds)); }
public void WasJustLikeLightning_ThreeBackToBackBuilds() { var fakePersonSetting = new PersonSetting { RawName = "currentUser" }; var builds = new List<BuildStatus> { new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 2, 2), FinishedTime = new DateTime(2010, 2, 2, 2, 3, 2)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 3, 3), FinishedTime = new DateTime(2010, 2, 2, 2, 4, 3)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 4, 4), FinishedTime = new DateTime(2010, 2, 2, 2, 5, 4)}, }; Assert.AreEqual(true, new LikeLightning(fakePersonSetting, builds).HasJustAchieved()); }
public void CurrentBuildRatio() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser" }; List<BuildStatus> builds = new List<BuildStatus>(); builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Broken }); builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Working }); builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Working }); builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Working }); builds.Add(new BuildStatus { RequestedBy = "someoneElse", BuildStatusEnum = BuildStatusEnum.Working }); Assert.AreEqual(0.25, BuildRatio.CalculateCurrentBuildRatio(personSetting, builds)); }
public static int GetMaxBuildsInOneDay(PersonSetting personSetting, List<BuildStatus> currentBuildDefinitionOrderedChronoligically) { var buildsGroupedByDay = currentBuildDefinitionOrderedChronoligically .Where(i => i.RequestedBy == personSetting.RawName && i.StartedTime != null) .GroupBy(i => new DateTime(i.StartedTime.Value.Year, i.StartedTime.Value.Month, i.StartedTime.Value.Day)) .ToList(); if (buildsGroupedByDay.Count == 0) return 0; // rare: only if there's one build and it didn't have a start date int maxBuildsInOneDay = buildsGroupedByDay.Max(i => i.Count()); _log.Debug("Max builds in one day for " + personSetting.RawName + " on " + currentBuildDefinitionOrderedChronoligically.First().BuildDefinitionId + " is " + maxBuildsInOneDay); return maxBuildsInOneDay; }
public void WasJustLikeLightning_ThreeBuildsOneSecondApartWithDifferentUser() { var fakePersonSetting = new PersonSetting { RawName = "currentUser" }; var builds = new List<BuildStatus> { new BuildStatus { BuildStatusEnum = BuildStatusEnum.Broken, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 2, 2), FinishedTime = new DateTime(2010, 2, 2, 2, 3, 2)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "someoneElse", StartedTime = new DateTime(2010, 2, 2, 2, 3, 3), FinishedTime = new DateTime(2010, 2, 2, 2, 4, 3)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 4, 4), FinishedTime = new DateTime(2010, 2, 2, 2, 5, 4)}, }; Assert.AreEqual(false, new LikeLightning(fakePersonSetting, builds).HasJustAchieved()); }
public void OneBuildEachDay_MaxIsOne() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser" }; List<BuildStatus> builds = new List<BuildStatus> { new BuildStatus { RequestedBy = "currentUser", StartedTime = new DateTime(2010, 1, 1, 1, 1, 1)}, new BuildStatus { RequestedBy = "currentUser", StartedTime = new DateTime(2010, 1, 2, 1, 1, 1)}, }; var max = MaxBuildsInOneDay.GetMaxBuildsInOneDay(personSetting, builds); Assert.AreEqual(1, max); }
public void WasJustLikeLightning_OneBuildIsMissingFinishedTime() { var fakePersonSetting = new PersonSetting { RawName = "currentUser" }; var builds = new List<BuildStatus> { new BuildStatus { BuildStatusEnum = BuildStatusEnum.Broken, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 2, 2), FinishedTime = new DateTime(2010, 2, 2, 2, 3, 2)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 3, 3), FinishedTime = new DateTime(2010, 2, 2, 2, 4, 3)}, new BuildStatus { BuildStatusEnum = BuildStatusEnum.Working, RequestedBy = "currentUser", StartedTime = new DateTime(2010, 2, 2, 2, 4, 4), FinishedTime = null}, }; Assert.AreEqual(false, new LikeLightning(fakePersonSetting, builds).HasJustAchieved()); }
public NewNewsItemEventArgs AsNewNewsItem(PersonSetting person) { return(new NewNewsItemEventArgs { Person = person, EventDate = DateTime.Now, NewsItemType = NewsItemTypeEnum.NewAchievement, BuildDefinitionId = null, ReputationChange = null, Title = "Achieved " + Name, }); }
public void Exactly50BuildsOneFailed_ButFailedBuildIsSomeoneElse() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser"}; List<BuildStatus> builds = new List<BuildStatus>(); builds.Add(new BuildStatus { RequestedBy = "someoneElse", BuildStatusEnum = BuildStatusEnum.Broken }); for (int i = 0; i < 49; i++) { builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Working }); } Assert.AreEqual(50, builds.Count); Assert.IsNull(BuildRatio.CalculateLowestBuildRatioAfter50Builds(personSetting, builds)); }
public void Exactly100BuildsOneFailedLowestPercentageIsOnePercent() { PersonSetting personSetting = new PersonSetting { RawName = "currentUser"}; List<BuildStatus> builds = new List<BuildStatus>(); builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Broken }); for (int i = 0; i < 99; i++) { builds.Add(new BuildStatus { RequestedBy = "currentUser", BuildStatusEnum = BuildStatusEnum.Working }); } Assert.AreEqual(100, builds.Count); Assert.AreEqual(0.01, BuildRatio.CalculateLowestBuildRatioAfter50Builds(personSetting, builds)); }