/// <summary> Returns the count of Site_data for specified start/end time, WD bounds, time of day bin and season bin. </summary> public int GetDataCount(MCP.Site_data[] site, DateTime startTime, DateTime endTime, int WD_index, Met.TOD TOD, Met.Season season, MetCollection metList, bool getAll) { int avgCount = 0; foreach (MCP.Site_data thisSite in site) { if (thisSite.thisDate >= startTime && thisSite.thisDate <= endTime) { if (getAll == true) { avgCount++; } else { int thisWD_Ind = metList.GetWD_Ind(thisSite.thisWD); Met.TOD thisTOD = metList.GetTOD(thisSite.thisDate); Met.Season thisSeason = metList.GetSeason(thisSite.thisDate); if (((thisWD_Ind == WD_index) || WD_index == metList.numWD) && (thisTOD == TOD) && (thisSeason == season)) { avgCount++; } } } } return(avgCount); }
/// <summary> Calculates and returns the average wind speed for specified wind speed range, time interval range, /// wind direction range, time of day, and season </summary> public double CalcAvgWS(MCP.Site_data[] site, DateTime startTime, DateTime endTime, double minWD, double maxWD, Met.TOD TOD, Met.Season season, MetCollection metList) { double avgWS = 0; int avgCount = 0; foreach (MCP.Site_data thisSite in site) { if (thisSite.thisDate >= startTime && thisSite.thisDate <= endTime) { Met.TOD thisTOD = metList.GetTOD(thisSite.thisDate); Met.Season thisSeason = metList.GetSeason(thisSite.thisDate); if ((TOD == thisTOD || TOD == Met.TOD.All) && (thisSeason == season || season == Met.Season.All)) { if (((maxWD > minWD) && (thisSite.thisWD >= minWD && thisSite.thisWD <= maxWD)) || ((maxWD < minWD) && (thisSite.thisWD >= minWD || thisSite.thisWD <= maxWD))) { avgWS = avgWS + thisSite.thisWS; avgCount = avgCount + 1; } } } } if (avgCount > 0) { avgWS = avgWS / avgCount; } return(avgWS); }
public void Get_Data_Count_Test() { Continuum thisInst = new Continuum(""); string Filename = testingFolder + "\\Stats testing.cfm"; thisInst.Open(Filename); Met thisMet = thisInst.metList.metItem[0]; MCP thisMCP = thisMet.mcp; Stats thisStats = new Stats(); // Test 1 DateTime Start = Convert.ToDateTime("1/1/2005 12:00:00 AM"); DateTime End = Convert.ToDateTime("12/31/2010 11:00:00 PM"); int WD_Ind = 16; Met.TOD TOD = Met.TOD.All; Met.Season season = Met.Season.All; int thisCount = thisStats.GetDataCount(thisMCP.refData, Start, End, WD_Ind, TOD, season, thisInst.metList, false); Assert.AreEqual(thisCount, 52584, 1, "Wrong Count Test 1"); // Test 2 Start = Convert.ToDateTime("8/5/2007 1:30"); End = Convert.ToDateTime("11/2/2010 21:00"); WD_Ind = 4; TOD = Met.TOD.Day; season = Met.Season.Winter; thisInst.metList.numTOD = 2; thisInst.metList.numSeason = 4; thisCount = thisStats.GetDataCount(thisMCP.refData, Start, End, WD_Ind, TOD, season, thisInst.metList, false); Assert.AreEqual(thisCount, 163, 0, "Wrong Count Test 2"); // Test 3 Start = Convert.ToDateTime("6/24/2008 15:00"); End = Convert.ToDateTime("9/30/2008 23:50"); WD_Ind = 16; TOD = Met.TOD.All; season = Met.Season.All; thisInst.metList.numTOD = 1; thisInst.metList.numSeason = 1; thisCount = thisStats.GetDataCount(thisMCP.targetData, Start, End, WD_Ind, TOD, season, thisInst.metList, false); Assert.AreEqual(thisCount, 2361, 0, "Wrong Count Test 3"); // Test 4 Start = Convert.ToDateTime("9/3/2008 2:40"); End = Convert.ToDateTime("9/7/2008 15:20"); WD_Ind = 15; TOD = Met.TOD.Night; season = Met.Season.Fall; thisInst.metList.numTOD = 2; thisInst.metList.numSeason = 4; thisCount = thisStats.GetDataCount(thisMCP.targetData, Start, End, WD_Ind, TOD, season, thisInst.metList, false); Assert.AreEqual(thisCount, 7, 0, "Wrong Count Test 4"); // Test 5 Start = Convert.ToDateTime("6/24/2008 15:00"); End = Convert.ToDateTime("9/30/2008 23:50"); WD_Ind = 0; TOD = Met.TOD.All; season = Met.Season.All; thisInst.metList.numTOD = 1; thisInst.metList.numSeason = 1; thisCount = thisStats.GetDataCount(thisMCP.targetData, Start, End, WD_Ind, TOD, season, thisInst.metList, false); Assert.AreEqual(thisCount, 93, 0.001, "Wrong Count Test 5"); thisInst.Close(); }
public void Calc_Avg_WS_Test() { Continuum thisInst = new Continuum(""); string Filename = testingFolder + "\\Stats testing.cfm"; thisInst.Open(Filename); Met thisMet = thisInst.metList.metItem[0]; MCP thisMCP = thisMet.mcp; Stats thisStats = new Stats(); // Test 1 DateTime Start = Convert.ToDateTime("1/1/2005 12:00:00 AM"); DateTime End = Convert.ToDateTime("12/31/2010 11:00:00 PM"); double minDir = 0; double maxDir = 360; Met.TOD TOD = Met.TOD.All; Met.Season season = Met.Season.All; double This_Avg = thisStats.CalcAvgWS(thisMCP.refData, Start, End, minDir, maxDir, TOD, season, thisInst.metList); Assert.AreEqual(This_Avg, 6.61373, 0.001, "Wrong Avg WS Test 1"); // Test 2 Start = Convert.ToDateTime("8/5/2007 1:30"); End = Convert.ToDateTime("11/2/2010 21:00"); minDir = 78.75; maxDir = 101.25; TOD = Met.TOD.Day; season = Met.Season.Winter; thisInst.metList.numTOD = 2; thisInst.metList.numSeason = 4; This_Avg = thisStats.CalcAvgWS(thisMCP.refData, Start, End, minDir, maxDir, TOD, season, thisInst.metList); Assert.AreEqual(This_Avg, 5.853279, 0.001, "Wrong Avg WS Test 2"); // Test 3 Start = Convert.ToDateTime("6/24/2008 15:00"); End = Convert.ToDateTime("9/30/2008 23:50"); minDir = 0; maxDir = 360; TOD = Met.TOD.All; season = Met.Season.All; thisInst.metList.numTOD = 1; thisInst.metList.numSeason = 1; This_Avg = thisStats.CalcAvgWS(thisMCP.targetData, Start, End, minDir, maxDir, TOD, season, thisInst.metList); Assert.AreEqual(This_Avg, 5.134299, 0.001, "Wrong Avg WS Test 3"); // Test 4 Start = Convert.ToDateTime("9/3/2008 2:40"); End = Convert.ToDateTime("9/7/2008 15:20"); minDir = 326.25; maxDir = 348.75; TOD = Met.TOD.Night; season = Met.Season.Fall; thisInst.metList.numTOD = 2; thisInst.metList.numSeason = 4; This_Avg = thisStats.CalcAvgWS(thisMCP.targetData, Start, End, minDir, maxDir, TOD, season, thisInst.metList); Assert.AreEqual(This_Avg, 4.765827, 0.001, "Wrong Avg WS Test 4"); // Test 5 Start = Convert.ToDateTime("6/24/2008 15:00"); End = Convert.ToDateTime("9/30/2008 23:50"); minDir = 348.75; maxDir = 11.25; TOD = Met.TOD.All; season = Met.Season.All; thisInst.metList.numTOD = 1; thisInst.metList.numSeason = 1; This_Avg = thisStats.CalcAvgWS(thisMCP.targetData, Start, End, minDir, maxDir, TOD, season, thisInst.metList); Assert.AreEqual(This_Avg, 5.166236, 0.001, "Wrong Avg WS Test 5"); thisInst.Close(); }