Exemplo n.º 1
0
        public static ConfigurationData LoadConfiguration(string configurationName)
        {
            var data = new ConfigurationData();

            using(var ctx = new CityContainer())
            {
                var configuration = ctx.Configurations.Single(c => c.Name == configurationName);

                data.ConfigurationName = configurationName;

                // Load POI circle areas

                var circleAreaObjects = new List<CircleAreaObject>();

            // ReSharper disable LoopCanBeConvertedToQuery
                foreach (var circleArea in configuration.CircleAreas)
            // ReSharper restore LoopCanBeConvertedToQuery
                    circleAreaObjects.Add(new CircleAreaObject(circleArea.Lat, circleArea.Lng, circleArea.Range));

                data.CircleAreas = circleAreaObjects;

                // Load POI types

                data.PoiTypes = configuration.PoiTypes.Select(poiType => poiType.Code).ToList();

                var polygons = new List<MapDistrict>();
                foreach (var district in configuration.Districts)
                {
                    var newPolygon = new MapDistrict {DistrictName = district.Name, Population = district.Population, Locations = new LocationCollection()};

                    foreach (var mapPoint in district.MapPoints)
                        newPolygon.Locations.Add(new Location(mapPoint.Lat, mapPoint.Lng));

                    polygons.Add(newPolygon);
                }

                data.Polygons = polygons;

                // simulation settings
                data.SimulationMethodName = configuration.SelectionMethod.Name;
                data.DemandsPerPersonPerDay = configuration.PersonDemandsPerDay;
                data.SimulationStartDate = configuration.SimulationStartDate;
                data.SimulationEndDate = configuration.SimulationEndDate;

                data.CreditCardBalanceMin = configuration.CreditCardBalanceMin;
                data.CreditCardBalanceMax = configuration.CreditCardBalanceMax;
                data.CreditCardLimitMin = configuration.CreditCardLimitMin;
                data.CreditCardLimitMax = configuration.CreditCardLimitMax;
                data.TransactionValueMin = configuration.TransactionValueMin;
                data.TransactionValueMax = configuration.TransactionValueMax;
            }
            return data;
        }
Exemplo n.º 2
0
        public static bool SaveConfiguration(ConfigurationData data)
        {
            using (var ctx = new CityContainer())
            {
                var configurationExists = ctx.Configurations.Any(c => c.Name == data.ConfigurationName);
                if (configurationExists) return false;

                var poiTypes = ctx.PoiTypes.Where(t => data.PoiTypes.Contains(t.Code));

                var newConfiguration = new Configuration
                                           {
                                               Name = data.ConfigurationName,
                                               SelectionMethod = ctx.SelectionMethods.Single(m => m.Name == data.SimulationMethodName),
                                               SimulationStartDate = data.SimulationStartDate,
                                               SimulationEndDate = data.SimulationEndDate,
                                               PersonDemandsPerDay = data.DemandsPerPersonPerDay,
                                               CreditCardBalanceMin = data.CreditCardBalanceMin,
                                               CreditCardBalanceMax = data.CreditCardBalanceMax,
                                               CreditCardLimitMin = data.CreditCardLimitMin,
                                               CreditCardLimitMax = data.CreditCardLimitMax,
                                               TransactionValueMin = data.TransactionValueMin,
                                               TransactionValueMax = data.TransactionValueMax
                                           };

                // Assign POI circle areas
                foreach (var circleAreaObject in data.CircleAreas)
                {
                    newConfiguration.CircleAreas.Add(new CircleArea
                                                         {
                                                             Configuration = newConfiguration,
                                                             Lat = circleAreaObject.Pushpin.Location.Latitude,
                                                             Lng = circleAreaObject.Pushpin.Location.Longitude,
                                                             Range = circleAreaObject.Range
                                                         });
                }

                // Assign POI types for configuration
                foreach (var poiType in poiTypes)
                    newConfiguration.PoiTypes.Add(poiType);

                // Assign Districts for configuration
                foreach (var polygon in data.Polygons)
                {
                    var district = new District
                                       {
                                           Configuration = newConfiguration,
                                           Population = polygon.Population,
                                           Name = polygon.DistrictName
                                       };

                    foreach (var location in polygon.Locations)
                    {
                        district.MapPoints.Add(new MapPoint
                                                   {
                                                       Lat = location.Latitude,
                                                       Lng = location.Longitude
                                                   });
                    }
                }

                ctx.Configurations.AddObject(newConfiguration);
                ctx.SaveChanges();

                return true;
            }
        }
Exemplo n.º 3
0
        private void SaveConfigurationBtnClick(object sender, RoutedEventArgs e)
        {
            var configurationName = configurationNameTextBox.Text;

            var selectedPoi = from poiBox in PoiTypeBoxes where poiBox.IsChecked == true select poiBox.Name;

            double demandsPerPersonPerDay;
            if (!double.TryParse(demandsPerPersonPerDayTextBox.Text, out demandsPerPersonPerDay))
            {
                MessageBox.Show("Could not save configuration. Non numeric value for Person Demands / Day field.");
                return;
            }

            var configurationData = new ConfigurationData
                                        {
                                            ConfigurationName = configurationName,
                                            CircleAreas = AreaSelectorPageInstance.Areas,
                                            PoiTypes = selectedPoi,
                                            Polygons = districtArchitect.Polygons,
                                            SimulationMethodName = symulationTypeComboBox.Text,
                                            SimulationStartDate = startDatePicker.SelectedDate ?? DateTime.Now,
                                            SimulationEndDate = endDatePicker.SelectedDate ?? DateTime.Now,
                                            DemandsPerPersonPerDay = demandsPerPersonPerDay,
                                            CreditCardBalanceMin = int.Parse(StatisticalData.CreditCardBalanceMin),
                                            CreditCardBalanceMax = int.Parse(StatisticalData.CreditCardBalanceMax),
                                            CreditCardLimitMin = int.Parse(StatisticalData.CreditCardLimitMin),
                                            CreditCardLimitMax = int.Parse(StatisticalData.CreditCardLimitMax),
                                            TransactionValueMin = int.Parse(StatisticalData.TransactionValueMin),
                                            TransactionValueMax = int.Parse(StatisticalData.TransactionValueMax)
                                        };

            if(!DBUtilities.SaveConfiguration(configurationData))
            {
                MessageBox.Show(string.Format("Configuration with name \"{0}\" already exists.", configurationName));
                return;
            }

            configurationNameTextBox.Foreground = SavedConfigurationNameColor;
            UpdateConfigurationList();
        }