public PredictiveForecastServiceResponse GetDailyPredictiveItem(PrecdictiveForecastServiceRequest predictiveServiceRequest) { var precdictiveForecastServiceResponse = new PredictiveForecastServiceResponse(); string apiUrl = "https://spendwise-prediction.herokuapp.com/category"; //string inputJson = (new JavaScriptSerializer()).Serialize(predictiveServiceRequest); WebClient client = new WebClient(); client.Headers["Content-type"] = "application/json"; client.Encoding = Encoding.UTF8; string json = client.DownloadString(apiUrl); precdictiveForecastServiceResponse.DailyPredictiveItem = (new JavaScriptSerializer()).Deserialize <List <PredictiveItem> >(json); return(precdictiveForecastServiceResponse); }
public PredictiveForecastServiceResponse GetPredictiveForecast(PrecdictiveForecastServiceRequest predictiveServiceRequest) { var precdictiveForecastServiceResponse = new PredictiveForecastServiceResponse(); string result = string.Empty; //using (var client = new HttpClient()) //{ // //const string apiKey = "eCXHJn+ovrhVvuue7wLvy4k27z5XmwkytUMrLAeYdz3hju4uaWP4rF+/HOxJQ1dPtmYQciy96z9OP79XsZdnvQ=="; // Replace this with the API key for the web service // //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); // client.BaseAddress = new Uri("https://spendwise-prediction.herokuapp.com/predict?userID=1"); // //HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest); // //var response = client.PostAsync("", new StringContent( // //new JavaScriptSerializer().Serialize(""), Encoding.UTF8, "application/json")).Result; // var response = client.GetAsync("https://spendwise.azurewebsites.net/predict?userID=1").Result; // if (response.IsSuccessStatusCode) // { // result = response.Content.ReadAsStringAsync().Result; // Console.WriteLine("Result: {0}", result); // } // else // { // Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode)); // // Print the headers - they include the requert ID and the timestamp, // // which are useful for debugging the failure // Console.WriteLine(response.Headers.ToString()); // //string responseContent = await response.Content.ReadAsStringAsync(); // //Console.WriteLine(responseContent); // } //} //string apiUrl = "http://spendwiseservicemain.azurewebsites.net/api/PredictiveForecast/GetPredictiveForecastExpense"; string apiUrl = "https://spendwise-prediction.herokuapp.com/predict?userID=1"; //string inputJson = (new JavaScriptSerializer()).Serialize(predictiveServiceRequest); WebClient client = new WebClient(); client.Headers["Content-type"] = "text/plain"; //client.Encoding = Encoding.UTF8; string json = client.DownloadString(apiUrl); var objects = JArray.Parse(json); // parse as array List <PredictiveForecast> listforecast = new List <PredictiveForecast>(); foreach (JObject root in objects) { PredictiveForecast forecast = new PredictiveForecast(); foreach (KeyValuePair <String, JToken> app in root) { if (app.Key.Equals("spending")) { forecast.Spending = Convert.ToInt32(Math.Round(Convert.ToDouble((String)app.Value))); } if (app.Key.Equals("time")) { forecast.time = Convert.ToDateTime(app.Value.ToString()).ToString("MM/dd"); } //listforecast.Add( // new PredictiveForecast { // Spending = Convert.ToInt32(Math.Round(Convert.ToDouble((String)app.Value))), // time = (Convert.ToDateTime (app.Key["time"])) // } // ); //precdictiveForecastServiceResponse.PredictiveForecast[count].Saving = Convert.ToInt32(Math.Round(Convert.ToDouble((String)app.Value))); //var spending = precdictiveForecastServiceResponse.PredictiveForecast[count].Spending; //precdictiveForecastServiceResponse.PredictiveForecast[count].Spending = Convert.ToInt32(Math.Round(Convert.ToDouble(spending))); } listforecast.Add(forecast); } //precdictiveForecastServiceResponse.PredictiveForecast = (new JavaScriptSerializer()).Deserialize<List<PredictiveForecast>>(json); precdictiveForecastServiceResponse.PredictiveForecast = listforecast; //apiUrl = "http://spendwiseservicemain.azurewebsites.net/api/PredictiveForecast/GetPredictiveForecastSavings"; apiUrl = "https://spendwise-prediction.herokuapp.com/savingPrediction?days=30"; json = client.DownloadString(apiUrl); objects = JArray.Parse(json); // parse as array foreach (JObject root in objects) { int count = 0; foreach (KeyValuePair <String, JToken> app in root) { precdictiveForecastServiceResponse.PredictiveForecast[count].Saving = Convert.ToInt32(Math.Round(Convert.ToDouble((String)app.Value))); var spending = precdictiveForecastServiceResponse.PredictiveForecast[count].Spending; precdictiveForecastServiceResponse.PredictiveForecast[count].Spending = Convert.ToInt32(Math.Round(Convert.ToDouble(spending))); count++; } } return(precdictiveForecastServiceResponse); }