Ejemplo n.º 1
0
        private static List <CalcDesireDto> MakeCalcDesires(int timeStepsPerHour, AffordanceWithTimeLimit aff,
                                                            [NotNull] string affordanceName)
        {
            var calcDesires = new List <CalcDesireDto>();

            foreach (var affDesire in aff.Affordance.AffordanceDesires)
            {
                var cd = new CalcDesireDto(affordanceName + " - " + affDesire.Name, affDesire.Desire.IntID, 0,
                                           0, affDesire.SatisfactionValue, 0, timeStepsPerHour, -1, null, aff.SrcTraitName, "");
                calcDesires.Add(cd);
            }

            return(calcDesires);
        }
Ejemplo n.º 2
0
        private List <CalcAffordanceVariableOpDto> MakeVariableOps([NotNull] CalcLocationDto calcloc,
                                                                   [NotNull] LocationDtoDict
                                                                   locDict, [NotNull] HouseholdKey householdKey,
                                                                   AffordanceWithTimeLimit aff)
        {
            var variableOps = new List <CalcAffordanceVariableOpDto>();

            foreach (var affVariableOperation in aff.Affordance.ExecutedVariables)
            {
                CalcLocationDto loc = null;
                if (affVariableOperation.LocationMode == VariableLocationMode.OtherLocation)
                {
                    if (affVariableOperation.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    if (locDict.SimulateLocation(affVariableOperation.Location))
                    {
                        loc = locDict.GetDtoForLocation(affVariableOperation.Location);
                    }

                    // if the Location does not exist, don't do anything.
                }
                else
                {
                    loc = calcloc;
                }

                if (loc != null)
                {
                    if (affVariableOperation.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    var variable = _variableRepository.RegisterVariableIfNotRegistered(
                        affVariableOperation.Variable, affVariableOperation.Location, householdKey, locDict);

                    variableOps.Add(new CalcAffordanceVariableOpDto(affVariableOperation.Variable.Name,
                                                                    affVariableOperation.Value, loc.Name, loc.Guid, affVariableOperation.Action,
                                                                    affVariableOperation.ExecutionTime, variable.Guid));
                }
            }

            return(variableOps);
        }
Ejemplo n.º 3
0
        private void MakeAffordanceTimelimit([NotNull] TemperatureProfile temperatureProfile,
                                             [NotNull] GeographicLocation geographicLocation,
                                             [NotNull] Random rnd, [NotNull][ItemNotNull] List <VacationTimeframe> vacationTimeframes,
                                             [NotNull] string holidayKey, [NotNull] List <DateTime> bridgeDays,
                                             AffordanceWithTimeLimit aff,
                                             [NotNull] out AvailabilityDataReferenceDto availabilityDataReference)
        {
            //time limit stuff
            if (aff.Affordance.TimeLimit == null)
            {
                throw new DataIntegrityException("The time limit on the affordance was null. Please fix",
                                                 aff.Affordance);
            }

            var tl = aff.Affordance.TimeLimit;

            if (aff.TimeLimit != null)
            {
                tl = aff.TimeLimit;
            }
            if (tl.RootEntry == null)
            {
                throw new LPGException("Root Entry was null");
            }

            var tmparr = tl.RootEntry.GetOneYearArray(
                _cp.InternalStepsize,
                _cp.InternalStartTime,
                _cp.InternalEndTime, temperatureProfile, geographicLocation, rnd,
                vacationTimeframes, holidayKey, out var tmpBridgeDays, aff.StartMinusTime, aff.StartPlusTime,
                aff.EndMinusTime,
                aff.EndPlusTime);

            foreach (var tmpBridgeDay in tmpBridgeDays)
            {
                if (!bridgeDays.Contains(tmpBridgeDay))
                {
                    bridgeDays.Add(tmpBridgeDay);
                }
            }

            // invertieren von erlaubten zu verbotenen zeiten
            tmparr = tmparr.Not();
            availabilityDataReference = _availabilityDtoRepository.MakeNewReference(tl.Name, tmparr);
        }
Ejemplo n.º 4
0
        private List <VariableRequirementDto> MakeVariableRequirements([NotNull] CalcLocationDto calcloc,
                                                                       [NotNull] LocationDtoDict locDict,
                                                                       [NotNull] HouseholdKey householdKey,
                                                                       AffordanceWithTimeLimit aff)
        {
            var variableRequirements =
                new List <VariableRequirementDto>();

            foreach (var affVariableRequirement in aff.Affordance.RequiredVariables)
            {
                CalcLocationDto loc = null;
                if (affVariableRequirement.LocationMode == VariableLocationMode.OtherLocation)
                {
                    if (affVariableRequirement.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    if (locDict.SimulateLocation(affVariableRequirement.Location))
                    {
                        loc = locDict.GetDtoForLocation(affVariableRequirement.Location);
                    }
                }
                else
                {
                    loc = calcloc;
                }

                if (loc != null)
                {
                    if (affVariableRequirement.Location == null)
                    {
                        throw new LPGException("Location was null");
                    }
                    var variable = _variableRepository.RegisterVariableIfNotRegistered
                                       (affVariableRequirement.Variable, affVariableRequirement.Location, householdKey, locDict);
                    variableRequirements.Add(new VariableRequirementDto(affVariableRequirement.Variable.Name,
                                                                        affVariableRequirement.Value, loc.Name, loc.Guid, affVariableRequirement.Condition,
                                                                        variable.Guid));
                }
            }

            return(variableRequirements);
        }
Ejemplo n.º 5
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.");
            }
        }