ul-wukong 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +60 -0
- data/.gitmodules +6 -0
- data/.rspec +2 -0
- data/.travis.yml +19 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +17 -0
- data/Guardfile +12 -0
- data/LICENSE.md +95 -0
- data/NOTES-travis.md +31 -0
- data/README-old.md +422 -0
- data/README.md +1308 -0
- data/Rakefile +28 -0
- data/TODO.md +99 -0
- data/bin/cutc +30 -0
- data/bin/cuttab +5 -0
- data/bin/greptrue +6 -0
- data/bin/md5sort +20 -0
- data/bin/setcat +11 -0
- data/bin/tabchar +5 -0
- data/bin/uniq-ord +59 -0
- data/bin/uniqc +3 -0
- data/bin/wu +34 -0
- data/bin/wu-clean-encoding +31 -0
- data/bin/wu-date +13 -0
- data/bin/wu-datetime +13 -0
- data/bin/wu-hist +3 -0
- data/bin/wu-lign +186 -0
- data/bin/wu-local +4 -0
- data/bin/wu-plus +9 -0
- data/bin/wu-source +5 -0
- data/bin/wu-sum +31 -0
- data/diagrams/wu_local.dot +39 -0
- data/diagrams/wu_local.dot.png +0 -0
- data/examples/Gemfile +38 -0
- data/examples/README.md +9 -0
- data/examples/basic/string_reverser.rb +23 -0
- data/examples/basic/tiny_count.rb +8 -0
- data/examples/basic/word_count/accumulator.rb +26 -0
- data/examples/basic/word_count/tokenizer.rb +13 -0
- data/examples/basic/word_count/word_count.rb +6 -0
- data/examples/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/deploy_pack/Gemfile +6 -0
- data/examples/deploy_pack/README.md +6 -0
- data/examples/deploy_pack/a/b/c/.gitkeep +0 -0
- data/examples/deploy_pack/app/processors/string_reverser.rb +5 -0
- data/examples/deploy_pack/config/environment.rb +1 -0
- data/examples/dsl/dataflow/fibonacci_series.rb +101 -0
- data/examples/dsl/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/dsl/dataflow/simple.rb +12 -0
- data/examples/dsl/dataflow/telegram.rb +45 -0
- data/examples/dsl/workflow/cherry_pie.dot +97 -0
- data/examples/dsl/workflow/cherry_pie.md +104 -0
- data/examples/dsl/workflow/cherry_pie.png +0 -0
- data/examples/dsl/workflow/cherry_pie.rb +101 -0
- data/examples/empty/.gitkeep +0 -0
- data/examples/examples_helper.rb +9 -0
- data/examples/geo.rb +4 -0
- data/examples/geo/geo_grids.numbers +0 -0
- data/examples/geo/geolocated.rb +331 -0
- data/examples/geo/quadtile.rb +69 -0
- data/examples/geo/spec/geolocated_spec.rb +247 -0
- data/examples/geo/tile_fetcher.rb +77 -0
- data/examples/graph/implied_geolocation/README.md +63 -0
- data/examples/graph/minimum_spanning_tree/airfares_graphviz.rb +73 -0
- data/examples/improver/tweet_summary.rb +73 -0
- data/examples/loadable.rb +2 -0
- data/examples/munging/airline_flights/airline_flights.rake +83 -0
- data/examples/munging/airline_flights/airplane.rb +0 -0
- data/examples/munging/airline_flights/airport_id_unification.rb +129 -0
- data/examples/munging/airline_flights/airport_ok_chars.rb +4 -0
- data/examples/munging/airline_flights/indexable.rb +75 -0
- data/examples/munging/airline_flights/indexable_spec.rb +90 -0
- data/examples/munging/airline_flights/reconcile_airports.rb +142 -0
- data/examples/munging/airline_flights/tasks.rake +83 -0
- data/examples/munging/airline_flights/topcities.rb +167 -0
- data/examples/munging/geo/geo_json.rb +54 -0
- data/examples/munging/geo/geo_models.rb +69 -0
- data/examples/munging/geo/geonames_models.rb +107 -0
- data/examples/munging/geo/iso_codes.rb +172 -0
- data/examples/munging/geo/reconcile_countries.rb +124 -0
- data/examples/munging/geo/tasks.rake +71 -0
- data/examples/munging/wikipedia/articles/extract_articles-parsed.rb +79 -0
- data/examples/munging/wikipedia/articles/extract_articles-templated.rb +136 -0
- data/examples/munging/wikipedia/articles/textualize_articles.rb +54 -0
- data/examples/munging/wikipedia/articles/verify_structure.rb +43 -0
- data/examples/munging/wikipedia/articles/wp2txt-LICENSE.txt +22 -0
- data/examples/munging/wikipedia/articles/wp2txt_article.rb +259 -0
- data/examples/munging/wikipedia/articles/wp2txt_utils.rb +452 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_common.rb +5 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_extract_geocoordinates.rb +78 -0
- data/examples/munging/wikipedia/dbpedia/extract_links-cruft.rb +66 -0
- data/examples/munging/wikipedia/dbpedia/extract_links.rb +260 -0
- data/examples/munging/wikipedia/dbpedia/sameas_extractor.rb +20 -0
- data/examples/rake_helper.rb +97 -0
- data/examples/ruby_project/Gemfile +6 -0
- data/examples/ruby_project/README.md +6 -0
- data/examples/ruby_project/a/b/c/.gitkeep +0 -0
- data/examples/server_logs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/server_logs/logline.rb +95 -0
- data/examples/server_logs/models.rb +66 -0
- data/examples/server_logs/page_counts.pig +48 -0
- data/examples/server_logs/server_logs-01-parse-script.rb +13 -0
- data/examples/server_logs/server_logs-02-histograms-full.rb +33 -0
- data/examples/server_logs/server_logs-02-histograms-mapper.rb +14 -0
- data/examples/server_logs/server_logs-03-breadcrumbs-full.rb +71 -0
- data/examples/server_logs/server_logs-04-page_page_edges-full.rb +40 -0
- data/examples/serverlogs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/serverlogs/models/logline.rb +102 -0
- data/examples/serverlogs/parser/apache_parser_widget.rb +46 -0
- data/examples/serverlogs/visit_paths/common.rb +4 -0
- data/examples/serverlogs/visit_paths/page_counts.pig +48 -0
- data/examples/serverlogs/visit_paths/serverlogs-01-parse-script.rb +11 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-full.rb +31 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-mapper.rb +12 -0
- data/examples/serverlogs/visit_paths/serverlogs-03-breadcrumbs-full.rb +67 -0
- data/examples/serverlogs/visit_paths/serverlogs-04-page_page_edges-full.rb +38 -0
- data/examples/splitter.rb +94 -0
- data/examples/string_reverser.rb +7 -0
- data/examples/text/pig_latin/pig_latinizer.rb +35 -0
- data/examples/text/pig_latin/pig_latinizer_widget.rb +16 -0
- data/examples/text/regional_flavor/README.md +14 -0
- data/examples/text/regional_flavor/article_wordbags.pig +39 -0
- data/examples/text/regional_flavor/j01-article_wordbags.rb +4 -0
- data/examples/text/regional_flavor/simple_pig_script.pig +27 -0
- data/examples/twitter.rb +5 -0
- data/lib/hanuman.rb +36 -0
- data/lib/hanuman/graph.rb +97 -0
- data/lib/hanuman/graphvizzer.rb +206 -0
- data/lib/hanuman/graphvizzer/gv_models.rb +161 -0
- data/lib/hanuman/graphvizzer/gv_presenter.rb +97 -0
- data/lib/hanuman/link.rb +35 -0
- data/lib/hanuman/registry.rb +46 -0
- data/lib/hanuman/stage.rb +128 -0
- data/lib/hanuman/tree.rb +67 -0
- data/lib/wu/geo.rb +4 -0
- data/lib/wu/geo/geo_grids.numbers +0 -0
- data/lib/wu/geo/geolocated.rb +331 -0
- data/lib/wu/geo/quadtile.rb +69 -0
- data/lib/wu/graph/union_find.rb +62 -0
- data/lib/wu/model/reconcilable.rb +63 -0
- data/lib/wu/munging.rb +71 -0
- data/lib/wu/social/models/twitter.rb +31 -0
- data/lib/wu/wikipedia/models.rb +20 -0
- data/lib/wukong.rb +54 -0
- data/lib/wukong/dataflow.rb +43 -0
- data/lib/wukong/doc_helpers.rb +14 -0
- data/lib/wukong/doc_helpers/dataflow_handler.rb +29 -0
- data/lib/wukong/doc_helpers/field_handler.rb +91 -0
- data/lib/wukong/doc_helpers/processor_handler.rb +29 -0
- data/lib/wukong/driver.rb +214 -0
- data/lib/wukong/driver/event_machine_driver.rb +15 -0
- data/lib/wukong/driver/wiring.rb +68 -0
- data/lib/wukong/local.rb +42 -0
- data/lib/wukong/local/runner.rb +96 -0
- data/lib/wukong/local/stdio_driver.rb +104 -0
- data/lib/wukong/logger.rb +102 -0
- data/lib/wukong/model/faker.rb +136 -0
- data/lib/wukong/model/flatpack_parser/flat.rb +60 -0
- data/lib/wukong/model/flatpack_parser/flatpack.rb +4 -0
- data/lib/wukong/model/flatpack_parser/lang.rb +46 -0
- data/lib/wukong/model/flatpack_parser/parser.rb +55 -0
- data/lib/wukong/model/flatpack_parser/tokens.rb +130 -0
- data/lib/wukong/plugin.rb +48 -0
- data/lib/wukong/processor.rb +110 -0
- data/lib/wukong/rake_helper.rb +6 -0
- data/lib/wukong/runner.rb +169 -0
- data/lib/wukong/runner/boot_sequence.rb +123 -0
- data/lib/wukong/runner/code_loader.rb +52 -0
- data/lib/wukong/runner/command_runner.rb +44 -0
- data/lib/wukong/runner/deploy_pack_loader.rb +75 -0
- data/lib/wukong/runner/help_message.rb +42 -0
- data/lib/wukong/source.rb +33 -0
- data/lib/wukong/source/source_driver.rb +74 -0
- data/lib/wukong/source/source_runner.rb +38 -0
- data/lib/wukong/spec_helpers.rb +74 -0
- data/lib/wukong/spec_helpers/integration_tests.rb +150 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb +207 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb +97 -0
- data/lib/wukong/spec_helpers/shared_examples.rb +22 -0
- data/lib/wukong/spec_helpers/unit_tests.rb +135 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb +132 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb +169 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_runner.rb +60 -0
- data/lib/wukong/version.rb +3 -0
- data/lib/wukong/widget/echo.rb +55 -0
- data/lib/wukong/widget/extract.rb +122 -0
- data/lib/wukong/widget/filters.rb +452 -0
- data/lib/wukong/widget/logger.rb +56 -0
- data/lib/wukong/widget/operators.rb +82 -0
- data/lib/wukong/widget/reducers.rb +10 -0
- data/lib/wukong/widget/reducers/accumulator.rb +73 -0
- data/lib/wukong/widget/reducers/bin.rb +368 -0
- data/lib/wukong/widget/reducers/count.rb +73 -0
- data/lib/wukong/widget/reducers/group.rb +128 -0
- data/lib/wukong/widget/reducers/group_concat.rb +98 -0
- data/lib/wukong/widget/reducers/improver.rb +71 -0
- data/lib/wukong/widget/reducers/join_xml.rb +37 -0
- data/lib/wukong/widget/reducers/moments.rb +72 -0
- data/lib/wukong/widget/reducers/sort.rb +180 -0
- data/lib/wukong/widget/reducers/uniq.rb +91 -0
- data/lib/wukong/widget/serializers.rb +317 -0
- data/lib/wukong/widget/utils.rb +46 -0
- data/lib/wukong/widgets.rb +7 -0
- data/spec/examples/dataflow/fibonacci_series_spec.rb +18 -0
- data/spec/examples/dataflow/parse_apache_logs_spec.rb +8 -0
- data/spec/examples/dataflow/parsing_spec.rb +14 -0
- data/spec/examples/dataflow/simple_spec.rb +34 -0
- data/spec/examples/dataflow/telegram_spec.rb +43 -0
- data/spec/examples/graph/minimum_spanning_tree_spec.rb +34 -0
- data/spec/examples/munging/airline_flights/identifiers_spec.rb +16 -0
- data/spec/examples/munging/airline_flights_spec.rb +202 -0
- data/spec/examples/text/pig_latin_spec.rb +18 -0
- data/spec/examples/workflow/cherry_pie_spec.rb +36 -0
- data/spec/hanuman/graph_spec.rb +119 -0
- data/spec/hanuman/hanuman_spec.rb +10 -0
- data/spec/hanuman/registry_spec.rb +123 -0
- data/spec/hanuman/stage_spec.rb +81 -0
- data/spec/hanuman/tree_spec.rb +119 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/example_test_helpers.rb +95 -0
- data/spec/support/hanuman_test_helpers.rb +92 -0
- data/spec/support/integration_helper.rb +38 -0
- data/spec/support/model_test_helpers.rb +115 -0
- data/spec/support/shared_context_for_graphs.rb +57 -0
- data/spec/support/shared_context_for_reducers.rb +37 -0
- data/spec/support/shared_examples_for_builders.rb +94 -0
- data/spec/support/shared_examples_for_shortcuts.rb +57 -0
- data/spec/wu/model/reconcilable_spec.rb +152 -0
- data/spec/wukong/dataflow_spec.rb +87 -0
- data/spec/wukong/driver_spec.rb +154 -0
- data/spec/wukong/local/runner_spec.rb +29 -0
- data/spec/wukong/local/stdio_driver_spec.rb +73 -0
- data/spec/wukong/local_spec.rb +6 -0
- data/spec/wukong/logger_spec.rb +49 -0
- data/spec/wukong/model/faker_spec.rb +132 -0
- data/spec/wukong/processor_spec.rb +21 -0
- data/spec/wukong/runner_spec.rb +132 -0
- data/spec/wukong/source_spec.rb +6 -0
- data/spec/wukong/widget/extract_spec.rb +101 -0
- data/spec/wukong/widget/filters_spec.rb +79 -0
- data/spec/wukong/widget/logger_spec.rb +23 -0
- data/spec/wukong/widget/operators_spec.rb +25 -0
- data/spec/wukong/widget/reducers/bin_spec.rb +92 -0
- data/spec/wukong/widget/reducers/count_spec.rb +11 -0
- data/spec/wukong/widget/reducers/group_spec.rb +21 -0
- data/spec/wukong/widget/reducers/join_xml_spec.rb +25 -0
- data/spec/wukong/widget/reducers/moments_spec.rb +36 -0
- data/spec/wukong/widget/reducers/sort_spec.rb +26 -0
- data/spec/wukong/widget/reducers/uniq_spec.rb +14 -0
- data/spec/wukong/widget/serializers_spec.rb +114 -0
- data/spec/wukong/widget/sink_spec.rb +19 -0
- data/spec/wukong/widget/source_spec.rb +65 -0
- data/spec/wukong/wu-local_spec.rb +109 -0
- data/spec/wukong/wu-source_spec.rb +32 -0
- data/spec/wukong/wu_spec.rb +14 -0
- data/spec/wukong/wukong_spec.rb +10 -0
- data/wukong.gemspec +35 -0
- metadata +465 -0
File without changes
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'wukong'
|
3
|
+
require 'gorillib/type/ip_address'
|
4
|
+
require 'gorillib/pathname'
|
5
|
+
require 'gorillib/model/serialization'
|
6
|
+
require 'gorillib/model/positional_fields'
|
7
|
+
|
8
|
+
Pathname.register_paths(
|
9
|
+
maxmind: '../../../data/server_logs/maxmind',
|
10
|
+
geolite_ip_blocks: [:maxmind, 'GeoLiteCity_20121002/GeoLiteCity-Blocks.csv'],
|
11
|
+
geolite_locations: [:maxmind, 'GeoLiteCity_20121002/GeoLiteCity-Location.csv'],
|
12
|
+
)
|
13
|
+
|
14
|
+
class IpGeo
|
15
|
+
include Gorillib::Model
|
16
|
+
include Gorillib::Model::PositionalFields
|
17
|
+
#
|
18
|
+
field :location_id, Integer
|
19
|
+
field :longitude, Float # note: longitude, latitude
|
20
|
+
field :latitude, Float
|
21
|
+
#
|
22
|
+
field :country_id, String, blankish: ["", nil, '""']
|
23
|
+
field :admin1_id, String, blankish: ["", nil, '""']
|
24
|
+
field :city, String, blankish: ["", nil, '""']
|
25
|
+
#
|
26
|
+
field :postal_code, String, blankish: ["", nil, '""']
|
27
|
+
field :metro_code, String, blankish: ["", nil, '""']
|
28
|
+
field :area_code, String, blankish: ["", nil, '""']
|
29
|
+
end
|
30
|
+
|
31
|
+
lines = 0
|
32
|
+
LOCATIONS = {}
|
33
|
+
locations_file = Pathname.of(:geolite_locations).open(encoding: "ISO-8859-1")
|
34
|
+
locations_file.readline; locations_file.readline
|
35
|
+
locations_file.
|
36
|
+
# readlines[0..1000].
|
37
|
+
each do |line|
|
38
|
+
location_id, country_id, admin1_id, city, postal_code, latitude, longitude, metro_code, area_code = line.chomp.gsub(/"/, '').split(',', 9)
|
39
|
+
LOCATIONS[location_id.to_i] = [ location_id.to_i, longitude.to_f, latitude.to_f, country_id, admin1_id, city, postal_code, metro_code, area_code ]
|
40
|
+
end
|
41
|
+
|
42
|
+
module IpCensus
|
43
|
+
class IpBlocksMapper < Wukong::Streamer::RecordStreamer
|
44
|
+
|
45
|
+
def initialize(*)
|
46
|
+
super
|
47
|
+
@last = IpNumeric.from_dotted('0.116.0.0')
|
48
|
+
end
|
49
|
+
|
50
|
+
def recordize line
|
51
|
+
beg_ip, end_ip, location_id = line.gsub(/\"/, '').split(",", 3)
|
52
|
+
[IpNumeric.new(Integer(beg_ip)), IpNumeric.new(Integer(end_ip)), Integer(location_id)]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Use the regex to break line into fields
|
56
|
+
# Emit each record as flat line
|
57
|
+
def process(beg_ip, end_ip, location_id, &block)
|
58
|
+
emit_range(IpRange.new(@last, beg_ip), 0, &block) if @last != beg_ip.to_int
|
59
|
+
emit_range IpRange.new(beg_ip, end_ip), location_id, &block
|
60
|
+
@last = end_ip.to_i + 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def emit_range(rng, location_id)
|
64
|
+
location = LOCATIONS[location_id]
|
65
|
+
warn "No location #{location_id.inspect}" unless location || (location_id == 0)
|
66
|
+
rng.bitness_blocks(16).each do |blk_min, blk_max|
|
67
|
+
# raise [blk_min, blk_max, blk_min.to_hex[0..-5], blk_max.to_hex[0..-5]].inspect if blk_min.to_hex[0..-3] != blk_max.to_hex[0..-3]
|
68
|
+
yield [
|
69
|
+
blk_min.to_hex[0..3],
|
70
|
+
blk_min.to_hex[4..-1],
|
71
|
+
blk_max.to_hex[4..-1],
|
72
|
+
blk_min.to_i,
|
73
|
+
blk_max.to_i,
|
74
|
+
location,
|
75
|
+
].flatten
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Wukong::Script.new(IpCensus::IpBlocksMapper, nil).run
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# # Parse logs to TSV
|
2
|
+
#
|
3
|
+
# bzcat data/star_wars_kid.log.bz2 | head -n 100200 | tail -n 100 > data/swk-100.log
|
4
|
+
# cat data/swk-100.tsv
|
5
|
+
# cat data/swk-100.log | ./apache_log_parser.rb --map | wu-lign | cutc 150
|
6
|
+
# cat data/swk-100.log | ./apache_log_parser.rb --map > data/swk-100.tsv
|
7
|
+
# ./histograms.rb --run data/star_wars_kid.log data/star_wars_kid.tsv
|
8
|
+
|
9
|
+
# # Histograms
|
10
|
+
#
|
11
|
+
# cat data/swk-100.tsv | ./histograms.rb --map | wu-lign
|
12
|
+
# cat data/swk-hist-map.tsv | ./histograms.rb --reduce
|
13
|
+
# ./histograms.rb --run data/star_wars_kid.tsv data/star_wars_kid-pages_by_hour.tsv
|
14
|
+
|
15
|
+
# # Sessionize
|
16
|
+
#
|
17
|
+
# cat data/swk-100.tsv | ./histograms.rb --map | wu-lign
|
18
|
+
# cat data/swk-hist-map.tsv | ./histograms.rb --reduce
|
19
|
+
# ./histograms.rb --run data/star_wars_kid.tsv data/star_wars_kid-pages_by_hour.tsv
|
20
|
+
|
21
|
+
class Logline
|
22
|
+
include Gorillib::Model
|
23
|
+
include Gorillib::Model::PositionalFields
|
24
|
+
|
25
|
+
field :ip, String
|
26
|
+
field :junk1, String
|
27
|
+
field :junk2, String
|
28
|
+
#
|
29
|
+
field :visit_time, Time
|
30
|
+
field :http_method, String
|
31
|
+
field :path, String
|
32
|
+
field :protocol, String
|
33
|
+
field :response_code, Integer
|
34
|
+
field :size, Integer, blankish: ['', nil, '-']
|
35
|
+
field :referer, String
|
36
|
+
field :ua, String
|
37
|
+
field :cruft, String
|
38
|
+
|
39
|
+
#
|
40
|
+
# Regular expression to parse an apache log line.
|
41
|
+
#
|
42
|
+
# 83.240.154.3 - - [07/Jun/2008:20:37:11 +0000] "GET /faq HTTP/1.1" 200 569 "http://infochimps.org/search?query=CAC" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16"
|
43
|
+
#
|
44
|
+
LOG_RE = Regexp.compile(%r{\A
|
45
|
+
(\S+) # ip 83.240.154.3
|
46
|
+
\s(\S+) # j1 -
|
47
|
+
\s(\S+) # j2 -
|
48
|
+
\s\[(\d+/\w+/\d+ # date part [07/Jun/2008
|
49
|
+
:\d+:\d+:\d+ # time part :20:37:11
|
50
|
+
\s[\+\-]\S*)\] # timezone +0000]
|
51
|
+
\s\"(?:(\S+) # http_method "GET
|
52
|
+
\s(\S+) # path /faq
|
53
|
+
\s(\S+)|-)\" # protocol HTTP/1.1"
|
54
|
+
\s(\d+) # response_code 200
|
55
|
+
\s(\d+|-) # size 569
|
56
|
+
\s\"([^\"]*)\" # referer "http://infochimps.org/search?query=CAC"
|
57
|
+
\s\"([^\"]*)\" # ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16"
|
58
|
+
\z}x)
|
59
|
+
MONTHS = { 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12, }
|
60
|
+
|
61
|
+
def receive_visit_time(val)
|
62
|
+
if %r{(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+)\s([\+\-]\d\d)(\d\d)} === val
|
63
|
+
day, mo, yr, hour, min, sec, tz1, tz2 = [$1, $2, $3, $4, $5, $6, $7, $8]
|
64
|
+
val = Time.new(yr.to_i, MONTHS[mo], day.to_i,
|
65
|
+
hour.to_i, min.to_i, sec.to_i, "#{tz1}:#{tz2}")
|
66
|
+
end
|
67
|
+
super(val)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Use the regex to break line into fields
|
71
|
+
# Emit each record as flat line
|
72
|
+
def self.parse(line)
|
73
|
+
m = LOG_RE.match(line.chomp) or return BadRecord.new('no match', line)
|
74
|
+
new(* m.captures)
|
75
|
+
end
|
76
|
+
|
77
|
+
FILE_EXT_RE = %r{\.[^/]+\z}
|
78
|
+
def page_type
|
79
|
+
file_ext = path[FILE_EXT_RE]
|
80
|
+
case file_ext
|
81
|
+
when nil then 'page'
|
82
|
+
when '.wmv' then 'video'
|
83
|
+
when '.html','.shtml' then 'page'
|
84
|
+
when '.css', '.js' then 'asset'
|
85
|
+
when '.png', '.gif', '.ico' then 'image'
|
86
|
+
when '.wmv' then 'image'
|
87
|
+
when '.pl','.asp','.jsp','.cgi' then 'page'
|
88
|
+
else 'other'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def day_hr
|
93
|
+
[visit_time.year, visit_time.month, visit_time.day, visit_time.hour].join
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Logline
|
2
|
+
include Gorillib::Model
|
3
|
+
include Gorillib::Model::PositionalFields
|
4
|
+
|
5
|
+
field :ip, String
|
6
|
+
field :junk1, String
|
7
|
+
field :junk2, String
|
8
|
+
#
|
9
|
+
field :visit_time, Time
|
10
|
+
field :http_method, String
|
11
|
+
field :path, String
|
12
|
+
field :protocol, String
|
13
|
+
field :response_code, Integer
|
14
|
+
field :size, Integer, blankish: ['', nil, '-']
|
15
|
+
field :referer, String
|
16
|
+
field :ua, String
|
17
|
+
field :cruft, String
|
18
|
+
end
|
19
|
+
class Logline
|
20
|
+
def day_hr
|
21
|
+
[visit_time.year, visit_time.month, visit_time.day, visit_time.hour].join
|
22
|
+
end
|
23
|
+
end
|
24
|
+
class Logline
|
25
|
+
|
26
|
+
MONTHS = { 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12, }
|
27
|
+
|
28
|
+
def receive_visit_time(val)
|
29
|
+
if %r{(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+)\s([\+\-]\d\d)(\d\d)} === val
|
30
|
+
day, mo, yr, hour, min, sec, tz1, tz2 = [$1, $2, $3, $4, $5, $6, $7, $8]
|
31
|
+
val = Time.new(yr.to_i, MONTHS[mo], day.to_i,
|
32
|
+
hour.to_i, min.to_i, sec.to_i, "#{tz1}:#{tz2}")
|
33
|
+
end
|
34
|
+
super(val)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
class Logline
|
38
|
+
# Use the regex to break line into fields
|
39
|
+
# Emit each record as flat line
|
40
|
+
def self.parse(line)
|
41
|
+
m = LOG_RE.match(line.chomp) or return BadRecord.new('no match', line)
|
42
|
+
new(* m.captures)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
class Logline
|
46
|
+
#
|
47
|
+
# Regular expression to parse an apache log line.
|
48
|
+
#
|
49
|
+
# 83.240.154.3 - - [07/Jun/2008:20:37:11 +0000] "GET /faq HTTP/1.1" 200 569 "http://infochimps.org/search?query=CAC" "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16"
|
50
|
+
#
|
51
|
+
LOG_RE = Regexp.compile(%r{\A
|
52
|
+
(\S+) # ip 83.240.154.3
|
53
|
+
\s(\S+) # j1 -
|
54
|
+
\s(\S+) # j2 -
|
55
|
+
\s\[(\d+/\w+/\d+ # date part [07/Jun/2008
|
56
|
+
:\d+:\d+:\d+ # time part :20:37:11
|
57
|
+
\s[\+\-]\S*)\] # timezone +0000]
|
58
|
+
\s\"(?:(\S+) # http_method "GET
|
59
|
+
\s(\S+) # path /faq
|
60
|
+
\s(HTTP/[\d\.]+)|-)\" # protocol HTTP/1.1"
|
61
|
+
\s(\d+) # response_code 200
|
62
|
+
\s(\d+|-) # size 569
|
63
|
+
\s\"([^\"]*)\" # referer "http://infochimps.org/search?query=CAC"
|
64
|
+
\s\"([^\"]*)\" # ua "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16"
|
65
|
+
\z}x)
|
66
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
LOAD common_pages FROM 'data/common_pages' AS (ip:chararray, from_path:chararray, into_path:chararray);
|
4
|
+
|
5
|
+
--
|
6
|
+
-- Build adjacency list <A pr B,C,D> from edges (<A B>, <A C>, <A D>)
|
7
|
+
--
|
8
|
+
|
9
|
+
adj_list_j = GROUP common_pages BY from_path;
|
10
|
+
adj_list = FOREACH adj_list_j GENERATE
|
11
|
+
group AS from_path,
|
12
|
+
1.0F AS pagerank:float,
|
13
|
+
common_pages.(dest) AS into_paths
|
14
|
+
;
|
15
|
+
STORE adj_list INTO 'data/pagerank/pr_iter_00';
|
16
|
+
|
17
|
+
|
18
|
+
--
|
19
|
+
-- Iterate pagerank <A pr_00 B,C,D> to become <A pr_01 B,C,D>
|
20
|
+
--
|
21
|
+
|
22
|
+
-- find partial share: A.rank / A.into_paths.length
|
23
|
+
-- dispatch <into_path partial_share> to each page
|
24
|
+
sent_shares = FOREACH adj_list GENERATE
|
25
|
+
FLATTEN(into_paths) AS path,
|
26
|
+
(float)(pagerank / (float)SIZE(into_paths)) AS share:float;
|
27
|
+
|
28
|
+
-- dispatch <from_path into_paths> to yourself, so you have the links still around
|
29
|
+
sent_edges = FOREACH adj_list GENERATE
|
30
|
+
from_path AS path, into_paths;
|
31
|
+
|
32
|
+
-- assemble all the received shared, and the self-sent edge list;
|
33
|
+
rcvd_shares = COGROUP sent_edges BY path INNER, sent_shares BY path PARALLEL $PARALLEL;
|
34
|
+
|
35
|
+
-- calculate the new rank, and emit a record that looked just like the input.
|
36
|
+
next_iter = FOREACH rcvd_shares {
|
37
|
+
raw_rank = (float)SUM(sent_shares.share);
|
38
|
+
-- treat the case that a node has no in links
|
39
|
+
damped_rank = ((raw_rank IS NOT NULL AND raw_rank > 1.0e-12f) ? raw_rank*0.85f + 0.15f : 0.0f);
|
40
|
+
GENERATE
|
41
|
+
group AS from_path,
|
42
|
+
damped_rank AS rank,
|
43
|
+
FLATTEN(sent_edges.into_paths)
|
44
|
+
; };
|
45
|
+
|
46
|
+
STORE next_iter INTO 'data/pagerank/pr_iter_01';
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
|
3
|
+
require 'wukong/script'
|
4
|
+
require_relative './logline'
|
5
|
+
|
6
|
+
class ApacheLogParser < Wukong::Streamer::LineStreamer
|
7
|
+
# create a Logline object from each record and serialize it flat to disk
|
8
|
+
def process line
|
9
|
+
yield Logline.parse(line)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Wukong.run( ApacheLogParser )
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
|
3
|
+
require 'wukong/script'
|
4
|
+
require_relative './logline'
|
5
|
+
|
6
|
+
# cat data/swk-100.tsv | ./histograms.rb --map | sort > data/swk-hist-map.tsv
|
7
|
+
# cat data/swk-hist-map.tsv | ./histograms.rb --reduce > data/swk-hist.tsv
|
8
|
+
|
9
|
+
class HistogramsMapper < Wukong::Streamer::ModelStreamer
|
10
|
+
self.model_klass = Logline
|
11
|
+
def process visit
|
12
|
+
yield [visit.path, visit.day_hr]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class HistogramsReducer < Wukong::Streamer::Reducer
|
17
|
+
def get_key path, day_hr
|
18
|
+
[path, day_hr]
|
19
|
+
end
|
20
|
+
def start!(*args)
|
21
|
+
@count = 0
|
22
|
+
super
|
23
|
+
end
|
24
|
+
def accumulate path, day_hr
|
25
|
+
@count += 1
|
26
|
+
end
|
27
|
+
def finalize
|
28
|
+
yield [key, @count]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Wukong.run( HistogramsMapper )
|
33
|
+
Wukong.run( HistogramsMapper, HistogramsReducer, :sort_fields => 3 )
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
|
3
|
+
require 'wukong/script'
|
4
|
+
require_relative './logline'
|
5
|
+
|
6
|
+
class HistogramsMapper < Wukong::Streamer::ModelStreamer
|
7
|
+
self.model_klass = Logline
|
8
|
+
def process visit
|
9
|
+
yield [visit.path, visit.day_hr]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Wukong.run( HistogramsMapper )
|
14
|
+
Wukong.run( HistogramsMapper )
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', File.dirname(__FILE__))
|
3
|
+
require 'configliere'
|
4
|
+
Settings.define :page_types, type: Array, default: ['page', 'video'], description: "Acceptable page types"
|
5
|
+
require 'wukong/script'
|
6
|
+
require_relative './logline'
|
7
|
+
|
8
|
+
|
9
|
+
#
|
10
|
+
# Group all visitors, and then troll through all the pages they've visited
|
11
|
+
# breaking each into distinct visits (where more than an [hour|day|whatever]
|
12
|
+
# separate subsequent pageviews
|
13
|
+
#
|
14
|
+
|
15
|
+
#
|
16
|
+
# Mapper parses log files and created a visitor_id from the visitor's user_id,
|
17
|
+
# cookie or ip. It emits
|
18
|
+
#
|
19
|
+
# <visitor_id> <datetime> <url_path>
|
20
|
+
#
|
21
|
+
# where the partition key is visitor_id, and we sort by visitor_id and datetime.
|
22
|
+
#
|
23
|
+
class BreadcrumbsMapper < Wukong::Streamer::ModelStreamer
|
24
|
+
self.model_klass = Logline
|
25
|
+
def process visit, *args
|
26
|
+
# return unless Settings.page_types.include?(visit.page_type)
|
27
|
+
yield [visit.ip, visit.day_hr, visit.visit_time.to_i, visit.path]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Reducer:
|
33
|
+
#
|
34
|
+
# The reducer is given all page requests for the given visitor id, sorted by
|
35
|
+
# timestamp.
|
36
|
+
#
|
37
|
+
# It group by visits (pageviews separated by more than DISTINCT_VISIT_TIMEGAP)
|
38
|
+
# and emits
|
39
|
+
#
|
40
|
+
# trail <visitor_id> <n_pages_in_visit> <duration> <timestamp> < page1,page2,... >
|
41
|
+
#
|
42
|
+
# where the last is a comma-separated string of URL encoded paths (any internal comma is converted to %2C).
|
43
|
+
#
|
44
|
+
# You can instead emit
|
45
|
+
#
|
46
|
+
# page_trails <page1> <n_pages_in_visit> <duration> <timestamp> < page1,page2,... >
|
47
|
+
# page_trails <page2> <n_pages_in_visit> <duration> <timestamp> < page1,page2,... >
|
48
|
+
# ....
|
49
|
+
# page_trails <pagen> <n_pages_in_visit> <duration> <timestamp> < page1,page2,... >
|
50
|
+
#
|
51
|
+
# to discover all trails passing through a given page.
|
52
|
+
class BreadcrumbsReducer < Wukong::Streamer::Reducer
|
53
|
+
def get_key ip, day_hr, itime, path, *args
|
54
|
+
[ip]
|
55
|
+
end
|
56
|
+
def start!(*args)
|
57
|
+
@path_times = []
|
58
|
+
super
|
59
|
+
end
|
60
|
+
def accumulate ip, day_hr, itime, path, *args
|
61
|
+
# @path_times << "(#{itime},#{path})"
|
62
|
+
@path_times << "#{itime}:#{path}"
|
63
|
+
end
|
64
|
+
def finalize
|
65
|
+
# yield [key, "{" << @path_times.join(",") << "}"]
|
66
|
+
yield [key, @path_times.join("|")]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
Wukong.run( BreadcrumbsMapper, BreadcrumbsReducer, :sort_fields => 2 )
|