private static void EnergyEstimateNew(int pvSystemID, DateTime startDate, double[] monthly, double annualDegradeRate, int degradeYear, double degradeRateStart, int channelID, bool deleteSeries, bool useFOD9Table = false) { //cng 7-30-14. the Reference Data is migrated from SB_D5 table to FO_D9 tabe to support higher precision. SqlConnection cnn = null; try { SEPrincipal.ToCallContext(_sePrincipal); Source source = ServiceManager.Monitoring.GetSource(SourceType.PVSystem, pvSystemID, true); Series series = ServiceManager.Monitoring.GetPrimarySeries(source.SourceID, channelID, true); SEPrincipal.ClearCallContext(); SunPrincipal.ToCallContext(_sunPrincipal); double total = 0; for (int i = 0; i < 12; i++) { total += monthly[i]; } PVSystem pvSystem = ServiceManager.Design.GetPVSystem(pvSystemID); pvSystem.WarranteedYear1Output = total; ServiceManager.Design.UpdatePVSystem(pvSystem); double[] energyPerDay; EnergyEstimater estimater = new EnergyEstimater(); estimater.Calculate(monthly, out energyPerDay); DateTime start = startDate; DateTime end = start.AddYears(degradeYear).AddDays(-1); DateTime date = start; int dayOfYear = date.DayOfYear - 1; if (((double)date.Year / 4) == (int)((double)date.Year / 4) && date.Month > 2) { dayOfYear--; } double factor = degradeRateStart; SunPrincipal.ClearCallContext(); cnn = new SqlConnection(@"Data Source=10.8.65.3\prod_sf;Initial Catalog=SOIL_PROD;User ID=SAM_USER;password=#se2007"); cnn.Open(); StringBuilder builder = new StringBuilder(); StringWriter writer = new StringWriter(builder); string sql = ""; if (deleteSeries) { if (useFOD9Table) { sql = "EXEC DAT.SP_FO_D9_DELETE_ALL " + series.SeriesID; } else { sql = "EXEC DAT.SP_SB_D5_DELETE_ALL " + series.SeriesID; } writer.WriteLine(sql); } while (date <= end) { double leapYearFactor = Program.GetLeapYearFactor(date, monthly[1], energyPerDay[31 + 28 - 1]); double refEnergy = energyPerDay[dayOfYear] * factor * leapYearFactor; if (useFOD9Table) { sql = string.Format("EXEC DAT.SP_FO_D9_ADD {0}, {1}, 0, 0, {2}", series.SeriesID, +date.Subtract(new DateTime(2000, 1, 1)).TotalDays, refEnergy); } else { sql = string.Format("EXEC DAT.SP_SB_D5_ADD {0}, {1}, 0, 0, {2}", series.SeriesID, +date.Subtract(new DateTime(2000, 1, 1)).TotalDays, refEnergy); } writer.WriteLine(sql); //Console.WriteLine(refEnergy); date = date.AddDays(1); if (!(date.Month == 2 && date.Day == 29)) { dayOfYear++; } if (date.Month == 1 && date.Day == 1) { dayOfYear = 0; } if (date.Month == start.Month && date.Day == start.Day) { factor *= (1 - annualDegradeRate); } } writer.Close(); sql = builder.ToString(); SqlCommand cmd = new SqlCommand(sql, cnn); cmd.CommandTimeout = 1000000; cmd.ExecuteNonQuery(); //Save last data point of the degradation period _lastDegradationFactor = factor; } catch (Exception ex) { throw ex; } finally { if (cnn != null) { cnn.Close(); } } }
public static void Main(string[] args) { //args = new string[1]; //args[0] = "/i"; // Initialize input arguments bool insolationOnly = false; foreach (var arg in args) { var splitArg = arg.Split('='); string value = ""; if (splitArg != null && splitArg.Count() > 0) { var command = splitArg[0].ToLower(); if (splitArg.Count() > 1) { value = splitArg[1].ToLower().Trim(); } switch (command) { //interval case "/i": insolationOnly = true; break; } } } // create IPrincipal string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string path = Assembly.GetExecutingAssembly().Location + ".config"; RemotingConfiguration.Configure(path, true); _sunPrincipal = SunPrincipalFactory.CreateSystemSunPrincipal(); // For SAM API calls _sePrincipal = SEPrincipalFactory.CreateSystemSEPrincipal(); // For SMART API Calls // Get insolation path from Configuration //_insolationPath = System.Configuration.ConfigurationManager.AppSettings.Get("InsolationPath"); _insolationPath = string.Format("{0}\\{1}\\", directory, "insolation"); // JobStart Heading Console.WriteLine("--------------------------"); Console.WriteLine("Reference Data Import Tool"); Console.WriteLine("--------------------------"); Console.WriteLine(); Console.WriteLine("This tool is used to import Energy Estimates from SAM into SMART."); Console.WriteLine(); // import reference data ImportInsolation(); if (!insolationOnly) { ImportEnergyEstimates(); } Console.WriteLine(); Console.WriteLine(); }
public static void Main(string[] args) { //args = new string[1]; //args[0] = "/i"; // Initialize input arguments bool insolationOnly = false; foreach (var arg in args) { var splitArg = arg.Split('='); string value = ""; if (splitArg != null && splitArg.Count() > 0) { var command = splitArg[0].ToLower(); if (splitArg.Count() > 1) value = splitArg[1].ToLower().Trim(); switch (command) { //interval case "/i": insolationOnly = true; break; } } } // create IPrincipal string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); string path = Assembly.GetExecutingAssembly().Location + ".config"; RemotingConfiguration.Configure(path, true); _sunPrincipal = SunPrincipalFactory.CreateSystemSunPrincipal(); // For SAM API calls _sePrincipal = SEPrincipalFactory.CreateSystemSEPrincipal(); // For SMART API Calls // Get insolation path from Configuration //_insolationPath = System.Configuration.ConfigurationManager.AppSettings.Get("InsolationPath"); _insolationPath = string.Format("{0}\\{1}\\", directory, "insolation"); // JobStart Heading Console.WriteLine("--------------------------"); Console.WriteLine("Reference Data Import Tool"); Console.WriteLine("--------------------------"); Console.WriteLine(); Console.WriteLine("This tool is used to import Energy Estimates from SAM into SMART."); Console.WriteLine(); // import reference data ImportInsolation(); if (!insolationOnly) { ImportEnergyEstimates(); } Console.WriteLine(); Console.WriteLine(); }