Skip to content

Commit

Permalink
api: update to phase 6 (closed alpha) (#6)
Browse files Browse the repository at this point in the history
* api: update to phase 6 (closed alpha)

* examples: update for phase 6

* docs: update for phase 6

* examples: update usage instructions

* ci: run example script on actions
  • Loading branch information
q9f authored Dec 19, 2024
1 parent 39fcffe commit 36d6748
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ jobs:
- name: Run Tests
run: |
bundle exec rspec
bundle exec rspec
- run: |
ruby ./examples/distance.rb "D:S299" "Y:1SII"
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Frontier.rb
Library to handle EVE Frontier graph and pathfinding operations.

_Work in progress._
API Version: `Phase 6` (Closed Alpha)

API Version: `Phase 5`
_Work in progress._

Limitations:
- no closed alpha ("phase 6") data yet
- ~~no closed alpha ("phase 6") data yet~~
- no graph database implemented (TODO), i.e., you have to rebuild the graph each time you run computations which takes some time
- path finding on 24k star systems can hit the limits of Ruby (SystemStackError: stack level too deep), try running shorter queries over less distance and combine the results

Expand Down Expand Up @@ -41,7 +41,7 @@ See [examples/](./examples/) for usage and options to fine-tune.

```bash
❯ ruby examples/distance.rb "D:S299" "Y:1SII"
1974.926982542737
D:S299 --> Y:1SII: 885.623 ly
```

### Shortest jump-path between two star systems
Expand All @@ -54,13 +54,10 @@ best_smart_gate_path = UNIVERSE_GRAPH.shortest_path("D:S299", "Y:1SII")
See [examples/](./examples/) for usage and options to fine-tune.

```bash
❯ ruby examples/pathfinder.rb
Mapping all star systems ... done.
Building universe graph ... done.
{"source"=>"D:S299",
"dest"=>"Y:1SII",
"path"=>["D:S299", "G.QXJ.4SH", "P:S696", "Q:1A97", "J:3K85", "Y:1SII"],
"dist"=>1978.63507044974}
❯ ruby examples/pathfinder.rb "D:S299" "Y:1SII"
Mapping all star systems ... done.
Building universe graph ... done.
D:S299 --> Y:1SII: 885.623 ly(D:S299 --> G.QXJ.4SH --> P:S696 --> Q:1A97 --> J:3K85 --> Y:1SII)
```

### Frontier console
Expand Down
6 changes: 5 additions & 1 deletion bin/api
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash


# Update available star systems from swagger API (Phase 5)
curl https://blockchain-gateway-stillness.live.tech.evefrontier.com/solarsystems -o ./spec/fixtures/stars_phase5.json
### curl https://blockchain-gateway-stillness.live.tech.evefrontier.com/solarsystems -o ./spec/fixtures/stars_phase5.json

# Update available star systems from swagger API (Phase 6)
curl https://blockchain-gateway-nova.nursery.reitnorf.com/solarsystems -o ./spec/fixtures/stars_closed_alpha.json
35 changes: 14 additions & 21 deletions examples/distance.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env ruby

# USAGE
# ruby examples/distance.rb "D:S299" "Y:1SII"
# D:S299 --> Y:1SII: 885.623 ly

# use the local version of the code instead of a globally installed gem
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)

Expand All @@ -10,34 +14,23 @@

if __FILE__ == $0

# Star system IDs are offset by 30 million
STAR_ID_OFFSET = 30_000_000

# Amount of star systems in phase 5
STAR_COUNT = 20_230
LAST_STAR_ID = STAR_ID_OFFSET + STAR_COUNT

# Make the universe available in these varaibles
ALL_STARS = {}

# Read star data (locally or from API)
stars_phase5 = File.read "./spec/fixtures/stars_phase5.json"
stars_phase5 = JSON.parse stars_phase5
mapping_closed_alpha = File.read "./spec/fixtures/mapping_closed_alpha.json"
mapping_closed_alpha = JSON.parse mapping_closed_alpha
stars_closed_alpha = File.read "./spec/fixtures/stars_closed_alpha.json"
stars_closed_alpha = JSON.parse stars_closed_alpha

# Create all star system objects with coordinates
c_id = STAR_ID_OFFSET + 1
prog = 0
while c_id < LAST_STAR_ID
id = c_id.to_s
location = Coords.new stars_phase5[id]["location"]["x"], stars_phase5[id]["location"]["y"], stars_phase5[id]["location"]["z"]
star = Star.new id, mapping_closed_alpha[id], location
stars_closed_alpha.each do |star|
key = star[0]
value = star[1]
location = Coords.new value["location"]["x"], value["location"]["y"], value["location"]["z"]
star = Star.new key, value["solarSystemName"], location
ALL_STARS[star.name] = star
c_id += 1
end

# Direct distance between "D:S299" to "Y:1SII"
direct_distance = ALL_STARS["D:S299"].distance_ly(ALL_STARS["Y:1SII"])
pp direct_distance
# Direct distance between argument 1 and 2
direct_distance = ALL_STARS[ARGV[0]].distance_ly(ALL_STARS[ARGV[1]])
pp "#{ARGV[0]} --> #{ARGV[1]}: #{"%.3f" % direct_distance} ly"
end
37 changes: 20 additions & 17 deletions examples/pathfinder.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#!/usr/bin/env ruby

# USAGE
# ruby examples/pathfinder.rb "D:S299" "Y:1SII"
# Mapping all star systems ... done.
# Building universe graph ... done.
# D:S299 --> Y:1SII: 885.623 ly(D:S299 --> G.QXJ.4SH --> P:S696 --> Q:1A97 --> J:3K85 --> Y:1SII)

# use the local version of the code instead of a globally installed gem
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)

Expand All @@ -21,24 +27,21 @@
LAST_STAR_ID = STAR_ID_OFFSET + STAR_COUNT

# Make the universe available in these varaibles
ALL_STARS = []
ALL_STARS = {}
UNIVERSE_GRAPH = Graph.new

# Read star data (locally or from API)
stars_phase5 = File.read "./spec/fixtures/stars_phase5.json"
stars_phase5 = JSON.parse stars_phase5
mapping_closed_alpha = File.read "./spec/fixtures/mapping_closed_alpha.json"
mapping_closed_alpha = JSON.parse mapping_closed_alpha
stars_closed_alpha = File.read "./spec/fixtures/stars_closed_alpha.json"
stars_closed_alpha = JSON.parse stars_closed_alpha

# Create all star system objects with coordinates
c_id = STAR_ID_OFFSET + 1
prog = 0
while c_id < LAST_STAR_ID
id = c_id.to_s
location = Coords.new stars_phase5[id]["location"]["x"], stars_phase5[id]["location"]["y"], stars_phase5[id]["location"]["z"]
star = Star.new id, mapping_closed_alpha[id], location
ALL_STARS << star
c_id += 1
stars_closed_alpha.each do |star|
key = star[0]
value = star[1]
location = Coords.new value["location"]["x"], value["location"]["y"], value["location"]["z"]
star = Star.new key, value["solarSystemName"], location
ALL_STARS[star.name] = star
prog += 1
perc = prog.to_f / ALL_STARS.length.to_f * 100.0
print "Mapping all star systems ... #{"%3.2f" % perc}%\r"
Expand All @@ -50,9 +53,9 @@
prog = 0
ALL_STARS.each do |a|
ALL_STARS.each do |b|
dist = a.distance_ly(b)
dist = a[1].distance_ly(b[1])
if dist < MAX_JUMP_RANGE && dist > 0
UNIVERSE_GRAPH.add_edge a.name, b.name, dist
UNIVERSE_GRAPH.add_edge a[1].name, b[1].name, dist
end
prog += 1
perc = prog.to_f / (ALL_STARS.length.to_f * ALL_STARS.length.to_f) * 100.0
Expand All @@ -61,7 +64,7 @@
end
print "Building universe graph ... done.\n"

# Path from "D:S299" to "Y:1SII"
best_smart_gate_path = UNIVERSE_GRAPH.shortest_path("D:S299", "Y:1SII")
pp best_smart_gate_path
# Path from argument 1 and 2
best_smart_gate_path = UNIVERSE_GRAPH.shortest_path(ARGV[0], ARGV[1])
pp "#{ARGV[0]} --> #{ARGV[1]}: #{"%.3f" % best_smart_gate_path.dist} ly (#{best_smart_gate_path.path.join(" --> ")})"
end
1 change: 1 addition & 0 deletions spec/fixtures/stars_closed_alpha.json

Large diffs are not rendered by default.

63 changes: 44 additions & 19 deletions spec/frontier/star_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
describe Star do
let(:stars_phase5_file) { File.read "spec/fixtures/stars_phase5.json" }
subject(:stars_phase5) { JSON.parse stars_phase5_file }
let(:stars_closed_alpha_file) { File.read "spec/fixtures/stars_closed_alpha.json" }
subject(:stars_closed_alpha) { JSON.parse stars_closed_alpha_file }
let(:mapping_closed_alpha_file) { File.read "spec/fixtures/mapping_closed_alpha.json" }
subject(:mapping_closed_alpha) { JSON.parse mapping_closed_alpha_file }

Expand All @@ -18,30 +20,53 @@
expect(sun.location.z).to eq 0
end

it "can create frontier star systems" do
id = "30000001"
loc = Coords.new stars_phase5[id]["location"]["x"], stars_phase5[id]["location"]["y"], stars_phase5[id]["location"]["z"]
a2560 = Star.new(id, mapping_closed_alpha[id], loc)
expect(a2560.id).to eq 30000001
expect(a2560.name).to eq "A 2560"
expect(a2560.location.x).to eq -4904707237374110000
expect(a2560.location.y).to eq -332297545060131000
expect(a2560.location.z).to eq 122856493430790000
end

it "knows light years" do
expect(Star::LIGHT_YEAR).to eq 9460800000000000
end

it "can compute distance between two stars" do
loc = Coords.new(0, 0, 0)
sun = Star.new(1, "Sun", loc)
context "phase 5" do
it "can create frontier star systems" do
id = "30000001"
loc = Coords.new stars_phase5[id]["location"]["x"], stars_phase5[id]["location"]["y"], stars_phase5[id]["location"]["z"]
a2560 = Star.new(id, mapping_closed_alpha[id], loc)
expect(a2560.id).to eq 30000001
expect(a2560.name).to eq "A 2560"
expect(a2560.location.x).to eq -4904707237374110000
expect(a2560.location.y).to eq -332297545060131000
expect(a2560.location.z).to eq 122856493430790000
end

it "can compute distance between two stars" do
loc = Coords.new(0, 0, 0)
sun = Star.new(1, "Sun", loc)
id = "30000001"
loc = Coords.new stars_phase5[id]["location"]["x"], stars_phase5[id]["location"]["y"], stars_phase5[id]["location"]["z"]
a2560 = Star.new(id, mapping_closed_alpha[id], loc)
expect(sun.distance_mt(a2560)).to eq 4917485989891691520
expect(sun.distance_ly(a2560)).to eq 519.7748594084741
end
end

id = "30000001"
loc = Coords.new stars_phase5[id]["location"]["x"], stars_phase5[id]["location"]["y"], stars_phase5[id]["location"]["z"]
a2560 = Star.new(id, mapping_closed_alpha[id], loc)
context "closed alpha (phase 6)" do
it "can create frontier star systems" do
id = "30000001"
loc = Coords.new stars_closed_alpha[id]["location"]["x"], stars_closed_alpha[id]["location"]["y"], stars_closed_alpha[id]["location"]["z"]
a2560 = Star.new(id, stars_closed_alpha[id]["solarSystemName"], loc)
expect(a2560.id).to eq 30000001
expect(a2560.name).to eq "A 2560"
expect(a2560.location.x).to eq -3350000000000000000
expect(a2560.location.y).to eq -510000000000000000
expect(a2560.location.z).to eq 396000000000000000
end

expect(sun.distance_mt(a2560)).to eq 4917485989891691520
expect(sun.distance_ly(a2560)).to eq 519.7748594084741
it "can compute distance between two stars" do
loc = Coords.new(0, 0, 0)
sun = Star.new(1, "Sun", loc)
id = "30000001"
loc = Coords.new stars_closed_alpha[id]["location"]["x"], stars_closed_alpha[id]["location"]["y"], stars_closed_alpha[id]["location"]["z"]
a2560 = Star.new(id, stars_closed_alpha[id]["solarSystemName"], loc)
expect(sun.distance_mt(a2560)).to eq 3411658834057121792
expect(sun.distance_ly(a2560)).to eq 360.6099731584139
end
end
end

0 comments on commit 36d6748

Please sign in to comment.