Пример #1
0
        public async Task <string> ForecastSpecificCustomerOrderChart(string dbPath, string pythonFile)
        {
            Trace.WriteLine("Getting the orders chart ...");
            //pythonScriptsPath = System.IO.Path.GetFullPath(pythonScriptsPath); //trasforma i path relativi in path assoluti
            string fcast = "";

            try
            {
                // Funzione asincrona, restituisce una stringa.
                string str = await pyRunnes.getStringsAsync(
                    this.pythonScriptsPath,
                    pythonFile,
                    this.pythonScriptsPath,
                    dbPath,
                    this.strCustomers);

                string[] lines = str.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string s in lines)
                {
                    if (s.StartsWith("Actual"))
                    {
                        fcast = s.Substring(s.LastIndexOf(" "));
                        //Trace.WriteLine(fcast);
                    }
                }
                return(fcast);
            }
            catch (Exception e)
            {
                Trace.WriteLine($"[ForecastSpecificCustomerOrderChart]: {e.ToString()}");
                return(null);
            }
        }
Пример #2
0
        // restituisce le previsioni di uno specifico customer
        public async Task <string> readCustomersOrdersPrevision(string pythonScript, string customer)
        {
            string fcast = "";

            Trace.WriteLine("Getting the orders chart (prevision) ...");
            pythonScriptPath = System.IO.Path.GetFullPath(pythonScriptPath);
            try
            {
                string list = await pyRunner.getStringsAsync(
                    this.pythonScriptPath,
                    pythonScript,
                    this.pythonScriptPath,
                    this.dbPath,
                    customer);

                string[] lines = list.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string s in lines)
                {
                    if (s.StartsWith("Actual"))
                    {
                        fcast = fcast + Environment.NewLine + s;
                    }
                }

                return(fcast);
            }
            catch (Exception e)
            {
                Trace.WriteLine($"[ReadCustomerOrdersChart]: {e.ToString()}");
                return(null);
            }
        }
Пример #3
0
        //actual e forecast per ogni cliente
        public async Task <int> ForecastSpecificCustomerOrderChart(string dbOrdiniPath, string pyScript, string customer)
        {
            pythonScriptsPath = @"C:\Users\federica.pecci2\Documents\GitHub\SSD19-1\DSS19\DSS19\python_scripts";
            double fcast = double.NaN;

            try
            {
                string list = await pyRunner.getStringsAsync(
                    pythonScriptsPath,
                    pyScript,  // chartOrders.py o nuovo script
                    pythonScriptsPath,
                    dbOrdiniPath,
                    customer); //strCustomers riga dei customer restituita dal db, select dei customer random

                NumberFormatInfo provider = new NumberFormatInfo();
                provider.NumberDecimalSeparator = ".";
                string[] lines = list.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string s in lines)
                {
                    if (s.StartsWith("Actual"))
                    {
                        fcast = Convert.ToDouble(s.Substring(s.LastIndexOf(" ")), provider);
                        Trace.WriteLine(s);
                    }
                }
            }
            catch (Exception exception)
            {
                Trace.WriteLine("[CONTROLLER] errore: " + exception.Message);
            }

            return((int)Math.Round(fcast)); // da strina a double a intero
        }
Пример #4
0
        public async Task sarimaForecasts(string dbPath)
        {
            Trace.WriteLine("Getting forecast's values ... ");
            pythonScriptsPath = System.IO.Path.GetFullPath(pythonScriptsPath);

            double fcast = -1;
            string cust;

            for (int i = 0; i < NUMCUST; i++)
            {
                cust = $"'cust{i + 1}'";

                try
                {
                    string list = await pyRunner.getStringsAsync(
                        pythonScriptsPath,
                        "arima_forecast.py",
                        pythonScriptsPath,
                        dbPath,
                        cust);

                    string[] lines = list.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
                    foreach (string s in lines)
                    {
                        if (s.StartsWith("Orders"))
                        {
                            Trace.WriteLine($"Ordini cliente {cust}: {s.Substring(("Orders:").Length)}");
                        }

                        if (s.StartsWith("Actual"))
                        {
                            fcast = double.Parse(s.Substring(s.LastIndexOf("forecast") + ("forecast").Length),
                                                 System.Globalization.CultureInfo.InvariantCulture);
                            try
                            {
                                GAP.req[i] = (int)Math.Round(fcast);
                            }
                            catch (Exception) { }
                        }
                    }
                    fcast = Math.Round(fcast, 2, MidpointRounding.AwayFromZero);
                    forecastsList.Add(fcast);
                    Trace.WriteLine(String.Format("Forecast value: {0:0.00}", fcast));
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                }
            }
        }