Ejemplo n.º 1
0
        public double CalculateModulePowerLoss(PanelModuleType moduleType, double temperatureCelsius)
        {
            switch (moduleType)
            {
            case PanelModuleType.Monocrystalline:
            {
                double referenceTemperature = 25;
                double powerLossCoefficient = -0.47;
                return(CalculateModulePowerLoss(temperatureCelsius, referenceTemperature, powerLossCoefficient));
            }

            case PanelModuleType.Polycrystalline:
            {
                double referenceTemperature = 25;
                double powerLossCoefficient = -0.35;
                return(CalculateModulePowerLoss(temperatureCelsius, referenceTemperature, powerLossCoefficient));
            }

            case PanelModuleType.ThinFilm:
            {
                double referenceTemperature = 25;
                double powerLossCoefficient = -0.20;
                return(CalculateModulePowerLoss(temperatureCelsius, referenceTemperature, powerLossCoefficient));
            }

            default: throw new InvalidProgramException($"Invalid {nameof(PanelModuleType)}");
            }
        }
Ejemplo n.º 2
0
 public async Task <SystemInfo> GetSystemInfoAsync(
     double systemCapacity,
     PanelModuleType moduleType,
     PanelArrayType arrayType,
     double systemLosses,
     double?tilt,
     double azmuth,
     GeoCoords coords)
 {
     try
     {
         return(await GetSystemInfoAsync("intl", systemCapacity, moduleType, arrayType, systemLosses, tilt, azmuth, coords));
     }
     catch (Exception e)
     {
         return(await GetSystemInfoAsync("tmy3", systemCapacity, moduleType, arrayType, systemLosses, tilt, azmuth, coords));
     }
 }
Ejemplo n.º 3
0
        public async Task <SystemInfo> GetSystemInfoCachedAsync(
            long cacheID,
            double systemCapacity,
            PanelModuleType moduleType,
            PanelArrayType arrayType,
            double systemLosses,
            double?tilt,
            double azmuth,
            GeoCoords coords)
        {
            if (sysInfoCache.TryGetValue(cacheID, out SystemInfo cached))
            {
                return(cached);
            }
            else
            {
                SystemInfo systemInfo = await GetSystemInfoAsync(systemCapacity, moduleType, arrayType, systemLosses, tilt, azmuth, coords);

                sysInfoCache.TryAdd(cacheID, systemInfo);
                return(systemInfo);
            }
        }
Ejemplo n.º 4
0
        private async Task <SystemInfo> GetSystemInfoAsync(
            string dataset,
            double systemCapacity,
            PanelModuleType moduleType,
            PanelArrayType arrayType,
            double systemLosses,
            double?tilt,
            double azmuth,
            GeoCoords coords)
        {
            using (var client = new HttpClient())
            {
                string query = CreateQueryParams(new Params
                {
                    { "api_key", apiKey },
                    { "timeframe", "hourly" },
                    { "dataset", dataset },
                    { "system_capacity", systemCapacity.ToString() },
                    { "module_type", ((int)moduleType).ToString() },
                    { "losses", systemLosses.ToString() },
                    { "array_type", ((int)arrayType).ToString() },
                    { "tilt", tilt.ToString() },
                    { "azimuth", azmuth.ToString() },
                    { "lat", coords.Latitude.ToString() },
                    { "lon", coords.Longitude.ToString() },
                    { "radius", "0" }
                });

                string requestUrl = $"{BaseUrl}?{query}";
                string json       = null;

                try
                {
                    json = await client.GetStringAsync(requestUrl);
                }
                catch (Exception e)
                {
                    throw e;
                }

                JObject data   = JObject.Parse(json);
                JArray  errors = data["errors"] as JArray;

                if (errors != null && errors.Count != 0)
                {
                    throw new AggregateException(errors.Select(error => new Exception(error.ToString())));
                }
                else
                {
                    JObject output = (JObject)data["outputs"];

                    List <double> dcArrayOutputMonthly  = ((JArray)output["dc_monthly"]).Values <double>().ToList();
                    double        dcArrayOutputAnnually = dcArrayOutputMonthly.Sum();

                    return(new SystemInfo
                    {
                        HourlyDCArrayOutput = ((JArray)output["dc"]).Values <double>().Select(x => x / 1000).ToList(),
                        MonthlyDCArrayOutput = dcArrayOutputMonthly.ToList(),
                        AnnualDCArrayOutput = dcArrayOutputAnnually
                    });
                }
            }
        }