@RequestMapping(value = "/StockPrices", method = RequestMethod.POST) public String pr( ModelMap model, HttpServletRequest request, @Valid stocksearchhelper StockSearchHelper, BindingResult result) { /*if(result.hasErrors()) { model.addAttribute("se","Please Check the Values Entered"); model.addAttribute("StockSearchHelper",new stocksearchhelper()); model.addAttribute("CompanyName",new CompanyReports()); List<stock> x=stockServiceInterface.liststock("NASDAQ"); List<stock> y=stockServiceInterface.liststock("NASDAQCOMPOSITE"); List<stock> z=stockServiceInterface.liststock("DOWJONES"); List<stock> a=stockServiceInterface.liststock("GOLD"); List<stock> b=stockServiceInterface.liststock("SANDP"); List<stock> c=stockServiceInterface.liststock("OIL"); model.addAttribute("NASDAQ",x.get(0).getPrice()); model.addAttribute("NASDAQCOMPOSITE",y.get(0).getPrice()); model.addAttribute("DOWJONES",z.get(0).getPrice()); model.addAttribute("GOLD",a.get(0).getPrice()); model.addAttribute("SANDP",b.get(0).getPrice()); model.addAttribute("OIL",c.get(0).getPrice()); List<TopPerformers> opds1= topPerformerServiceInterface.liststock(); model.addAttribute("first",opds1.get(0).getTickerCode()); model.addAttribute("second",opds1.get(1).getTickerCode()); model.addAttribute("third",opds1.get(2).getTickerCode()); model.addAttribute("fourth",opds1.get(3).getTickerCode()); return "ClientHome"; }*/ /* else {*/ long currentTime = (new Date()).getTime(); // long String symbol = StockSearchHelper.getName(); try { URL yahoofin = new URL( "http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=sl1d1t1c1ohgvjkm4&e=.csv"); URLConnection yc = yahoofin.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { String[] yahooStockInfo = inputLine.split(","); StockBean stockInfo = new StockBean(); stockInfo.setTicker(yahooStockInfo[0].replaceAll("\"", "")); stockInfo.setPrice(Float.valueOf(yahooStockInfo[1])); stockInfo.setChange(Float.valueOf(yahooStockInfo[4])); // 91011 stockInfo.setWeekLow(String.valueOf(yahooStockInfo[9])); stockInfo.setWeekHigh(String.valueOf(yahooStockInfo[10])); stockInfo.setMA(String.valueOf(yahooStockInfo[11])); stockInfo.setChartUrlSmall("http://ichart.finance.yahoo.com/t?s=" + stockInfo.getTicker()); stockInfo.setChartUrlLarge("http://chart.finance.yahoo.com/w?s=" + stockInfo.getTicker()); stockInfo.setLastUpdated(currentTime); // stocks.put(symbol, stockInfo); model.addAttribute("stocksdata", stockInfo); com.mkyong.common.Service.RssFeedManager rssFeedManager = new com.mkyong.common.Service.RssFeedManager(); String url = "http://news.google.com/news?q=" + symbol + "&output=rss"; com.mkyong.common.Service.RssFeed rssFeed = rssFeedManager.processRssURL(url); if (rssFeed == null) return "error"; model.addAttribute("rssFeed", rssFeed); break; } in.close(); } catch (Exception ex) { } return "displayshares"; // } }
@RequestMapping(value = "/Regression", method = RequestMethod.POST) public String regression( ModelMap model, HttpServletRequest request, @Valid stocksearchhelper StockSearchHelper, BindingResult result) throws MalformedURLException, IOException { if (result.hasErrors()) { model.addAttribute("re", "Please Check the Values Entered"); model.addAttribute("StockSearchHelper", new stocksearchhelper()); model.addAttribute("CompanyName", new CompanyReports()); List<stock> x = stockServiceInterface.liststock("NASDAQ"); List<stock> y = stockServiceInterface.liststock("NASDAQCOMPOSITE"); List<stock> z = stockServiceInterface.liststock("DOWJONES"); List<stock> a = stockServiceInterface.liststock("GOLD"); List<stock> b = stockServiceInterface.liststock("SANDP"); List<stock> c = stockServiceInterface.liststock("OIL"); model.addAttribute("NASDAQ", x.get(0).getPrice()); model.addAttribute("NASDAQCOMPOSITE", y.get(0).getPrice()); model.addAttribute("DOWJONES", z.get(0).getPrice()); model.addAttribute("GOLD", a.get(0).getPrice()); model.addAttribute("SANDP", b.get(0).getPrice()); model.addAttribute("OIL", c.get(0).getPrice()); List<TopPerformers> opds1 = topPerformerServiceInterface.liststock(); model.addAttribute("first", opds1.get(0).getTickerCode()); model.addAttribute("second", opds1.get(1).getTickerCode()); model.addAttribute("third", opds1.get(2).getTickerCode()); model.addAttribute("fourth", opds1.get(3).getTickerCode()); return "ClientHome"; } else { String symbol = StockSearchHelper.getName(); statistics s = statisticServiceInterface.refreshStockInfo(symbol); // System.out.println("apple"+s.getRsquare()); double[] x = s.getX(); double[] y = new double[20]; for (int i = 0; i < y.length; i++) { y[i] = x[i] / 10; } // Data data = Data.newData(y); Line line1 = Plots.newLine(Data.newData(y), Color.newColor("CA3D05"), "Trend"); line1.setLineStyle(LineStyle.newLineStyle(3, 1, 0)); line1.addShapeMarkers(Shape.DIAMOND, Color.newColor("CA3D05"), 12); line1.addShapeMarkers(Shape.DIAMOND, Color.WHITE, 8); LineChart chart = GCharts.newLineChart(line1); chart.setSize(600, 450); chart.setTitle("Market Trend|(in 100's)", Color.WHITE, 14); AxisLabels yAxis = AxisLabelsFactory.newAxisLabels("", "1", "2", "3", "4"); AxisLabels xAxis3 = AxisLabelsFactory.newAxisLabels("Weeks", 25.0); xAxis3.setAxisStyle(AxisStyle.newAxisStyle(Color.WHITE, 14, AxisTextAlignment.CENTER)); yAxis.setAxisStyle(AxisStyle.newAxisStyle(Color.WHITE, 14, AxisTextAlignment.CENTER)); chart.setBackgroundFill(Fills.newSolidFill(Color.newColor("1F1D1D"))); LinearGradientFill fill = Fills.newLinearGradientFill(0, Color.newColor("363433"), 100); fill.addColorAndOffset(Color.newColor("2E2B2A"), 0); chart.setAreaFill(fill); chart.addXAxisLabels(yAxis); chart.addXAxisLabels(xAxis3); String url = chart.toURLString(); // Passing the chart to the JSP for rendering. model.addAttribute("url", chart.toURLString()); model.addAttribute("Statistics", s); long currentTime = (new Date()).getTime(); // long try { URL yahoofin = new URL("http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=e7e8e9r6r7&e=.csv"); URLConnection yc = yahoofin.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { String[] yahooStockInfo = inputLine.split(","); model.addAttribute("epsestimatecurrentyear", Float.valueOf(yahooStockInfo[0])); model.addAttribute("epsestimatenextyear", Float.valueOf(yahooStockInfo[1])); model.addAttribute("epsestimatenextquarter", Float.valueOf(yahooStockInfo[2])); model.addAttribute("pricesestimatecurrentyear", Float.valueOf(yahooStockInfo[3])); model.addAttribute("priceestimatenextyear", Float.valueOf(yahooStockInfo[4])); break; } in.close(); return "statisticanalysis"; } catch (Exception ex) { } return "statisticanalysis"; } }