Exemple #1
0
        /// <summary>
        /// This will Update the 'Accepted' Stats details and referenced id's from one Pull Request ID to another Pull Request ID.
        /// </summary>
        /// <param name="currentPullRequestID"></param>
        /// <param name="acceptedPullRequestID"></param>
        private void UpdateAcceptedStatsforPullRequest(int currentPullRequestID, int acceptedPullRequestID)
        {
            //Do I need to update the log table
            string HelperMessage = string.Empty;
            string connectStr    = Utilities.GetConnectionString();

            using (SqlConnection sqlCon = new SqlConnection(connectStr))
            {
                sqlCon.Open();
                try
                {
                    List <ApsimFile> currentApsimFiles = DBFunctions.GetApsimFilesRelatedPredictedObservedData(sqlCon, currentPullRequestID);

                    //need to get the (latest) run date for the acceptedPullRequestID
                    DateTime acceptedRunDate = DBFunctions.GetLatestRunDateForPullRequest(sqlCon, acceptedPullRequestID);

                    foreach (ApsimFile currentApsimFile in currentApsimFiles)
                    {
                        foreach (PredictedObservedDetails currentPODetails in currentApsimFile.PredictedObserved)
                        {
                            int acceptedPredictedObservedDetailsID = DBFunctions.GetAcceptedPredictedObservedDetailsId(sqlCon, acceptedPullRequestID, currentApsimFile.FileName, currentPODetails);
                            if (acceptedPredictedObservedDetailsID > 0)
                            {
                                HelperMessage = string.Format("Current Pull Request Id: {0} to Accepted Pull Request Id: {1} for FileName: {2} - PO TableName: {3}, Current PO Id: {4}, Accepted PO Id: {5}.", currentPullRequestID, acceptedPullRequestID, currentApsimFile.FileName, currentPODetails.DatabaseTableName, currentPODetails.ID, acceptedPredictedObservedDetailsID);

                                DataTable currentPOValues = DBFunctions.GetPredictedObservedValues(sqlCon, currentPODetails.ID);
                                DataTable currentStats    = Tests.CalculateStatsOnPredictedObservedValues(currentPOValues);

                                DataTable acceptedPOValues = DBFunctions.GetPredictedObservedValues(sqlCon, acceptedPredictedObservedDetailsID);
                                DataTable acceptedStats    = Tests.CalculateStatsOnPredictedObservedValues(acceptedPOValues);

                                //DataTable acceptedStats = DBFunctions.getPredictedObservedTestsData(connectStr, acceptedPredictedObservedDetailsID);

                                DataTable dtTests = Tests.MergeTestsStatsAndCompare(currentStats, acceptedStats);
                                DBFunctions.AddPredictedObservedTestsData(sqlCon, currentApsimFile.FileName, currentPODetails.ID, currentPODetails.DatabaseTableName, dtTests);

                                //Update the accepted reference for Predicted Observed Values, so that it can be
                                DBFunctions.UpdatePredictedObservedDetails(sqlCon, acceptedPredictedObservedDetailsID, currentPODetails.ID);
                            }
                        }
                    }
                    DBFunctions.UpdateApsimFileAcceptedDetails(sqlCon, currentPullRequestID, acceptedPullRequestID, acceptedRunDate);
                }
                catch (Exception ex)
                {
                    Utilities.WriteToLogFile(string.Format("ERROR:  Unable to update {0}: {1}", HelperMessage, ex.Message.ToString()));;
                }
            }
        }
        public void TestGetApsimFilesRelatedPredictedObservedDetailsData()
        {
            foreach (DbConnection connection in emptyConnections)
            {
                List <ApsimFile> apsimFiles = DBFunctions.GetApsimFilesRelatedPredictedObservedData(connection, 1);
                Assert.AreEqual(0, apsimFiles.Count);
            }

            foreach (DbConnection connection in populousConnections)
            {
                Assert.AreEqual(0, DBFunctions.GetApsimFilesRelatedPredictedObservedData(connection, 0).Count);
                List <ApsimFile> apsimFiles = DBFunctions.GetApsimFilesRelatedPredictedObservedData(connection, 1);
                Assert.AreEqual(1, apsimFiles.Count);

                ApsimFile file = apsimFiles[0];
                Assert.AreEqual(-1, file.AcceptedPullRequestId);
                Assert.AreEqual("wheat.apsimx", file.FileName);
                Assert.AreEqual("~/wheat.apsimx", file.FullFileName);
                Assert.AreEqual(1, file.ID);
                Assert.AreEqual(true, file.IsMerged);
                Assert.AreEqual(1, file.PullRequestId);
                Assert.AreEqual(new DateTime(2020, 1, 1), file.RunDate);
                Assert.AreEqual(null, file.Simulations); // todo: should we implement this?
                Assert.AreEqual(false, file.StatsAccepted);
                Assert.AreEqual("submitdetails", file.SubmitDetails);

                Assert.AreEqual(1, file.PredictedObserved.Count());
                PredictedObservedDetails details = file.PredictedObserved.ElementAt(0);

                Assert.AreEqual(0, details.AcceptedPredictedObservedDetailsId);
                Assert.AreEqual(null, details.ApsimFile); // Not brave enough to change this yet
                Assert.AreEqual(1, details.ApsimID);
                Assert.AreEqual(null, details.Data);      // Not brave enough to change this yet
                Assert.AreEqual("PredictedObserved", details.DatabaseTableName);
                Assert.AreEqual("xval", details.FieldNameUsedForMatch);
                Assert.AreEqual(null, details.FieldName2UsedForMatch);
                Assert.AreEqual(null, details.FieldName3UsedForMatch);
                Assert.AreEqual(1, details.HasTests);
                Assert.AreEqual(1, details.ID);
                Assert.AreEqual("Observations", details.ObservedTableName);
                Assert.AreEqual(0, details.PassedTests);
                Assert.AreEqual("HarvestReport", details.PredictedTableName);
            }
        }