private void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox t = (TextBox)sender;

            t.Text = StringToFormula.Eval(t.Text).ToString("0.00");
            UpdateVariable();
        }
Ejemplo n.º 2
0
    private long EvaluateExpressionAdvanced(string expression)
    {
        StringToFormula stf    = new StringToFormula();
        long            result = stf.Eval(expression);

        return(result);
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Mohamad Fahrizal
        /// 2018 01 31
        /// Untuk merubah semua rumus, menjadi nilai
        /// Contoh : Nilai PPN adalah : {{ @@NilaiKontrak - @@NilaiDPP }}
        /// Maka akan menghasilkan    :        55.000.000 - 50.000.000
        ///        Hasil Akhir          Nilai PPN adalah : 5.000.000
        ///
        /// Note : Rumusan perhitungan hanya bisa di eksekusi apabila berada di dalam double kurung kurawal {{ a + b }}
        /// </summary>
        public static string HitungRumus(string SMS)
        {
            string output = SMS;

            //Cari teks yg di apit oleh {{ }}
            var formulas = Regex.Matches(SMS, @"\{{(.*?)\}}");

            if (formulas.Count > 0)
            {
                foreach (Match m in formulas)
                {
                    StringToFormula stf = new StringToFormula();

                    double hasilHitung = 0;

                    try
                    {
                        hasilHitung = stf.Eval(m.Groups[1].Value);
                    }
                    catch { }

                    output = output.Replace(m.Groups[1].Value, Cf.Num(hasilHitung));
                }
            }

            return(output.Replace("{{", "").Replace("}}", ""));
        }
Ejemplo n.º 4
0
    void Awake()
    {
        _goalTotal         = GetComponent <GoalTotal>();
        _tileStack         = new Stack <GameTile>();
        _equationGenerator = GameObject.FindObjectOfType <EquationGenerator>();

        _stf = new StringToFormula();
    }
Ejemplo n.º 5
0
        public static int GetDiceResult(string input)
        {
            var fixedInput = input.Replace('x', '*');
            var stf        = new StringToFormula();
            var db         = stf.Eval(fixedInput);
            var number     = (int)Math.Round(db);

            return(_random.Next(1, number));
        }
Ejemplo n.º 6
0
        public void CalculateTotals()
        {
            Material.CalculateTotals();
            //Clear Values
            MaterialName = Material.Name;
            //EEI = Material.EEI;
            ECI     = Material.ECI + Additional;
            Density = Material.Density;

            if (AllElements != null)
            {
                if (AllElements.Count > 0)
                {
                    Volume = 0;
                    foreach (CarboElement ce in AllElements)
                    {
                        ce.Calculate(Material);
                        Volume += ce.Volume;
                    }
                }
            }

            double wasteFact = 1 + (Waste / 100);

            Volume = Math.Round(Volume, 3);

            //Calculate the real volume based on a correction if required.
            if (Utils.isValidExpression(Correction) == true)
            {
                string          volumeStr = Volume.ToString();
                StringToFormula stf       = new StringToFormula();
                double          result    = stf.Eval(volumeStr + Correction);
                TotalVolume = Math.Round((B4Factor * (result * wasteFact)), 3);
            }
            else
            {
                TotalVolume = Math.Round(B4Factor * (Volume * wasteFact), 3);
            }


            //Calculate corrected mass
            Mass = TotalVolume * Density;
            //EC = Total corrected Mass * EE;I
            EC = (Mass * ECI) / 1000;
        }
Ejemplo n.º 7
0
        public static decimal HitungRumus2(string SMS)
        {
            StringToFormula stf = new StringToFormula();

            double hasilHitung = 0;

            try
            {
                hasilHitung = stf.Eval(SMS);
            }
            catch { }
            if (Double.IsInfinity(hasilHitung))
            {
                hasilHitung = 0;
            }

            return(Convert.ToDecimal(hasilHitung));
        }
Ejemplo n.º 8
0
        private static void FindEquationAnswers(double startInterval, double endInterval, string equation)
        {
            Console.WriteLine("{0}		{1}		{2}", "x", "F(x)", "F'(x)");
            double steps = 0.01;
            double i     = startInterval;

            while (i <= endInterval)
            {
                string          newEquation1 = equation.Replace("x", Convert.ToString(i));
                StringToFormula stf1         = new StringToFormula();
                double          Fx           = stf1.Eval(newEquation1);
                string          newEquation2 = equation.Replace("x", Convert.ToString(i));
                StringToFormula stf2         = new StringToFormula();
                double          Fx1          = stf2.Eval(newEquation2);
                Console.WriteLine("{0}		{1}		{2}", i, Fx, Fx1);
                i += steps;
            }
        }
Ejemplo n.º 9
0
        public void CalculateTotals()
        {
            Material.CalculateTotals();
            //Clear Values
            MaterialName = Material.Name;
            //EEI = Material.EEI;
            ECI     = Material.ECI;
            Density = Material.Density;

            if (AllElements != null)
            {
                if (AllElements.Count > 0)
                {
                    Volume = 0;
                    foreach (CarboElement ce in AllElements)
                    {
                        Volume += ce.Volume;
                    }
                }
            }

            //Calculate the real volume based on a correction if required.
            if (Utils.isValidExpression(Correction) == true)
            {
                string          volumeStr = Volume.ToString();
                StringToFormula stf       = new StringToFormula();
                double          result    = stf.Eval(volumeStr + Correction);
                TotalVolume = result;
            }
            else
            {
                TotalVolume = Volume;
            }


            //Calculate Valuesl
            Mass = TotalVolume * Density;
            //EE = Mass * EEI;
            EC = (Mass * ECI) / 1000;
        }
Ejemplo n.º 10
0
 private void SliderText_LostFocus(object sender, RoutedEventArgs e)
 {
     SliderValue.Value = (float)StringToFormula.Eval(SliderText.Text);
     SliderText.Text   = SliderValue.Value.ToString("0.00");
     UpdateVariable();
 }
Ejemplo n.º 11
0
        public async Task <bool> process(Result result)
        {
            return(await Task.Run(() =>
            {
                MainListener.Instance.StopListening();
                for (int i = 0; i < result.SubQueries.Count; i++)
                {
                    SubQuery query = result.SubQueries[i];
                    Intent intent = query.IdentId;
                    if (intent.StartPrgramsFromList)
                    {
                        bool found = false;
                        foreach (string star in query.InputStar)
                        {
                            string keyName = star.ToLower().Trim();
                            if (database.ContainsKey(keyName))
                            {
                                lastProgramFound = database[keyName];
                                if (intent.hasConfirmDialog)
                                {
                                    MainListener.Instance.StartConfirm(new string[] { intent.ConfirmWord, intent.ConfirmWord });
                                    if (!intent.hasAnswer)
                                    {
                                        MouthManager.Instance.Speak("Are you sure you want to open " + keyName + " ?");
                                    }
                                    lastActivatedTime = Time.time + listenTime;
                                    isConfirmActivated = true;
                                }
                                else
                                {
                                    processConfirmOpenProgram(intent.ConfirmWord);
                                }
                                found = true;
                                break;
                            }
                            else
                            {
                                if (keyName.Equals("settings") || keyName.Equals("setting"))
                                {
                                    TaskPanel.Instance.openSettings();
                                    return false;
                                }
                                if (keyName.Equals("config") || keyName.Equals("configs"))
                                {
                                    TaskPanel.Instance.openConfigs();
                                    return false;
                                }
                                if (keyName.Equals("test processor"))
                                {
                                    TaskPanel.Instance.openTests();
                                    return false;
                                }
                            }
                        }
                        if (!found && intent.LearnDialog)
                        {
                            openLearningSystem(LearnType.program);
                        }
                    }
                    if (intent.hasSearchInWeb)
                    {
                        bool found = false;
                        if (query.InputStar.Count == 2)
                        {
                            string keyName = query.InputStar[1].ToLower().Trim();
                            string value = query.InputStar[0].ToLower().Trim();
                            if (sites.ContainsKey(keyName))
                            {
                                IProgram dummy = new IProgram();
                                dummy.Name = sites[keyName].Name;
                                dummy.Path = sites[keyName].Url;
                                dummy.Path += sites[keyName].Parameters + value;
                                lastProgramFound = dummy;
                                if (intent.hasConfirmDialog)
                                {
                                    MainListener.Instance.StartConfirm(new string[] { intent.ConfirmWord, intent.ConfirmWord });
                                    if (!intent.hasAnswer)
                                    {
                                        MouthManager.Instance.Speak("Are you sure you want to open " + keyName + " ?");
                                    }
                                    lastActivatedTime = Time.time + listenTime;
                                    isConfirmActivated = true;
                                }
                                else
                                {
                                    processConfirmOpenProgram(intent.ConfirmWord);
                                }
                            }
                        }

                        if (!found && intent.LearnDialog)
                        {
                            openLearningSystem(LearnType.search);
                        }
                    }
                    if (intent.isMathQuestion)
                    {
                        string formula = FixResult(query.FullPath.ToUpper()); //or get it from DB
                        int index = formula.IndexOf("<THAT>");
                        if (index > 0)
                        {
                            formula = formula.Substring(0, index);
                        }

                        formula = RemoveUnwantedCharacters(formula, "0123456789+-*/.".ToCharArray());

                        StringToFormula stf = new StringToFormula();
                        double resultx = stf.Eval(formula);
                        TaskPanel.Instance.setClipBoardText(resultx.ToString());
                        MouthManager.Instance.Speak(resultx.ToString() + "! For your convenience result was copy to clipboard.");
                    }
                    if (intent.hasAnswer)
                    {
                        MouthManager.Instance.Speak(result.Output);
                    }
                }
                return true;
            }));
        }