コード例 #1
0
        }                                                   // should be init to DateTime.MinValue

        /// <summary>
        /// Update Time of Last Frame Progress based on Current and Parsed UnitInfo
        /// </summary>
        private void UpdateTimeOfLastProgress(UnitInfoModel parsedUnitInfo)
        {
            // Matches the Current Project and Raw Download Time
            if (UnitInfoModel.UnitInfoData.IsSameUnitAs(parsedUnitInfo.UnitInfoData))
            {
                // If the Unit Start Time Stamp is no longer the same as the UnitInfoLogic
                if (parsedUnitInfo.UnitInfoData.UnitStartTimeStamp.Equals(TimeSpan.MinValue) == false &&
                    UnitInfoModel.UnitInfoData.UnitStartTimeStamp.Equals(TimeSpan.MinValue) == false &&
                    parsedUnitInfo.UnitInfoData.UnitStartTimeStamp.Equals(UnitInfoModel.UnitInfoData.UnitStartTimeStamp) == false)
                {
                    TimeOfLastUnitStart = DateTime.Now;
                }

                // If the Frames Complete is greater than the UnitInfoLogic Frames Complete
                if (parsedUnitInfo.FramesComplete > UnitInfoModel.FramesComplete)
                {
                    // Update the Time Of Last Frame Progress
                    TimeOfLastFrameProgress = DateTime.Now;
                }
            }
            else // Different UnitInfo - Update the Time Of Last
            // Unit Start and Clear Frame Progress Value
            {
                TimeOfLastUnitStart     = DateTime.Now;
                TimeOfLastFrameProgress = DateTime.MinValue;
            }
        }
コード例 #2
0
        private UnitInfoModel BuildUnitInfoLogic(UnitInfo unitInfo, bool updateUnitInfo)
        {
            Debug.Assert(unitInfo != null);

            Protein protein = ProteinService.Get(unitInfo.ProjectID, true) ?? new Protein();

            if (updateUnitInfo)
            {
                // update the data
                unitInfo.UnitRetrievalTime = LastRetrievalTime;
                unitInfo.OwningClientName  = Settings.Name;
                unitInfo.OwningClientPath  = Settings.DataPath();
                if (unitInfo.SlotType == SlotType.Unknown)
                {
                    unitInfo.SlotType = protein.Core.ToSlotType();
                    if (unitInfo.SlotType == SlotType.Unknown)
                    {
                        unitInfo.SlotType = unitInfo.CoreID.ToSlotType();
                    }
                }
            }
            // build unit info logic
            var unitInfoLogic = new UnitInfoModel(BenchmarkService);

            unitInfoLogic.CurrentProtein = protein;
            unitInfoLogic.UnitInfoData   = unitInfo;
            return(unitInfoLogic);
        }
コード例 #3
0
        public SlotModel()
        {
            _unitInfoModel = new UnitInfoModel();

            Initialize();
            TimeOfLastUnitStart     = DateTime.MinValue;
            TimeOfLastFrameProgress = DateTime.MinValue;
        }
コード例 #4
0
        public bool Insert(UnitInfoModel unitInfoModel)
        {
            // if the work unit is not valid simply return
            if (!ValidateUnitInfo(unitInfoModel.UnitInfoData))
            {
                return(false);
            }

            // The Insert operation does not setup a WuHistory table if
            // it does not exist.  This was already handled when the
            // the DatabaseFilePath was set.
            Debug.Assert(TableExists(SqlTable.WuHistory));

            // ensure this unit is not written twice
            if (UnitInfoExists(unitInfoModel.UnitInfoData))
            {
                return(false);
            }

            var entry = AutoMapper.Mapper.Map <HistoryEntry>(unitInfoModel.UnitInfoData);

            // cannot map these two properties from a UnitInfo instance
            // they only live at the UnitInfoLogic level
            entry.FramesCompleted = unitInfoModel.FramesComplete;
            entry.FrameTimeValue  = unitInfoModel.GetRawTime(PpdCalculationType.AllFrames);
            // copy protein values for insert
            entry.WorkUnitName  = unitInfoModel.CurrentProtein.WorkUnitName;
            entry.KFactor       = unitInfoModel.CurrentProtein.KFactor;
            entry.Core          = unitInfoModel.CurrentProtein.Core;
            entry.Frames        = unitInfoModel.CurrentProtein.Frames;
            entry.Atoms         = unitInfoModel.CurrentProtein.NumberOfAtoms;
            entry.BaseCredit    = unitInfoModel.CurrentProtein.Credit;
            entry.PreferredDays = unitInfoModel.CurrentProtein.PreferredDays;
            entry.MaximumDays   = unitInfoModel.CurrentProtein.MaximumDays;
            using (var connection = new SQLiteConnection(ConnectionString))
            {
                connection.Open();
                using (var database = new PetaPoco.Database(connection))
                {
                    database.Insert(entry);
                }
            }

            return(true);
        }
コード例 #5
0
        internal void UpdateBenchmarkData(UnitInfoModel currentUnitInfo, UnitInfoModel[] parsedUnits, int currentUnitIndex)
        {
            var foundCurrent   = false;
            var processUpdates = false;

            foreach (int index in UnitIndexIterator(currentUnitIndex, parsedUnits.Length))
            {
                var unitInfoModel = parsedUnits[index];

                // If Current has not been found, check the nextUnitIndex
                // or try to match the Current Project and Raw Download Time
                if (unitInfoModel != null && processUpdates == false && (index == currentUnitIndex || currentUnitInfo.UnitInfoData.IsSameUnitAs(unitInfoModel.UnitInfoData)))
                {
                    foundCurrent   = true;
                    processUpdates = true;
                }

                if (processUpdates)
                {
                    int previousFramesComplete = 0;
                    if (foundCurrent)
                    {
                        // current frame has already been recorded, increment to the next frame
                        previousFramesComplete = currentUnitInfo.FramesComplete + 1;
                        foundCurrent           = false;
                    }

                    // Even though the current UnitInfoLogic has been found in the parsed UnitInfoLogic array doesn't
                    // mean that all entries in the array will be present.  See TestFiles\SMP_12\FAHlog.txt.
                    if (unitInfoModel != null)
                    {
                        // Update benchmarks
                        BenchmarkService.UpdateData(unitInfoModel.UnitInfoData, previousFramesComplete, unitInfoModel.FramesComplete);
                        // Update history database
                        UpdateUnitInfoDatabase(unitInfoModel);
                    }
                }
            }
        }
コード例 #6
0
 protected void UpdateUnitInfoDatabase(UnitInfoModel unitInfoModel)
 {
     // Update history database
     if (UnitInfoDatabase != null && UnitInfoDatabase.Connected)
     {
         try
         {
             if (UnitInfoDatabase.Insert(unitInfoModel))
             {
                 if (Logger.IsDebugEnabled)
                 {
                     string message = String.Format(CultureInfo.CurrentCulture, "Inserted {0} into database.", unitInfoModel.UnitInfoData.ToProjectString());
                     Logger.DebugFormat(Constants.ClientNameFormat, unitInfoModel.UnitInfoData.OwningSlotName, message);
                 }
             }
         }
         catch (Exception ex)
         {
             Logger.ErrorFormat(ex, "{0}", ex.Message);
         }
     }
 }
コード例 #7
0
 internal void UpdateBenchmarkData(UnitInfoModel currentUnitInfo, IEnumerable <UnitInfoModel> parsedUnits, int currentUnitIndex)
 {
     foreach (var unitInfoModel in parsedUnits.Where(x => x != null))
     {
         if (currentUnitInfo.UnitInfoData.IsSameUnitAs(unitInfoModel.UnitInfoData))
         {
             // found the current unit
             // current frame has already been recorded, increment to the next frame
             int previousFramesComplete = currentUnitInfo.FramesComplete + 1;
             // Update benchmarks
             BenchmarkService.UpdateData(unitInfoModel.UnitInfoData, previousFramesComplete, unitInfoModel.FramesComplete);
         }
         // Update history database
         if (unitInfoModel.UnitInfoData.UnitResult != WorkUnitResult.Unknown)
         {
             UpdateUnitInfoDatabase(unitInfoModel);
         }
         //// used when there is no currentUnitInfo
         //else if (unitInfoLogic.UnitInfoData.QueueIndex == currentUnitIndex)
         //{
         //   BenchmarkCollection.UpdateData(unitInfoLogic.UnitInfoData, 0, unitInfoLogic.FramesComplete);
         //}
     }
 }
コード例 #8
0
        /// <summary>
        /// Process the cached log files that exist on this machine
        /// </summary>
        private void Process()
        {
            var sw = Stopwatch.StartNew();

            // Set successful Last Retrieval Time
            LastRetrievalTime = DateTime.Now;
            // Re-Init Slot Level Members Before Processing
            _slotModel.Initialize();

            #region Setup Aggregator

            var dataAggregator = new LegacyDataAggregator {
                Logger = Logger
            };
            dataAggregator.ClientName = Settings.Name;
            string queueFilePath       = Path.Combine(Prefs.CacheDirectory, Settings.CachedQueueFileName());
            string fahLogFilePath      = Path.Combine(Prefs.CacheDirectory, Settings.CachedFahLogFileName());
            string unitInfoLogFilePath = Path.Combine(Prefs.CacheDirectory, Settings.CachedUnitInfoFileName());

            #endregion

            #region Run the Aggregator

            var queue    = ReadQueueFile(queueFilePath);
            var fahLog   = FahLog.Read(File.ReadLines(fahLogFilePath), FahLogType.Legacy);
            var unitInfo = ReadUnitInfoFile(unitInfoLogFilePath);

            var result = dataAggregator.AggregateData(fahLog, queue, unitInfo);
            // Issue 126 - Use the Folding ID, Team, User ID, and Machine ID from the FAHlog data.
            // Use the Current Queue Entry as a backup data source.
            PopulateRunLevelData(result, _slotModel);
            if (result.Queue != null)
            {
                PopulateRunLevelData(result.Queue.Current, _slotModel);
            }

            _slotModel.Queue           = result.Queue;
            _slotModel.CurrentLogLines = result.CurrentLogLines;
            _slotModel.UnitLogLines    = result.UnitInfos.OrderBy(x => x.Key).Select(x => x.Value != null ? x.Value.LogLines : null).ToArray();

            #endregion

            var parsedUnits = new UnitInfoModel[result.UnitInfos.Count];
            for (int i = 0; i < result.UnitInfos.Count; i++)
            {
                if (result.UnitInfos[i] != null)
                {
                    parsedUnits[i] = BuildUnitInfoLogic(result.UnitInfos[i], true);
                }
            }

            // *** THIS HAS TO BE DONE BEFORE UPDATING SlotModel.UnitInfoLogic ***
            UpdateBenchmarkData(_slotModel.UnitInfoModel, parsedUnits, result.CurrentUnitIndex);

            // Update the UnitInfoLogic if we have a Status
            if (result.Status != SlotStatus.Unknown)
            {
                _slotModel.UnitInfoModel = parsedUnits[result.CurrentUnitIndex];
            }

            HandleReturnedStatus(result.Status, _slotModel);

            _slotModel.UnitInfoModel.ShowPPDTrace(Logger, _slotModel.Name, _slotModel.Status,
                                                  Prefs.Get <PpdCalculationType>(Preference.PpdCalculation),
                                                  Prefs.Get <BonusCalculationType>(Preference.BonusCalculation));

            string statusMessage = String.Format(CultureInfo.CurrentCulture, "Client Status: {0}", _slotModel.Status);
            Logger.InfoFormat(Constants.ClientNameFormat, _slotModel.Name, statusMessage);

            string message = String.Format(CultureInfo.CurrentCulture, "Retrieval finished: {0}", sw.GetExecTime());
            Logger.InfoFormat(Constants.ClientNameFormat, Settings.Name, message);
        }
コード例 #9
0
ファイル: Client.cs プロジェクト: harlam357/hfm-net
 protected void UpdateUnitInfoDatabase(UnitInfoModel unitInfoModel)
 {
    // Update history database
    if (UnitInfoDatabase != null && UnitInfoDatabase.Connected)
    {
       try
       {
          if (UnitInfoDatabase.Insert(unitInfoModel))
          {
             if (Logger.IsDebugEnabled)
             {
                string message = String.Format(CultureInfo.CurrentCulture, "Inserted {0} into database.", unitInfoModel.UnitInfoData.ToProjectInfo());
                Logger.DebugFormat(Constants.ClientNameFormat, unitInfoModel.UnitInfoData.OwningSlotName, message);
             }
          }
       }
       catch (Exception ex)
       {
          Logger.ErrorFormat(ex, "{0}", ex.Message);
       }
    }
 }
コード例 #10
0
        public void FahClient_UpdateBenchmarkData_Test()
        {
            // setup
            var benchmarkCollection = new ProteinBenchmarkService();
            var database            = MockRepository.GenerateMock <IUnitInfoDatabase>();
            var fahClient           = new FahClient(MockRepository.GenerateStub <IMessageConnection>())
            {
                BenchmarkService = benchmarkCollection, UnitInfoDatabase = database
            };

            var unitInfo1 = new UnitInfo();

            unitInfo1.OwningClientName = "Owner";
            unitInfo1.OwningClientPath = "Path";
            unitInfo1.OwningSlotId     = 0;
            unitInfo1.ProjectID        = 2669;
            unitInfo1.ProjectRun       = 1;
            unitInfo1.ProjectClone     = 2;
            unitInfo1.ProjectGen       = 3;
            unitInfo1.FinishedTime     = new DateTime(2010, 1, 1);
            unitInfo1.QueueIndex       = 0;
            var currentUnitInfo = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo1
            };

            var unitInfo1Clone = unitInfo1.DeepClone();

            unitInfo1Clone.FramesObserved = 4;
            var frameDataDictionary = new Dictionary <int, WorkUnitFrameData>()
                                      .With(new WorkUnitFrameData {
                Duration = TimeSpan.FromMinutes(0), ID = 0
            },
                                            new WorkUnitFrameData {
                Duration = TimeSpan.FromMinutes(5), ID = 1
            },
                                            new WorkUnitFrameData {
                Duration = TimeSpan.FromMinutes(5), ID = 2
            },
                                            new WorkUnitFrameData {
                Duration = TimeSpan.FromMinutes(5), ID = 3
            });

            unitInfo1Clone.FrameData  = frameDataDictionary;
            unitInfo1Clone.UnitResult = WorkUnitResult.FinishedUnit;
            var unitInfoLogic1 = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone
            };

            var parsedUnits = new[] { unitInfoLogic1 };

            // arrange
            database.Stub(x => x.Connected).Return(true);
            database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(1);

            var benchmarkClient = new ProteinBenchmarkSlotIdentifier("Owner Slot 00", "Path");

            // assert before act
            Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient));
            Assert.AreEqual(false, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
            Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData));

            // act
            fahClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 0);

            // assert after act
            Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient));
            Assert.AreEqual(true, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
            Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime);

            database.VerifyAllExpectations();
        }
コード例 #11
0
ファイル: UnitInfoDatabase.cs プロジェクト: harlam357/hfm-net
 private static QueryParameters BuildUnitKeyQueryParameters(UnitInfoModel unitInfoModel)
 {
    var parameters = new QueryParameters { Name = String.Format(CultureInfo.InvariantCulture, "Query for existing {0}", unitInfoModel.UnitInfoData.ToProjectInfo()) };
    parameters.Fields.Add(new QueryField { Name = QueryFieldName.ProjectID, Type = QueryFieldType.Equal, Value = unitInfoModel.UnitInfoData.ProjectID });
    parameters.Fields.Add(new QueryField { Name = QueryFieldName.ProjectRun, Type = QueryFieldType.Equal, Value = unitInfoModel.UnitInfoData.ProjectRun });
    parameters.Fields.Add(new QueryField { Name = QueryFieldName.ProjectClone, Type = QueryFieldType.Equal, Value = unitInfoModel.UnitInfoData.ProjectClone });
    parameters.Fields.Add(new QueryField { Name = QueryFieldName.ProjectGen, Type = QueryFieldType.Equal, Value = unitInfoModel.UnitInfoData.ProjectGen });
    parameters.Fields.Add(new QueryField { Name = QueryFieldName.DownloadDateTime, Type = QueryFieldType.Equal, Value = unitInfoModel.UnitInfoData.DownloadTime });
    return parameters;
 }
コード例 #12
0
ファイル: UnitInfoDatabase.cs プロジェクト: harlam357/hfm-net
 private bool UnitInfoExists(UnitInfoModel unitInfoModel)
 {
    var rows = Fetch(BuildUnitKeyQueryParameters(unitInfoModel));
    return rows.Count != 0;
 }
コード例 #13
0
ファイル: UnitInfoDatabase.cs プロジェクト: harlam357/hfm-net
      public bool Insert(UnitInfoModel unitInfoModel)
      {
         // if the work unit is not valid simply return
         if (!ValidateUnitInfo(unitInfoModel.UnitInfoData))
         {
            return false;
         }

         // The Insert operation does not setup a WuHistory table if
         // it does not exist.  This was already handled when the
         // the DatabaseFilePath was set.
         Debug.Assert(TableExists(SqlTable.WuHistory));

         // ensure this unit is not written twice
         if (UnitInfoExists(unitInfoModel))
         {
            return false;
         }

         var entry = AutoMapper.Mapper.Map<HistoryEntry>(unitInfoModel.UnitInfoData);
         // cannot map these two properties from a UnitInfo instance
         // they only live at the UnitInfoLogic level
         entry.FramesCompleted = unitInfoModel.FramesComplete;
         entry.FrameTimeValue = unitInfoModel.GetRawTime(PpdCalculationType.AllFrames);
         // copy protein values for insert
         entry.WorkUnitName = unitInfoModel.CurrentProtein.WorkUnitName;
         entry.KFactor = unitInfoModel.CurrentProtein.KFactor;
         entry.Core = unitInfoModel.CurrentProtein.Core;
         entry.Frames = unitInfoModel.CurrentProtein.Frames;
         entry.Atoms = unitInfoModel.CurrentProtein.NumberOfAtoms;
         entry.BaseCredit = unitInfoModel.CurrentProtein.Credit;
         entry.PreferredDays = unitInfoModel.CurrentProtein.PreferredDays;
         entry.MaximumDays = unitInfoModel.CurrentProtein.MaximumDays;
         using (var connection = new SQLiteConnection(ConnectionString))
         {
            connection.Open();
            using (var database = new PetaPoco.Database(connection))
            {
               database.Insert(entry);
            }
         }

         return true;
      }
コード例 #14
0
ファイル: BenchmarksForm.cs プロジェクト: harlam357/hfm-net
      /// <summary>
      /// Return Multi-Line String (Array)
      /// </summary>
      private IEnumerable<string> ToMultiLineString(ProteinBenchmark benchmark, UnitInfoModel unitInfoModel, bool valuesOk, SlotStatus status, string ppdFormatString)
      {
         var output = new List<string>(12);

         Protein protein = _proteinService.Get(benchmark.ProjectID);
         if (protein != null)
         {
            var calculateBonus = _prefs.Get<BonusCalculationType>(Preference.BonusCalculation);

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

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

            output.Add(String.Empty);
         }
         else
         {
            _logger.WarnFormat("Could not find Project {0}.", benchmark.ProjectID);
         }

         return output.ToArray();
      }
コード例 #15
0
ファイル: SlotModel.cs プロジェクト: harlam357/hfm-net
      public DateTime TimeOfLastFrameProgress { get; set; } // should be init to DateTime.MinValue

      /// <summary>
      /// Update Time of Last Frame Progress based on Current and Parsed UnitInfo
      /// </summary>
      private void UpdateTimeOfLastProgress(UnitInfoModel parsedUnitInfo)
      {
         // Matches the Current Project and Raw Download Time
         if (UnitInfoModel.UnitInfoData.IsSameUnitAs(parsedUnitInfo.UnitInfoData))
         {
            // If the Unit Start Time Stamp is no longer the same as the UnitInfoLogic
            if (parsedUnitInfo.UnitInfoData.UnitStartTimeStamp.Equals(TimeSpan.MinValue) == false &&
                UnitInfoModel.UnitInfoData.UnitStartTimeStamp.Equals(TimeSpan.MinValue) == false &&
                parsedUnitInfo.UnitInfoData.UnitStartTimeStamp.Equals(UnitInfoModel.UnitInfoData.UnitStartTimeStamp) == false)
            {
               TimeOfLastUnitStart = DateTime.Now;
            }

            // If the Frames Complete is greater than the UnitInfoLogic Frames Complete
            if (parsedUnitInfo.FramesComplete > UnitInfoModel.FramesComplete)
            {
               // Update the Time Of Last Frame Progress
               TimeOfLastFrameProgress = DateTime.Now;
            }
         }
         else // Different UnitInfo - Update the Time Of Last 
         // Unit Start and Clear Frame Progress Value
         {
            TimeOfLastUnitStart = DateTime.Now;
            TimeOfLastFrameProgress = DateTime.MinValue;
         }
      }
コード例 #16
0
ファイル: SlotModel.cs プロジェクト: harlam357/hfm-net
      public SlotModel()
      {
         _unitInfoModel = new UnitInfoModel();

         Initialize();
         TimeOfLastUnitStart = DateTime.MinValue;
         TimeOfLastFrameProgress = DateTime.MinValue;
      }