public void TestMineHistoricWeatherValues() { // Arrange var regionSubUrl = "us/nj/princeton"; string smartGridRegionName = "PJM"; var timeZone = "Eastern Standard Time"; var regionLat = 40.348444276169; var regionLong = -74.6428556442261; var startDateTime = DateTime.Now.AddDays(-3); var endDateTime = DateTime.Now.AddDays(-1); var wundergroundApiUrl = CloudConfigurationManager.GetSetting("WundergroundApiUrl"); var wundergroundApiKey = CloudConfigurationManager.GetSetting("WundergroundApiKey"); var selfThrottlingMethod = "AzureTableStorageCallRecollection"; var maxNumberOfCallsPerMinute = 5; int regionId; using (var _objectModel = new SmartEnergyOM(databaseConnectionString)) { regionId = _objectModel.AddWeatherRegion(smartGridRegionName, timeZone, regionLat, regionLong).WeatherRegionID; } var wundergroundWeatherInteraction = new WundergroundWeatherInteraction( selfThrottlingMethod, maxNumberOfCallsPerMinute); WeatherDataMiner weatherDataMiner = new WeatherDataMiner( wundergroundApiUrl, wundergroundApiKey, selfThrottlingMethod, databaseConnectionString, maxNumberOfCallsPerMinute, wundergroundWeatherInteraction); // Act weatherDataMiner.MineHistoricWeatherValues(startDateTime, endDateTime, regionSubUrl, regionId); // Assert // Verify that each data point has been recorded in the database var results = wundergroundWeatherInteraction.GetHistoricWeatherData( wundergroundApiUrl, regionSubUrl, wundergroundApiKey, startDateTime, endDateTime); using (var _objectModel = new SmartEnergyOM(databaseConnectionString)) { foreach (var result in results) { var dataPoint = _objectModel.FindWeatherDataPoints(regionId, result.observationDateTime); Assert.IsNotNull(dataPoint); } } }
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 selfThrottlingMethod = regionConfiguration.WeatherMiningRegion.SelfThrottlingMethod; var maxNumberOfCallsPerMinute = regionConfiguration.WeatherMiningRegion.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, startDateTime, endDateTime, null, wattTimeApiKey); 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.FindCarbonEmissionsDataPoints(regionId, result.timestamp); Assert.IsNotNull(dataPoint); } } } // Verify weather was mined successfully for each region in the Config File if (regionConfiguration.WeatherMiningRegion != null) { var emissionsRegionName = regionConfiguration.WeatherMiningRegion.friendlyName; var timeZone = regionConfiguration.WeatherMiningRegion.TimeZone; var regionLat = regionConfiguration.WeatherMiningRegion.Latitude; var regionLong = regionConfiguration.WeatherMiningRegion.Longitude; var weatherRegionWundergroundSubUrl = regionConfiguration.WeatherMiningRegion.weatherRegionWundergroundSubUrl; var wundergroundApiUrl = regionConfiguration.WeatherMiningRegion.ApiUrl; var wundergroundApiKey = regionConfiguration.WeatherMiningRegion.ApiKey; var selfThrottlingMethod = regionConfiguration.WeatherMiningRegion.SelfThrottlingMethod; var maxNumberOfCallsPerMinute = regionConfiguration.WeatherMiningRegion.MaxNumberOfCallsPerMinute; var wundergroundWeatherInteraction = new WundergroundWeatherInteraction( selfThrottlingMethod, maxNumberOfCallsPerMinute); var results = wundergroundWeatherInteraction.GetTenDayHourlyForecastWeatherData( wundergroundApiUrl, weatherRegionWundergroundSubUrl, wundergroundApiKey); 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.FindWeatherDataPoints( regionId, result.observationDateTime); Assert.IsNotNull(dataPoint); } } } } } }