コード例 #1
0
ファイル: UnitInfoModel.cs プロジェクト: pnoodles/hfm-net
        private double GetPPD(TimeSpan frameTime, TimeSpan eftByDownloadTime, TimeSpan eftByFrameTime, SlotStatus status, BonusCalculationType calculateBonus)
        {
            if (CurrentProtein.IsUnknown)
            {
                return(0);
            }

            // Issue 125
            if (calculateBonus.Equals(BonusCalculationType.DownloadTime))
            {
                // Issue 183
                if (status.Equals(SlotStatus.RunningAsync) ||
                    status.Equals(SlotStatus.RunningNoFrameTimes))
                {
                    return(ProductionCalculator.GetPPD(frameTime, CurrentProtein, eftByFrameTime));
                }

                return(ProductionCalculator.GetPPD(frameTime, CurrentProtein, eftByDownloadTime));
            }
            if (calculateBonus.Equals(BonusCalculationType.FrameTime))
            {
                return(ProductionCalculator.GetPPD(frameTime, CurrentProtein, eftByFrameTime));
            }

            return(ProductionCalculator.GetPPD(frameTime, CurrentProtein));
        }
コード例 #2
0
ファイル: BenchmarksForm.cs プロジェクト: pnoodles/hfm-net
        private void PopulateBenchmarkInformation(Protein protein, ProteinBenchmark benchmark, UnitInfoModel unitInfoModel, SlotStatus status, string ppdFormatString, ICollection <string> lines)
        {
            if (protein == null)
            {
                return;
            }

            var calculateBonus = _prefs.Get <BonusCalculationType>(Preference.BonusCalculation);

            lines.Add(String.Empty);
            lines.Add(String.Format(" Name: {0}", benchmark.OwningSlotName));
            lines.Add(String.Format(" Path: {0}", benchmark.OwningClientPath));
            lines.Add(String.Format(" Number of Frames Observed: {0}", benchmark.FrameTimes.Count));
            lines.Add(String.Empty);
            lines.Add(String.Format(" Min. Time / Frame : {0} - {1:" + ppdFormatString + "} PPD",
                                    benchmark.MinimumFrameTime, ProductionCalculator.GetPPD(benchmark.MinimumFrameTime, protein, calculateBonus.IsEnabled())));
            lines.Add(String.Format(" Avg. Time / Frame : {0} - {1:" + ppdFormatString + "} PPD",
                                    benchmark.AverageFrameTime, ProductionCalculator.GetPPD(benchmark.AverageFrameTime, protein, calculateBonus.IsEnabled())));

            if (unitInfoModel != null)
            {
                lines.Add(String.Format(" Cur. Time / Frame : {0} - {1:" + ppdFormatString + "} PPD",
                                        unitInfoModel.GetFrameTime(PpdCalculationType.LastFrame), unitInfoModel.GetPPD(status, PpdCalculationType.LastFrame, calculateBonus)));
                lines.Add(String.Format(" R3F. Time / Frame : {0} - {1:" + ppdFormatString + "} PPD",
                                        unitInfoModel.GetFrameTime(PpdCalculationType.LastThreeFrames), unitInfoModel.GetPPD(status, PpdCalculationType.LastThreeFrames, calculateBonus)));
                lines.Add(String.Format(" All  Time / Frame : {0} - {1:" + ppdFormatString + "} PPD",
                                        unitInfoModel.GetFrameTime(PpdCalculationType.AllFrames), unitInfoModel.GetPPD(status, PpdCalculationType.AllFrames, calculateBonus)));
                lines.Add(String.Format(" Eff. Time / Frame : {0} - {1:" + ppdFormatString + "} PPD",
                                        unitInfoModel.GetFrameTime(PpdCalculationType.EffectiveRate), unitInfoModel.GetPPD(status, PpdCalculationType.EffectiveRate, calculateBonus)));
            }

            lines.Add(String.Empty);
        }
コード例 #3
0
        public void GetMultiplier_Test1()
        {
            var protein = new Protein {
                Credit = 700, PreferredDays = 3, MaximumDays = 5, KFactor = 26.4
            };

            Assert.AreEqual(19.5, ProductionCalculator.GetMultiplier(protein, TimeSpan.FromMinutes(5 * 100)), 0.01);
        }
コード例 #4
0
        public void GetCredit_Test2()
        {
            var protein = new Protein {
                Credit = 700, PreferredDays = 3, MaximumDays = 5, KFactor = 26.4
            };

            Assert.AreEqual(13648.383, ProductionCalculator.GetCredit(protein, TimeSpan.FromMinutes(5 * 100)));
        }
コード例 #5
0
        public void GetCredit_Test1()
        {
            var protein = new Protein {
                Credit = 700, PreferredDays = 3, MaximumDays = 5, KFactor = 26.4
            };

            Assert.AreEqual(700, ProductionCalculator.GetCredit(protein, TimeSpan.Zero));
        }
コード例 #6
0
        public void GetUPD_Test1()
        {
            var protein = new Protein {
                Credit = 500
            };

            Assert.AreEqual(2.88, ProductionCalculator.GetUPD(TimeSpan.FromMinutes(5), protein.Frames));
        }
コード例 #7
0
        public void GetPPD_Test2()
        {
            var protein = new Protein {
                Credit = 700, PreferredDays = 3, MaximumDays = 5, KFactor = 26.4
            };

            Assert.AreEqual(39307.35, ProductionCalculator.GetPPD(TimeSpan.FromMinutes(5), protein, true), 0.01);
        }
コード例 #8
0
        public void Calculate()
        {
            Protein value = _proteinService.Get(SelectedProject);

            if (value == null)
            {
                return;
            }
            Protein protein = value.DeepClone();

            if (PreferredDeadlineChecked)
            {
                protein.PreferredDays = PreferredDeadline;
            }
            if (FinalDeadlineChecked)
            {
                protein.MaximumDays = FinalDeadline;
            }
            if (KFactorChecked)
            {
                protein.KFactor = KFactor;
            }

            TimeSpan frameTime        = TimeSpan.FromMinutes(TpfMinutes).Add(TimeSpan.FromSeconds(TpfSeconds));
            TimeSpan totalTimeByFrame = TimeSpan.FromSeconds(frameTime.TotalSeconds * protein.Frames);
            TimeSpan totalTimeByUser  = totalTimeByFrame;

            if (TotalWuTimeEnabled)
            {
                totalTimeByUser = TimeSpan.FromMinutes(TotalWuTimeMinutes).Add(TimeSpan.FromSeconds(TotalWuTimeSeconds));
                // user time is less than total time by frame, not permitted
                if (totalTimeByUser < totalTimeByFrame)
                {
                    totalTimeByUser = totalTimeByFrame;
                }
            }

            var decimalPlaces = _prefs.Get <int>(Preference.DecimalPlaces);
            var values        = ProductionCalculator.GetProductionValues(frameTime, protein, totalTimeByUser, totalTimeByFrame);

            CoreName          = protein.Core;
            SlotType          = protein.Core.ToSlotType().ToString();
            NumberOfAtoms     = protein.NumberOfAtoms;
            CompletionTime    = Math.Round((TotalWuTimeEnabled ? totalTimeByUser.TotalDays : totalTimeByFrame.TotalDays), decimalPlaces);
            PreferredDeadline = protein.PreferredDays;
            FinalDeadline     = protein.MaximumDays;
            KFactor           = protein.KFactor;
            BonusMultiplier   = Math.Round((TotalWuTimeEnabled ? values.DownloadTimeBonusMulti : values.FrameTimeBonusMulti), decimalPlaces);
            BaseCredit        = values.BaseCredit;
            TotalCredit       = Math.Round((TotalWuTimeEnabled ? values.DownloadTimeBonusCredit : values.FrameTimeBonusCredit), decimalPlaces);
            BasePpd           = values.BasePPD;
            TotalPpd          = Math.Round((TotalWuTimeEnabled ? values.DownloadTimeBonusPPD : values.FrameTimeBonusPPD), decimalPlaces);
        }
コード例 #9
0
        public ViewModelFactory(CommandFactory commandFactory,
                                ILanguageService languageService, User user, AppServicesFactory appServiceFactory, DataFactory dataFactory, ProductionCalculator productionCalculator)
        {
            _viewModels = new Dictionary <string, object>();

            _commandFactory       = commandFactory;
            _languageService      = languageService;
            _user                 = user;
            _appServiceFactory    = appServiceFactory;
            _dataFactory          = dataFactory;
            _productionCalculator = productionCalculator;
        }
            public override object Invoke(object[] args)
            {
                Debug.Assert(args.Length == 9);
                if (args.Any(x => x == null || Convert.IsDBNull(x)))
                {
                    return(0.0);
                }

                var frameTime = TimeSpan.FromSeconds((long)args[0]);
                // unbox then cast to int
                var      frames        = (int)((long)args[1]);
                var      baseCredit    = (double)args[2];
                var      kFactor       = (double)args[3];
                var      preferredDays = (double)args[4];
                var      maximumDays   = (double)args[5];
                DateTime downloadDateTime;

                DateTime.TryParseExact((string)args[6], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture,
                                       DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
                                       out downloadDateTime);
                DateTime completionDateTime;

                DateTime.TryParseExact((string)args[7], "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture,
                                       DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal,
                                       out completionDateTime);
                var calcOption = (long)args[8];

                TimeSpan unitTime = TimeSpan.Zero;

                switch (BonusCalculation)
                {
                case BonusCalculationType.FrameTime:
                    unitTime = TimeSpan.FromSeconds(frameTime.TotalSeconds * frames);
                    break;

                case BonusCalculationType.DownloadTime:
                    unitTime = completionDateTime.Subtract(downloadDateTime);
                    break;
                }

                if (calcOption != 0)
                {
                    return(ProductionCalculator.GetBonusCredit(baseCredit, kFactor, preferredDays, maximumDays, unitTime));
                }
                return(ProductionCalculator.GetBonusPPD(frameTime, frames, baseCredit, kFactor, preferredDays, maximumDays, unitTime));
            }
コード例 #11
0
ファイル: UnitInfoModel.cs プロジェクト: pnoodles/hfm-net
        public void ShowPPDTrace(ILogger logger, string slotName, SlotStatus status, PpdCalculationType calculationType, BonusCalculationType bonusCalculationType)
        {
            // test the level
            if (!logger.IsDebugEnabled)
            {
                return;
            }

            if (CurrentProtein.IsUnknown)
            {
                logger.DebugFormat(Constants.ClientNameFormat, slotName, "Protein is unknown... 0 PPD.");
                return;
            }

            // Issue 125
            if (bonusCalculationType == BonusCalculationType.DownloadTime)
            {
                // Issue 183
                if (status.Equals(SlotStatus.RunningAsync) ||
                    status.Equals(SlotStatus.RunningNoFrameTimes))
                {
                    logger.DebugFormat(Constants.ClientNameFormat, slotName, "Calculate Bonus PPD by Frame Time.");
                }
                else
                {
                    logger.DebugFormat(Constants.ClientNameFormat, slotName, "Calculate Bonus PPD by Download Time.");
                }
            }
            else if (bonusCalculationType == BonusCalculationType.FrameTime)
            {
                logger.DebugFormat(Constants.ClientNameFormat, slotName, "Calculate Bonus PPD by Frame Time.");
            }
            else
            {
                logger.DebugFormat(Constants.ClientNameFormat, slotName, "Calculate Standard PPD.");
            }

            TimeSpan frameTime = GetFrameTime(calculationType);
            var      values    = ProductionCalculator.GetProductionValues(frameTime, CurrentProtein, GetEftByDownloadTime(frameTime), GetEftByFrameTime(frameTime));

            logger.DebugFormat(" - {0}", UnitInfoData.ToProjectString());
            logger.Debug(values.ToMultiLineString());
        }
コード例 #12
0
        public void GetProductionValues_Test1()
        {
            var protein = new Protein {
                Credit = 700, PreferredDays = 3, MaximumDays = 5, KFactor = 26.4
            };
            var values = ProductionCalculator.GetProductionValues(TimeSpan.FromMinutes(5), protein,
                                                                  TimeSpan.FromMinutes(5 * 100).Add(TimeSpan.FromMinutes(10)),
                                                                  TimeSpan.FromMinutes(5 * 100));

            Assert.AreEqual(TimeSpan.FromMinutes(5), values.TimePerFrame);
            Assert.AreEqual(700, values.BaseCredit);
            Assert.AreEqual(2016.0, values.BasePPD);
            Assert.AreEqual(TimeSpan.FromDays(3), values.PreferredTime);
            Assert.AreEqual(TimeSpan.FromDays(5), values.MaximumTime);
            Assert.AreEqual(26.4, values.KFactor);
            Assert.AreEqual(TimeSpan.FromMinutes(5 * 100).Add(TimeSpan.FromMinutes(10)), values.UnitTimeByDownloadTime);
            Assert.AreEqual(19.31, values.DownloadTimeBonusMulti, 0.01);
            Assert.AreEqual(13513.913, values.DownloadTimeBonusCredit);
            Assert.AreEqual(38920.07, values.DownloadTimeBonusPPD, 0.01);
            Assert.AreEqual(TimeSpan.FromMinutes(5 * 100), values.UnitTimeByFrameTime);
            Assert.AreEqual(19.5, values.FrameTimeBonusMulti, 0.01);
            Assert.AreEqual(13648.383, values.FrameTimeBonusCredit);
            Assert.AreEqual(39307.35, values.FrameTimeBonusPPD, 0.01);
        }
コード例 #13
0
        public void GetPPD_Test3()
        {
            var protein = new Protein();

            Assert.AreEqual(0.0, ProductionCalculator.GetPPD(TimeSpan.Zero, protein));
        }
コード例 #14
0
ファイル: WorkUnitModel.cs プロジェクト: benjaminzink/hfm-net
 /// <summary>
 /// Units per day (UPD) rating for this unit
 /// </summary>
 public double GetUPD(PPDCalculation ppdCalculation)
 {
     return(ProductionCalculator.GetUPD(GetFrameTime(ppdCalculation), CurrentProtein.Frames));
 }
コード例 #15
0
 /// <summary>
 /// Units per day (UPD) rating for this unit
 /// </summary>
 public double GetUPD(PpdCalculationType calculationType)
 {
     return(ProductionCalculator.GetUPD(GetFrameTime(calculationType), CurrentProtein.Frames));
 }
コード例 #16
0
ファイル: ZedGraphManager.cs プロジェクト: pnoodles/hfm-net
        public void CreatePpdGraph(ZedGraphControl zg, IList <string> projectInfoLines,
                                   IEnumerable <ProteinBenchmark> benchmarks,
                                   IList <Color> graphColors, int decimalPlaces,
                                   Protein protein, bool calculateBonus)
        {
            Debug.Assert(zg != null);

            try
            {
                // get a reference to the GraphPane
                GraphPane myPane = zg.GraphPane;

                // Clear the bars
                myPane.CurveList.Clear();
                // Clear the bar labels
                myPane.GraphObjList.Clear();
                // Clear the XAxis Project Information
                myPane.XAxis.Title.Text = String.Empty;

                // If no Project Information, get out
                if (projectInfoLines.Count == 0)
                {
                    return;
                }

                // Scale YAxis In Thousands?
                bool inThousands = false;

                // Create the bars for each benchmark
                int i = 0;
                foreach (ProteinBenchmark benchmark in benchmarks)
                {
                    double minimumFrameTimePPD = 0;
                    double averageFrameTimePPD = 0;
                    if (protein != null)
                    {
                        minimumFrameTimePPD = ProductionCalculator.GetPPD(benchmark.MinimumFrameTime, protein, calculateBonus);
                        averageFrameTimePPD = ProductionCalculator.GetPPD(benchmark.AverageFrameTime, protein, calculateBonus);
                    }

                    if (minimumFrameTimePPD >= 1000 || averageFrameTimePPD >= 1000)
                    {
                        inThousands = true;
                    }

                    var yPoints = new double[2];
                    yPoints[0] = Math.Round(minimumFrameTimePPD, decimalPlaces);
                    yPoints[1] = Math.Round(averageFrameTimePPD, decimalPlaces);

                    CreateBar(i, myPane, benchmark.OwningSlotName, yPoints, graphColors);
                    i++;
                }

                // Create the bar labels
                BarItem.CreateBarLabels(myPane, true, String.Empty, zg.Font.Name, zg.Font.Size, Color.Black, true, false, false);

                // Set the Titles
                myPane.Title.Text = "HFM.NET - Client Benchmarks";
                var sb = new StringBuilder();
                for (i = 0; i < projectInfoLines.Count - 2; i++)
                {
                    sb.Append(projectInfoLines[i]);
                    sb.Append("   ");
                }
                sb.Append(projectInfoLines[i]);
                myPane.XAxis.Title.Text = sb.ToString();
                myPane.YAxis.Title.Text = "PPD";

                // Draw the X tics between the labels instead of at the labels
                myPane.XAxis.MajorTic.IsBetweenLabels = true;
                // Set the XAxis labels
                var labels = new[] { "Min. Frame Time", "Avg. Frame Time" };
                myPane.XAxis.Scale.TextLabels = labels;
                // Set the XAxis to Text type
                myPane.XAxis.Type = AxisType.Text;

                // Don't show YAxis.Scale as 10^3
                myPane.YAxis.Scale.MagAuto = false;
                // Set the YAxis Steps
                if (inThousands)
                {
                    myPane.YAxis.Scale.MajorStep = 1000;
                    myPane.YAxis.Scale.MinorStep = 500;
                }
                else
                {
                    myPane.YAxis.Scale.MajorStep = 100;
                    myPane.YAxis.Scale.MinorStep = 10;
                }

                // Fill the Axis and Pane backgrounds
                myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
                myPane.Fill       = new Fill(Color.FromArgb(250, 250, 255));
            }
            finally
            {
                // Tell ZedGraph to refigure the
                // axes since the data have changed
                zg.AxisChange();
                // Refresh the control
                zg.Refresh();
            }
        }