Exemple #1
0
        /// <summary>
        /// Fills in the defined color keys of the opened simulation
        /// </summary>
        public static void UpdateColorKeys(TextEdit textEdit, IProcessingData processingData)
        {
            textEdit.ClearColors();
            List <string> booleanInputKeys = processingData.InputRegisters.BooleanKeys;

            foreach (string key in booleanInputKeys)
            {
                textEdit.AddKeywordColor(key, BooleanInputColor);
            }
            foreach (string key in St.Boolean.Constant.Values)
            {
                textEdit.AddKeywordColor(key, BooleanInputColor);
            }
            List <string> booleanOutputKeys = processingData.OutputRegisters.BooleanKeys;

            foreach (string key in booleanOutputKeys)
            {
                textEdit.AddKeywordColor(key, BooleanOutputColor);
            }

            List <string> IntegerInputKeys = processingData.InputRegisters.IntegerKeys;

            foreach (string key in IntegerInputKeys)
            {
                textEdit.AddKeywordColor(key, IntegerInputColor);
            }
            // Godot already forces integer static inputs and colors them. (They can not be deleted so far)
            textEdit.AddColorOverride("number_color", IntegerInputColor);
            List <string> IntegerOutputKeys = processingData.OutputRegisters.IntegerKeys;

            foreach (string key in IntegerOutputKeys)
            {
                textEdit.AddKeywordColor(key, IntegerInputColor);
            }
        }
        public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
        {
            if (this.requarementsAreSet)
            {
                bool requarementsAreSatisfied = true;
                if (this.typeOfGarbage == type)
                {
                    requarementsAreSatisfied = this.capitalBalance >= this.minCapitalBalance &&
                                               this.energyBalance >= this.minEnergyBalance;
                }
                if (!requarementsAreSatisfied)
                {
                    return(ProcessingDeniedMessage);
                }
            }



            IWaste someWaste = this.wasteFactory.Create(name, weight, volumePerKg, type);

            IProcessingData processedData = this.garbageProcessor.ProcessWaste(someWaste);

            this.capitalBalance += processedData.CapitalBalance;
            this.energyBalance  += processedData.EnergyBalance;

            string formattedMessage = string.Format(ProcessGarbageMessageToFormat, someWaste.Weight.ToString(FloatingPointNumberFormat), someWaste.Name);

            return(formattedMessage);
            // return $"{someWaste.Weight} kg of {someWaste.Name} successfully processed!";
        }
        public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
        {
            if (this.requirmentsAreSet == true)
            {
                bool requirmentsAreSatisfied = true;
                if (this.typeOfGarbage == type)
                {
                    requirmentsAreSatisfied = this.capitalBalance >= minimumCapitalBalance &&
                                              this.energyBalance >= this.minimumEnergyBalance;
                }

                if (requirmentsAreSatisfied == false)
                {
                    return("Processing Denied!");
                }
            }

            IWaste someWaste = this.wasteFactory.Create(name, weight, volumePerKg, type);

            IProcessingData processedData = this.garbageProcessor.ProcessWaste(someWaste);

            this.capitalBalance += processedData.CapitalBalance;
            this.energyBalance  += processedData.EnergyBalance;

            return($"{(someWaste.Weight):f2} kg of {someWaste.Name} successfully processed!");
        }
Exemple #4
0
        public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
        {
            // Bonus task: Check current Management Min Requirements
            if (this.hasRequierementsSet)
            {
                bool meetsRequirements = true;
                if (this.garbageTypeRequirement == type)
                {
                    meetsRequirements = this.energyBalance >= this.minEnergyBalanceRequirement &&
                                        this.capitalBalance >= this.minCapitalBalanceRequirement;
                }

                if (!meetsRequirements)
                {
                    return(ProcessingDeniedMessage);
                }
            }

            IWaste waste = this.wasteFactory.Create(name, weight, volumePerKg, type);

            IProcessingData processedData = this.garbageProcessor.ProcessWaste(waste);

            this.capitalBalance += processedData.CapitalBalance;
            this.energyBalance  += processedData.EnergyBalance;

            //return $"{waste.Weight:f2} kg of {waste.Name} successfully processed!";

            var formattedMessage = string.Format(
                ProcessedGarbageMessageToFormat,
                waste.Weight.ToString(FloatingPointNumberFormat),
                waste.Name);

            return(formattedMessage);
        }
Exemple #5
0
        public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
        {
            if (this.requirementsAreSet)
            {
                bool requirementsAreSatisfied = true;

                if (this.requiredGarbageType == type)
                {
                    requirementsAreSatisfied = this.capitalBalance >= this.minCapitalBalance && this.energyBalance >= this.minEnergyBalance;
                }

                if (!requirementsAreSatisfied)
                {
                    return($"Processing Denied!");
                }
            }

            IWaste waste = this.wasteFactory.Create(name, weight, volumePerKg, type);

            IProcessingData processingData = this.garbageProcessor.ProcessWaste(waste);

            this.capitalBalance += processingData.CapitalBalance;
            this.energyBalance  += processingData.EnergyBalance;

            return($"{waste.Weight:F2} kg of {waste.Name} successfully processed!");
        }
Exemple #6
0
        public GarbageProcessor(IProcessingData processingData, IStrategyHolder strategyHolder)
        {
            this.ProcessingData = processingData;
            this.StrategyHolder = new StrategyHolder();

            this.InitialiseStrategyHoder();
        }
        public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
        {
            //Add checks for ChangedMenagementRequirement
            if (requirenmentsAreSet)
            {
                bool requirementsAreSatisfied = true;
                if (this.typeOfGarbage == type)
                {
                    requirementsAreSatisfied = this.capitalBalance >= minimumCapitalBalance && this.energyBalance >= minimumEnergyBalance;
                }

                if (!requirementsAreSatisfied)
                {
                    return(ProcessingDeniedMessage);
                }
            }

            IWaste someWaste = this.wasteFactory.Create(name, weight, volumePerKg, type);

            IProcessingData processedData = this.garbageProcessor.ProcessWaste(someWaste);

            capitalBalance += processedData.CapitalBalance;
            energyBalance  += processedData.EnergyBalance;

            string formatedMessage = string.Format(ProcessGarbageMessageToFormat, someWaste.Weight.ToString(FloatingPointNumberFormat), someWaste.Name);

            return(formatedMessage);
        }
 public void AddData(IProcessingData newData)
 {
     if (newData != null)
     {
         this.data.Add(newData);
     }
 }
Exemple #9
0
 /// <summary>
 /// If there is only one word in the action box, it can be assumed that the user likes to activate / set a boolean.
 /// From a feature request: It seem to be like this in other SFC-ST actions.
 /// </summary>
 private static Boolean InterpretAsDirectBooleanAssignment(string targetWord, IProcessingData context)
 {
     if (context.OutputRegisters.ContainsBoolean(targetWord))
     {
         return(new Boolean(targetWord, new St.Boolean.Constant("true"), context));
     }
     return(null);
 }
        public void GivingNullGarbageToProcessShouldThrowError()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(RecyclableGarbage), new RecyclableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            IWaste          burnableWasteTestObject = null;
            IProcessingData tempData = this.garbageProcessor.ProcessWaste(burnableWasteTestObject);
        }
        public void GarbageProcessorShouldThrowErrorIfNoStrategyIsPresentForGivenType()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(RecyclableGarbage), new RecyclableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            IWaste          burnableWasteTestObject = new BurnableGarbage("RecyclMePls", 10, 10);
            IProcessingData tempData = this.garbageProcessor.ProcessWaste(burnableWasteTestObject);
        }
Exemple #12
0
        private void AddActionEditor(IProcessingData data)
        {
            Node         node         = ((PackedScene)GD.Load(EditorScenePath)).Instance();
            ActionEditor actionEditor = (ActionEditor)node;

            _actionEditors.Add(actionEditor);
            GetNode <BoxContainer>("ScrollContainer/VerticalBoxContainer").AddChild(actionEditor);
            actionEditor.InitializeWith(this, data);
        }
Exemple #13
0
        public string ProcessGarbage(string name, double volumePerKg, double weight, string type)
        {
            var currentWaste = this.wasteFactory.CreateWaste(name, volumePerKg, weight, type);

            IProcessingData info = this.garbageProcessor.ProcessWaste(currentWaste);

            this.energyBalance  += info.EnergyBalance;
            this.capitalBalance += info.CapitalBalance;
            return($"{currentWaste.Weight:F2} kg of {currentWaste.Name} successfully processed!");
        }
Exemple #14
0
        public void ProcessWaste_WithVallidWaste_ShoudReturnCorrectEnergyAndCapitalBalance()
        {
            IProcessingData result = this.processor.ProcessWaste(this.waste);

            double expectedEnergyBalance = 464.0;
            double capitalEnergyBalance  = 0.0;

            Assert.AreEqual(expectedEnergyBalance, result.EnergyBalance, "Energy Balance not calculated correctly");
            Assert.AreEqual(capitalEnergyBalance, result.CapitalBalance, "CapitalBalance not calculated correctly");
        }
Exemple #15
0
 public void InitializeWith(ActionEditorBox controller, IProcessingData data)
 {
     _controller            = controller;
     _actionDescriptionNode = GetNode <TextEdit>("ActionTextEditor");
     _actionDescriptionNode.Connect("focus_exited", this, nameof(OnTextEditorFocusExited));
     _actionDescriptionNode.Connect("text_changed", this, nameof(OnActionTextChanged));
     _qualifierNode = GetNode <MenuButton>("ActionQualifierSelector");
     ConfigureQualifierPopupMenu();
     ActionMaster.UpdateColorKeys(_actionDescriptionNode, data);
 }
        /// <summary>
        /// Converts the string to a logical model.
        /// </summary>
        public static BooleanExpression AsBooleanExpression(string transition, IProcessingData context)
        {
            Terminals         data           = new Terminals(transition);
            BooleanExpression mainExpression = InterpretBooleanExpression(data, context);

            if (!data.IsEndReached)
            {
                mainExpression = AppendFailureInfo(data, mainExpression);
            }
            return(mainExpression);
        }
 private static BooleanExpression InterpretBoolean(string word, IProcessingData context)
 {
     if (Constant.Values.Contains(word))
     {
         return(new Constant(word));
     }
     if (context.HasBoolVariable(word))
     {
         return(new StepReference(word));
     }
     return(new PlantReference(word, context));
 }
        public void GarbageProcessorProperlyProcessingBurnableGarbageWithBurnableStrategy()
        {
            IStrategyHolder testStrategy = new StrategyHolder();

            testStrategy.AddStrategy(typeof(BurnableGarbage), new BurnableStrategy());
            this.garbageProcessor = new GarbageProcessor(testStrategy);
            IWaste          burnableWasteTestObject = new BurnableGarbage("BurnItUp", 10, 10);
            IProcessingData tempData = this.garbageProcessor.ProcessWaste(burnableWasteTestObject);

            Assert.AreEqual(0, tempData.CapitalBalance);
            Assert.AreEqual(80, tempData.EnergyBalance);
        }
 /// <summary>
 /// Converts the string to a numerical Expression.
 /// </summary>
 public static NumericalExpression AsNumericalExpression(string word, IProcessingData context)
 {
     if (int.TryParse(word, out int number))
     {
         return(new Constant(number));
     }
     if (context.HasIntVariable(word))
     {
         return(new StepReference(word));
     }
     return(new PlantReference(word, context));
 }
Exemple #20
0
        public string ProcessGarbage(string[] parameters)
        {
            IWaste garbage = this.InstantiateWaste(parameters);

            if (this.BalanceManager.CheckWasteForProcessing(garbage))
            {
                IProcessingData result = this.GarbageProcessor.ProcessWaste(garbage);
                this.BalanceManager.ApplyProcessingResult(result);
                return(string.Format("{0:F2} kg of {1} successfully processed!", garbage.Weight, garbage.Name));
            }

            return("Processing Denied!");
        }
        public override void Execute()
        {
            string name            = this.Parameters[0];
            double volumePerKg     = double.Parse(this.Parameters[2]);
            double weight          = double.Parse(this.Parameters[1]);
            string garbageTypeName = this.Parameters[3];

            IWaste waste = null;

            var garbageTypes = Assembly.GetExecutingAssembly()
                               .GetTypes()
                               .Where(t => t.GetCustomAttributes().Any(a => a.GetType() == typeof(GarbageAttribute)));

            foreach (var garbageType in garbageTypes)
            {
                var attribute = (GarbageAttribute)garbageType.GetCustomAttribute(typeof(GarbageAttribute));

                if (attribute.Name == garbageTypeName)
                {
                    waste = (IWaste)Activator.CreateInstance(
                        garbageType,
                        new object[] { name, volumePerKg, weight });

                    break;
                }
            }

            if (waste == null)
            {
                return;
            }

            IProcessingData processData = this.garbageProcessor.ProcessWaste(waste);

            IChangeManagementRequirement requirement =
                this.repository.GetManagmentRequirement(garbageTypeName);

            if (requirement != null)
            {
                if (this.repository.Energy < requirement.EnergyBalance ||
                    this.repository.Capital < requirement.CapitalBalance)
                {
                    this.inputOutput.WriteMessage("Processing Denied!");
                    return;
                }
            }

            this.repository.Add(processData);

            this.inputOutput.WriteMessage($"{waste.Weight:f2} kg of {waste.Name} successfully processed!");
        }
Exemple #22
0
        /// <summary>
        /// Called when the model has changed or is initialized.
        /// </summary>
        public void UpdateAction(ActionEntity action, IProcessingData context)
        {
            _selectedQualifier = action.Qualifier;
            SetQualifierText((int)_selectedQualifier);
            _actionDescriptionNode.Text = action.Action;
            _isRelevant = !string.IsNullOrEmpty(_actionDescriptionNode.Text);
            AssignmentExpression expression = ActionMaster.InterpretTransitionText(action.Action, context);

            _actionDescriptionNode.HintTooltip = expression == null ? "???" : expression.ToString();
            bool  validExpression = expression != null && expression.IsValid();
            Color background      = validExpression ? new Color(1, 0, 0, 0f) : new Color(1, 0, 0, 0.2f);

            _actionDescriptionNode.AddColorOverride("background_color", background);
        }
        //{name}|{weight}|{volumePerKg}|{type}
        public override string Execute()
        {
            string name        = base.Data[1];
            double weight      = double.Parse(base.Data[2]);
            double volumePerKg = double.Parse(base.Data[3]);
            string type        = base.Data[4];

            IWaste          garbage = this.wasteFactory.CreateWaste(name, weight, volumePerKg, type);
            IProcessingData data    = this.processor.ProcessWaste(garbage);

            this.repo.CalculateBalance(data);

            return($"{(garbage.Weight):F2} kg of { garbage.Name} successfully processed!");
        }
Exemple #24
0
        private void AssignActionsFrom(PatchEntity source, IProcessingData context)
        {
            _actions = new Dictionary <ActionQualifier, List <AssignmentExpression> >();
            foreach (ActionQualifier qualifier in (ActionQualifier[])Enum.GetValues(typeof(ActionQualifier)))
            {
                _actions.Add(qualifier, new List <AssignmentExpression>());
            }

            for (int i = 0; i < source.ActionEntries.Count; i++)
            {
                AssignmentExpression expression = ActionMaster.InterpretTransitionText(source.ActionEntries[i].Action, context);
                _actions[source.ActionEntries[i].Qualifier].Add(expression);
            }
        }
        public bool UpdateData(IProcessingData data)
        {
            if (this.isManagementSet &&
                data.Type == this.typeOfGarbageToCheck &&
                (this.capitalBalanceMin > this.capital ||
                 this.energyBalanceMin > this.energy))
            {
                return(false);
            }

            this.energy  += data.EnergyBalance;
            this.capital += data.CapitalBalance;

            return(true);
        }
Exemple #26
0
        public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
        {
            IWaste someWaste = this.wasteFactory.Create(name, weight, volumePerKg, type);

            IProcessingData processedData = this.garbageProcessor.ProcessWaste(someWaste);

            this.capitalBalance += processedData.CapitalBalance;
            this.energyBalance  += processedData.EnergyBalance;

            string formattedMessage = string.Format(ProcessGarbageMessageToFormat,
                                                    someWaste.Weight.ToString(FloatingPointNumberFormat),
                                                    someWaste.Name);

            return(formattedMessage);
        }
        public string ProcessGarbage(string[] parameters)
        {
            IWaste garbage = InstantiateWaste(parameters);

            if (this.BalanceManager.CheckWasteForProcessing(garbage))
            {
                IProcessingData processingData = this.GarbageProcessor.ProcessWaste(garbage);
                this.BalanceManager.ApplyProcessedResult(processingData);

                return($"{garbage.Weight:f2} kg of {garbage.Name} successfully processed!");
            }
            else
            {
                return("Processing Denied!");
            }
        }
        /// <inheritdoc/>
        public async Task ProcessDataAsync(IProcessingData data, CancellationToken cancellationToken = default)
        {
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            using var _ = _logger.BeginScope("Processing data {@data}.", data);

            _logger.LogInformation("Start processing.");

            await _uow.ProcessDataAsync(data, cancellationToken).ConfigureAwait(false);

            await _uow.SaveAsync(cancellationToken).ConfigureAwait(false);

            _logger.LogInformation("End processing.");
        }
Exemple #29
0
        public void ProcessWaste()
        {
            double expectedRecCapital    = 4000;
            double expectedRecBurnEnergy = -5.7;
            double expectedBurnEnergy    = 97.0012;
            double expectedCapital       = 0;
            double expectedStorCapital   = -2.2961;
            double expectedStorEnergy    = -0.4592;

            BurnableGarbage   burnGarbage = new BurnableGarbage("Burnable", 3.657, 33.156);
            RecyclableGarbage recGarbage  = new RecyclableGarbage("rec", 1.14, 10);
            StorableGarbage   storGarbage = new StorableGarbage("stor", 1.57, 2.25);

            IStrategyHolder strategyHolder = new StrategyHolder();

            strategyHolder.AddStrategy(
                typeof(BurnableDisposableAttribute),
                new BurnableDisposalStrategy());

            strategyHolder.AddStrategy(
                typeof(RecyclableDisposableAttribute),
                new RecyclableDisposalStrategy());

            strategyHolder.AddStrategy(
                typeof(StorableDisposableAttribute),
                new StorableDisposalStrategy());

            IGarbageProcessor processor   = new GarbageProcessor(strategyHolder);
            IProcessingData   processData = processor.ProcessWaste(burnGarbage);

            Assert.AreEqual(expectedBurnEnergy, Math.Round(processData.EnergyBalance, 4));
            Assert.AreEqual(expectedCapital, processData.CapitalBalance);

            processData = processor.ProcessWaste(recGarbage);

            Assert.AreEqual(expectedRecBurnEnergy, Math.Round(processData.EnergyBalance, 1));
            Assert.AreEqual(expectedRecCapital, processData.CapitalBalance);

            processData = processor.ProcessWaste(storGarbage);

            Assert.AreEqual(expectedStorEnergy, Math.Round(processData.EnergyBalance, 4));
            Assert.AreEqual(expectedStorCapital, Math.Round(processData.CapitalBalance, 4));
        }
    public string ProcessGarbage(string name, double weight, double volumePerKg, string type)
    {
        if (type == restrictedType)
        {
            if (energyBalance < energyRequired || capitalBalance < capitalRequired)
            {
                return("Processing Denied!");
            }
        }

        IWaste waste = this.wasteFactory.CreateWaste(name, weight, volumePerKg, type);

        IProcessingData result = this.garbageProcessor.ProcessWaste(waste);

        this.energyBalance  += result.EnergyBalance;
        this.capitalBalance += result.CapitalBalance;

        return($"{weight:f2} kg of {name} successfully processed!");
    }