Board logo

标题: 在 Bluemix 上用 Ruby 创建一个具有 BLU Acceleration 的商业智能和分析服务 [打印本页]

作者: look_w    时间: 2017-12-24 16:50     标题: 在 Bluemix 上用 Ruby 创建一个具有 BLU Acceleration 的商业智能和分析服务

简介IBM Bluemix™ 中提供的 BLU Acceleration Service      服务为商业智能和分析提供了一个强大的、易于使用的、敏捷的平台。BLU Acceleration Service      是一个企业级的托管服务,受到内存中优化的、按列组织的 BLU Acceleration 数据仓库技术的支持。只需在 Bluemix UI      上单击几下,就可以为您的应用程序创建一个随时可用的商业智能和分析服务。然后,通过一系列的步骤,我们可以创建一个使用 BLU Acceleration      服务的基于图表的简单应用程序,并在 Bluemix 上部署它。
开始之前为了构建本文中的应用程序,您需要:
在具体的过程中,您要在 Bluemix 上构建和部署一个基于 Ruby 的 Sinatra 应用程序,该应用程序使用了 BLU                    Acceleration 服务。
步骤                      1. 创建一个基本的 Sinatra 应用程序步骤    2.对 BLU Acceleration 服务发出查询现在,您可以使用 ibm_db gem 从您的应用程序访问 BLU Acceleration 服务,然后对它运行查询。
步骤 3. 使用 Googlecharts 创建一个条形图接下来,我们将介绍如何基于使用 Google Charts 从 BLU Acceleration 检索的  来绘制条形图。Google  Charts 提供了多种选项来生成多种图表类型,比如折线图、条形图或饼图。
此代码示例使用 Ruby     模块为我们从数据库中检索的数据绘制条形图,该模块是一个基于 Google Chart API 的简单包装程序。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def renderBarGraph data
  array2011 = [] #Array group that contains profits for Brands respectively for year 2011
  array2012 = []
  array2013 = []
  productNames = []
  #Render a Bar chart that shows profits of each Product Brand in comparison year-to-year
  data.each do |product,profitHash|
    productNames << product
    profitHash.each do |year, profit|
      if(year == 2011)
        array2011 << profit
      elsif (year == 2012)
        array2012 << profit
      else
        array2013 << profit
      end
      if(profit > max)
        max = profit
      end
    end
  end
#Render the Bar chart using the gchart library and return the img html tag for display
  Gchart.bar(
           :title => "rofit by Product Brand",
           :data => [array2011, array2012, array2013],
           :background => 'efefef', :chart_background => 'CCCCCC',
           :bar_colors => '0000DD,00AA00,EE00EE',
           :stacked => false,
           :size => '600x400',
           :bar_width_and_spacing => '15,0,30',
           :legend => ['2011', '2012','2013'],
           :axis_with_labels => 'x,y',
           :axis_labels => [productNames.join('|'), [0,(max/2).to_f,max.to_f].join('|')],
           #:format => 'file', :filename => 'custom_filename.png') #To save to a file
           :format => 'image_tag',:alt => "rofit by brand img") #To be rendered as an image on web page
end




步骤 4.  将代码结合在一起现在,您需要将前面小节的代码示例结合成一个可运行的应用程序。
首先,将前面小节中的代码示例放入一个名为 bluaccl.rb 的文件中,并配置应用程序的 'get' 方法来调用    getDataFromDW 和 renderBarGraph 函数。
接下来,修改 index.html.erb 文件,提供关于应用程序的信息,并提供一个用来执行查询并显示图表的按钮。
在 JazzHub 存储库中访问这些步骤的代码。
完成这些步骤后,我们已经准备好在 Bluemix 上部署该应用程序了。
步骤 5.      在 Bluemix 上部署应用程序结束语在这个示例应用程序中,您学习了如何轻松地访问 Bluemix 上的企业级 BLU Acceleration 服务。只需单击几下,就可以部署一个使用      BLU Acceleration 数据仓库特性的应用程序。 这个快捷的 Ru​​by 应用程序会响应 Web 请求,并使用 ibm_db 和      Googlecharts 模块显示从数据仓库中挖掘的数据。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0