public string forecastSARIMAindex(string attribute) { //res e' il campo testo da inviare string res = "\"text\":\""; string interpreter = @"C:\Users\lollo\Anaconda3\envs\opanalytics\python.exe"; PythonRunner runner = new PythonRunner(interpreter, "opanalytics"); Bitmap mp = null; try { //faccio il parsing dell'output string command = $"Models/forecastStat.py {attribute}.csv"; string list = runner.runDosCommands(command); string[] lines = list.Split(new[] { Environment.NewLine }, StringSplitOptions.None); string strmp = ""; //prendo tutte le righe e guardo se sono da inviare alla textbox o contiene un'immagine //se b' allora immagine, stringa altrimenti foreach (string s in lines) { if (s.StartsWith("Alert:")) { res += s; } if (s.StartsWith("b'")) { strmp = s.Trim(); break; } } strmp = strmp.Substring(strmp.IndexOf("b'")); //creo immagine res += "\",\"img\":\"" + strmp + "\""; mp = runner.FromPythonBase64String(strmp); } catch { } return(res); }
public string createPortfolio() { string interpreter = @"C:\Users\lollo\Anaconda3\envs\opanalytics\python.exe"; PythonRunner runner = new PythonRunner(interpreter, "opanalytics"); try { //faccio il parsing dell'output string command = $"Models/test.py"; string list = runner.runDosCommands(command); string[] lines = list.Split(new[] { Environment.NewLine }, StringSplitOptions.None); foreach (string s in lines) { Console.WriteLine(s); } } catch { Console.WriteLine("error"); } return("ok"); }
public string forecastSARIMAindex(string attribute) { string res = "\"text\":\""; string interpreter = "C:/Users/camerum/anaconda3/envs/open/python.exe"; string environment = "open"; int timeout = 10000; PythonRunner pr = new PythonRunner(interpreter, environment, timeout); Bitmap bmp = null; try { string command = $"Models/MainPortafoglio.py"; string[] indices = new string[] { "SP_500", "FTSE_MIB", "GOLD_SPOT", "MSCI_EM", "MSCI_EURO", "All_Bonds", "US_Treasury" }; if (indices.Contains(attribute)) { command = command + " " + attribute; } Console.WriteLine("On going.+..+...+...." + command); string list = pr.runDosCommands(command); if (string.IsNullOrWhiteSpace(list)) { Console.WriteLine("Error in the script call"); return(res); } string[] lines = list.Split(new[] { Environment.NewLine }, StringSplitOptions.None); string strBitmaps = "["; foreach (string s in lines) { if (s.StartsWith("rmse") || s.StartsWith("Actual")) { Console.WriteLine(s); res += (s + "\\n"); } if (s.StartsWith("Expected return") || s.StartsWith("Standar_Devst") || s.StartsWith("Portfolio")) { Console.WriteLine(s); res += (s + "\\n"); } if (s.StartsWith("b'")) { strBitmaps += "\"" + s.Trim().Substring(s.IndexOf("b'")) + "\","; try { bmp = pr.FromPythonBase64String(s.Trim().Substring(s.IndexOf("b'"))); } catch (Exception e) { throw new Exception("Error while creating image from Python script", e); } } } strBitmaps = strBitmaps.TrimEnd(','); strBitmaps += "]"; res += "\",\"img\":" + strBitmaps; } catch (Exception e) { Console.WriteLine(e.ToString()); } return(res); }