Skip to content

Commit

Permalink
levels
Browse files Browse the repository at this point in the history
  • Loading branch information
pghodgman committed Sep 23, 2013
1 parent 75c8462 commit 4f3785c
Show file tree
Hide file tree
Showing 23 changed files with 276 additions and 118 deletions.
3 changes: 3 additions & 0 deletions .idea/osprey-model.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

217 changes: 100 additions & 117 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions app/controllers/models_controller.rb
Expand Up @@ -11,6 +11,9 @@ def bodies
def location
render json: Model.find(params[:id]).location, :except=> [:image]
end
def levels
render json: Model.find(params[:id]).levels, :except=> [:uuid]
end
def preview
model = Model.find(params[:id])
send_data model.preview, :type => 'image/png',:disposition => 'inline'
Expand Down
35 changes: 35 additions & 0 deletions app/io/model_processor.rb
Expand Up @@ -20,6 +20,7 @@ def self.process(model_filename)
get_location(model, model_file, directory['IMAG'])
get_preview(model, model_file, directory['PRVW'])
get_meta(model, model_file, directory['META'])
get_levels(model, model_file, directory['LEVS'])


end
Expand Down Expand Up @@ -202,5 +203,39 @@ def self.get_meta(model, model_file, offset)
model.save
end

def self.get_levels(model, model_file, offset)
model_file.seek(offset, IO::SEEK_SET)

block_id = model_file.read(4).unpack("L").first
version = model_file.read(4).unpack("L").first
size = model_file.read(4).unpack("L").first
cksum = model_file.read(4).unpack("L").first

num_levels = model_file.read(4).unpack("L").first

num_levels.times do |n|
# skip header
model_file.read(16)

# level
uuid = model_file.read(16)
elevation = model_file.read(8).unpack("D").first
namesize = model_file.read(4).unpack("L").first
name = model_file.read(namesize)

level = Level.new
level.uuid = uuid
level.elevation = elevation
level.name = name
level.model = model
level.save


end


end



end
3 changes: 3 additions & 0 deletions app/models/body_level.rb
@@ -0,0 +1,3 @@
class BodyLevel < ActiveRecord::Base
belongs_to :body
end
3 changes: 3 additions & 0 deletions app/models/level.rb
@@ -0,0 +1,3 @@
class Level < ActiveRecord::Base
belongs_to :model
end
1 change: 1 addition & 0 deletions app/models/model.rb
@@ -1,4 +1,5 @@
class Model < ActiveRecord::Base
has_many :bodies
has_one :location
has_many :levels
end
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,7 @@
get 'models/:id/bodies' => 'models#bodies'
get 'models/:id/location' => 'models#location'
get 'models/:id/preview' => 'models#preview'
get 'models/:id/levels' => 'models#levels'


get 'bodies' => 'bodies#all'
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20130921153928_create_levels.rb
@@ -0,0 +1,11 @@
class CreateLevels < ActiveRecord::Migration
def change
create_table :levels do |t|
t.string :uuid
t.float :elevation
t.string :name

t.timestamps
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130921155057_add_model_id_to_level.rb
@@ -0,0 +1,5 @@
class AddModelIdToLevel < ActiveRecord::Migration
def change
add_column :levels, "model_id", :integer
end
end
7 changes: 7 additions & 0 deletions db/migrate/20130922214948_remove_string_uuid.rb
@@ -0,0 +1,7 @@
class RemoveStringUuid < ActiveRecord::Migration
def change
def change
remove_column :levels, "uuid", :string
end
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130922215700_remove_uuid.rb
@@ -0,0 +1,5 @@
class RemoveUuid < ActiveRecord::Migration
def change
remove_column :levels, :uuid
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130922215852_add_uuid_binary.rb
@@ -0,0 +1,5 @@
class AddUuidBinary < ActiveRecord::Migration
def change
add_column :levels, :uuid, :binary
end
end
10 changes: 10 additions & 0 deletions db/migrate/20130923010620_create_b_levels.rb
@@ -0,0 +1,10 @@
class CreateBLevels < ActiveRecord::Migration
def change
create_table :b_levels do |t|
t.string :name
t.binary :uuid

t.timestamps
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20130923010804_create_body_levels.rb
@@ -0,0 +1,10 @@
class CreateBodyLevels < ActiveRecord::Migration
def change
create_table :body_levels do |t|
t.string :name
t.binary :uuid

t.timestamps
end
end
end
25 changes: 24 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,14 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20130915143011) do
ActiveRecord::Schema.define(version: 20130923010804) do

create_table "b_levels", force: true do |t|
t.string "name"
t.binary "uuid"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "bodies", force: true do |t|
t.binary "data"
Expand All @@ -22,6 +29,22 @@
t.integer "model_id"
end

create_table "body_levels", force: true do |t|
t.string "name"
t.binary "uuid"
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "levels", force: true do |t|
t.float "elevation"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "model_id"
t.binary "uuid"
end

create_table "locations", force: true do |t|
t.binary "image"
t.float "latitude"
Expand Down
Binary file added public/uploads/layers.axm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/fixtures/b_levels.yml
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
name: MyString
uuid:

two:
name: MyString
uuid:
9 changes: 9 additions & 0 deletions test/fixtures/body_levels.yml
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
name: MyString
uuid:

two:
name: MyString
uuid:
11 changes: 11 additions & 0 deletions test/fixtures/levels.yml
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
uuid: MyString
elevation: 1.5
name: MyString

two:
uuid: MyString
elevation: 1.5
name: MyString
7 changes: 7 additions & 0 deletions test/models/b_level_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class BLevelTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/body_level_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class BodyLevelTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/level_test.rb
@@ -0,0 +1,7 @@
require 'test_helper'

class LevelTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 4f3785c

Please sign in to comment.