mlr 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ee80c68b8bfa8b710d10ddc145d2767a2353f767ba312c00ef8cf06fd6a82868
4
+ data.tar.gz: 1fc654793659844b0db38f94c4ffb0c16d025b8546cddbf646d52334cd2d44c8
5
+ SHA512:
6
+ metadata.gz: c5b708d5d2c63a4f0ded13b4693e81366a3f2be740889c07e8af8452231d45e418af081e71b10d3dae6fcad3b2cf522dda1185840b0e03105b2dbc50253720ad
7
+ data.tar.gz: 57a689231bfd5c029189761581e52b96b7120a4aea40f8a72779e94940af0586b50a1595cecc91925554c01596ab05b3942bd4dc59d2158708466ca358d59eee
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at skcc321@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mlr.gemspec
6
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mlr (0.1.0)
5
+ pycall (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ method_source (0.9.2)
12
+ minitest (5.11.3)
13
+ pry (0.12.2)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
16
+ pycall (1.0.3)
17
+ rake (10.5.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (~> 1.17)
24
+ minitest (~> 5.0)
25
+ mlr!
26
+ pry (~> 0.10)
27
+ rake (~> 10.0)
28
+
29
+ BUNDLED WITH
30
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 rafael
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # Mlr
2
+
3
+ multilateration solution
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'mlr'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mlr
20
+
21
+ Also you need python libraries
22
+
23
+ $ pip install localization
24
+ $ pip install numpy
25
+ $ pip install scipy
26
+ $ pip install shapely
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mlr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,61 @@
1
+ require "mlr/strategy/python"
2
+ require "mlr/version"
3
+
4
+ module Mlr
5
+ class Error < StandardError; end
6
+
7
+ # define point struct
8
+ # it is used everywhere
9
+ AnchorPoint3D = Struct.new(:x, :y, :z, :distance)
10
+
11
+ AnchorPoint2D = Struct.new(:x, :y, :distance) do
12
+ def z; 0; end
13
+ end
14
+
15
+ ResultPoint2D = Struct.new(:x, :y)
16
+ ResultPoint3D = Struct.new(:x, :y, :z)
17
+
18
+ # modes
19
+ MODE2D = '2D'.freeze
20
+ MODE3D = '3D'.freeze
21
+
22
+ # sorvers
23
+ SOLVER_LSE = 'LSE'.freeze
24
+
25
+ # STRATEGIES
26
+ PYTHON = 'python'.freeze
27
+ STRATEGY = PYTHON
28
+
29
+ DETECT_MODE = ->(points) {
30
+ if points.all? { |point| point.is_a?(Mlr::AnchorPoint2D) }
31
+ Mlr::MODE2D
32
+ elsif points.all? { |point| point.is_a?(Mlr::AnchorPoint3D) }
33
+ Mlr::MODE3D
34
+ end
35
+ }
36
+
37
+ # strategy selector
38
+ def self.strategy
39
+ case STRATEGY
40
+ when PYTHON then Mlr::Strategy::Python
41
+ end
42
+ end
43
+
44
+ # interface
45
+ def self.from_array(array)
46
+ points = array.map do |line|
47
+ case line.size
48
+ when 3 then Mlr::AnchorPoint2D.new(*line)
49
+ when 4 then Mlr::AnchorPoint3D.new(*line)
50
+ else
51
+ raise 'wrong number of elements in array'
52
+ end
53
+ end
54
+
55
+ from_points(points)
56
+ end
57
+
58
+ def self.from_points(points)
59
+ strategy.get_point(points: points, mode: DETECT_MODE.call(points))
60
+ end
61
+ end
@@ -0,0 +1,94 @@
1
+ require 'pycall'
2
+
3
+ module Mlr
4
+ module Strategy
5
+ class Python
6
+ SCRIPT = <<~PYTHON
7
+ import localization as lx
8
+ P=lx.Project(mode='%{mode}',solver='%{solver}')
9
+ %{anchors}
10
+ t,label=P.add_target()
11
+ %{measures}
12
+ P.solve()
13
+ PYTHON
14
+
15
+ def self.get_point(options)
16
+ new(options).run
17
+ end
18
+
19
+ def initialize(points:, mode: Mlr::MODE2D, solver: Mlr::SOLVER_LSE)
20
+ @points = points
21
+ @mode = mode
22
+ @solver = solver
23
+ end
24
+
25
+ def run
26
+ # run python script
27
+ PyCall.exec(SCRIPT % options)
28
+
29
+ # get result from python
30
+ make_point(PyCall.eval('t.loc'))
31
+ end
32
+
33
+ def options
34
+ {
35
+ anchors: get_anchors,
36
+ measures: get_measures,
37
+ mode: get_mode,
38
+ solver: get_solver
39
+ }
40
+ end
41
+
42
+ private
43
+
44
+ def make_point(point)
45
+ case @mode
46
+ when Mlr::MODE2D
47
+ Mlr::ResultPoint2D.new(point.x, point.y)
48
+ when Mlr::MODE3D
49
+ Mlr::ResultPoint3D.new(point.x, point.y, point.z)
50
+ else
51
+ raise 'incompatible mode'
52
+ end
53
+ end
54
+
55
+ def result_point
56
+ case @mode
57
+ when Mlr::MODE2D then Mlr::ResultPoint2D
58
+ when Mlr::MODE3D then Mlr::ResultPoint3D
59
+ else
60
+ raise 'incompatible mode'
61
+ end
62
+ end
63
+
64
+ def get_mode
65
+ case @mode
66
+ when Mlr::MODE2D then '2D'
67
+ when Mlr::MODE3D then '3D'
68
+ else
69
+ raise 'incompatible mode'
70
+ end
71
+ end
72
+
73
+ def get_solver
74
+ case @solver
75
+ when Mlr::SOLVER_LSE then "LSE"
76
+ else
77
+ raise 'incompatible solver'
78
+ end
79
+ end
80
+
81
+ def get_anchors
82
+ @points.map.with_index do |point, index|
83
+ "P.add_anchor('point_#{index}',(#{point.x},#{point.y},#{point.z}))"
84
+ end.join(';')
85
+ end
86
+
87
+ def get_measures
88
+ @points.map.with_index do |point, index|
89
+ "t.add_measure('point_#{index}',#{point.distance})"
90
+ end.join(';')
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module Mlr
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "mlr/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mlr"
8
+ spec.version = Mlr::VERSION
9
+ spec.authors = ["rafael"]
10
+ spec.email = ["skcc321@gmail.com"]
11
+
12
+ spec.summary = %q{multilateration}
13
+ spec.description = %q{ruby wrapper from this python multilateration solution - https://github.com/kamalshadi/Localization}
14
+ spec.homepage = "https://github.com/skcc321/mlr"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = spec.homepage
24
+ spec.metadata["changelog_uri"] = spec.homepage
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_runtime_dependency "pycall", "~> 1.0"
40
+ spec.add_development_dependency "bundler", "~> 1.17"
41
+ spec.add_development_dependency "rake", "~> 10.0"
42
+ spec.add_development_dependency "pry", "~> 0.10"
43
+ spec.add_development_dependency "minitest", "~> 5.0"
44
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mlr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rafael
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pycall
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: ruby wrapper from this python multilateration solution - https://github.com/kamalshadi/Localization
84
+ email:
85
+ - skcc321@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/mlr.rb
101
+ - lib/mlr/strategy/python.rb
102
+ - lib/mlr/version.rb
103
+ - mlr.gemspec
104
+ homepage: https://github.com/skcc321/mlr
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ homepage_uri: https://github.com/skcc321/mlr
110
+ source_code_uri: https://github.com/skcc321/mlr
111
+ changelog_uri: https://github.com/skcc321/mlr
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: multilateration
132
+ test_files: []