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
@@ -0,0 +1,97 @@
|
|
1
|
+
digraph Warrant {
|
2
|
+
rankdir = TB;
|
3
|
+
subgraph "cluster_cherry_pie" {
|
4
|
+
label = "cherry_pie";
|
5
|
+
subgraph "cluster_cherry_pie.crust" {
|
6
|
+
label = "crust";
|
7
|
+
"cherry_pie.crust.add_to_0" [ shape = record,label = "{{<container>c|<flour>f|<salt>s|<shortening>s}|add\nto|{<out_crumbly_mixture>c}}" ];
|
8
|
+
"cherry_pie.crust.flour" [ shape = Mrecord,label = "{flour}" ];
|
9
|
+
"cherry_pie.crust.salt" [ shape = Mrecord,label = "{salt}" ];
|
10
|
+
"cherry_pie.crust.shortening" [ shape = Mrecord,label = "{shortening}" ];
|
11
|
+
"cherry_pie.crust.small_bowl" [ shape = Mrecord,label = "{small\nbowl}" ];
|
12
|
+
"cherry_pie.crust.crumbly_mixture"[ shape = Mrecord,label = "{crumbly\nmixture}" ];
|
13
|
+
"cherry_pie.crust.add_to_6" [ shape = record,label = "{{<container>c|<buttermilk>b}|add\nto|{<out_dough>d}}" ];
|
14
|
+
"cherry_pie.crust.buttermilk" [ shape = Mrecord,label = "{buttermilk}" ];
|
15
|
+
"cherry_pie.crust.dough" [ shape = Mrecord,label = "{dough}" ];
|
16
|
+
"cherry_pie.crust.split_9" [ shape = record,label = "{{<dough>d}|split|{<out_ball_for_top>b|<out_ball_for_bottom>b}}" ];
|
17
|
+
"cherry_pie.crust.ball_for_top" [ shape = Mrecord,label = "{ball\nfor\ntop}" ];
|
18
|
+
"cherry_pie.crust.ball_for_bottom"[ shape = Mrecord,label = "{ball\nfor\nbottom}" ];
|
19
|
+
"cherry_pie.crust.rolling_pin_12" [ shape = record,label = "{{<ball_for_bottom>b}|rolling\npin|{<out_combine_13>c}}" ];
|
20
|
+
"cherry_pie.crust.combine_13" [ shape = record,label = "{{<pie_tin>p|<rolling_pin_12>r}|combine|{<out_pie_tin_with_crust>p}}" ];
|
21
|
+
"cherry_pie.crust.pie_tin" [ shape = Mrecord,label = "{pie\ntin}" ];
|
22
|
+
"cherry_pie.crust.pie_tin_with_crust"[ shape = Mrecord,label = "{pie\ntin\nwith\ncrust}" ];
|
23
|
+
"cherry_pie.crust.flour" -> "cherry_pie.crust.add_to_0":flour;
|
24
|
+
"cherry_pie.crust.salt" -> "cherry_pie.crust.add_to_0":salt;
|
25
|
+
"cherry_pie.crust.shortening" -> "cherry_pie.crust.add_to_0":shortening;
|
26
|
+
"cherry_pie.crust.small_bowl" -> "cherry_pie.crust.add_to_0":container;
|
27
|
+
"cherry_pie.crust.add_to_0":out_crumbly_mixture -> "cherry_pie.crust.crumbly_mixture";
|
28
|
+
"cherry_pie.crust.crumbly_mixture" -> "cherry_pie.crust.add_to_6":container;
|
29
|
+
"cherry_pie.crust.buttermilk" -> "cherry_pie.crust.add_to_6":buttermilk;
|
30
|
+
"cherry_pie.crust.add_to_6":out_dough -> "cherry_pie.crust.dough";
|
31
|
+
"cherry_pie.crust.dough" -> "cherry_pie.crust.split_9":dough;
|
32
|
+
"cherry_pie.crust.split_9":out_ball_for_top -> "cherry_pie.crust.ball_for_top";
|
33
|
+
"cherry_pie.crust.split_9":out_ball_for_bottom -> "cherry_pie.crust.ball_for_bottom";
|
34
|
+
"cherry_pie.crust.ball_for_bottom" -> "cherry_pie.crust.rolling_pin_12":ball_for_bottom;
|
35
|
+
"cherry_pie.crust.pie_tin" -> "cherry_pie.crust.combine_13":pie_tin;
|
36
|
+
"cherry_pie.crust.rolling_pin_12":out_combine_13 -> "cherry_pie.crust.combine_13":rolling_pin_12;
|
37
|
+
"cherry_pie.crust.combine_13":out_pie_tin_with_crust -> "cherry_pie.crust.pie_tin_with_crust";
|
38
|
+
}
|
39
|
+
"cherry_pie.crust" [ shape = record,label = "{crust}" ];
|
40
|
+
subgraph "cluster_cherry_pie.filling" {
|
41
|
+
label = "filling";
|
42
|
+
"cherry_pie.filling.drain_0" [ shape = record,label = "{{<cherries>c}|drain|{<out_drained_cherries>d|<out_cherry_juice>c}}" ];
|
43
|
+
"cherry_pie.filling.cherries" [ shape = Mrecord,label = "{cherries}" ];
|
44
|
+
"cherry_pie.filling.drained_cherries"[ shape = Mrecord,label = "{drained\ncherries}" ];
|
45
|
+
"cherry_pie.filling.cherry_juice" [ shape = Mrecord,label = "{cherry\njuice}" ];
|
46
|
+
"cherry_pie.filling.add_to_4" [ shape = record,label = "{{<container>c|<corn_starch>c|<sugar>s|<salt>s}|add\nto|{<out_whisk_9>w}}" ];
|
47
|
+
"cherry_pie.filling.corn_starch" [ shape = Mrecord,label = "{corn\nstarch}" ];
|
48
|
+
"cherry_pie.filling.sugar" [ shape = Mrecord,label = "{sugar}" ];
|
49
|
+
"cherry_pie.filling.salt" [ shape = Mrecord,label = "{salt}" ];
|
50
|
+
"cherry_pie.filling.saucepan" [ shape = Mrecord,label = "{saucepan}" ];
|
51
|
+
"cherry_pie.filling.whisk_9" [ shape = record,label = "{{<cherry_juice>c|<add_to_4>a}|whisk|{<out_raw_goop>r}}" ];
|
52
|
+
"cherry_pie.filling.raw_goop" [ shape = Mrecord,label = "{raw\ngoop}" ];
|
53
|
+
"cherry_pie.filling.cook_11" [ shape = record,label = "{{<raw_goop>r}|cook|{<out_goop>g}}" ];
|
54
|
+
"cherry_pie.filling.goop" [ shape = Mrecord,label = "{goop}" ];
|
55
|
+
"cherry_pie.filling.add_to_13" [ shape = record,label = "{{<container>c|<drained_cherries>d|<butter>b}|add\nto|{<out_cool_15>c}}" ];
|
56
|
+
"cherry_pie.filling.butter" [ shape = Mrecord,label = "{butter}" ];
|
57
|
+
"cherry_pie.filling.cool_15" [ shape = record,label = "{{<add_to_13>a}|cool|{<out_filling>f}}" ];
|
58
|
+
"cherry_pie.filling.cherries" -> "cherry_pie.filling.drain_0":cherries;
|
59
|
+
"cherry_pie.filling.drain_0":out_drained_cherries -> "cherry_pie.filling.drained_cherries";
|
60
|
+
"cherry_pie.filling.drain_0":out_cherry_juice -> "cherry_pie.filling.cherry_juice";
|
61
|
+
"cherry_pie.filling.corn_starch" -> "cherry_pie.filling.add_to_4":corn_starch;
|
62
|
+
"cherry_pie.filling.sugar" -> "cherry_pie.filling.add_to_4":sugar;
|
63
|
+
"cherry_pie.filling.salt" -> "cherry_pie.filling.add_to_4":salt;
|
64
|
+
"cherry_pie.filling.saucepan" -> "cherry_pie.filling.add_to_4":container;
|
65
|
+
"cherry_pie.filling.cherry_juice" -> "cherry_pie.filling.whisk_9":cherry_juice;
|
66
|
+
"cherry_pie.filling.add_to_4":out_whisk_9 -> "cherry_pie.filling.whisk_9":add_to_4;
|
67
|
+
"cherry_pie.filling.whisk_9":out_raw_goop -> "cherry_pie.filling.raw_goop";
|
68
|
+
"cherry_pie.filling.raw_goop" -> "cherry_pie.filling.cook_11":raw_goop;
|
69
|
+
"cherry_pie.filling.cook_11":out_goop -> "cherry_pie.filling.goop";
|
70
|
+
"cherry_pie.filling.drained_cherries" -> "cherry_pie.filling.add_to_13":drained_cherries;
|
71
|
+
"cherry_pie.filling.butter" -> "cherry_pie.filling.add_to_13":butter;
|
72
|
+
"cherry_pie.filling.goop" -> "cherry_pie.filling.add_to_13":container;
|
73
|
+
"cherry_pie.filling.add_to_13":out_cool_15 -> "cherry_pie.filling.cool_15":add_to_13;
|
74
|
+
"cherry_pie.filling.cool_15":out_filling -> "cherry_pie.filling";
|
75
|
+
}
|
76
|
+
"cherry_pie.filling" [ shape = record,label = "{filling}" ];
|
77
|
+
"cherry_pie.rolling_pin_2" [ shape = record,label = "{{<ball_for_top>b}|rolling\npin|{<out_top_crust>t}}" ];
|
78
|
+
"cherry_pie.top_crust" [ shape = Mrecord,label = "{top\ncrust}" ];
|
79
|
+
"cherry_pie.add_to_4" [ shape = record,label = "{{<container>c|<filling>f|<top_crust>t}|add\nto|{<out_cook_5>c}}" ];
|
80
|
+
"cherry_pie.cook_5" [ shape = record,label = "{{<oven>o|<add_to_4>a}|cook|{<out_cool_7>c}}" ];
|
81
|
+
"cherry_pie.oven" [ shape = Mrecord,label = "{oven}" ];
|
82
|
+
"cherry_pie.cool_7" [ shape = record,label = "{{<wire_rack>w|<cook_5>c}|cool|{<out_cherry_pie>c}}" ];
|
83
|
+
"cherry_pie.wire_rack" [ shape = Mrecord,label = "{wire\nrack}" ];
|
84
|
+
"cherry_pie.crust.ball_for_bottom" -> "cherry_pie.crust";
|
85
|
+
"cherry_pie.crust.pie_tin_with_crust" -> "cherry_pie.add_to_4":container;
|
86
|
+
"cherry_pie.crust.ball_for_top" -> "cherry_pie.rolling_pin_2":ball_for_top;
|
87
|
+
"cherry_pie.rolling_pin_2":out_top_crust -> "cherry_pie.top_crust";
|
88
|
+
"cherry_pie.filling" -> "cherry_pie.add_to_4":filling;
|
89
|
+
"cherry_pie.top_crust" -> "cherry_pie.add_to_4":top_crust;
|
90
|
+
"cherry_pie.oven" -> "cherry_pie.cook_5":oven;
|
91
|
+
"cherry_pie.add_to_4":out_cook_5 -> "cherry_pie.cook_5":add_to_4;
|
92
|
+
"cherry_pie.wire_rack" -> "cherry_pie.cool_7":wire_rack;
|
93
|
+
"cherry_pie.cook_5":out_cool_7 -> "cherry_pie.cool_7":cook_5;
|
94
|
+
"cherry_pie.cool_7":out_cherry_pie -> "cherry_pie";
|
95
|
+
}
|
96
|
+
"cherry_pie" [ shape = record,label = "{cherry\npie}" ];
|
97
|
+
}
|
@@ -0,0 +1,104 @@
|
|
1
|
+
* http://www.tasteofhome.com/Recipes/Fresh-Cherry-Pie
|
2
|
+
* [Cherry Pie](http://www.foodgeeks.com/recipes/1014) by Zenny on foodgeeks.com
|
3
|
+
|
4
|
+
### SERVINGS
|
5
|
+
|
6
|
+
6 to 8 servings scale / convert
|
7
|
+
|
8
|
+
### INGREDIENTS
|
9
|
+
|
10
|
+
#### Buttermilk Crust
|
11
|
+
|
12
|
+
3 cups flour
|
13
|
+
2 tbsp. sugar
|
14
|
+
1-1/2 tsp. salt
|
15
|
+
1/2 cup unsalted butter, cut up
|
16
|
+
6 tbsp. cold vegetable shortening
|
17
|
+
1/2 cup buttermilk
|
18
|
+
|
19
|
+
#### Filling
|
20
|
+
|
21
|
+
4 cups tart cherries
|
22
|
+
1-1/2 cups sugar
|
23
|
+
1/3 cup cornstarch
|
24
|
+
1 dash salt
|
25
|
+
2 tbsp. butter, cut up
|
26
|
+
|
27
|
+
### INSTRUCTIONS
|
28
|
+
|
29
|
+
### Make crust:
|
30
|
+
|
31
|
+
* Combine flour, sugar and salt.
|
32
|
+
* Add butter and shortening and mix until mixture resembles coarse crumbs.
|
33
|
+
* Gradually add buttermilk.
|
34
|
+
|
35
|
+
* Divide pastry into 2 balls, one slightly larger than the other.
|
36
|
+
* Flatten into two disks.
|
37
|
+
* Wrap and refrigerate 30 minutes.
|
38
|
+
|
39
|
+
### Make filling:
|
40
|
+
|
41
|
+
* Drain cherries, reserving 1/2 cup juice.
|
42
|
+
* Whisk together sugar, cornstarch and salt in saucepan.
|
43
|
+
* Whisk in reserved cherry juice.
|
44
|
+
* Bring to boil over medium heat;
|
45
|
+
- boil, stirring, 2 to 30 minutes until slightly thickened.
|
46
|
+
* Remove from heat; stir in cherries and butter.
|
47
|
+
* Cool.
|
48
|
+
|
49
|
+
### Assemble
|
50
|
+
|
51
|
+
* On lightly floured surface, roll larger pastry disk into 12-inch circle.
|
52
|
+
- Fit into a 9-inch pie plate, leaving 3/4-inch overhang.
|
53
|
+
* Spoon filling into pastry.
|
54
|
+
* Roll remaining pastry into a 10-inch circle; place on top of filling.
|
55
|
+
* Press edges together; trim and flute.
|
56
|
+
* With a small knife,
|
57
|
+
- cut decorations from scraps and place on top of pie.
|
58
|
+
- Cut vents in top.
|
59
|
+
|
60
|
+
### Bake
|
61
|
+
|
62
|
+
* Arrange a jelly-roll pan on center rack of oven.
|
63
|
+
* Heat oven to 425°.
|
64
|
+
* Place pie on jelly-roll pan and bake 15 minutes.
|
65
|
+
* Reduce oven temperature to 375°.
|
66
|
+
* Bake 55 minutes more until filling is bubbly.
|
67
|
+
* Remove from oven, cool on a wire rack
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
__________________________________________________________________________
|
72
|
+
|
73
|
+
Below is an example of a simple Rake script to build a C HelloWorld program.
|
74
|
+
|
75
|
+
file 'hello.o' => ['hello.c'] do
|
76
|
+
sh 'cc -c -o hello.o hello.c'
|
77
|
+
end
|
78
|
+
file 'hello' => ['hello.o'] do
|
79
|
+
sh 'cc -o hello hello.o'
|
80
|
+
end
|
81
|
+
|
82
|
+
Below is an example of a simple Rake recipe
|
83
|
+
|
84
|
+
namespace :cake do
|
85
|
+
desc 'make pancakes'
|
86
|
+
task :pancake => [:flour,:milk,:egg,:baking_powder] do
|
87
|
+
puts "sizzle"
|
88
|
+
end
|
89
|
+
task :butter do
|
90
|
+
puts "cut 3 tablespoons of butter into tiny squares"
|
91
|
+
end
|
92
|
+
task :flour => :butter do
|
93
|
+
puts "use hands to knead butter squares into 1{{frac|1|2}} cup flour"
|
94
|
+
end
|
95
|
+
task :milk do
|
96
|
+
puts "add 1{{frac|1|4}} cup milk"
|
97
|
+
end
|
98
|
+
task :egg do
|
99
|
+
puts "add 1 egg"
|
100
|
+
end
|
101
|
+
task :baking_powder do
|
102
|
+
puts "add 3{{frac|1|2}} teaspoons baking powder"
|
103
|
+
end
|
104
|
+
end
|
Binary file
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class Wukong::Workflow < Hanuman::Graph
|
2
|
+
|
3
|
+
class Container < Hanuman::Product
|
4
|
+
register_stage
|
5
|
+
end
|
6
|
+
|
7
|
+
class Qty < Hanuman::Product
|
8
|
+
doc 'a quantity of an ingredient'
|
9
|
+
register_stage
|
10
|
+
field :amount, String, :position => 1
|
11
|
+
end
|
12
|
+
class Utensil < Hanuman::Product ; register_stage ; end
|
13
|
+
|
14
|
+
class Cook < ActionWithInputs
|
15
|
+
register_action
|
16
|
+
field :trigger, String, :doc => 'stop cooking when this event is reached'
|
17
|
+
end
|
18
|
+
|
19
|
+
class Cool < ActionWithInputs ; register_action ; end
|
20
|
+
|
21
|
+
class Combine < ActionWithInputs ; register_action ; end
|
22
|
+
class Split < ActionWithInputs ; register_action ; end
|
23
|
+
class RollingPin < ActionWithInputs ; register_action ; end
|
24
|
+
class Drain < ActionWithInputs ; register_action ; end
|
25
|
+
class Whisk < ActionWithInputs ; register_action ; end
|
26
|
+
|
27
|
+
class AddTo < ActionWithInputs
|
28
|
+
register_action
|
29
|
+
|
30
|
+
magic :container, Hanuman::Stage
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
Hanuman::Graph.class_eval{ alias_method :product, :product }
|
36
|
+
|
37
|
+
# TODO: make repeated calls not retrieve object again -- it seems lookup is the special case, not creation.
|
38
|
+
|
39
|
+
#
|
40
|
+
# Make Warrant happy
|
41
|
+
#
|
42
|
+
# class Warrant ; extend Wukong::Universe ; end
|
43
|
+
Wukong.workflow(:cherry_pie) do
|
44
|
+
|
45
|
+
subgraph(:crust) do
|
46
|
+
|
47
|
+
add_to(container(:small_bowl),
|
48
|
+
qty(:flour, '3 cups'),
|
49
|
+
qty(:salt, '1.5 tsp'),
|
50
|
+
qty(:shortening, '6 tbsp')
|
51
|
+
) > product(:crumbly_mixture)
|
52
|
+
|
53
|
+
# equvalently:
|
54
|
+
# add_to(:crumbly_mixture, qty(:buttermilk)) > product(:dough)
|
55
|
+
add_to(:crumbly_mixture) << qty(:buttermilk) > product(:dough)
|
56
|
+
|
57
|
+
split(:dough) do
|
58
|
+
into owner.product(:ball_for_top)
|
59
|
+
into owner.product(:ball_for_bottom)
|
60
|
+
end
|
61
|
+
|
62
|
+
# equvalently:
|
63
|
+
# combine << :pie_tin << (rolling_pin << :ball_for_bottom) > :pie_tin_w_crust
|
64
|
+
combine(container(:pie_tin),
|
65
|
+
(rolling_pin << :ball_for_bottom)
|
66
|
+
).into(product(:pie_tin_w_crust))
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
subgraph(:filling) do
|
71
|
+
|
72
|
+
qty(:cherries, '4 cups')
|
73
|
+
|
74
|
+
drain(:cherries).into(
|
75
|
+
product(:drained_cherries),
|
76
|
+
).into( # FIXME - should be a multiple-output
|
77
|
+
product(:cherry_juice)
|
78
|
+
)
|
79
|
+
qty(:butter, '2 tbsp, cut up')
|
80
|
+
add_to(container(:saucepan),
|
81
|
+
qty(:corn_starch, '1/3 cup'),
|
82
|
+
qty(:sugar, '1.5 cups'),
|
83
|
+
qty(:salt, '1 dash')) >
|
84
|
+
whisk << :cherry_juice >
|
85
|
+
product(:raw_goop)
|
86
|
+
cook(:raw_goop, :trigger => 'goop slightly thickened') > product(:goop)
|
87
|
+
add_to(:goop, :drained_cherries, :butter) > cool > product(:output)
|
88
|
+
end
|
89
|
+
|
90
|
+
rolling_pin << stage(:crust).stage(:ball_for_top) > product(:top_crust)
|
91
|
+
|
92
|
+
raw_pie = add_to(
|
93
|
+
stage(:crust).stage(:pie_tin_w_crust),
|
94
|
+
stage(:filling).product(:output))
|
95
|
+
raw_pie << :top_crust
|
96
|
+
|
97
|
+
x = utensil(:oven)
|
98
|
+
|
99
|
+
cook(utensil(:oven), raw_pie) > cool(utensil(:wire_rack))
|
100
|
+
|
101
|
+
end
|
File without changes
|
@@ -0,0 +1,9 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
|
2
|
+
require 'wukong'
|
3
|
+
|
4
|
+
Pathname.register_path(:wukong_root, File.expand_path('..', File.dirname(__FILE__)))
|
5
|
+
Pathname.register_path(:examples, :wukong_root, 'examples')
|
6
|
+
Pathname.register_path(:tmp, :wukong_root, 'tmp')
|
7
|
+
Pathname.register_path(:data, :wukong_root, 'data')
|
8
|
+
|
9
|
+
class ExampleUniverse ; extend Wukong::Universe ; end
|
data/examples/geo.rb
ADDED
Binary file
|
@@ -0,0 +1,331 @@
|
|
1
|
+
require 'gorillib/numeric/clamp'
|
2
|
+
|
3
|
+
Numeric.class_eval do
|
4
|
+
def to_radians() self.to_f * Math::PI / 180.0 ; end
|
5
|
+
def to_degrees() self.to_f * 180.0 / Math::PI ; end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Wukong
|
9
|
+
#
|
10
|
+
# reference: [Bing Maps Tile System](http://msdn.microsoft.com/en-us/library/bb259689.aspx)
|
11
|
+
#
|
12
|
+
module Geolocated
|
13
|
+
module_function # call methods as eg Wukong::Geolocated.tile_xy_to_quadkey or, if included in class, on self as private methods
|
14
|
+
|
15
|
+
# field :longitude, type: Float, description: "Longitude (X) of a point, in decimal degrees"
|
16
|
+
# field :latitude, type: Float, description: "Latitude (Y) of a point, in decimal degrees"
|
17
|
+
# field :zoom_level, type: Integer, description: "Zoom level of tile to fetch. An integer between 0 (world) and 16 or so"
|
18
|
+
# field :quadkey, type: String, description: "Quadkey of tile, eg 002313012"
|
19
|
+
# field :tile_x, type: Integer, description: "Tile X index, an integer between 0 and 2^zoom_level - 1"
|
20
|
+
# field :tile_y, type: Integer, description: "Tile Y index, an integer between 0 and 2^zoom_level - 1"
|
21
|
+
|
22
|
+
module ByCoordinates
|
23
|
+
extend Gorillib::Concern
|
24
|
+
|
25
|
+
# The quadkey is a string of 2-bit tile selectors for a quadtile
|
26
|
+
#
|
27
|
+
# @example
|
28
|
+
# infochimps_hq = Geo::Place.receive("Infochimps HQ", -97.759003, 30.273884)
|
29
|
+
# infochimps_hq.quadkey(8) # => "02313012"
|
30
|
+
#
|
31
|
+
# Interesting quadkey properties:
|
32
|
+
#
|
33
|
+
# * The quadkey length is its zoom level
|
34
|
+
#
|
35
|
+
# * To zoom out (lower zoom level, larger quadtile), just truncate the
|
36
|
+
# quadkey: austin at ZL=8 has quadkey "02313012"; at ZL=3, "023"
|
37
|
+
#
|
38
|
+
# * Nearby points typically have "nearby" quadkeys: up to the smallest
|
39
|
+
# tile that contains both, their quadkeys will have a common prefix.
|
40
|
+
# If you sort your records by quadkey,
|
41
|
+
# - Nearby points are nearby-ish on disk. (hello, HBase/Cassandra
|
42
|
+
# database owners!) This allows efficient lookup and caching of
|
43
|
+
# "popular" regions or repeated queries in an area.
|
44
|
+
# - the tiles covering a region can be covered by a limited, enumerable
|
45
|
+
# set of range scans. For map-reduce programmers, this leads to very
|
46
|
+
# efficient reducers
|
47
|
+
#
|
48
|
+
# * The quadkey is the bit-interleaved combination of its tile ids:
|
49
|
+
#
|
50
|
+
# tile_x 58 binary 0 0 1 1 1 0 1 0
|
51
|
+
# tile_y 105 binary 0 1 1 0 1 0 0 1
|
52
|
+
# interleaved binary 00 10 11 01 11 00 01 10
|
53
|
+
# quadkey 0 2 3 1 3 0 1 2 # "02313012"
|
54
|
+
#
|
55
|
+
def quadkey(zl) ; Wukong::Geolocated.tile_xy_zl_to_quadkey( tile_x(zl), tile_y(zl), zl) ; end
|
56
|
+
|
57
|
+
# the packed quadkey is the integer formed by interleaving the bits of tile_x with tile_y:
|
58
|
+
#
|
59
|
+
# tile_x 58 binary 0 0 1 1 1 0 1 0
|
60
|
+
# tile_y 105 binary 0 1 1 0 1 0 0 1
|
61
|
+
# interleaved binary 00 10 11 01 11 00 01 10
|
62
|
+
# quadkey 0 2 3 1 3 0 1 2 # "02313012"
|
63
|
+
#
|
64
|
+
# (see `quadkey` for more.)
|
65
|
+
#
|
66
|
+
# At zoom level 15, the packed quadkey is a 30-bit unsigned integer --
|
67
|
+
# meaning you can store it in a pig `int`; for languages with an `unsigned
|
68
|
+
# int` type, you can go to zoom level 16 before you have to use a
|
69
|
+
# less-efficient type. Zoom level 15 has a resolution of about one tile
|
70
|
+
# per kilometer (about 1.25 km/tile near the equator; 0.75 km/tile at
|
71
|
+
# London's latitude). It takes 1 billion tiles to tile the world at that
|
72
|
+
# scale. Ruby's integer type goes up to 60 bits, enough for any practical
|
73
|
+
# zoom level.
|
74
|
+
#
|
75
|
+
def packed_qk ; Wukong::Geolocated.tile_xy_zl_to_packed_qk(tile_x(zl), tile_y(zl), zl) ; end
|
76
|
+
|
77
|
+
# @return [Float] x index of the tile this object lies on at given zoom level
|
78
|
+
def tile_xf(zl) ; Wukong::Geolocated.lng_zl_to_tile_xf(longitude, zl) ; end
|
79
|
+
# @return [Float] y index of the tile this object lies on at given zoom level
|
80
|
+
def tile_yf(zl) ; Wukong::Geolocated.lat_zl_to_tile_yf(latitude, zl) ; end
|
81
|
+
# @return [Integer] x index of the tile this object lies on at given zoom level
|
82
|
+
def tile_x(zl) ; tile_xf(zl).floor ; end
|
83
|
+
# @return [Integer] y index of the tile this object lies on at given zoom level
|
84
|
+
def tile_y(zl) ; tile_yf(zl).floor ; end
|
85
|
+
|
86
|
+
# @return [Float] tile coordinates `(x,y)` for this object at given zoom level
|
87
|
+
def tile_xy(zl) ; [tile_x(xl), tile_y(zl)] ; end
|
88
|
+
|
89
|
+
# @returns [Array<Numeric, Numeric>] a `[longitude, latitude]` pair representing object as a point.
|
90
|
+
def lng_lat ; [longitude, latitude] ; end
|
91
|
+
|
92
|
+
# @returns [left, btm, right, top]
|
93
|
+
def bbox_for_radius(radius) ; Wukong::Geolocated.lng_lat_rad_to_bbox(longitude, latitude, radius) ; end
|
94
|
+
end
|
95
|
+
|
96
|
+
EARTH_RADIUS = 6371000 # meters
|
97
|
+
MIN_LONGITUDE = -180
|
98
|
+
MAX_LONGITUDE = 180
|
99
|
+
MIN_LATITUDE = -85.05112878
|
100
|
+
MAX_LATITUDE = 85.05112878
|
101
|
+
ALLOWED_LONGITUDE = (MIN_LONGITUDE..MAX_LONGITUDE)
|
102
|
+
ALLOWED_LATITUDE = (MIN_LATITUDE..MAX_LATITUDE)
|
103
|
+
TILE_PIXEL_SIZE = 256
|
104
|
+
|
105
|
+
# Width or height in number of tiles
|
106
|
+
def map_tile_size(zl)
|
107
|
+
1 << zl
|
108
|
+
end
|
109
|
+
|
110
|
+
#
|
111
|
+
# Tile coordinates
|
112
|
+
#
|
113
|
+
|
114
|
+
# Convert longitude in degrees to _floating-point_ tile x,y coordinates at given zoom level
|
115
|
+
def lng_zl_to_tile_xf(longitude, zl)
|
116
|
+
raise ArgumentError, "longitude must be within bounds ((#{longitude}) vs #{ALLOWED_LONGITUDE})" unless (ALLOWED_LONGITUDE.include?(longitude))
|
117
|
+
xx = (longitude.to_f + 180.0) / 360.0
|
118
|
+
(map_tile_size(zl) * xx)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Convert latitude in degrees to _floating-point_ tile x,y coordinates at given zoom level
|
122
|
+
def lat_zl_to_tile_yf(latitude, zl)
|
123
|
+
raise ArgumentError, "latitude must be within bounds ((#{latitude}) vs #{ALLOWED_LATITUDE})" unless (ALLOWED_LATITUDE.include?(latitude))
|
124
|
+
sin_lat = Math.sin(latitude.to_radians)
|
125
|
+
yy = Math.log((1 + sin_lat) / (1 - sin_lat)) / (4 * Math::PI)
|
126
|
+
(map_tile_size(zl) * (0.5 - yy))
|
127
|
+
end
|
128
|
+
|
129
|
+
# Convert latitude in degrees to integer tile x,y coordinates at given zoom level
|
130
|
+
def lng_lat_zl_to_tile_xy(longitude, latitude, zl)
|
131
|
+
[lng_zl_to_tile_xf(longitude, zl).floor, lat_zl_to_tile_yf(latitude, zl).floor]
|
132
|
+
end
|
133
|
+
|
134
|
+
# Convert from tile_x, tile_y, zoom level to longitude and latitude in
|
135
|
+
# degrees (slight loss of precision).
|
136
|
+
#
|
137
|
+
# Tile coordinates may be floats or integer; they must lie within map range.
|
138
|
+
def tile_xy_zl_to_lng_lat(tile_x, tile_y, zl)
|
139
|
+
tile_size = map_tile_size(zl)
|
140
|
+
raise ArgumentError, "tile index must be within bounds ((#{tile_x},#{tile_y}) vs #{tile_size})" unless ((0..(tile_size-1)).include?(tile_x)) && ((0..(tile_size-1)).include?(tile_x))
|
141
|
+
xx = (tile_x.to_f / tile_size)
|
142
|
+
yy = 0.5 - (tile_y.to_f / tile_size)
|
143
|
+
lng = 360.0 * xx - 180.0
|
144
|
+
lat = 90 - 360 * Math.atan(Math.exp(-yy * 2 * Math::PI)) / Math::PI
|
145
|
+
[lng, lat]
|
146
|
+
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# Quadkey coordinates
|
150
|
+
#
|
151
|
+
|
152
|
+
# converts from even/odd state of tile x and tile y to quadkey. NOTE: bit order means y, x
|
153
|
+
BIT_TO_QUADKEY = { [false, false] => "0", [false, true] => "1", [true, false] => "2", [true, true] => "3", }
|
154
|
+
# converts from quadkey char to bits. NOTE: bit order means y, x
|
155
|
+
QUADKEY_TO_BIT = { "0" => [0,0], "1" => [0,1], "2" => [1,0], "3" => [1,1]}
|
156
|
+
|
157
|
+
# Convert from tile x,y into a quadkey at a specified zoom level
|
158
|
+
def tile_xy_zl_to_quadkey(tile_x, tile_y, zl)
|
159
|
+
quadkey_chars = []
|
160
|
+
tx = tile_x.to_i
|
161
|
+
ty = tile_y.to_i
|
162
|
+
zl.times do
|
163
|
+
quadkey_chars.push BIT_TO_QUADKEY[[ty.odd?, tx.odd?]] # bit order y,x
|
164
|
+
tx >>= 1 ; ty >>= 1
|
165
|
+
end
|
166
|
+
quadkey_chars.join.reverse
|
167
|
+
end
|
168
|
+
|
169
|
+
# Convert a quadkey into tile x,y coordinates and level
|
170
|
+
def quadkey_to_tile_xy_zl(quadkey)
|
171
|
+
raise ArgumentError, "Quadkey must contain only the characters 0, 1, 2 or 3: #{quadkey}!" unless quadkey =~ /\A[0-3]*\z/
|
172
|
+
zl = quadkey.to_s.length
|
173
|
+
tx = 0 ; ty = 0
|
174
|
+
quadkey.chars.each do |char|
|
175
|
+
ybit, xbit = QUADKEY_TO_BIT[char] # bit order y, x
|
176
|
+
tx = (tx << 1) + xbit
|
177
|
+
ty = (ty << 1) + ybit
|
178
|
+
end
|
179
|
+
[tx, ty, zl]
|
180
|
+
end
|
181
|
+
|
182
|
+
# Convert from tile x,y into a packed quadkey at a specified zoom level
|
183
|
+
def tile_xy_zl_to_packed_qk(tile_x, tile_y, zl)
|
184
|
+
# don't optimize unless you're sure your way is faster; string ops are
|
185
|
+
# faster than you think and loops are slower than you think
|
186
|
+
quadkey_str = tile_xy_zl_to_quadkey(tile_x, tile_y, zl)
|
187
|
+
quadkey_str.to_i(4)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Convert a packed quadkey (integer) into tile x,y coordinates and level
|
191
|
+
def packed_qk_zl_to_tile_xy(packed_qk, zl=16)
|
192
|
+
# don't "optimize" this without testing... string operations are faster than you think in ruby
|
193
|
+
raise ArgumentError, "Quadkey must be an integer in range of the zoom level: #{packed_qk}, #{zl}" unless packed_qk.is_a?(Fixnum) && (packed_qk < 2 ** (zl*2))
|
194
|
+
quadkey_rhs = packed_qk.to_s(4)
|
195
|
+
quadkey = ("0" * (zl - quadkey_rhs.length)) << quadkey_rhs
|
196
|
+
quadkey_to_tile_xy_zl(quadkey)
|
197
|
+
end
|
198
|
+
|
199
|
+
# Convert a lat/lng and zoom level into a quadkey
|
200
|
+
def lng_lat_zl_to_quadkey(longitude, latitude, zl)
|
201
|
+
tile_x, tile_y = lng_lat_zl_to_tile_xy(longitude, latitude, zl)
|
202
|
+
tile_xy_zl_to_quadkey(tile_x, tile_y, zl)
|
203
|
+
end
|
204
|
+
|
205
|
+
#
|
206
|
+
# Bounding box coordinates
|
207
|
+
#
|
208
|
+
|
209
|
+
# Convert a quadkey into a bounding box using adjacent tile
|
210
|
+
def quadkey_to_bbox(quadkey)
|
211
|
+
tile_x, tile_y, zl = quadkey_to_tile_xy_zl(quadkey)
|
212
|
+
# bottom right of me is top left of my southeast neighbor
|
213
|
+
left, top = tile_xy_zl_to_lng_lat(tile_x, tile_y, zl)
|
214
|
+
right, btm = tile_xy_zl_to_lng_lat(tile_x + 1, tile_y + 1, zl)
|
215
|
+
[left, btm, right, top]
|
216
|
+
end
|
217
|
+
|
218
|
+
# Retuns the smallest quadkey containing both of corners of the given bounding box
|
219
|
+
def quadkey_containing_bbox(left, btm, right, top)
|
220
|
+
qk_tl = lng_lat_zl_to_quadkey(left, top, 23)
|
221
|
+
qk_2 = lng_lat_zl_to_quadkey(right, btm, 23)
|
222
|
+
# the containing qk is the longest one that both agree on
|
223
|
+
containing_key = ""
|
224
|
+
qk_tl.chars.zip(qk_2.chars).each do |char_tl, char_2|
|
225
|
+
break if char_tl != char_2
|
226
|
+
containing_key << char_tl
|
227
|
+
end
|
228
|
+
containing_key
|
229
|
+
end
|
230
|
+
|
231
|
+
# Returns a bounding box containing the circle created by the lat/lng and radius
|
232
|
+
def lng_lat_rad_to_bbox(longitude, latitude, radius)
|
233
|
+
left, _ = point_east( longitude, latitude, -radius)
|
234
|
+
_, btm = point_north(longitude, latitude, -radius)
|
235
|
+
right, _ = point_east( longitude, latitude, radius)
|
236
|
+
_, top = point_north(longitude, latitude, radius)
|
237
|
+
[left, btm, right, top]
|
238
|
+
end
|
239
|
+
|
240
|
+
# Returns the centroid of a bounding box
|
241
|
+
#
|
242
|
+
# @param [Array<Float, Float>] left_btm Longitude, Latitude of SW point
|
243
|
+
# @param [Array<Float, Float>] right_top Longitude, Latitude of NE point
|
244
|
+
#
|
245
|
+
# @return [Array<Float, Float>] Longitude, Latitude of centroid
|
246
|
+
def bbox_centroid(left_btm, right_top)
|
247
|
+
haversine_midpoint(*left_btm, *right_top)
|
248
|
+
end
|
249
|
+
|
250
|
+
# Return the haversine distance in meters between two points
|
251
|
+
def haversine_distance(left, btm, right, top)
|
252
|
+
delta_lng = (right - left).abs.to_radians
|
253
|
+
delta_lat = (top - btm ).abs.to_radians
|
254
|
+
btm_rad = btm.to_radians
|
255
|
+
top_rad = top.to_radians
|
256
|
+
|
257
|
+
aa = (Math.sin(delta_lat / 2.0))**2 + Math.cos(top_rad) * Math.cos(btm_rad) * (Math.sin(delta_lng / 2.0))**2
|
258
|
+
cc = 2.0 * Math.atan2(Math.sqrt(aa), Math.sqrt(1.0 - aa))
|
259
|
+
cc * EARTH_RADIUS
|
260
|
+
end
|
261
|
+
|
262
|
+
# Return the haversine midpoint in meters between two points
|
263
|
+
def haversine_midpoint(left, btm, right, top)
|
264
|
+
cos_btm = Math.cos(btm.to_radians)
|
265
|
+
cos_top = Math.cos(top.to_radians)
|
266
|
+
bearing_x = cos_btm * Math.cos((right - left).to_radians)
|
267
|
+
bearing_y = cos_btm * Math.sin((right - left).to_radians)
|
268
|
+
mid_lat = Math.atan2(
|
269
|
+
(Math.sin(top.to_radians) + Math.sin(btm.to_radians)),
|
270
|
+
(Math.sqrt((cos_top + bearing_x)**2 + bearing_y**2)))
|
271
|
+
mid_lng = left.to_radians + Math.atan2(bearing_y, (cos_top + bearing_x))
|
272
|
+
[mid_lng.to_degrees, mid_lat.to_degrees]
|
273
|
+
end
|
274
|
+
|
275
|
+
# From a given point, calculate the point directly north a specified distance
|
276
|
+
def point_north(longitude, latitude, distance)
|
277
|
+
north_lat = (latitude.to_radians + (distance.to_f / EARTH_RADIUS)).to_degrees
|
278
|
+
[longitude, north_lat]
|
279
|
+
end
|
280
|
+
|
281
|
+
# From a given point, calculate the change in degrees directly east a given distance
|
282
|
+
def point_east(longitude, latitude, distance)
|
283
|
+
radius = EARTH_RADIUS * Math.sin(((Math::PI / 2.0) - latitude.to_radians.abs))
|
284
|
+
east_lng = (longitude.to_radians + (distance.to_f / radius)).to_degrees
|
285
|
+
[east_lng, latitude]
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# Pixel coordinates
|
290
|
+
#
|
291
|
+
# Use with a standard (256x256 pixel) grid-based tileserver
|
292
|
+
#
|
293
|
+
|
294
|
+
# Width or height of grid bitmap in pixels at given zoom level
|
295
|
+
def map_pixel_size(zl)
|
296
|
+
TILE_PIXEL_SIZE * map_tile_size(zl)
|
297
|
+
end
|
298
|
+
|
299
|
+
# Return pixel resolution in meters per pixel at a specified latitude and zoom level
|
300
|
+
def pixel_resolution(latitude, zl)
|
301
|
+
lat = latitude.clamp(MIN_LATITUDE, MAX_LATITUDE)
|
302
|
+
Math.cos(lat.to_radians) * 2 * Math::PI * EARTH_RADIUS / map_pixel_size(zl).to_f
|
303
|
+
end
|
304
|
+
|
305
|
+
# Map scale at a specified latitude, zoom level, & screen resolution in dpi
|
306
|
+
def map_scale_for_dpi(latitude, zl, screen_dpi)
|
307
|
+
pixel_resolution(latitude, zl) * screen_dpi / 0.0254
|
308
|
+
end
|
309
|
+
|
310
|
+
# Convert from x,y pixel pair into tile x,y coordinates
|
311
|
+
def pixel_xy_to_tile_xy(pixel_x, pixel_y)
|
312
|
+
[pixel_x / TILE_PIXEL_SIZE, pixel_y / TILE_PIXEL_SIZE]
|
313
|
+
end
|
314
|
+
|
315
|
+
# Convert from x,y tile pair into pixel x,y coordinates (top left corner)
|
316
|
+
def tile_xy_to_pixel_xy(tile_x, tile_y)
|
317
|
+
[tile_x * TILE_PIXEL_SIZE, tile_y * TILE_PIXEL_SIZE]
|
318
|
+
end
|
319
|
+
|
320
|
+
def pixel_xy_zl_to_lng_lat(pixel_x, pixel_y, zl)
|
321
|
+
tile_xy_zl_to_lng_lat(pixel_x.to_f / TILE_PIXEL_SIZE, pixel_y.to_f / TILE_PIXEL_SIZE, zl)
|
322
|
+
end
|
323
|
+
|
324
|
+
def lng_lat_zl_to_pixel_xy(lng, lat, zl)
|
325
|
+
pixel_x = lng_zl_to_tile_xf(lng, zl)
|
326
|
+
pixel_y = lat_zl_to_tile_yf(lat, zl)
|
327
|
+
[(pixel_x * TILE_PIXEL_SIZE + 0.5).floor, (pixel_y * TILE_PIXEL_SIZE + 0.5).floor]
|
328
|
+
end
|
329
|
+
|
330
|
+
end
|
331
|
+
end
|