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)); } }
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); } }
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 }); } } }