Board logo

标题: 利用 dashDB 服务用 Ruby 创建商业智能和分析服务 [打印本页]

作者: look_w    时间: 2017-12-26 08:38     标题: 利用 dashDB 服务用 Ruby 创建商业智能和分析服务

IBM Bluemix™ 中包含的  服务(以前称为 Analytics Warehouse 服务)为商业智能和分析任务提供了一个功能强大、易于使用和灵活的平台。dashDB        服务是一个企业级托管服务,受到经过内存优化的、列式组织的 BLU Acceleration 数据仓库技术的支持。只需点击几下 Bluemix        UI,就可以为您的应用程序创建一个随时可用的商业智能和分析服务。然后,通过一系列的步骤创建一个使用了 dashDB 服务的简单的基于图表的应用程序,并在 Bluemix        上部署它。

开始之前要构建本文中的应用程序,您需要:
循序渐进地构建一个使用了  服务的基于 Ruby 的 Sinatra 应用程序,并在 Bluemix 上部署它。
第 1 步. 创建一个基本的 Sinatra 应用程序第 2. 查询 dashDB        服务现在,您已经准备好使用 ibm_db gem 从您的应用程序访问 dashDB 服务,然后对它执行查询。
第 3 步. 使用 Googlecharts        创建一个条形图接下来,我们将描述如何基于从  服务中检索的数据,通过使用         来绘制一个条形图。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
37
38
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 文件,以便提供有关应用程序的信息和一个执行查询,并显示图表的按钮。
在 DevOps Services (JazzHub) 存储库中访问这些步骤的代码。
完成这些步骤后,我们已经准备好在 Bluemix 上部署应用程序。
第 5 步. 在 Bluemix 上部署应用程序结束语在这个示例应用程序,您学习了如何轻松地在 Bluemix 上访问企业级 dashDB 服务。只需几次点击,您就可以部署一个使用了 dashDB 功能的应用程序。这种很容易快速上手的 Ruby 应用程序将会响应 Web 请求,并使用        ibm_db 和 Googlecharts 模块来呈现从数据仓库挖掘的结果。




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