Пример #1
0
 public CalcDeviceDtoFactory([NotNull] IDeviceCategoryPicker picker, [NotNull] CalcParameters calcParameters,
                             [NotNull] Random rnd, [NotNull] CalcLoadTypeDtoDictionary loadTypeDictionary,
                             [NotNull] CalcVariableDtoFactory calcVariableRepositoryDtoFactory,
                             [NotNull] AvailabilityDtoRepository availabilityDtoRepository)
 {
     _picker             = picker;
     _calcParameters     = calcParameters;
     _rnd                = rnd;
     _loadTypeDictionary = loadTypeDictionary;
     _calcVariableRepositoryDtoFactory = calcVariableRepositoryDtoFactory;
     _availabilityDtoRepository        = availabilityDtoRepository;
 }
Пример #2
0
        public List <CalcAffordanceDto> SetCalcAffordances([NotNull][ItemNotNull] IEnumerable <CalcLocationDto> locs,
                                                           [NotNull] TemperatureProfile temperatureProfile,
                                                           [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                                           [NotNull] GeographicLocation geographicLocation,
                                                           [NotNull] Random rnd,
                                                           int timeStepsPerHour, TimeSpan internalStepSize,
                                                           [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes, [NotNull] string holidayKey,
                                                           [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions,
                                                           [NotNull] Dictionary <CalcLocationDto, List <AffordanceWithTimeLimit> > affordanceDict,
                                                           [NotNull] LocationDtoDict locDict,
                                                           [NotNull] out List <DateTime> bridgeDays,
                                                           [NotNull] HouseholdKey householdKey, [NotNull][ItemNotNull] List <CalcDeviceDto> allCalcDeviceDtos,
                                                           [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            List <CalcAffordanceDto> allCalcAffordances = new List <CalcAffordanceDto>();

            bridgeDays = new List <DateTime>();
            // get affordances
            foreach (var calcLocation in locs)
            {
                var affs = affordanceDict[calcLocation];
                var tmp  = affs.Distinct();
                if (affs.Count != tmp.Count())
                {
                    throw new LPGException("double affordances!?!");
                }

                var devicesAtLoc = allCalcDeviceDtos.Where(x => x.LocationGuid == calcLocation.Guid).ToList();
                var affordances  = GetCalcAffordancesAtLocation(calcLocation, affs, internalStepSize, timeStepsPerHour, temperatureProfile,
                                                                ltdict, geographicLocation, rnd, vacationTimeframes, holidayKey, deviceActions,
                                                                locDict,
                                                                out var tmpBridgeDays, householdKey, devicesAtLoc, deviceCategoryDtos);
                allCalcAffordances.AddRange(affordances);
                foreach (var tmpBridgeDay in tmpBridgeDays)
                {
                    if (!bridgeDays.Contains(tmpBridgeDay))
                    {
                        bridgeDays.Add(tmpBridgeDay);
                    }
                }

                //calcLocation.SortAffordances();
            }

            return(allCalcAffordances);
        }
 public CalcModularHouseholdDtoFactory([NotNull] CalcLoadTypeDtoDictionary ltDict, [NotNull] Random random,
                                       [NotNull] CalcPersonDtoFactory calcPersonDtoFactory,
                                       [NotNull] CalcDeviceDtoFactory calcDeviceDtoFactory,
                                       [NotNull] CalcLocationDtoFactory calcLocationDtoFactory,
                                       [NotNull] CalcVariableDtoFactory calcVariableRepositoryDtoFactory,
                                       [NotNull] CalcAffordanceDtoFactory calcAffordanceDtoFactory,
                                       [NotNull] CalcTransportationDtoFactory transportationDtoFactory,
                                       CalcRepo calcRepo)
 {
     _ltDict = ltDict;
     _random = random;
     _calcPersonDtoFactory             = calcPersonDtoFactory;
     _calcDeviceDtoFactory             = calcDeviceDtoFactory;
     _calcLocationDtoFactory           = calcLocationDtoFactory;
     _calcVariableRepositoryDtoFactory = calcVariableRepositoryDtoFactory;
     _calcAffordanceDtoFactory         = calcAffordanceDtoFactory;
     _transportationDtoFactory         = transportationDtoFactory;
     _calcRepo = calcRepo;
 }
Пример #4
0
        public void MakeCalcLocationsTest()
        {
            var locations = new List <Location>();
            var loc       = new Location("loc", 1, string.Empty, Guid.NewGuid().ToStrGuid());

            locations.Add(loc);
            Random r = new Random(1);
            DeviceCategoryPicker picker = new DeviceCategoryPicker(r, null);
            //var cp = new CalcFactoryParameters(picker);
            //var dict =new Dictionary<CalcLocation, List<IAssignableDevice>>();
            var deviceActions = new ObservableCollection <DeviceAction>();
            //var locdict = new Dictionary<Location, CalcLocation>();
            CalcParameters cp = CalcParametersFactory.MakeGoodDefaults();
            //var mock = new Mock<IOnlineDeviceActivationProcessor>();
            //var iodap = mock.Object;
            var locationDtoDict         = new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>());
            var ltDict                  = new CalcLoadTypeDictionary(new Dictionary <CalcLoadTypeDto, CalcLoadType>());
            CalcLocationDtoFactory cldt = new CalcLocationDtoFactory(cp, picker, locationDtoDict);
            Dictionary <CalcLocationDto, List <IAssignableDevice> > deviceLocationDict = new Dictionary <CalcLocationDto, List <IAssignableDevice> >();
            LocationDtoDict          calclocdict = new LocationDtoDict();
            List <DeviceCategoryDto> devcat      = new List <DeviceCategoryDto>();

            using CalcRepo calcRepo = new CalcRepo();
            //devcat.Add(new DeviceCategoryDto(dc.FullPath, Guid.NewGuid().ToStrGuid()));
            var locdtos = cldt.MakeCalcLocations(locations,
                                                 new HouseholdKey("hh1"),
                                                 EnergyIntensityType.EnergyIntensive,
                                                 deviceLocationDict,
                                                 deviceActions,
                                                 calclocdict,
                                                 devcat);

            locdtos.Count.Should().Be(1);
            locdtos[0].Name.Should().Be(loc.Name);
            CalcLocationFactory clf = new CalcLocationFactory(ltDict, calcRepo);
            //"HH1", EnergyIntensityType.EnergySaving, dict,deviceActions,
            DtoCalcLocationDict dcl = new DtoCalcLocationDict();
            var calclocs            = clf.MakeCalcLocations(locdtos, dcl, calcRepo);

            calclocs.Count.Should().Be(1);
            calclocs[0].Name.Should().Be(loc.Name);
            calclocs[0].Guid.Should().Be(locdtos[0].Guid);
        }
Пример #5
0
 public void RunTest()
 {
     using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
     {
         SqlResultLoggingService srls      = new SqlResultLoggingService(wd.WorkingDirectory);
         var calcParameters                = CalcParametersFactory.MakeGoodDefaults();
         CalcLoadTypeDtoDictionary   cltd  = new CalcLoadTypeDtoDictionary(new Dictionary <VLoadType, CalcLoadTypeDto>());
         CalcDeviceTaggingSetFactory cdtsf = new CalcDeviceTaggingSetFactory(calcParameters, cltd);
         using (DatabaseSetup ds = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
         {
             Simulator                          sim = new Simulator(ds.ConnectionString);
             CalcDeviceTaggingSets              devicetaggingset = cdtsf.GetDeviceTaggingSets(sim, 2);
             DeviceTaggingSetLogger             dtsl             = new DeviceTaggingSetLogger(srls);
             List <DeviceTaggingSetInformation> cdts             = new List <DeviceTaggingSetInformation>();
             cdts.AddRange(devicetaggingset.AllCalcDeviceTaggingSets);
             dtsl.Run(Constants.GeneralHouseholdKey, cdts);
             wd.CleanUp();
             ds.Cleanup();
         }
     }
 }
Пример #6
0
        public static List <CalcDeviceLoadDto> MakeCalcDeviceLoads([NotNull] RealDevice device,
                                                                   [NotNull] CalcLoadTypeDtoDictionary ltdtodict)
        {
            var deviceLoads = new List <CalcDeviceLoadDto>();

            foreach (var realDeviceLoadType in device.Loads)
            {
                if (realDeviceLoadType.LoadType == null)
                {
                    throw new LPGException("Loadtype was null");
                }

                if (ltdtodict.SimulateLoadtype(realDeviceLoadType.LoadType))
                {
                    var cdl = new CalcDeviceLoadDto(realDeviceLoadType.Name, realDeviceLoadType.IntID,
                                                    ltdtodict.Ltdtodict[realDeviceLoadType.LoadType].Name, ltdtodict.Ltdtodict[realDeviceLoadType.LoadType].Guid,
                                                    realDeviceLoadType.AverageYearlyConsumption, realDeviceLoadType.StandardDeviation,
                                                    Guid.NewGuid().ToStrGuid(), realDeviceLoadType.MaxPower);
                    deviceLoads.Add(cdl);
                }
            }

            return(deviceLoads);
        }
Пример #7
0
        public List <CalcDeviceDto> MakeCalcDevices([NotNull][ItemNotNull] List <CalcLocationDto> locs,
                                                    [ItemNotNull][NotNull] List <DeviceLocationTuple> devlocs,
                                                    EnergyIntensityType energyIntensity,
                                                    [NotNull] HouseholdKey householdKey,
                                                    [NotNull]
                                                    Dictionary <CalcLocationDto, List <IAssignableDevice> >
                                                    allreadyAssigendDeviceLocationDict,
                                                    [NotNull][ItemNotNull] ObservableCollection <DeviceAction> deviceActions,
                                                    [NotNull] CalcLoadTypeDtoDictionary loadtypes,
                                                    [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategories)
        {
            List <CalcDeviceDto> calcDeviceDtos = new List <CalcDeviceDto>();

            foreach (var devloc in devlocs)
            {
                var locdto = locs.First(x => x.ID == devloc.Location.IntID);
                // ggf dev category / device action in dev umwandeln
                var devicesAtLocation =
                    devlocs.Where(x => x.Location == devloc.Location).Select(x => x.Device).ToList();
                var rd = _picker.GetOrPickDevice(devloc.Device, devloc.Location, energyIntensity,
                                                 devicesAtLocation, deviceActions);
                //save the picked device so that next time it will be picked again
                if (!allreadyAssigendDeviceLocationDict[locdto].Contains(devloc.Device))
                {
                    allreadyAssigendDeviceLocationDict[locdto].Add(devloc.Device);
                }

                if (!allreadyAssigendDeviceLocationDict[locdto].Contains(rd))
                {
                    allreadyAssigendDeviceLocationDict[locdto].Add(rd);
                }

                if (rd == null) // null means that no device needed to be picked since it already exists
                {
                    continue;
                }

                bool found = calcDeviceDtos.Any(x => rd.Name == x.Name && locdto.Guid == x.LocationGuid);
                if (found)
                {
                    Logger.Info(
                        "Device " + rd.Name + " existed already in the Location " + locdto.Name +
                        ". Skipping...");
                }
                else
                {
                    if (rd.DeviceCategory == null)
                    {
                        throw new LPGException("Device Category was null");
                    }

                    DeviceCategoryDto dcdto =
                        deviceCategories.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath);
                    CalcDeviceDto cdd = new CalcDeviceDto(rd.Name, dcdto.Guid, householdKey, OefcDeviceType.Device,
                                                          rd.DeviceCategory.FullPath, string.Empty, Guid.NewGuid().ToStrGuid(),
                                                          locdto.Guid, locdto.Name);
                    cdd.AddLoads(MakeCalcDeviceLoads(rd, loadtypes));
                    calcDeviceDtos.Add(cdd);
                }
            }

            return(calcDeviceDtos);
        }
Пример #8
0
 public CalcLocationDtoFactory([NotNull] CalcParameters calcParameters, [NotNull] IDeviceCategoryPicker picker, [NotNull] CalcLoadTypeDtoDictionary calcLoadTypeDict)
 {
     _picker           = picker;
     _calcLoadTypeDict = calcLoadTypeDict;
     _calcParameters   = calcParameters;
 }
 public CalcDeviceTaggingSetFactory([NotNull] CalcParameters calcParameters,
                                    [NotNull] CalcLoadTypeDtoDictionary ltDict)
 {
     _calcParameters = calcParameters;
     _ltDict         = ltDict;
 }
Пример #10
0
        private List <CalcAffordanceDto> GetCalcAffordancesAtLocation([NotNull] CalcLocationDto calcloc,
                                                                      [NotNull] List <AffordanceWithTimeLimit> affordancesAtLocation,
                                                                      TimeSpan internalStepSize, int timeStepsPerHour,
                                                                      [NotNull] TemperatureProfile temperatureProfile,
                                                                      [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                                                      [NotNull] GeographicLocation geographicLocation, [NotNull] Random rnd,
                                                                      [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes,
                                                                      [NotNull] string holidayKey,
                                                                      [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions,
                                                                      [NotNull]
                                                                      LocationDtoDict locDict,
                                                                      [NotNull] out List <DateTime> bridgeDays, [NotNull] HouseholdKey householdKey,
                                                                      [NotNull][ItemNotNull] List <CalcDeviceDto> deviceDtosAtLocation,
                                                                      [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            List <CalcAffordanceDto> createdAffordances = new List <CalcAffordanceDto>();

            bridgeDays = new List <DateTime>();
            foreach (AffordanceWithTimeLimit aff in affordancesAtLocation)
            {
                var affordanceName = CalcAffordanceFactory.FixAffordanceName(aff.Affordance.Name, _cp.CSVCharacter);
                if (aff.Affordance.PersonProfile == null)
                {
                    throw new DataIntegrityException("Person profile on " + aff.Affordance.PrettyName + " was null. Please fix.");
                }

                var cp1 = CalcDeviceDtoFactory.GetCalcProfileDto(aff.Affordance.PersonProfile);
                List <CalcDesireDto> calcDesires = MakeCalcDesires(timeStepsPerHour, aff, affordanceName);
                List <CalcAffordanceVariableOpDto> variableOps          = MakeVariableOps(calcloc, locDict, householdKey, aff);
                List <VariableRequirementDto>      variableRequirements =
                    MakeVariableRequirements(calcloc, locDict, householdKey, aff);

                MakeAffordanceTimelimit(temperatureProfile, geographicLocation, rnd, vacationTimeframes,
                                        holidayKey, bridgeDays, aff, out var availabilityDataReference);

                //make the affordance
                Logger.Debug("Converting the time limit to a bitarray for the affordance " + aff.Affordance.Name);
                //caff.IsBusyArray = tmparr;
                string timeLimitName = "";

                if (aff.TimeLimit != null)
                {
                    timeLimitName = aff.TimeLimit.Name;
                }

                var caff = new CalcAffordanceDto(affordanceName, aff.Affordance.IntID, cp1, calcloc.Name, calcloc.Guid,
                                                 aff.Affordance.RandomDesireResults, calcDesires, aff.Affordance.MinimumAge,
                                                 aff.Affordance.MaximumAge,
                                                 aff.Affordance.PermittedGender,
                                                 aff.Affordance.NeedsLight, (double)aff.Affordance.TimeStandardDeviation,
                                                 aff.Affordance.CarpetPlotColor.R, aff.Affordance.CarpetPlotColor.G, aff.Affordance.CarpetPlotColor.B,
                                                 aff.Affordance.AffCategory,
                                                 aff.Affordance.IsInterruptable, aff.Affordance.IsInterrupting, variableOps, variableRequirements,
                                                 aff.Affordance.ActionAfterInterruption, timeLimitName, aff.Weight,
                                                 aff.Affordance.RequireAllDesires, aff.SrcTraitName,
                                                 Guid.NewGuid().ToStrGuid(), availabilityDataReference, householdKey, aff.Affordance.BodilyActivityLevel);
                foreach (var devtup in aff.Affordance.AffordanceDevices)
                {
                    MakeAffordanceDevices(calcloc, internalStepSize, ltdict, allDeviceActions, aff, caff, devtup, deviceDtosAtLocation,
                                          deviceCategoryDtos);
                }

                MakeSubAffordances(caff, aff.Affordance, timeStepsPerHour, internalStepSize, calcloc,
                                   locDict, _cp.CSVCharacter, aff.Weight, aff.SrcTraitName, householdKey);
                createdAffordances.Add(caff);
            }
            return(createdAffordances);
        }
Пример #11
0
        private void MakeAffordanceDevices([NotNull] CalcLocationDto calcloc, TimeSpan internalStepSize,
                                           [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                           [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions,
                                           AffordanceWithTimeLimit aff, [NotNull] CalcAffordanceDto caff, [NotNull] AffordanceDevice devtup,
                                           [NotNull][ItemNotNull] List <CalcDeviceDto> devicesAtLocation,
                                           [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            if (devtup.Device == null)
            {
                throw new LPGException("Device was null");
            }
            // pick the device itself
            var pickedDevice = _picker.GetDeviceDtoForAffordance(devtup.Device, devicesAtLocation,
                                                                 calcloc.ID, allDeviceActions, deviceCategoryDtos);

            if (pickedDevice == null)
            {
                throw new DataIntegrityException(
                          "Affordance " + aff.Affordance.Name + " has broken devices. Please fix",
                          aff.Affordance);
            }

            // find the device in the calc devices
            var dev = devicesAtLocation.Single(calcDevice => calcDevice.Name == pickedDevice.Name);

            if (dev == null)
            {
                throw new DataIntegrityException(
                          "Affordance " + aff.Affordance.Name + " has broken devices. Please fix",
                          aff.Affordance);
            }

            if (devtup.Device == null)
            {
                throw new LPGException("Device was null");
            }

            switch (devtup.Device.AssignableDeviceType)
            {
            case AssignableDeviceType.Device:
            case AssignableDeviceType.DeviceCategory:
            {
                if (devtup.LoadType == null)
                {
                    throw new LPGException("No load type set");
                }
                if (ltdict.SimulateLoadtype(devtup.LoadType))
                {
                    if (devtup.TimeProfile == null)
                    {
                        throw new DataIntegrityException(
                                  "Affordance " + aff.Affordance.Name + " has broken time profiles. Please fix.",
                                  aff.Affordance);
                    }

                    var newprof =
                        CalcDeviceDtoFactory.GetCalcProfileDto(devtup.TimeProfile);
                    CalcLoadTypeDto loadtype = ltdict.GetLoadtypeDtoByLoadType(devtup.LoadType);
                    caff.AddDeviceTuple(dev.Name, dev.Guid, newprof, loadtype.Name, loadtype.Guid,
                                        devtup.TimeOffset, internalStepSize, 1, devtup.Probability);
                }
            }
            break;

            case AssignableDeviceType.DeviceAction:
            case AssignableDeviceType.DeviceActionGroup:
            {
                DeviceAction da;
                // if it's a device action group, then go back to the picker to select a specific
                // device action based on the available devices
                if (devtup.Device.AssignableDeviceType == AssignableDeviceType.DeviceActionGroup)
                {
                    da =
                        _picker.GetDeviceActionFromGroup(devtup.Device, devicesAtLocation,
                                                         allDeviceActions);
                }
                else
                {
                    da = (DeviceAction)devtup.Device;
                }
                if (da == null)
                {
                    throw new LPGException("Device action was null");
                }

                if (da.Profiles.Count == 0)
                {
                    throw new DataIntegrityException(
                              "The device action " + da.Name + " has no time profiles. Please fix", da);
                }

                foreach (var profile in da.Profiles)
                {
                    if (profile.VLoadType == null)
                    {
                        throw new LPGException("Profile was null");
                    }

                    if (ltdict.SimulateLoadtype(profile.VLoadType))
                    {
                        if (profile.Timeprofile == null)
                        {
                            throw new DataIntegrityException(
                                      "The device action " + da.Name + " has broken time profiles. Please fix.",
                                      da);
                        }

                        if (profile.VLoadType == null)
                        {
                            throw new DataIntegrityException(
                                      "The device action " + da.Name + " has broken load types. Please fix.", da);
                        }

                        var newprof =
                            CalcDeviceDtoFactory.GetCalcProfileDto(profile.Timeprofile);
                        CalcLoadTypeDto loadType = ltdict.GetLoadtypeDtoByLoadType(profile.VLoadType);
                        caff.AddDeviceTuple(dev.Name, dev.Guid, newprof, loadType.Name, loadType.Guid,
                                            profile.TimeOffset + devtup.TimeOffset, internalStepSize, profile.Multiplier,
                                            devtup.Probability);
                    }
                }
            }
            break;

            default:
                throw new LPGException(
                          "Missing an AssignableDeviceType at GetCalcAffordancesAtLocation! Please report to the programmer.");
            }
        }
Пример #12
0
 public AffordanceTaggingSetFactory([NotNull] CalcLoadTypeDtoDictionary loadTypeDictionary)
 {
     _ltDict = loadTypeDictionary;
 }