public void TestParseMinerSettingsFileAndMineData()
        {
            // Arrange
            var ConfigPath = @".\ApiDataMinerConfigs\ApiDataMinerConfigs.xml";

            // Act
            var apiDataMiner = new ApiDataMiner(databaseConnectionString);

            apiDataMiner.ParseMinerSettingsFileAndMineData(ConfigPath);

            // Assert
            using (var streamReader = new StreamReader(ConfigPath))
            {
                var xmlSerializer = new XmlSerializer(typeof(ApiMinerConfigLayout));
                var minerConfigs  = (ApiMinerConfigLayout)xmlSerializer.Deserialize(streamReader);

                foreach (var regionConfiguration in minerConfigs.Regions)
                {
                    // Verify emissions were mined successfully for each region in the Config File
                    if (regionConfiguration.EmissionsMiningRegion != null)
                    {
                        var emissionsRegionName = regionConfiguration.EmissionsMiningRegion.friendlyName;
                        var timeZone            = regionConfiguration.EmissionsMiningRegion.TimeZone;
                        var regionLat           = regionConfiguration.EmissionsMiningRegion.Latitude;
                        var regionLong          = regionConfiguration.EmissionsMiningRegion.Longitude;
                        var regionWattTimeName  = regionConfiguration.EmissionsMiningRegion.EmissionsWattTimeAbbreviation;
                        var wattTimeApiUrl      = regionConfiguration.EmissionsMiningRegion.ApiUrl;
                        var wattTimeApiKey      = regionConfiguration.EmissionsMiningRegion.ApiKey;

                        var wattTimeApiV2Url     = regionConfiguration.EmissionsMiningRegion.WattTimeApiV2Url;
                        var wattTimeUsername     = regionConfiguration.EmissionsMiningRegion.WattTimeUsername;
                        var wattTimePassword     = regionConfiguration.EmissionsMiningRegion.WattTimePassword;
                        var wattTimeEmail        = regionConfiguration.EmissionsMiningRegion.WattTimeEmail;
                        var wattTimeOrganization = regionConfiguration.EmissionsMiningRegion.WattTimeOrganization;

                        var selfThrottlingMethod      = regionConfiguration.WundergroundWeatherMiningRegion.SelfThrottlingMethod;
                        var maxNumberOfCallsPerMinute =
                            regionConfiguration.WundergroundWeatherMiningRegion.MaxNumberOfCallsPerMinute;
                        var startDateTime = DateTime.UtcNow.AddDays(-2);
                        var endDateTime   = DateTime.UtcNow.AddDays(10);

                        var wattTimeInteraction = new EmissionsApiInteraction(selfThrottlingMethod, maxNumberOfCallsPerMinute);
                        var results             = wattTimeInteraction.GetObservedMarginalCarbonResults(
                            wattTimeApiUrl,
                            regionWattTimeName,
                            wattTimeUsername,
                            wattTimePassword,
                            startDateTime,
                            endDateTime,
                            null);

                        int regionId;
                        using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                        {
                            regionId =
                                _objectModel.AddEmissionsRegion(emissionsRegionName, timeZone, regionLat, regionLong)
                                .EmissionsRegionID;
                        }

                        using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                        {
                            foreach (var result in results)
                            {
                                var dataPoint = _objectModel.FindCarbonEmissionsDataPoint(regionId, result.point_time);
                                Assert.IsNotNull(dataPoint);
                            }
                        }
                    }

                    // Verify weather was mined successfully for each region in the Config File
                    if (regionConfiguration.WundergroundWeatherMiningRegion != null)
                    {
                        var emissionsRegionName             = regionConfiguration.WundergroundWeatherMiningRegion.friendlyName;
                        var timeZone                        = regionConfiguration.WundergroundWeatherMiningRegion.TimeZone;
                        var regionLat                       = regionConfiguration.WundergroundWeatherMiningRegion.Latitude;
                        var regionLong                      = regionConfiguration.WundergroundWeatherMiningRegion.Longitude;
                        var weatherRegionWundergroundSubUrl =
                            regionConfiguration.WundergroundWeatherMiningRegion.weatherRegionWundergroundSubUrl;
                        var wundergroundApiUrl        = regionConfiguration.WundergroundWeatherMiningRegion.ApiUrl;
                        var wundergroundApiKey        = regionConfiguration.WundergroundWeatherMiningRegion.ApiKey;
                        var selfThrottlingMethod      = regionConfiguration.WundergroundWeatherMiningRegion.SelfThrottlingMethod;
                        var maxNumberOfCallsPerMinute =
                            regionConfiguration.WundergroundWeatherMiningRegion.MaxNumberOfCallsPerMinute;

                        var wundergroundWeatherInteraction = new WundergroundWeatherInteraction(
                            selfThrottlingMethod,
                            maxNumberOfCallsPerMinute);
                        List <HourlyForecast> results = new List <HourlyForecast>();

                        switch (regionConfiguration.WundergroundWeatherMiningRegion.MiningMethod)
                        {
                        case "GPS":
                            results =
                                wundergroundWeatherInteraction.GetTenDayHourlyForecastWeatherData(
                                    wundergroundApiUrl,
                                    regionConfiguration.WundergroundWeatherMiningRegion.Latitude,
                                    regionConfiguration.WundergroundWeatherMiningRegion.Longitude,
                                    wundergroundApiKey);
                            break;

                        case "WundergroundPageSubUrl":
                        default:
                            results =
                                wundergroundWeatherInteraction.GetTenDayHourlyForecastWeatherData(
                                    wundergroundApiUrl,
                                    weatherRegionWundergroundSubUrl,
                                    wundergroundApiKey);
                            break;
                        }

                        int regionId;
                        using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                        {
                            regionId =
                                _objectModel.AddWeatherRegion(emissionsRegionName, timeZone, regionLat, regionLong)
                                .WeatherRegionID;
                        }

                        using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                        {
                            foreach (var result in results)
                            {
                                var dataPoint = _objectModel.FindWeatherDataPoint(
                                    regionId,
                                    result.observationDateTime);
                                Assert.IsNotNull(dataPoint);
                            }
                        }
                    }

                    // Verify weather was mined successfully for each region in the Config File
                    if (regionConfiguration.DarkSkyWeatherMiningRegion != null)
                    {
                        var regionName                = regionConfiguration.DarkSkyWeatherMiningRegion.friendlyName;
                        var timeZone                  = regionConfiguration.DarkSkyWeatherMiningRegion.TimeZone;
                        var regionLat                 = regionConfiguration.DarkSkyWeatherMiningRegion.Latitude;
                        var regionLong                = regionConfiguration.DarkSkyWeatherMiningRegion.Longitude;
                        var apiUrl                    = regionConfiguration.DarkSkyWeatherMiningRegion.ApiUrl;
                        var apiKey                    = regionConfiguration.DarkSkyWeatherMiningRegion.ApiKey;
                        var selfThrottlingMethod      = regionConfiguration.DarkSkyWeatherMiningRegion.SelfThrottlingMethod;
                        var maxNumberOfCallsPerMinute =
                            regionConfiguration.DarkSkyWeatherMiningRegion.MaxNumberOfCallsPerMinute;
                        var maxNumberOfCallsPerDay =
                            regionConfiguration.DarkSkyWeatherMiningRegion.MaxNumberOfCallsPerDay;

                        var darkSkyWeatherInteraction = new DarkSkyWeatherInteraction(
                            selfThrottlingMethod,
                            maxNumberOfCallsPerMinute,
                            maxNumberOfCallsPerDay);
                        List <HourlyDatum> results = new List <HourlyDatum>();

                        var forecastStartDateTime = DateTime.UtcNow;
                        var forecastEndDateTime   = DateTime.UtcNow.AddDays(10);

                        results = darkSkyWeatherInteraction.GetForecastWeatherData(
                            apiUrl,
                            apiKey,
                            regionLat,
                            regionLong,
                            forecastStartDateTime,
                            forecastEndDateTime);

                        int regionId;
                        using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                        {
                            regionId =
                                _objectModel.AddWeatherRegion(regionName, timeZone, regionLat, regionLong)
                                .WeatherRegionID;
                        }

                        using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                        {
                            foreach (var result in results)
                            {
                                var dataPoint = _objectModel.FindWeatherDataPoint(
                                    regionId,
                                    result.dateTime);
                                Assert.IsNotNull(dataPoint);
                            }
                        }
                    }
                }
            }
        }
        public void TestMineForecastMarginalCarbonResults()
        {
            // Arrange
            var regionWattTimeName  = "PJM";
            var smartGridRegionName = "PJM";
            var timeZone            = "Eastern Standard Time";
            var regionLat           = 40.348444276169;
            var regionLong          = -74.6428556442261;

            var startDateTime = DateTime.UtcNow.AddDays(-2);
            var endDateTime   = DateTime.UtcNow.AddDays(10);

            var    wattTimeApiUrl            = CloudConfigurationManager.GetSetting("WattTimeApiUrl");
            var    wattTimeApiKey            = CloudConfigurationManager.GetSetting("WattTimeApiKey");
            string wattTimeApiV2Url          = CloudConfigurationManager.GetSetting("WattTimeApiV2Url");
            string WattTimeUsername          = CloudConfigurationManager.GetSetting("WattTimeUsername");
            string WattTimePassword          = CloudConfigurationManager.GetSetting("WattTimePassword");
            string WattTimeEmail             = CloudConfigurationManager.GetSetting("WattTimeEmail");
            string WattTimeOrganization      = CloudConfigurationManager.GetSetting("WattTimeOrganization");
            var    selfThrottlingMethod      = "AzureTableStorageCallRecollection";
            var    maxNumberOfCallsPerMinute = 9;

            int regionId;

            using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
            {
                regionId =
                    _objectModel.AddEmissionsRegion(smartGridRegionName, timeZone, regionLat, regionLong)
                    .EmissionsRegionID;
            }


            var wattTimeInteraction = new EmissionsApiInteraction(selfThrottlingMethod, maxNumberOfCallsPerMinute);

            CarbonEmissionsMiner carbonEmissionsMiner = new CarbonEmissionsMiner(
                wattTimeApiUrl,
                wattTimeApiKey,
                wattTimeApiV2Url,
                WattTimeUsername,
                WattTimePassword,
                WattTimeEmail,
                WattTimeOrganization,
                selfThrottlingMethod,
                databaseConnectionString,
                maxNumberOfCallsPerMinute,
                wattTimeInteraction);

            // Act
            carbonEmissionsMiner.MineForecastMarginalCarbonResults(
                startDateTime,
                endDateTime,
                regionWattTimeName,
                regionId);

            // Assert
            // Verify that each data point has been recorded in the database
            var results = wattTimeInteraction.GetForecastMarginalCarbonResults(
                wattTimeApiV2Url,
                regionWattTimeName,
                WattTimeUsername,
                WattTimePassword,
                startDateTime,
                endDateTime,
                null);

            using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
            {
                foreach (var result in results)
                {
                    var dataPoint = _objectModel.FindCarbonEmissionsDataPoint(regionId, result.point_time);
                    Assert.IsNotNull(dataPoint);
                    Assert.AreEqual(
                        wattTimeInteraction.ConvertLbsPerMWhTo_GCo2PerkWh((double)result.value),
                        dataPoint.MarginalCO2Intensity_Forcast_gCO2kWh);
                }
            }
        }
        public void TestMineHistoricMarginalCarbonResults()
        {
            // Arrange
            var startDateTime = DateTime.Now.AddDays(-10);
            var endDateTime   = DateTime.Now.AddDays(-1);

            var    wattTimeApiUrl            = CloudConfigurationManager.GetSetting("WattTimeApiUrl");
            var    wattTimeApiKey            = CloudConfigurationManager.GetSetting("WattTimeApiKey");
            string wattTimeApiV2Url          = CloudConfigurationManager.GetSetting("WattTimeApiV2Url");
            string WattTimeUsername          = CloudConfigurationManager.GetSetting("WattTimeUsername");
            string WattTimePassword          = CloudConfigurationManager.GetSetting("WattTimePassword");
            string WattTimeEmail             = CloudConfigurationManager.GetSetting("WattTimeEmail");
            string WattTimeOrganization      = CloudConfigurationManager.GetSetting("WattTimeOrganization");
            var    selfThrottlingMethod      = "AzureTableStorageCallRecollection";
            var    maxNumberOfCallsPerMinute = 9;

            List <WattTimeBalancingAuthorityInformation> regionsToMine = new List <WattTimeBalancingAuthorityInformation>();

            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("PSEI", "US_PugetSoundEnergy", "Pacific Standard Time", 47.68009593341535, -122.11638450372567));

            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("BPA", "US_BPA", "Pacific Standard Time", 40.348444276169, -74.6428556442261));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("CAISO", "US_CAISO", "Pacific Standard Time", 41.7324, -123.409423));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("ERCOT", "US_ERCOT", "Central Standard Time", 32.79878236662912, -96.77856445062508));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("ISONE", "US_ISONewEngland", "Eastern Standard Time", 42.70864591994315, -72.16918945062508));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("MISO", "US_UpperMidwestISO", "Central Standard Time", 41.91853269857261, -93.55193137872567));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("SPP", "US_SouthwesternPublicServiceISO", "Eastern Standard Time", 34.41133502036136, -103.19243430841317));

            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("PJM", "US_PJM", "Eastern Standard Time", 40.348444276169, -74.6428556442261));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("PJM_ATLANTIC", "US_PJM_ATLANTIC", "Eastern Standard Time", 40.566564, -76.98465597395705));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("PJM_SOUTH", "US_PJM_SOUTH", "Eastern Standard Time", 37.44276433719146, -76.87479269270705));
            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("PJM_WEST", "US_PJM_WEST", "Eastern Standard Time", 38.69484915602888, -85.11453878645705));

            foreach (var region in regionsToMine)
            {
                int regionId;
                using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                {
                    regionId =
                        _objectModel.AddEmissionsRegion(region.smartGridRegionName, region.timeZone, region.regionLat, region.regionLong)
                        .EmissionsRegionID;

                    _objectModel.AddMarketWeatherEmissionsRegionMapping(
                        region.smartGridRegionName,
                        null,
                        null,
                        regionId);
                }


                var wattTimeInteraction = new EmissionsApiInteraction(selfThrottlingMethod, maxNumberOfCallsPerMinute);

                CarbonEmissionsMiner carbonEmissionsMiner = new CarbonEmissionsMiner(
                    wattTimeApiUrl,
                    wattTimeApiKey,
                    wattTimeApiV2Url,
                    WattTimeUsername,
                    WattTimePassword,
                    WattTimeEmail,
                    WattTimeOrganization,
                    selfThrottlingMethod,
                    databaseConnectionString,
                    maxNumberOfCallsPerMinute,
                    wattTimeInteraction);

                // Act
                carbonEmissionsMiner.MineHistoricMarginalCarbonResults(
                    startDateTime,
                    endDateTime,
                    region.regionWattTimeName,
                    regionId);

                // Assert
                // Verify that each data point has been recorded in the database
                var results = wattTimeInteraction.GetObservedMarginalCarbonResults(
                    wattTimeApiV2Url,
                    region.regionWattTimeName,
                    WattTimeUsername,
                    WattTimePassword,
                    startDateTime,
                    endDateTime,
                    null,
                    null);

                using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                {
                    foreach (var result in results)
                    {
                        var dataPoint = _objectModel.FindCarbonEmissionsDataPoint(regionId, result.point_time);
                        Assert.IsNotNull(dataPoint);
                    }
                }
            }
        }
        public void TestMineHistoricSystemWideCarbonResults()
        {
            // Arrange
            var startDateTime = DateTime.Now.AddDays(-10);
            var endDateTime   = DateTime.Now.AddDays(-1);

            var    wattTimeApiUrl            = CloudConfigurationManager.GetSetting("WattTimeApiUrl");
            var    wattTimeApiKey            = CloudConfigurationManager.GetSetting("WattTimeApiKey");
            string wattTimeApiV2Url          = CloudConfigurationManager.GetSetting("WattTimeApiV2Url");
            string WattTimeUsername          = CloudConfigurationManager.GetSetting("WattTimeUsername");
            string WattTimePassword          = CloudConfigurationManager.GetSetting("WattTimePassword");
            string WattTimeEmail             = CloudConfigurationManager.GetSetting("WattTimeEmail");
            string WattTimeOrganization      = CloudConfigurationManager.GetSetting("WattTimeOrganization");
            var    selfThrottlingMethod      = "AzureTableStorageCallRecollection";
            var    maxNumberOfCallsPerMinute = 9;

            List <WattTimeBalancingAuthorityInformation> regionsToMine = new List <WattTimeBalancingAuthorityInformation>();

            regionsToMine.Add(new WattTimeBalancingAuthorityInformation("ERCOT", "US_ERCOT", "Central Standard Time", 32.79878236662912, -96.77856445062508));

            foreach (var region in regionsToMine)
            {
                int regionId;
                using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                {
                    regionId =
                        _objectModel.AddEmissionsRegion(region.smartGridRegionName, region.timeZone, region.regionLat, region.regionLong)
                        .EmissionsRegionID;

                    _objectModel.AddMarketWeatherEmissionsRegionMapping(
                        region.smartGridRegionName,
                        null,
                        null,
                        regionId);
                }


                var wattTimeInteraction = new EmissionsApiInteraction(selfThrottlingMethod, maxNumberOfCallsPerMinute);

                CarbonEmissionsMiner carbonEmissionsMiner = new CarbonEmissionsMiner(
                    wattTimeApiUrl,
                    wattTimeApiKey,
                    wattTimeApiV2Url,
                    WattTimeUsername,
                    WattTimePassword,
                    WattTimeEmail,
                    WattTimeOrganization,
                    selfThrottlingMethod,
                    databaseConnectionString,
                    maxNumberOfCallsPerMinute,
                    wattTimeInteraction);

                // Act
                carbonEmissionsMiner.MineHistoricSystemWideCarbonResults(
                    startDateTime,
                    endDateTime,
                    region.regionWattTimeName,
                    regionId);

                // Assert
                // Verify that each data point has been recorded in the database
                var results = wattTimeInteraction.GetGenerationMixAndSystemWideEmissionsResults(
                    wattTimeApiUrl,
                    region.regionWattTimeName,
                    startDateTime,
                    endDateTime,
                    null,
                    wattTimeApiKey);

                using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                {
                    foreach (var result in results)
                    {
                        var dataPoint = _objectModel.FindCarbonEmissionsDataPoint(regionId, result.timestamp);
                        Assert.IsNotNull(dataPoint);
                    }
                }
            }
        }
Exemple #5
0
        public void TestMineHistoricWeatherData()
        {
            // Arrange
            var smartGridRegionName = "Ireland";
            var timeZone            = "GMT Standard Time";
            var regionLat           = 53.3498;
            var regionLong          = -6.2603;

            var startDateTime = DateTime.UtcNow.AddDays(-10);
            var endDateTime   = DateTime.UtcNow.AddDays(-1);

            var DarkSkyApiUrl             = CloudConfigurationManager.GetSetting("DarkSkyApiUrl");
            var DarkSkyApiKey             = CloudConfigurationManager.GetSetting("DarkSkyApiKey");
            var selfThrottlingMethod      = "AzureTableStorageCallRecollection";
            var maxNumberOfCallsPerMinute = 9;
            var maxNumberOfCallsPerDay    = 250;

            int regionId;

            using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
            {
                regionId =
                    _objectModel.AddWeatherRegion(smartGridRegionName, timeZone, regionLat, regionLong)
                    .WeatherRegionID;
            }

            var darkSkyWeatherInteraction = new DarkSkyWeatherInteraction(
                selfThrottlingMethod, maxNumberOfCallsPerMinute);

            DarkSkyWeatherDataMiner miner = new DarkSkyWeatherDataMiner(
                DarkSkyApiUrl,
                DarkSkyApiKey,
                selfThrottlingMethod,
                databaseConnectionString,
                maxNumberOfCallsPerMinute,
                maxNumberOfCallsPerDay,
                darkSkyWeatherInteraction);

            // Act
            miner.MineHistoricWeatherValues(
                startDateTime,
                endDateTime,
                regionLat,
                regionLong,
                regionId);

            // Assert
            // Verify that each data point has been recorded in the database
            var results = darkSkyWeatherInteraction.GetHistoricWeatherData(
                DarkSkyApiUrl, DarkSkyApiKey,
                regionLat,
                regionLong,
                startDateTime,
                endDateTime,
                null);

            using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
            {
                foreach (var result in results)
                {
                    var dataPoint = _objectModel.FindCarbonEmissionsDataPoint(regionId, result.dateTime);
                    Assert.IsNotNull(dataPoint);
                }
            }
        }
        public void TestMineHistoricMarginalCarbonResults()
        {
            // Arrange
            var startDateTime = DateTime.Now.AddDays(-10);
            var endDateTime   = DateTime.Now.AddDays(-9);

            var wattTimeApiUrl            = CloudConfigurationManager.GetSetting("WattTimeApiUrl");
            var wattTimeApiKey            = CloudConfigurationManager.GetSetting("WattTimeApiKey");
            var selfThrottlingMethod      = "AzureTableStorageCallRecollection";
            var maxNumberOfCallsPerMinute = 9;

            List <WattTimeBalancingAuthorityInformation> regionsToMine =
                new List <WattTimeBalancingAuthorityInformation>
            {
                new WattTimeBalancingAuthorityInformation(
                    "PJM",
                    "US_PJM",
                    "Eastern Standard Time",
                    40.348444276169,
                    -74.6428556442261)
            };

            foreach (var region in regionsToMine)
            {
                int regionId;
                using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                {
                    regionId =
                        _objectModel.AddEmissionsRegion(region.smartGridRegionName, region.timeZone, region.regionLat, region.regionLong)
                        .EmissionsRegionID;

                    _objectModel.AddMarketWeatherEmissionsRegionMapping(
                        region.smartGridRegionName,
                        null,
                        null,
                        regionId);
                }


                var wattTimeInteraction = new EmissionsApiInteraction(selfThrottlingMethod, maxNumberOfCallsPerMinute);

                CarbonEmissionsMiner carbonEmissionsMiner = new CarbonEmissionsMiner(
                    wattTimeApiUrl,
                    wattTimeApiKey,
                    selfThrottlingMethod,
                    databaseConnectionString,
                    maxNumberOfCallsPerMinute,
                    wattTimeInteraction);

                // Act
                carbonEmissionsMiner.MineHistoricMarginalCarbonResults(
                    startDateTime,
                    endDateTime,
                    region.regionWattTimeName,
                    regionId);

                // Assert
                // Verify that each data point has been recorded in the database
                var results = wattTimeInteraction.GetObservedMarginalCarbonResults(
                    wattTimeApiUrl,
                    region.regionWattTimeName,
                    startDateTime,
                    endDateTime,
                    null,
                    wattTimeApiKey);

                using (var _objectModel = new SmartEnergyOM(databaseConnectionString))
                {
                    foreach (var result in results)
                    {
                        var dataPoint = _objectModel.FindCarbonEmissionsDataPoint(regionId, result.timestamp);
                        Assert.IsNotNull(dataPoint);
                    }
                }
            }
        }