Ejemplo n.º 1
0
        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();
                }
            }
        }
Ejemplo n.º 2
0
        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();

            }
        }