omf_web 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/README.md +8 -2
- data/doc/screenshot.png +0 -0
- data/example/{basic → NOT_WORKING/basic}/hello-world-wired.rb +0 -0
- data/example/{basic → NOT_WORKING/basic}/visualisation.yml +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklynDemo.sq3 +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklyn_gps.dat +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklyn_server.rb +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/brooklyn_wimax.dat +0 -0
- data/example/{brooklyn → NOT_WORKING/brooklyn}/sql_source.rb +0 -0
- data/example/{code → NOT_WORKING/code}/code_server.rb +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/data_sources/parse_log.rb +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/data_sources/pxe_slice-2012-06-02t02.25.00-04.00.log +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/progress_chart.yaml +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/progress_tab.yaml +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/progress_table.yaml +0 -0
- data/example/{frisbee → NOT_WORKING/frisbee}/viz_server.rb +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/gec12-53.rb +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/gec12_demo.sq3 +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/gec12_demo_server.rb +0 -0
- data/example/{gec12 → NOT_WORKING/gec12}/visualization.rb +0 -0
- data/example/{incoming → NOT_WORKING/incoming}/ofpu_barchart_widget.yaml +0 -0
- data/example/{log → NOT_WORKING/log}/log_config.xml +0 -0
- data/example/{log → NOT_WORKING/log}/log_server.rb +0 -0
- data/example/{network → NOT_WORKING/network}/flow_tab.yaml +0 -0
- data/example/{network → NOT_WORKING/network}/network_server.rb +0 -0
- data/example/{text → NOT_WORKING/text}/test.md +0 -0
- data/example/{text → NOT_WORKING/text}/test.rb +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/downlink.yaml +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/power.yaml +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/snapshot.db +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/snapshot.sql +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/test.rb +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/uplink.yaml +0 -0
- data/example/{wimax → NOT_WORKING/wimax}/viz_server.rb +0 -0
- data/example/demo/data_sources/mobile_network.rb +3 -0
- data/example/demo/data_sources/static_network.rb +54 -0
- data/example/demo/widgets/charts_tab.yaml +21 -16
- data/example/demo/widgets/linked_graphs_tab.yaml +95 -0
- data/example/demo/widgets/mobile_network_widget.yaml +1 -1
- data/example/demo/widgets/pie_chart_widget.yaml +1 -1
- data/lib/omf-web/config.ru +2 -2
- data/lib/omf-web/data_source_proxy.rb +81 -19
- data/lib/omf-web/rack/websocket_handler.rb +77 -23
- data/lib/omf-web/theme/abstract_page.rb +43 -26
- data/lib/omf-web/theme/bright/code_renderer.rb +1 -1
- data/lib/omf-web/theme/bright/page.rb +1 -0
- data/lib/omf-web/theme/bright/tabbed_renderer.rb +7 -0
- data/lib/omf-web/version.rb +7 -0
- data/lib/omf-web/widget/data_widget.rb +38 -46
- data/lib/omf-web/widget/layout/stacked_layout.rb +2 -1
- data/lib/omf-web/widget/layout/tabbed_layout.rb +1 -2
- data/{MARUKU-LICENSE → lib/omf-web/widget/text/maruku/MARUKU-LICENSE} +0 -0
- data/lib/{maruku → omf-web/widget/text/maruku}/helpers.rb +0 -0
- data/lib/{maruku → omf-web/widget/text/maruku}/input/parse_block.rb +0 -0
- data/lib/{maruku → omf-web/widget/text/maruku}/output/to_html.rb +26 -21
- data/lib/omf-web/widget/text/maruku.rb +5 -0
- data/omf_web.gemspec +2 -1
- data/share/htdocs/{js → UNUSED}/log/table.js +0 -0
- data/share/htdocs/{css → graph/css}/graph.css +0 -0
- data/share/htdocs/{image/graph → graph/img}/bar_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/donut_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/funnel.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/info.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/line_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/line_chart_fill.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/misc.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/overview.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/pie_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/scatter_plot.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/stacked_bar_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/stacked_line_chart.png +0 -0
- data/share/htdocs/{image/graph → graph/img}/table.png +0 -0
- data/share/htdocs/{js/graph → graph/js}/abstract_chart.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/abstract_nv_chart.js +8 -13
- data/share/htdocs/{js/graph → graph/js}/abstract_widget.js +9 -16
- data/share/htdocs/{js/graph → graph/js}/axis.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/barchart.js +2 -2
- data/share/htdocs/{js/graph → graph/js}/code_mirror.js +1 -5
- data/share/htdocs/{js/graph → graph/js}/discrete_bar_chart.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/histogram2.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/holt_winters_chart.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/line_chart3.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/line_chart_with_focus.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/map2.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/multi_barchart.js +1 -1
- data/share/htdocs/graph/js/network2.js +412 -0
- data/share/htdocs/{js/graph → graph/js}/pie_chart2.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/scatter_plot.js +1 -1
- data/share/htdocs/{js/graph → graph/js}/table2.js +17 -20
- data/share/htdocs/js/data_source2.js +187 -60
- data/share/htdocs/js/require3.js +38 -57
- data/share/htdocs/theme/bright/css/bright.css +4 -4
- data/share/htdocs/vendor/jquery/jquery.js +9404 -0
- data/share/htdocs/vendor/osa/LICENSE.txt +11 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_arrow_green_left.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_arrow_yellow_right.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_awareness.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_camera-web.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_cloud.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_contract.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_database.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_desktop.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_desktop_imac.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-music.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-scanner.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-usb-wifi.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-usb.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_device-wireless-router.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_disposal.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_drive-harddisk.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_drive-optical.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_firewall.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_home.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_hub.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_iPhone.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_ics_drive.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_ics_plc.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_ics_thermometer.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_id_card.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_image-generic.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_laptop.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_lifecycle.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_lightning.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_media-flash.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_media-optical.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_media-tape.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_mobile_pda.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_padlock.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_printer.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_application.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_database.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_directory.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_distribution.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_file.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_gateway.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_identity.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_mail.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_media.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_monitor.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_proxy.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_terminal.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_server_web.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-branch.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-factory.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-head-office.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_site-neighbourhood.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_audit.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_black_hat.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_security_specialist.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_sysadmin.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_tester.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_blue_tie.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_architect.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_business_manager.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_developer.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_operations.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_project_manager.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_service_manager.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_green_warning.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_user_large_group.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_users_blue_green.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_vpn.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_warning.svg +0 -0
- data/share/htdocs/{svg/osa → vendor/osa/svg}/osa_wireless_network.svg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/.DS_Store +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/add_icon.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/alertbad_icon.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/alertgood_icon.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_disabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled_hover.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/back_enabled_hover.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/bottom-bg.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_disabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled_hover.jpg +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/forward_enabled_hover.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/icon-remove.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/indicator.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/laptop.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/logo-bottom.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/nav-tab-arrow.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/norbit_big.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/norbit_clipart.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/progress_bar.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/right-bg.gif +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_asc.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_asc_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_both.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_desc.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/sort_desc_disabled.png +0 -0
- data/share/htdocs/{image → vendor/unknown/image}/spinner.gif +0 -0
- data/share/htdocs/{svg → vendor/unknown/svg}/ap.svg +0 -0
- data/share/htdocs/{svg → vendor/unknown/svg}/router.svg +0 -0
- metadata +198 -216
- data/example/demo/widgets/dashboard_tab.yaml +0 -28
- data/example/demo/widgets/download_tab.yaml +0 -42
- data/example/demo/widgets/edit_tab.yaml +0 -20
- data/example/demo/widgets/generator_tab.yaml +0 -12
- data/lib/omf-oml/endpoint.rb +0 -175
- data/lib/omf-oml/indexed_table.rb +0 -57
- data/lib/omf-oml/network.rb +0 -413
- data/lib/omf-oml/oml_tuple.rb +0 -62
- data/lib/omf-oml/schema.rb +0 -191
- data/lib/omf-oml/sequel/sequel_server.rb +0 -412
- data/lib/omf-oml/sql_row.rb +0 -302
- data/lib/omf-oml/sql_source.rb +0 -131
- data/lib/omf-oml/table.rb +0 -131
- data/lib/omf-oml/tuple.rb +0 -97
- data/lib/omf_oml.rb +0 -4
- data/share/htdocs/css/coderay.css +0 -127
- data/share/htdocs/css/ie.css +0 -40
- data/share/htdocs/css/lightbox.css +0 -62
- data/share/htdocs/css/scaffold.css +0 -74
- data/share/htdocs/css/screen.css +0 -1313
- data/share/htdocs/css/search.css +0 -102
- data/share/htdocs/css/table.css +0 -538
- data/share/htdocs/css/table2.css +0 -191
- data/share/htdocs/css/welcome.css +0 -103
- data/share/htdocs/css/wfob.css +0 -171
- data/share/htdocs/css/wshow.css +0 -69
- data/share/htdocs/gec9_demo.html +0 -39
- data/share/htdocs/images +0 -1
- data/share/htdocs/js/graph/histogram.js +0 -229
- data/share/htdocs/js/graph/line_chart.js +0 -342
- data/share/htdocs/js/graph/line_chart2.js +0 -232
- data/share/htdocs/js/graph/line_chart_fc.js +0 -94
- data/share/htdocs/js/graph/map.js +0 -85
- data/share/htdocs/js/graph/network.js +0 -591
- data/share/htdocs/js/graph/network2.js +0 -318
- data/share/htdocs/js/graph/pie_chart.js +0 -130
- data/share/htdocs/js/graph/table.js +0 -94
- data/share/htdocs/js/require2.js +0 -1998
- data/share/htdocs/js/timelines.js +0 -101
- data/share/htdocs/stylesheet/grid.css +0 -31
data/lib/omf-oml/sql_row.rb
DELETED
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'omf-oml/tuple'
|
|
3
|
-
|
|
4
|
-
module OMF::OML
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
# Read the content of a table and feeds it out as a tuple store.
|
|
9
|
-
# After creation of the object. The actual tuple feed is started
|
|
10
|
-
# with a call to +run+.
|
|
11
|
-
#
|
|
12
|
-
class OmlSqlRow < OmlTuple
|
|
13
|
-
|
|
14
|
-
# *opts:
|
|
15
|
-
# - offset: Ignore first +offset+ rows. If negative or zero serve +offset+ rows initially
|
|
16
|
-
# - limit: Number of rows to fetch each time [1000]
|
|
17
|
-
# - check_interval: Interval in seconds when to check for new data. If 0, only run once.
|
|
18
|
-
#
|
|
19
|
-
def initialize(table_name, db_file, source, opts = {})
|
|
20
|
-
@sname = table_name
|
|
21
|
-
@db_file = db_file
|
|
22
|
-
@source = source
|
|
23
|
-
|
|
24
|
-
unless @offset = opts[:offset]
|
|
25
|
-
@offset = 0
|
|
26
|
-
end
|
|
27
|
-
@limit = opts[:limit]
|
|
28
|
-
@limit = 1000 unless @limit
|
|
29
|
-
|
|
30
|
-
@check_interval = opts[:check_interval]
|
|
31
|
-
@check_interval = 0 unless @check_interval
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@on_new_vector_proc = {}
|
|
35
|
-
|
|
36
|
-
schema = find_schema
|
|
37
|
-
super table_name, schema
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# Return a specific element of the vector identified either
|
|
42
|
-
# by it's name, or its col index
|
|
43
|
-
#
|
|
44
|
-
def [](name_or_index)
|
|
45
|
-
@vprocs[name_or_index].call(@raw)
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Return the elements of the vector as an array
|
|
49
|
-
def to_a(include_oml_internals = false)
|
|
50
|
-
include_oml_internals ? @row.dup : @row[4 .. -1]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
# Return an array including the values for the names elements
|
|
54
|
-
# given as parameters.
|
|
55
|
-
#
|
|
56
|
-
def select(*col_names)
|
|
57
|
-
r = @row
|
|
58
|
-
col_names.collect do |n|
|
|
59
|
-
p = @vprocs[n]
|
|
60
|
-
#puts "#{n}::#{p}"
|
|
61
|
-
p ? p.call(r) : nil
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def ts
|
|
66
|
-
self[:oml_ts_server]
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def seq_no
|
|
70
|
-
self[:oml_seq]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# Register a proc to be called when a new tuple arrived
|
|
74
|
-
# on this stream.
|
|
75
|
-
#
|
|
76
|
-
def on_new_tuple(key = :_, &proc)
|
|
77
|
-
if proc
|
|
78
|
-
@on_new_vector_proc[key] = proc
|
|
79
|
-
else
|
|
80
|
-
@on_new_vector_proc.delete key
|
|
81
|
-
end
|
|
82
|
-
run() unless @on_new_vector_proc.empty?
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
# Create and return an +OmlTable+ which captures this tuple stream
|
|
86
|
-
#
|
|
87
|
-
# The argument to this method are either a list of columns to
|
|
88
|
-
# to capture in the table, or an array of column names and
|
|
89
|
-
# an option hash or just
|
|
90
|
-
# the option hash to be provided to the +OmlTable+ constructor.
|
|
91
|
-
#
|
|
92
|
-
# If a block is provided, any arriving tuple is executed by the block
|
|
93
|
-
# which is expected to return an array which is added to the table
|
|
94
|
-
# or nil in which case nothing is added. If a selector array is given the
|
|
95
|
-
# block is called with an array of values in the order of the columns
|
|
96
|
-
# listed in the selector. Otherwise, the block is called directly
|
|
97
|
-
# with the tuple.
|
|
98
|
-
#
|
|
99
|
-
# opts:
|
|
100
|
-
# :schema - use this schema instead for the table
|
|
101
|
-
# :name - name to use for table
|
|
102
|
-
# .... - remaining options to be passed to table constructur
|
|
103
|
-
#
|
|
104
|
-
def capture_in_table(*args, &block)
|
|
105
|
-
if args.length == 1
|
|
106
|
-
if args[0].kind_of?(Array)
|
|
107
|
-
select = args[0]
|
|
108
|
-
elsif args[0].kind_of?(Hash)
|
|
109
|
-
opts = args[0]
|
|
110
|
-
end
|
|
111
|
-
elsif args.length == 2 && args[1].kind_of?(Hash)
|
|
112
|
-
select = args[0]
|
|
113
|
-
opts = args[1]
|
|
114
|
-
else
|
|
115
|
-
opts = {}
|
|
116
|
-
select = args
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
if (tschema = opts.delete(:schema))
|
|
120
|
-
# unless tschema[0].kind_of? Hash
|
|
121
|
-
# tschema = tschema.collect do |cname| {:name => cname} end
|
|
122
|
-
# end
|
|
123
|
-
else
|
|
124
|
-
tschema = select.collect do |cname| {:name => cname} end
|
|
125
|
-
end
|
|
126
|
-
tname = opts.delete(:name) || stream_name
|
|
127
|
-
t = OMF::OML::OmlTable.new(tname, tschema, opts)
|
|
128
|
-
if block
|
|
129
|
-
self.on_new_tuple() do |v|
|
|
130
|
-
#puts "New vector(#{tname}): #{v.schema.inspect} ---- #{v.select(*select).size} <#{v.select(*select).join('|')}>"
|
|
131
|
-
if select
|
|
132
|
-
row = block.call(v.select(*select))
|
|
133
|
-
else
|
|
134
|
-
row = block.call(v)
|
|
135
|
-
end
|
|
136
|
-
if row
|
|
137
|
-
raise "Expected kind of Array, but got '#{row.inspect}'" unless row.kind_of?(Array)
|
|
138
|
-
t.add_row(row)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
else
|
|
142
|
-
self.on_new_tuple() do |v|
|
|
143
|
-
#puts "New vector(#{tname}): #{v.select(*select).join('|')}"
|
|
144
|
-
t.add_row(v.select(*select))
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
t
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
def to_table(name = nil, opts = {})
|
|
151
|
-
unless name
|
|
152
|
-
name = @sname
|
|
153
|
-
end
|
|
154
|
-
t = OMF::OML::OmlTable.new(name, self.schema)
|
|
155
|
-
include_oml_internals = opts[:include_oml_internals] || true
|
|
156
|
-
self.on_new_tuple() do |v|
|
|
157
|
-
r = v.to_a(include_oml_internals)
|
|
158
|
-
t.add_row(r)
|
|
159
|
-
end
|
|
160
|
-
t
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
protected
|
|
165
|
-
|
|
166
|
-
def find_schema()
|
|
167
|
-
stmt = _statement
|
|
168
|
-
cnames = stmt.columns
|
|
169
|
-
ctypes = stmt.types
|
|
170
|
-
schema = []
|
|
171
|
-
#schema << {:name => :oml_sender, :type => 'STRING'}
|
|
172
|
-
cnames.size.times do |i|
|
|
173
|
-
name = cnames[i].to_sym
|
|
174
|
-
schema << {:name => name, :type => ctypes[i]}
|
|
175
|
-
end
|
|
176
|
-
# Rename first col
|
|
177
|
-
first = schema[0]
|
|
178
|
-
raise "BUG: Should be 'name'" if first[:name] != :name
|
|
179
|
-
first[:name] = :oml_sender
|
|
180
|
-
|
|
181
|
-
OmlSchema.new(schema)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
# override
|
|
185
|
-
def process_schema(schema)
|
|
186
|
-
i = 0
|
|
187
|
-
@vprocs = {}
|
|
188
|
-
schema.each_column do |col|
|
|
189
|
-
name = col[:name]
|
|
190
|
-
j = i + 0
|
|
191
|
-
l = @vprocs[name] = lambda do |r| r[j] end
|
|
192
|
-
@vprocs[i - 4] = l if i > 4
|
|
193
|
-
i += 1
|
|
194
|
-
end
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
def run(in_thread = true)
|
|
198
|
-
return if @running
|
|
199
|
-
if in_thread
|
|
200
|
-
if @db
|
|
201
|
-
# force opening of database in new thread
|
|
202
|
-
begin
|
|
203
|
-
@db.close
|
|
204
|
-
rescue Exception
|
|
205
|
-
# ALERT: issues with finalising statments, don't know how to deal with it
|
|
206
|
-
end
|
|
207
|
-
@db = nil
|
|
208
|
-
@stmt = nil
|
|
209
|
-
end
|
|
210
|
-
Thread.new do
|
|
211
|
-
begin
|
|
212
|
-
_run
|
|
213
|
-
rescue Exception => ex
|
|
214
|
-
error "Exception in OmlSqlRow: #{ex}"
|
|
215
|
-
debug "Exception in OmlSqlRow: #{ex.backtrace.join("\n\t")}"
|
|
216
|
-
end
|
|
217
|
-
end
|
|
218
|
-
else
|
|
219
|
-
_run
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
private
|
|
224
|
-
|
|
225
|
-
def _run
|
|
226
|
-
if @check_interval <= 0
|
|
227
|
-
_run_once
|
|
228
|
-
else
|
|
229
|
-
@running = true
|
|
230
|
-
while (@running)
|
|
231
|
-
begin
|
|
232
|
-
unless _run_once
|
|
233
|
-
# All rows read, wait a bit for news to show up
|
|
234
|
-
sleep @check_interval
|
|
235
|
-
end
|
|
236
|
-
rescue Exception => ex
|
|
237
|
-
warn ex
|
|
238
|
-
debug "\t", ex.backtrace.join("\n\t")
|
|
239
|
-
end
|
|
240
|
-
end
|
|
241
|
-
end
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
# Run a query on database an serve all rows found one at a time.
|
|
245
|
-
# Return true if there might be more rows in the database
|
|
246
|
-
def _run_once
|
|
247
|
-
row_cnt = 0
|
|
248
|
-
_statement.execute(@limit, @offset).each do |r|
|
|
249
|
-
@row = r
|
|
250
|
-
@on_new_vector_proc.each_value do |proc|
|
|
251
|
-
proc.call(self)
|
|
252
|
-
end
|
|
253
|
-
row_cnt += 1
|
|
254
|
-
end
|
|
255
|
-
@offset += row_cnt
|
|
256
|
-
debug "Read #{row_cnt}/#{@offset} rows from '#{@sname}'"
|
|
257
|
-
row_cnt >= @limit # there could be more to read
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
def _statement
|
|
261
|
-
unless @stmt
|
|
262
|
-
db = @db = SQLite3::Database.new(@db_file)
|
|
263
|
-
@db.type_translation = true
|
|
264
|
-
table_name = t = @sname
|
|
265
|
-
if @offset < 0
|
|
266
|
-
cnt = db.execute("select count(*) from #{table_name};")[0][0].to_i
|
|
267
|
-
#debug "CNT: #{cnt}.#{cnt.class} offset: #{@offset}"
|
|
268
|
-
@offset = cnt + @offset # @offset was negative here
|
|
269
|
-
debug("Initial offset #{@offset} in '#{table_name}' with #{cnt} rows")
|
|
270
|
-
@offset = 0 if @offset < 0
|
|
271
|
-
end
|
|
272
|
-
#@stmt = db.prepare("SELECT * FROM #{table_name} LIMIT ? OFFSET ?;")
|
|
273
|
-
@stmt = db.prepare("SELECT _senders.name, #{t}.* FROM #{t} JOIN _senders WHERE #{t}.oml_sender_id = _senders.id LIMIT ? OFFSET ?;")
|
|
274
|
-
end
|
|
275
|
-
@stmt
|
|
276
|
-
end
|
|
277
|
-
end # OmlSqlRow
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
if $0 == __FILE__
|
|
283
|
-
|
|
284
|
-
require 'omf-oml/table'
|
|
285
|
-
ep = OMF::OML::OmlSqlSource.new('brooklynDemo.sq3')
|
|
286
|
-
ep.on_new_stream() do |s|
|
|
287
|
-
puts ">>>>>>>>>>>> New stream #{s.stream_name}: #{s.names.join(', ')}"
|
|
288
|
-
case s.stream_name
|
|
289
|
-
when 'wimaxmonitor_wimaxstatus'
|
|
290
|
-
select = [:oml_ts_server, :sender_hostname, :frequency, :signal, :rssi, :cinr, :avg_tx_pw]
|
|
291
|
-
when 'GPSlogger_gps_data'
|
|
292
|
-
select = [:oml_ts_server, :oml_sender_id, :lat, :lon]
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
s.on_new_vector() do |v|
|
|
296
|
-
puts "New vector(#{s.stream_name}): #{v.select(*select).join('|')}"
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
ep.run()
|
|
300
|
-
|
|
301
|
-
end
|
|
302
|
-
|
data/lib/omf-oml/sql_source.rb
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'sqlite3'
|
|
3
|
-
|
|
4
|
-
require 'omf_common/lobject'
|
|
5
|
-
require 'omf-oml/endpoint'
|
|
6
|
-
require 'omf-oml/tuple'
|
|
7
|
-
require 'omf-oml/sql_row'
|
|
8
|
-
|
|
9
|
-
module OMF::OML
|
|
10
|
-
|
|
11
|
-
# This class fetches the content of an sqlite3 database and serves it as multiple
|
|
12
|
-
# OML streams.
|
|
13
|
-
#
|
|
14
|
-
# After creating the object, the @run@ method needs to be called to
|
|
15
|
-
# start producing the streams.
|
|
16
|
-
#
|
|
17
|
-
class OmlSqlSource < OMF::Common::LObject
|
|
18
|
-
|
|
19
|
-
# +opts+ - passed on as +opts+ to the OmlSqlRow constructor
|
|
20
|
-
#
|
|
21
|
-
def initialize(db_file, opts = {})
|
|
22
|
-
raise "Can't find database '#{db_file}'" unless File.readable?(db_file)
|
|
23
|
-
@db_file = db_file
|
|
24
|
-
@running = false
|
|
25
|
-
@on_new_stream_procs = {}
|
|
26
|
-
@tables = {}
|
|
27
|
-
@table_opts = opts
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Register a proc to be called when a new stream was
|
|
31
|
-
# discovered on this endpoint.
|
|
32
|
-
#
|
|
33
|
-
def on_new_stream(key = :_, &proc)
|
|
34
|
-
if proc
|
|
35
|
-
@on_new_stream_procs[key] = proc
|
|
36
|
-
else
|
|
37
|
-
@on_new_stream_procs.delete key
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# def report_new_stream(stream)
|
|
43
|
-
# @on_new_stream_procs.each_value do |proc|
|
|
44
|
-
# proc.call(stream)
|
|
45
|
-
# end
|
|
46
|
-
# end
|
|
47
|
-
|
|
48
|
-
# Start checking the database for tables and create a new stream
|
|
49
|
-
# by calling the internal +report_new_table+ method.
|
|
50
|
-
# If +check_every+ > 0 continue checking every +check_every+ seconds
|
|
51
|
-
# for new tables in the database, otherwise it's only checked once
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
def run(check_every = -1)
|
|
55
|
-
if check_every <= 0
|
|
56
|
-
run_once()
|
|
57
|
-
else
|
|
58
|
-
Thread.new do
|
|
59
|
-
@running = true
|
|
60
|
-
while (@running)
|
|
61
|
-
begin
|
|
62
|
-
run_once()
|
|
63
|
-
rescue Exception => ex
|
|
64
|
-
error "Exception in OmlSqlSource#run: #{ex}"
|
|
65
|
-
debug "Exception in OmlSqlSource#run: #{ex.backtrace.join("\n\t")}"
|
|
66
|
-
end
|
|
67
|
-
sleep check_every
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def run_once()
|
|
74
|
-
unless @db
|
|
75
|
-
@db = SQLite3::Database.new(@db_file)
|
|
76
|
-
@db.type_translation = true
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# first find tables
|
|
80
|
-
@db.execute( "SELECT * FROM sqlite_master WHERE type='table';") do |r|
|
|
81
|
-
table_name = r[1]
|
|
82
|
-
report_new_table(table_name, @table_opts) unless table_name.start_with?('_')
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
protected
|
|
88
|
-
|
|
89
|
-
# THis method is being called for every table detected in the database.
|
|
90
|
-
# It creates a new +OmlSqlRow+ object with +opts+ as the only argument.
|
|
91
|
-
# The tables is then streamed as a tuple stream.
|
|
92
|
-
# After the stream has been created, each block registered with
|
|
93
|
-
# +on_new_stream+ is then called with the new stream as its single
|
|
94
|
-
# argument.
|
|
95
|
-
#
|
|
96
|
-
def report_new_table(table_name, opts = {})
|
|
97
|
-
return if @tables.key?(table_name) # check if already reported before
|
|
98
|
-
debug "Found table: #{table_name}"
|
|
99
|
-
t = @tables[table_name] = OmlSqlRow.new(table_name, @db_file, self, opts)
|
|
100
|
-
@on_new_stream_procs.each_value do |proc|
|
|
101
|
-
proc.call(t)
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
if $0 == __FILE__
|
|
112
|
-
|
|
113
|
-
require 'omf-oml/table'
|
|
114
|
-
ep = OMF::OML::OmlSqlSource.new('brooklynDemo.sq3')
|
|
115
|
-
ep.on_new_stream() do |s|
|
|
116
|
-
puts ">>>>>>>>>>>> New stream #{s.stream_name}: #{s.names.join(', ')}"
|
|
117
|
-
case s.stream_name
|
|
118
|
-
when 'wimaxmonitor_wimaxstatus'
|
|
119
|
-
select = [:oml_ts_server, :sender_hostname, :frequency, :signal, :rssi, :cinr, :avg_tx_pw]
|
|
120
|
-
when 'GPSlogger_gps_data'
|
|
121
|
-
select = [:oml_ts_server, :oml_sender_id, :lat, :lon]
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
s.on_new_vector() do |v|
|
|
125
|
-
puts "New vector(#{s.stream_name}): #{v.select(*select).join('|')}"
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
ep.run()
|
|
129
|
-
|
|
130
|
-
end
|
|
131
|
-
|
data/lib/omf-oml/table.rb
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'monitor'
|
|
3
|
-
|
|
4
|
-
require 'omf_common/lobject'
|
|
5
|
-
require 'omf_oml'
|
|
6
|
-
require 'omf-oml/schema'
|
|
7
|
-
autoload :OmlIndexedTable, 'omf-oml/indexed_table'
|
|
8
|
-
|
|
9
|
-
module OMF::OML
|
|
10
|
-
|
|
11
|
-
# This class represents a database like table holding a sequence of OML measurements (rows) according
|
|
12
|
-
# a common schema.
|
|
13
|
-
#
|
|
14
|
-
class OmlTable < OMF::Common::LObject
|
|
15
|
-
include MonitorMixin
|
|
16
|
-
|
|
17
|
-
attr_reader :name
|
|
18
|
-
attr_accessor :max_size
|
|
19
|
-
attr_reader :schema
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
# tname - Name of table
|
|
23
|
-
# schema - OmlSchema or Array containing [name, type*] for every column in table
|
|
24
|
-
# TODO: define format of TYPE
|
|
25
|
-
# opts -
|
|
26
|
-
# :max_size - keep table to that size by dropping older rows
|
|
27
|
-
# :index - only keep the latest inserted row for a unique col value - messes with row order
|
|
28
|
-
#
|
|
29
|
-
def initialize(tname, schema, opts = {}, &on_before_row_added)
|
|
30
|
-
super tname
|
|
31
|
-
|
|
32
|
-
#@endpoint = endpoint
|
|
33
|
-
@name = tname
|
|
34
|
-
@schema = OmlSchema.create(schema)
|
|
35
|
-
@opts = opts
|
|
36
|
-
if (index = opts[:index])
|
|
37
|
-
@indexed_rows = {}
|
|
38
|
-
@index_col = @schema.index_for_col(index)
|
|
39
|
-
end
|
|
40
|
-
@on_before_row_added = on_before_row_added
|
|
41
|
-
@rows = []
|
|
42
|
-
@max_size = opts[:max_size]
|
|
43
|
-
@on_row_added = {}
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def rows
|
|
47
|
-
@indexed_rows ? @indexed_rows.values : @rows
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Register +callback+ to be called to process any newly
|
|
51
|
-
# offered row before it being added to internal storage.
|
|
52
|
-
# The callback's argument is the new row (TODO: in what form)
|
|
53
|
-
# and should return what is being added instead of the original
|
|
54
|
-
# row. If the +callback+ returns nil, nothing is being added.
|
|
55
|
-
#
|
|
56
|
-
def on_before_row_added(&callback)
|
|
57
|
-
@on_before_row_added = callback
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def on_row_added(key, &proc)
|
|
61
|
-
#debug "on_row_added: #{proc.inspect}"
|
|
62
|
-
if proc
|
|
63
|
-
@on_row_added[key] = proc
|
|
64
|
-
else
|
|
65
|
-
@on_row_added.delete key
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# NOTE: +on_row_added+ callbacks are done within the monitor.
|
|
70
|
-
#
|
|
71
|
-
def add_row(row, needs_casting = false)
|
|
72
|
-
synchronize do
|
|
73
|
-
_add_row(row, needs_casting)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def indexed_by(col_name)
|
|
78
|
-
OmlIndexedTable.new(col_name, self)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# Add an array of rows to this table
|
|
82
|
-
#
|
|
83
|
-
def add_rows(rows, needs_casting = false)
|
|
84
|
-
synchronize do
|
|
85
|
-
rows.each { |row| _add_row(row, needs_casting) }
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def describe()
|
|
90
|
-
rows
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def data_sources
|
|
94
|
-
self
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
private
|
|
98
|
-
|
|
99
|
-
# NOT synchronized
|
|
100
|
-
#
|
|
101
|
-
def _add_row(row, needs_casting = false)
|
|
102
|
-
if needs_casting
|
|
103
|
-
row = @schema.cast_row(row)
|
|
104
|
-
end
|
|
105
|
-
#puts row.inspect
|
|
106
|
-
if @on_before_row_added
|
|
107
|
-
row = @on_before_row_added.call(row)
|
|
108
|
-
end
|
|
109
|
-
return unless row
|
|
110
|
-
|
|
111
|
-
if @indexed_rows
|
|
112
|
-
@indexed_rows[row[@index_col]] = row
|
|
113
|
-
else
|
|
114
|
-
@rows << row
|
|
115
|
-
if @max_size && @max_size > 0 && (s = @rows.size) > @max_size
|
|
116
|
-
@rows.shift # not necessarily fool proof, but fast
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
_notify_row_added(row)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def _notify_row_added(row)
|
|
123
|
-
@on_row_added.each_value do |proc|
|
|
124
|
-
#puts "call: #{proc.inspect}"
|
|
125
|
-
proc.call(row)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
end # OMLTable
|
|
130
|
-
|
|
131
|
-
end
|
data/lib/omf-oml/tuple.rb
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
require 'omf_common/lobject'
|
|
3
|
-
require 'omf_oml'
|
|
4
|
-
require 'omf-oml/schema'
|
|
5
|
-
|
|
6
|
-
module OMF::OML
|
|
7
|
-
|
|
8
|
-
# This class represents a tuple with an associated schema.
|
|
9
|
-
# It provides various methods to access the tuple elements.
|
|
10
|
-
#
|
|
11
|
-
# NOTE: Do not store the tuple itself, but make a copy as the instance may be
|
|
12
|
-
# reused over various rows by the sender.
|
|
13
|
-
#
|
|
14
|
-
# Use +OmlTuple+ if the schema is an OML one. +OmlTuple+ has additional convenience
|
|
15
|
-
# methods.
|
|
16
|
-
#
|
|
17
|
-
class Tuple < OMF::Common::LObject
|
|
18
|
-
|
|
19
|
-
# Return a specific element of the tuple identified either
|
|
20
|
-
# by it's name, or its col index
|
|
21
|
-
#
|
|
22
|
-
def [](name_or_index)
|
|
23
|
-
@vprocs[name_or_index].call(@raw)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Return the elements of the tuple as an array
|
|
27
|
-
def to_a()
|
|
28
|
-
res = []
|
|
29
|
-
r = @raw
|
|
30
|
-
@schema.each do |col|
|
|
31
|
-
res << @vprocs[col[:name]].call(r)
|
|
32
|
-
end
|
|
33
|
-
res
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Return an array including the values for the names elements
|
|
37
|
-
# given as parameters.
|
|
38
|
-
#
|
|
39
|
-
def select(*col_names)
|
|
40
|
-
r = @raw
|
|
41
|
-
col_names.collect do |n|
|
|
42
|
-
p = @vprocs[n]
|
|
43
|
-
p ? p.call(r) : nil
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
attr_reader :schema
|
|
48
|
-
attr_reader :stream_name
|
|
49
|
-
|
|
50
|
-
def initialize(name, schema)
|
|
51
|
-
# if schema.kind_of? Array
|
|
52
|
-
# schema = OmlSchema.new(schema)
|
|
53
|
-
# end
|
|
54
|
-
@stream_name = name
|
|
55
|
-
@schema = OmlSchema.create(schema)
|
|
56
|
-
|
|
57
|
-
@raw = []
|
|
58
|
-
# puts "SCHEMA: #{schema.inspect}"
|
|
59
|
-
|
|
60
|
-
super name
|
|
61
|
-
process_schema(@schema)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
# Parse the array of strings into the proper typed vector elements
|
|
66
|
-
#
|
|
67
|
-
# NOTE: We assume that each element is only called at most once, with some
|
|
68
|
-
# never called. We therefore delay type-casting to the get function without
|
|
69
|
-
# keeping the casted values (would increase lookup time)
|
|
70
|
-
#
|
|
71
|
-
def parse_tuple(els)
|
|
72
|
-
@raw = els
|
|
73
|
-
@on_new_vector_proc.each_value do |proc|
|
|
74
|
-
proc.call(self)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
protected
|
|
79
|
-
def process_schema(schema)
|
|
80
|
-
i = 0
|
|
81
|
-
@vprocs = {}
|
|
82
|
-
schema.each_column do |col| #
|
|
83
|
-
name = col[:name] || raise("Ill-formed schema '#{schema}'")
|
|
84
|
-
type = col[:type] || raise("Ill-formed schema '#{schema}'")
|
|
85
|
-
@vprocs[name] = @vprocs[i] = case type
|
|
86
|
-
when :string
|
|
87
|
-
lambda do |r| r[i] end
|
|
88
|
-
when :double
|
|
89
|
-
lambda do |r| r[i].to_f end
|
|
90
|
-
else raise "Unrecognized Schema type '#{type}'"
|
|
91
|
-
end
|
|
92
|
-
i += 1
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
end # Tuple
|
|
97
|
-
end # OMF::OML
|
data/lib/omf_oml.rb
DELETED