Exemplo n.º 1
0
        public CalcVariableDto RegisterVariable([NotNull] Variable variable, [NotNull] string locationName, StrGuid locationGuid,
                                                [NotNull] HouseholdKey householdKey)
        {
            StrGuid         variableGuid = Guid.NewGuid().ToStrGuid();
            CalcVariableDto cvd          = new CalcVariableDto(variable.PrettyName, variableGuid, 0,
                                                               locationName, locationGuid, householdKey);
            string key = MakeKey(variable, locationName, householdKey);

            VariableDtos.Add(key, cvd);
            return(cvd);
        }
        private void CreateCalcConditions([NotNull] TransformationDevice trafo,
                                          [NotNull][ItemNotNull] List <CalcTransformationConditionDto> calcconditions)
        {
            foreach (var condition in trafo.Conditions)
            {
                CalcVariableDto variableDto = _calcVariableDtoFactory.RegisterVariableIfNotRegistered(
                    condition.Variable,
                    "House", Constants.HouseLocationGuid, Constants.HouseKey);

                CalcTransformationConditionDto trafocondition = new CalcTransformationConditionDto(condition.Name,
                                                                                                   condition.IntID,
                                                                                                   variableDto,
                                                                                                   condition.MinValue,
                                                                                                   condition.MaxValue,
                                                                                                   Guid.NewGuid().ToStrGuid());
                calcconditions.Add(trafocondition);
            }
        }
        private void MakeAutoDevFromDeviceAction(EnergyIntensityType energyIntensity,
                                                 [NotNull] HouseholdKey householdKey,
                                                 [ItemNotNull][NotNull] ObservableCollection <DeviceAction> deviceActions,
                                                 [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos,
                                                 [NotNull] HouseTypeDevice hhautodev,
                                                 [ItemNotNull][NotNull] List <IAssignableDevice> allAutonomousDevices,
                                                 [NotNull] CalcLocationDto calcLocation,
                                                 [NotNull] AvailabilityDataReferenceDto availref, List <CalcAutoDevDto> autodevs
                                                 )
        {
            if (hhautodev.Location == null)
            {
                throw new LPGException("Location was null");
            }

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

            var deviceAction = _picker.GetAutoDeviceActionFromGroup(hhautodev.Device,
                                                                    allAutonomousDevices,
                                                                    energyIntensity,
                                                                    deviceActions,
                                                                    hhautodev.Location.IntID);

            foreach (var actionProfile in deviceAction.Profiles)
            {
                if (actionProfile.VLoadType == null)
                {
                    throw new LPGException("Loadtype was null");
                }

                if (actionProfile.Timeprofile == null)
                {
                    throw new LPGException("Timeprofile was null");
                }

                if (_ltDict.SimulateLoadtype(actionProfile.VLoadType))
                {
                    var profile = CalcDeviceDtoFactory.GetCalcProfileDto(actionProfile.Timeprofile);
                    if (deviceAction.Device == null)
                    {
                        throw new LPGException("Device was null");
                    }

                    var             cdl      = CalcDeviceDtoFactory.MakeCalcDeviceLoads(deviceAction.Device, _ltDict);
                    var             lt       = _ltDict.Ltdtodict[actionProfile.VLoadType];
                    CalcVariableDto variable = null;
                    if (hhautodev.Variable != null)
                    {
                        var v = hhautodev.Variable;
                        variable = _calcVariableDtoFactory.RegisterVariableIfNotRegistered(v, calcLocation.Name, calcLocation.Guid, householdKey);
                    }

                    List <VariableRequirementDto> reqDtos = new List <VariableRequirementDto>();
                    if (variable?.Name != null)
                    {
                        VariableRequirementDto req = new VariableRequirementDto(variable.Name,
                                                                                hhautodev.VariableValue,
                                                                                calcLocation.Name,
                                                                                calcLocation.Guid,
                                                                                hhautodev.VariableCondition,
                                                                                variable.Guid);
                        reqDtos.Add(req);
                    }

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

                    DeviceCategoryDto devcat = deviceCategoryDtos.Single(x => x.FullCategoryName == deviceAction.Device?.DeviceCategory?.FullPath);
                    var cautodev             = new CalcAutoDevDto(deviceAction.Device.Name,
                                                                  profile,
                                                                  lt.Name,
                                                                  lt.Guid,
                                                                  cdl,
                                                                  (double)hhautodev.TimeStandardDeviation,
                                                                  devcat.Guid,
                                                                  householdKey,
                                                                  actionProfile.Multiplier,
                                                                  calcLocation.Name,
                                                                  calcLocation.Guid,
                                                                  devcat.FullCategoryName,
                                                                  Guid.NewGuid().ToStrGuid(),
                                                                  availref,
                                                                  reqDtos, devcat.FullCategoryName);
                    autodevs.Add(cautodev);
                    //cautodev.ApplyBitArry(, _ltDict.LtDict[actionProfile.VLoadType]);
                }
            }
        }
        private CalcAutoDevDto MakeAutoDevFromDevice(EnergyIntensityType energyIntensity,
                                                     [NotNull] HouseholdKey householdKey,
                                                     [ItemNotNull][NotNull] ObservableCollection <DeviceAction> deviceActions,
                                                     [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos,
                                                     [NotNull] HouseTypeDevice hhautodev,
                                                     [ItemNotNull][NotNull] List <IAssignableDevice> allAutonomousDevices,
                                                     [NotNull] CalcLocationDto calcLocation,
                                                     [NotNull] AvailabilityDataReferenceDto timearray
                                                     )
        {
            if (hhautodev.LoadType == null)
            {
                throw new LPGException("Loadtype was null");
            }

            if (hhautodev.TimeProfile == null)
            {
                throw new LPGException("TimeProfile was null");
            }

            if (_ltDict.SimulateLoadtype(hhautodev.LoadType))
            {
                var profile = CalcDeviceDtoFactory.GetCalcProfileDto(hhautodev.TimeProfile);
                if (hhautodev.Location == null)
                {
                    throw new LPGException("Location was null");
                }

                var rd = _picker.GetAutoDeviceDeviceFromDeviceCategoryOrDevice(hhautodev.Device,
                                                                               allAutonomousDevices,
                                                                               energyIntensity,
                                                                               deviceActions,
                                                                               hhautodev.Location.IntID);
                var             cdl      = CalcDeviceDtoFactory.MakeCalcDeviceLoads(rd, _ltDict);
                var             lt       = _ltDict.Ltdtodict[hhautodev.LoadType];
                CalcVariableDto variable = null;
                if (hhautodev.Variable != null)
                {
                    var v = hhautodev.Variable;
                    variable = _calcVariableDtoFactory.RegisterVariableIfNotRegistered(v, calcLocation.Name, calcLocation.Guid, householdKey);
                }

                List <VariableRequirementDto> reqDtos = new List <VariableRequirementDto>();
                if (variable?.Name != null)
                {
                    VariableRequirementDto req = new VariableRequirementDto(variable.Name,
                                                                            hhautodev.VariableValue,
                                                                            calcLocation.Name,
                                                                            calcLocation.Guid,
                                                                            hhautodev.VariableCondition,
                                                                            variable.Guid);
                    reqDtos.Add(req);
                }

                //TODO: xxx missing probability?
                if (rd.DeviceCategory == null)
                {
                    throw new LPGException("Device category was null");
                }

                DeviceCategoryDto deviceCategoryDto = deviceCategoryDtos.Single(x => x.FullCategoryName == rd.DeviceCategory.FullPath);
                var cautodev = new CalcAutoDevDto(rd.Name,
                                                  profile,
                                                  lt.Name,
                                                  lt.Guid,
                                                  cdl,
                                                  (double)hhautodev.TimeStandardDeviation,
                                                  deviceCategoryDto.Guid,
                                                  householdKey,
                                                  1,
                                                  calcLocation.Name,
                                                  calcLocation.Guid,
                                                  deviceCategoryDto.FullCategoryName,
                                                  Guid.NewGuid().ToStrGuid(),
                                                  timearray,
                                                  reqDtos, deviceCategoryDto.FullCategoryName);
                //cautodev.ApplyBitArry(busyarr, _ltDict.LtDict[hhautodev.LoadType]);
                return(cautodev);
            }

            return(null);
        }