예제 #1
0
파일: Program.cs 프로젝트: cng1/GitTest
        private static List <EnergyEstimateImportItem> GetRefDataFromFile()
        {
            string importFile;
            string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            importFile = Path.Combine(directory, "energy.txt");

            StreamReader reader     = new StreamReader(importFile);
            int          lineNumber = 0;

            List <EnergyEstimateImportItem> importItems = new List <EnergyEstimateImportItem>();

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                lineNumber++;
                try
                {
                    string[] stringValues = line.Split("\t".ToCharArray());
                    if (stringValues.Length >= 2)
                    {
                        string             projectNumber = stringValues[0];
                        List <Degradation> degradations  = new List <Degradation>();

                        for (var i = 1; i < stringValues.Length; i++)
                        {
                            var    rate = stringValues[i];
                            double degradationRate;
                            int    degradationYear = -1;

                            string[] rateValuePairs = rate.Split('|');

                            degradationRate = Convert.ToDouble(rateValuePairs[0]);
                            if (rateValuePairs.Length == 2)
                            {
                                degradationYear = Convert.ToInt32(rateValuePairs[1]);
                            }

                            Degradation degradation = new Degradation();
                            degradation.Rate = degradationRate;
                            degradation.Year = degradationYear;
                            degradations.Add(degradation);
                        }

                        EnergyEstimateImportItem importItem = new EnergyEstimateImportItem();
                        importItem.ProjectNumber = projectNumber;
                        importItem.Degradations  = degradations;
                        importItems.Add(importItem);
                    }
                    else
                    {
                        throw new Exception("Incorrect # of values");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on line #" + lineNumber);
                    Console.WriteLine(ex.Message);
                }
            }

            return(importItems);
        }
예제 #2
0
        private static List<EnergyEstimateImportItem> GetRefDataFromFile()
        {
            string importFile;
            string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

            importFile = Path.Combine(directory, "energy.txt");

            StreamReader reader = new StreamReader(importFile);
            int lineNumber = 0;

            List<EnergyEstimateImportItem> importItems = new List<EnergyEstimateImportItem>();

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine();
                lineNumber++;
                try
                {
                    string[] stringValues = line.Split("\t".ToCharArray());
                    if (stringValues.Length >= 2)
                    {
                        string projectNumber = stringValues[0];
                        List<Degradation> degradations = new List<Degradation>();

                        for (var i = 1; i < stringValues.Length; i++)
                        {
                            var rate = stringValues[i];
                            double degradationRate;
                            int degradationYear = -1;

                            string[] rateValuePairs = rate.Split('|');

                            degradationRate = Convert.ToDouble(rateValuePairs[0]);
                            if (rateValuePairs.Length == 2)
                            {
                                degradationYear = Convert.ToInt32(rateValuePairs[1]);
                            }

                            Degradation degradation = new Degradation();
                            degradation.Rate = degradationRate;
                            degradation.Year = degradationYear;
                            degradations.Add(degradation);
                        }

                        EnergyEstimateImportItem importItem = new EnergyEstimateImportItem();
                        importItem.ProjectNumber = projectNumber;
                        importItem.Degradations = degradations;
                        importItems.Add(importItem);

                    }
                    else
                        throw new Exception("Incorrect # of values");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error on line #" + lineNumber);
                    Console.WriteLine(ex.Message);
                }
            }

            return importItems;
        }
예제 #3
0
파일: Program.cs 프로젝트: cng1/GitTest
        // Column 1 = Project #
        // Column 2 = Decay rate1|year (rate in decimal ie 0.005 not 0.5%, year in integer applying to rate1. If no year, defaul to lifespan of the plant, 35 years)
        // Column 3 = Decay rate2|year (rate in decimal ie 0.005 not 0.5%, year in integer applying to rate2. This is optional)
        // The assumption is that the project has a Commercial Operation date; that is the date the projection will begin
        private static void ImportEnergy(EnergyEstimateImportItem energyImportItem)
        {
            SunPrincipal.ToCallContext(_sunPrincipal);

            string projectNumber = energyImportItem.ProjectNumber;

            Project         project      = ServiceManager.Projects.GetProjectForProjectNumber(projectNumber);
            List <PVSystem> pvSystemList = ServiceManager.Design.GetPVSystemListForProjectID(project.ProjectID);
            ProjectPlan     projectPlan  = ServiceManager.Planning.GetProjectPlan(EntityType.Project, project.ProjectID);
            DateTime        cod          = projectPlan.GetMilestone(MilestoneType.CommercialOperation).ActualEndDate.Value;

            double[] adjMonthly = new double[12];

            // Get 12 months projections from SAM
            EnergyEstimateHistory energyHistory = ServiceManager.Energy.GetEnergyEstimateHistoryForProjectID(project.ProjectID);

            if (energyHistory == null)
            {
                Console.Write("      (No Energy Estimates in SAM)");
                Console.WriteLine();
            }
            else
            {
                energyHistory.EnergyEstimateMonthList.Sort((a, b) => a.Month.CompareTo(b.Month));

                int month = 0;
                foreach (var estimateMonth in energyHistory.EnergyEstimateMonthList)
                {
                    double?refEnergy = estimateMonth.EnergyAfterLosses;
                    //double? refInsolation = estimateMonth.GlobalIncident;
                    double?refInsolation = estimateMonth.GlobalHorizon;

                    adjMonthly[month] = Convert.ToDouble(refEnergy / pvSystemList.Count);
                    month++;
                }

                SunPrincipal.ClearCallContext();

                DateTime startDate        = cod;
                DateTime lastDate         = cod;
                bool     deleteSeries     = true;
                double   degradeRateStart = 1.00;

                foreach (var degradation in energyImportItem.Degradations)
                {
                    double degradeRate = degradation.Rate;
                    int    degradeYear = degradation.Year;

                    if (degradeYear <= 0)
                    {
                        degradeYear = 35;   //default to 35 years if there is only one rate available
                    }

                    // Load estimates
                    foreach (PVSystem pvSystem in pvSystemList)
                    {
                        EnergyEstimateNew(pvSystem.PVSystemID, startDate, adjMonthly, degradeRate, degradeYear, degradeRateStart, 109, deleteSeries, useFOD9Table: true);  //Load to channel 109 in FO_D9 Table
                        EnergyEstimateNew(pvSystem.PVSystemID, startDate, adjMonthly, degradeRate, degradeYear, degradeRateStart, 109, deleteSeries, useFOD9Table: false); //Load to channel 109 in SB_D5 table
                    }

                    // start date for the next degradation period
                    startDate        = startDate.AddYears(degradeYear).AddDays(1);
                    deleteSeries     = false;
                    degradeRateStart = _lastDegradationFactor;
                }
            }
        }
예제 #4
0
        // Column 1 = Project #
        // Column 2 = Decay rate1|year (rate in decimal ie 0.005 not 0.5%, year in integer applying to rate1. If no year, defaul to lifespan of the plant, 35 years)
        // Column 3 = Decay rate2|year (rate in decimal ie 0.005 not 0.5%, year in integer applying to rate2. This is optional)
        // The assumption is that the project has a Commercial Operation date; that is the date the projection will begin
        private static void ImportEnergy(EnergyEstimateImportItem energyImportItem)
        {
            SunPrincipal.ToCallContext(_sunPrincipal);

            string projectNumber = energyImportItem.ProjectNumber;

            Project project = ServiceManager.Projects.GetProjectForProjectNumber(projectNumber);
            List<PVSystem> pvSystemList = ServiceManager.Design.GetPVSystemListForProjectID(project.ProjectID);
            ProjectPlan projectPlan = ServiceManager.Planning.GetProjectPlan(EntityType.Project, project.ProjectID);
            DateTime cod = projectPlan.GetMilestone(MilestoneType.CommercialOperation).ActualEndDate.Value;

            double[] adjMonthly = new double[12];

            // Get 12 months projections from SAM
            EnergyEstimateHistory energyHistory = ServiceManager.Energy.GetEnergyEstimateHistoryForProjectID(project.ProjectID);

            if (energyHistory == null)
            {
                Console.Write("      (No Energy Estimates in SAM)");
                Console.WriteLine();
            }
            else
            {
                energyHistory.EnergyEstimateMonthList.Sort((a, b) => a.Month.CompareTo(b.Month));

                int month = 0;
                foreach (var estimateMonth in energyHistory.EnergyEstimateMonthList)
                {
                    double? refEnergy = estimateMonth.EnergyAfterLosses;
                    //double? refInsolation = estimateMonth.GlobalIncident;
                    double? refInsolation = estimateMonth.GlobalHorizon;

                    adjMonthly[month] = Convert.ToDouble(refEnergy / pvSystemList.Count);
                    month++;
                }

                SunPrincipal.ClearCallContext();

                DateTime startDate = cod;
                DateTime lastDate = cod;
                bool deleteSeries = true;
                double degradeRateStart = 1.00;

                foreach (var degradation in energyImportItem.Degradations)
                {
                    double degradeRate = degradation.Rate;
                    int degradeYear = degradation.Year;

                    if (degradeYear <= 0)
                    {
                        degradeYear = 35;   //default to 35 years if there is only one rate available
                    }

                    // Load estimates
                    foreach (PVSystem pvSystem in pvSystemList)
                    {
                        EnergyEstimateNew(pvSystem.PVSystemID, startDate, adjMonthly, degradeRate, degradeYear, degradeRateStart, 109, deleteSeries, useFOD9Table: true); //Load to channel 109 in FO_D9 Table
                        EnergyEstimateNew(pvSystem.PVSystemID, startDate, adjMonthly, degradeRate, degradeYear, degradeRateStart, 109, deleteSeries, useFOD9Table: false); //Load to channel 109 in SB_D5 table
                    }

                    // start date for the next degradation period
                    startDate = startDate.AddYears(degradeYear).AddDays(1);
                    deleteSeries = false;
                    degradeRateStart = _lastDegradationFactor;

                }
            }

        }