Exemple #1
0
        private static void ImportInsolation()
        {
            SunPrincipal sunPrincipal = SunPrincipalFactory.CreateSystemSunPrincipal();

            SunPrincipal.ToCallContext(sunPrincipal);

            List <EnergyEstimateImportItem> energyImportItems = GetRefDataFromFile();

            try
            {
                string path = _insolationPath;

                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }

                DeleteAllFiles(path);

                Console.Write("Export insolation to files...");



                foreach (var energyImportItem in energyImportItems)
                {
                    Project project = ServiceManager.Projects.GetProjectForProjectNumber(energyImportItem.ProjectNumber);
                    EnergyEstimateHistory history = ServiceManager.Energy.GetEnergyEstimateHistoryForProjectID(project.ProjectID);

                    if (history != null)
                    {
                        history.EnergyEstimateMonthList.Sort((a, b) => a.Month.CompareTo(b.Month));

                        string projectName = project.ProjectName;
                        string projectNo   = project.ProjectNumber;

                        projectName = projectName.Replace(",", "-");
                        projectName = projectName.Replace("/", " ");
                        projectName = projectName.Replace("\\", " ");

                        // Check if there are reference insolation (GlobalInclined insolation) in SAM Energy Estimates
                        if (history.EnergyEstimateMonthList != null && history.EnergyEstimateMonthList[0].GlobalIncident != null)
                        {
                            // create csv file
                            string filename = string.Format("{0}", projectNo);
                            string file     = string.Format("{0}{1}.csv", path, filename);

                            StreamWriter sw = new StreamWriter(file);

                            foreach (var estimateMonth in history.EnergyEstimateMonthList)
                            {
                                int month = estimateMonth.Month;
                                sw.WriteLine("{0},{1}", estimateMonth.Month, estimateMonth.GlobalIncident);
                                //sw.WriteLine("{0},{1}", estimateMonth.Month, estimateMonth.GlobalHorizon);

                                sw.Flush();
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(string.Format("{0}: No estimate", energyImportItem.ProjectNumber));
                    }
                }

                Console.Write("Done");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                SunPrincipal.ClearCallContext();
            }
        }
Exemple #2
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;
                }
            }
        }