public void CurrentFrameTest3() { var unitInfo = new UnitInfo(); var unitFrame = new UnitFrame { FrameID = 0 }; unitInfo.SetUnitFrame(unitFrame); unitFrame = new UnitFrame { FrameID = 1 }; unitInfo.SetUnitFrame(unitFrame); unitFrame = new UnitFrame { FrameID = 5 }; unitInfo.SetUnitFrame(unitFrame); Assert.AreSame(unitFrame, unitInfo.CurrentFrame); }
public void GetUnitFrameTest2() { var unitInfo = new UnitInfo(); unitInfo.SetUnitFrame(new UnitFrame { FrameID = 0 }); Assert.IsNotNull(unitInfo.GetUnitFrame(0)); Assert.IsNull(unitInfo.GetUnitFrame(1)); }
public void CurrentFrameTest4() { var unitInfo = new UnitInfo(); var unitFrame = new UnitFrame { FrameID = -1 }; unitInfo.SetUnitFrame(unitFrame); Assert.IsNull(unitInfo.CurrentFrame); }
public void AllFramesCompleted1() { var unitInfo = new UnitInfo(); unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 100)); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.IsTrue(unitInfoLogic.AllFramesCompleted); }
public void PerThreeSectionsTest1() { var protein = new Protein { ProjectNumber = 1, Credit = 100 }; var unitInfo = new UnitInfo { FramesObserved = 5 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:05:10", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:11:30", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:17:40", 3)); unitInfo.SetUnitFrame(MakeUnitFrame("00:24:00", 4)); var unitInfoLogic = CreateUnitInfoLogic(protein, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(376, unitInfoLogic.GetRawTime(PpdCalculationType.LastThreeFrames)); Assert.AreEqual(TimeSpan.FromSeconds(376), unitInfoLogic.GetFrameTime(PpdCalculationType.LastThreeFrames)); Assert.AreEqual(229.78723, unitInfoLogic.GetPPD(SlotStatus.Unknown, PpdCalculationType.LastThreeFrames, BonusCalculationType.None)); }
public void PercentCompleteTest2() { var protein = new Protein { Frames = 200 }; var unitInfo = new UnitInfo(); unitInfo.SetUnitFrame(new UnitFrame { FrameID = 5 }); var unitInfoLogic = CreateUnitInfoLogic(protein, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(2, unitInfoLogic.PercentComplete); }
public void PercentCompleteTest1() { var unitInfo = new UnitInfo(); unitInfo.SetUnitFrame(new UnitFrame { FrameID = 5 }); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(5, unitInfoLogic.PercentComplete); }
public void SetCurrentFrameTest1() { var unitInfo = new UnitInfo(); var unitFrame = new UnitFrame { RawFramesComplete = 0, RawFramesTotal = 100000, FrameID = 0, TimeOfFrame = new TimeSpan(0, 0, 0), FrameDuration = new TimeSpan(0, 0, 0) }; unitInfo.SetUnitFrame(unitFrame); Assert.AreEqual(0, unitInfo.RawFramesComplete); Assert.AreEqual(100000, unitInfo.RawFramesTotal); Assert.AreEqual(1, unitInfo.FrameCount); Assert.AreSame(unitFrame, unitInfo.CurrentFrame); unitInfo.SetUnitFrame(unitFrame); // still only 1 frame Assert.AreEqual(1, unitInfo.FrameCount); }
private static UnitInfo BuildUnitInfo4() { var unitInfo = new UnitInfo(); unitInfo.ProjectID = 6903; unitInfo.ProjectRun = 2; unitInfo.ProjectClone = 3; unitInfo.ProjectGen = 4; unitInfo.OwningClientName = "Owner2"; unitInfo.OwningClientPath = "Path2"; unitInfo.OwningSlotId = 2; unitInfo.FoldingID = "harlam357"; unitInfo.Team = 32; unitInfo.CoreVersion = 2.27f; unitInfo.UnitResult = WorkUnitResult.FinishedUnit; // These values can be either Utc or Unspecified. Setting SQLite's DateTimeKind // connection string option to Utc will force SQLite to handle all DateTime // values as Utc regardless of the DateTimeKind specified in the value. unitInfo.DownloadTime = new DateTime(2012, 1, 2); unitInfo.FinishedTime = new DateTime(2012, 1, 5); // these values effect the value reported when UnitInfoLogic.GetRawTime() is called //unitInfo.FramesObserved = unitInfo.SetUnitFrame(new UnitFrame { FrameID = 99, TimeOfFrame = TimeSpan.Zero }); unitInfo.SetUnitFrame(new UnitFrame { FrameID = 100, TimeOfFrame = TimeSpan.FromMinutes(10) }); return unitInfo; }
public void CreditUPDAndPPDTest1() { var protein = new Protein { ProjectNumber = 1, Credit = 100, KFactor = 5, PreferredDays = 3, MaximumDays = 6 }; var utcNow = DateTime.UtcNow; var unitInfo = new UnitInfo { FinishedTime = utcNow, DownloadTime = utcNow.Subtract(TimeSpan.FromHours(2)), FramesObserved = 4 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:04:00", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:09:00", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:15:00", 3)); var unitInfoLogic = CreateUnitInfoLogic(protein, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(848.528, unitInfoLogic.GetCredit(SlotStatus.RunningNoFrameTimes, PpdCalculationType.LastFrame, BonusCalculationType.DownloadTime)); Assert.AreEqual(2.4, unitInfoLogic.GetUPD(PpdCalculationType.LastFrame)); Assert.AreEqual(2036.4672, unitInfoLogic.GetPPD(SlotStatus.RunningNoFrameTimes, PpdCalculationType.LastFrame, BonusCalculationType.DownloadTime)); }
public void TimePerSectionTest3() { var unitInfo = new UnitInfo { FramesObserved = 5 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:05:10", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:11:30", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:17:40", 3)); unitInfo.SetUnitFrame(MakeUnitFrame("00:24:00", 4)); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(360, unitInfoLogic.GetRawTime(PpdCalculationType.AllFrames)); Assert.AreEqual(TimeSpan.FromSeconds(360), unitInfoLogic.GetFrameTime(PpdCalculationType.AllFrames)); }
public void SetCurrentFrameTest4() { var unitInfo = new UnitInfo(); unitInfo.SetUnitFrame(null); }
public void SetCurrentFrameTest3() { // this tests GetDelta() rollover functionality var unitInfo = new UnitInfo(); var unitFrame = new UnitFrame { RawFramesComplete = 0, RawFramesTotal = 100000, FrameID = 0, TimeOfFrame = new TimeSpan(23, 55, 0), FrameDuration = new TimeSpan(0, 0, 0) }; unitInfo.SetUnitFrame(unitFrame); // no duration - first frame Assert.AreEqual(new TimeSpan(0, 0, 0), unitInfo.CurrentFrame.FrameDuration); unitFrame = new UnitFrame { RawFramesComplete = 1000, RawFramesTotal = 100000, FrameID = 1, TimeOfFrame = new TimeSpan(0, 5, 0), FrameDuration = new TimeSpan(0, 0, 0) }; // set observed count unitInfo.FramesObserved = 2; unitInfo.SetUnitFrame(unitFrame); // now we get a frame duration Assert.AreEqual(new TimeSpan(0, 10, 0), unitInfo.CurrentFrame.FrameDuration); }
public void SetCurrentFrameTest2() { var unitInfo = new UnitInfo(); var unitFrame = new UnitFrame { RawFramesComplete = 0, RawFramesTotal = 100000, FrameID = 0, TimeOfFrame = new TimeSpan(0, 0, 0), FrameDuration = new TimeSpan(0, 0, 0) }; unitInfo.SetUnitFrame(unitFrame); Assert.AreEqual(0, unitInfo.RawFramesComplete); Assert.AreEqual(100000, unitInfo.RawFramesTotal); Assert.AreEqual(1, unitInfo.FrameCount); Assert.AreSame(unitFrame, unitInfo.CurrentFrame); // no duration - first frame Assert.AreEqual(new TimeSpan(0, 0, 0), unitInfo.CurrentFrame.FrameDuration); unitFrame = new UnitFrame { RawFramesComplete = 1000, RawFramesTotal = 100000, FrameID = 1, TimeOfFrame = new TimeSpan(0, 5, 0), FrameDuration = new TimeSpan(0, 0, 0) }; unitInfo.SetUnitFrame(unitFrame); Assert.AreEqual(1000, unitInfo.RawFramesComplete); Assert.AreEqual(100000, unitInfo.RawFramesTotal); Assert.AreEqual(2, unitInfo.FrameCount); Assert.AreSame(unitFrame, unitInfo.CurrentFrame); // still no duration - unitInfo.FramesObserved must be > 1 Assert.AreEqual(new TimeSpan(0, 0, 0), unitInfo.CurrentFrame.FrameDuration); unitFrame = new UnitFrame { RawFramesComplete = 2000, RawFramesTotal = 100000, FrameID = 2, TimeOfFrame = new TimeSpan(0, 10, 0), FrameDuration = new TimeSpan(0, 0, 0) }; // set observed count unitInfo.FramesObserved = 2; unitInfo.SetUnitFrame(unitFrame); Assert.AreEqual(2000, unitInfo.RawFramesComplete); Assert.AreEqual(100000, unitInfo.RawFramesTotal); Assert.AreEqual(3, unitInfo.FrameCount); Assert.AreSame(unitFrame, unitInfo.CurrentFrame); // now we get a frame duration Assert.AreEqual(new TimeSpan(0, 5, 0), unitInfo.CurrentFrame.FrameDuration); }
public void CreditUPDAndPPDTest4() { var unitInfo = new UnitInfo { FramesObserved = 4 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:04:00", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:09:00", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:15:00", 3)); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(0, unitInfoLogic.GetCredit(SlotStatus.Unknown, PpdCalculationType.LastFrame, BonusCalculationType.None)); Assert.AreEqual(2.4, unitInfoLogic.GetUPD(PpdCalculationType.LastFrame)); Assert.AreEqual(0, unitInfoLogic.GetPPD(SlotStatus.Unknown, PpdCalculationType.LastFrame, BonusCalculationType.None)); }
public void PerUnitDownloadTest4() { var unitInfo = new UnitInfo { DownloadTime = DateTime.UtcNow, FramesObserved = 4 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", -1)); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(0, unitInfoLogic.GetRawTime(PpdCalculationType.EffectiveRate)); Assert.AreEqual(TimeSpan.FromSeconds(0), unitInfoLogic.GetFrameTime(PpdCalculationType.EffectiveRate)); Assert.AreEqual(0, unitInfoLogic.GetPPD(SlotStatus.Unknown, PpdCalculationType.EffectiveRate, BonusCalculationType.None)); }
public void EtaTest1() { var unitInfo = new UnitInfo { FramesObserved = 4 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:04:00", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:09:00", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:15:00", 3)); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(TimeSpan.FromMinutes(582), unitInfoLogic.GetEta(PpdCalculationType.LastFrame)); }
public void TimePerSectionTest4() { var protein = new Protein { ProjectNumber = 1, Credit = 100 }; var unitInfo = new UnitInfo { DownloadTime = DateTime.UtcNow, FramesObserved = 4 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:04:00", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:09:00", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:15:00", 3)); unitInfo.UnitRetrievalTime = unitInfo.DownloadTime.Add(TimeSpan.FromMinutes(30)); var unitInfoLogic = CreateUnitInfoLogic(protein, unitInfo); unitInfoLogic.UtcOffsetIsZero = true; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(600, unitInfoLogic.GetRawTime(PpdCalculationType.EffectiveRate)); Assert.AreEqual(TimeSpan.FromSeconds(600), unitInfoLogic.GetFrameTime(PpdCalculationType.EffectiveRate)); }
public void EtaTest2() { var unitInfo = new UnitInfo { DownloadTime = DateTime.UtcNow, FramesObserved = 4 }; unitInfo.SetUnitFrame(MakeUnitFrame("00:00:00", 0)); unitInfo.SetUnitFrame(MakeUnitFrame("00:04:00", 1)); unitInfo.SetUnitFrame(MakeUnitFrame("00:09:00", 2)); unitInfo.SetUnitFrame(MakeUnitFrame("00:15:00", 3)); unitInfo.UnitRetrievalTime = unitInfo.DownloadTime.Add(TimeSpan.FromMinutes(30)); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(unitInfo.DownloadTime.Add(TimeSpan.FromMinutes(612)), unitInfoLogic.GetEtaDate(PpdCalculationType.LastFrame)); }
private static UnitInfo BuildUnitInfo2() { var unitInfo = new UnitInfo(); unitInfo.ProjectID = 6900; unitInfo.ProjectRun = 4; unitInfo.ProjectClone = 5; unitInfo.ProjectGen = 6; unitInfo.OwningClientName = "Owner's"; unitInfo.OwningClientPath = "The Path's"; //unitInfo.OwningSlotId = unitInfo.FoldingID = "harlam357's"; unitInfo.Team = 100; unitInfo.CoreVersion = 2.27f; unitInfo.UnitResult = WorkUnitResult.EarlyUnitEnd; // These values can be either Utc or Unspecified. Setting SQLite's DateTimeKind // connection string option to Utc will force SQLite to handle all DateTime // values as Utc regardless of the DateTimeKind specified in the value. unitInfo.DownloadTime = new DateTime(2009, 5, 5); unitInfo.FinishedTime = DateTime.MinValue; // these values effect the value reported when UnitInfoLogic.GetRawTime() is called unitInfo.FramesObserved = 2; unitInfo.SetUnitFrame(new UnitFrame { FrameID = 55, TimeOfFrame = TimeSpan.Zero }); unitInfo.SetUnitFrame(new UnitFrame { FrameID = 56, TimeOfFrame = TimeSpan.FromSeconds(1000) }); return unitInfo; }
public void FramesCompleteTest3() { var unitInfo = new UnitInfo(); unitInfo.SetUnitFrame(new UnitFrame { FrameID = 101 }); var unitInfoLogic = CreateUnitInfoLogic(null, unitInfo); unitInfoLogic.UtcOffsetIsZero = false; unitInfoLogic.ClientTimeOffset = 0; Assert.AreEqual(100, unitInfoLogic.FramesComplete); }
private static void ParseFrameData(IEnumerable<LogLine> frameData, UnitInfo unit) { Debug.Assert(frameData != null); Debug.Assert(unit != null); foreach (var logLine in frameData) { // Check for FrameData var frame = logLine.LineData as UnitFrame; if (frame == null) { // If not found, clear the LineType and get out logLine.LineType = LogLineType.Unknown; continue; } unit.SetUnitFrame(frame); } }
private static List<UnitInfo> CreateTestList() { var list = new List<UnitInfo>(); for (int i = 0; i < 10; i++) { var unitInfo = new UnitInfo(); unitInfo.OwningClientName = "TestOwner"; unitInfo.OwningClientPath = "TestPath"; unitInfo.UnitRetrievalTime = new DateTime((2000 + i), 1, 1, 0, 0, 0); unitInfo.FoldingID = "TestID"; unitInfo.Team = 32; unitInfo.SlotType = SlotType.CPU; unitInfo.DownloadTime = new DateTime(2000, 2, 2, 0, 0, 0); unitInfo.DueTime = new DateTime(2000, 3, 3, 0, 0, 0); unitInfo.UnitStartTimeStamp = TimeSpan.FromHours(i + 1); unitInfo.FinishedTime = new DateTime(2000, 4, 4, 0, 0, 0); unitInfo.CoreVersion = 2.10f; unitInfo.ProjectID = 2669; unitInfo.ProjectRun = 1; unitInfo.ProjectClone = 2; unitInfo.ProjectGen = 3; unitInfo.ProteinName = "Protein"; unitInfo.ProteinTag = "ProteinTag"; unitInfo.UnitResult = WorkUnitResult.CoreOutdated; // values set by SetUnitFrame() below //unitInfo.RawFramesComplete = 7500; //unitInfo.RawFramesTotal = 250000; unitInfo.FramesObserved = 4; for (int j = 0; j < unitInfo.FramesObserved; j++) { var unitFrame = new UnitFrame { RawFramesComplete = 2500 * j, RawFramesTotal = 250000, FrameID = j, TimeOfFrame = TimeSpan.FromMinutes((j + 1) * (j + 1.5)) }; unitInfo.SetUnitFrame(unitFrame); } list.Add(unitInfo); } for (int i = 10; i < 20; i++) { var unitInfo = new UnitInfo(); unitInfo.OwningClientName = "TestOwner2"; unitInfo.OwningClientPath = "TestPath2"; unitInfo.OwningSlotId = i - 10; unitInfo.UnitRetrievalTime = new DateTime((2000 + i), 1, 1, 0, 0, 0); unitInfo.FoldingID = "TestID"; unitInfo.Team = 32; unitInfo.SlotType = SlotType.CPU; unitInfo.DownloadTime = new DateTime(2000, 2, 2, 0, 0, 0); unitInfo.DueTime = new DateTime(2000, 3, 3, 0, 0, 0); unitInfo.UnitStartTimeStamp = TimeSpan.FromHours(i + 1); unitInfo.FinishedTime = new DateTime(2000, 4, 4, 0, 0, 0); unitInfo.CoreVersion = 2.27f; unitInfo.ProjectID = 6903; unitInfo.ProjectRun = 1; unitInfo.ProjectClone = 2; unitInfo.ProjectGen = 3; unitInfo.ProteinName = "Protein"; unitInfo.ProteinTag = "ProteinTag"; unitInfo.UnitResult = WorkUnitResult.CoreOutdated; // values set by SetUnitFrame() below //unitInfo.RawFramesComplete = 7500; //unitInfo.RawFramesTotal = 250000; unitInfo.FramesObserved = 4; for (int j = 0; j < unitInfo.FramesObserved; j++) { var unitFrame = new UnitFrame { RawFramesComplete = 2500 * j, RawFramesTotal = 250000, FrameID = j, TimeOfFrame = TimeSpan.FromMinutes((j + 2) * (j + 0.75)) }; unitInfo.SetUnitFrame(unitFrame); } list.Add(unitInfo); } return list; }