From 28121b9c74d5fea690e28fb995ebbde656cd3c97 Mon Sep 17 00:00:00 2001 From: Mark Cottman-Fields Date: Tue, 11 Dec 2012 17:37:13 +1000 Subject: [PATCH] Added Analysis tables - jobs, items, scripts. Added seed data. Added byte range implementation, but it is disbaled and needs work. modified: Gemfile modified: Gemfile.lock new file: app/assets/stylesheets/analysis_items.css.scss new file: app/assets/stylesheets/analysis_jobs.css.scss new file: app/assets/stylesheets/analysis_scripts.css.scss new file: app/controllers/analysis_items_controller.rb new file: app/controllers/analysis_jobs_controller.rb new file: app/controllers/analysis_scripts_controller.rb modified: app/controllers/api/callbacks_controller.rb modified: app/controllers/api/sessions_controller.rb modified: app/controllers/application_controller.rb modified: app/controllers/media_controller.rb new file: app/helpers/analysis_items_helper.rb new file: app/helpers/analysis_jobs_helper.rb new file: app/helpers/analysis_scripts_helper.rb new file: app/models/analysis_item.rb new file: app/models/analysis_job.rb new file: app/models/analysis_script.rb modified: app/models/user.rb new file: app/serializers/analysis_item_serializer.rb new file: app/serializers/analysis_job_serializer.rb new file: app/serializers/analysis_script_serializer.rb new file: app/views/analysis_items/_form.html.erb new file: app/views/analysis_items/edit.html.erb new file: app/views/analysis_items/index.html.erb new file: app/views/analysis_items/new.html.erb new file: app/views/analysis_items/show.html.erb new file: app/views/analysis_jobs/_form.html.erb new file: app/views/analysis_jobs/edit.html.erb new file: app/views/analysis_jobs/index.html.erb new file: app/views/analysis_jobs/new.html.erb new file: app/views/analysis_jobs/show.html.erb new file: app/views/analysis_scripts/_form.html.erb new file: app/views/analysis_scripts/edit.html.erb new file: app/views/analysis_scripts/index.html.erb new file: app/views/analysis_scripts/new.html.erb new file: app/views/analysis_scripts/show.html.erb modified: config/application.rb modified: config/initializers/custom_configs.rb modified: config/initializers/devise.rb modified: config/initializers/secret_token.rb modified: config/routes.rb modified: db/development_seeds.rb new file: db/migrate/20121211011323_create_analysis_jobs.rb new file: db/migrate/20121211013133_create_analysis_scripts.rb new file: db/migrate/20121211020323_create_analysis_items.rb modified: db/schema.rb modified: lib/external/analysis_runner.rb new file: lib/modules/byte_range.rb new file: test/fixtures/analysis_items.yml new file: test/fixtures/analysis_jobs.yml new file: test/fixtures/analysis_scripts.yml new file: test/functional/analysis_items_controller_test.rb new file: test/functional/analysis_jobs_controller_test.rb new file: test/functional/analysis_scripts_controller_test.rb new file: test/unit/analysis_item_test.rb new file: test/unit/analysis_job_test.rb new file: test/unit/analysis_script_test.rb new file: test/unit/helpers/analysis_items_helper_test.rb new file: test/unit/helpers/analysis_jobs_helper_test.rb new file: test/unit/helpers/analysis_scripts_helper_test.rb --- .../stylesheets/analysis_items.css.scss | 3 + app/assets/stylesheets/analysis_jobs.css.scss | 3 + .../stylesheets/analysis_scripts.css.scss | 3 + app/controllers/analysis_items_controller.rb | 83 +++++++++++++++++++ app/controllers/analysis_jobs_controller.rb | 83 +++++++++++++++++++ .../analysis_scripts_controller.rb | 83 +++++++++++++++++++ app/controllers/api/callbacks_controller.rb | 1 + app/controllers/api/sessions_controller.rb | 2 + app/controllers/application_controller.rb | 2 - app/controllers/media_controller.rb | 3 + app/helpers/analysis_items_helper.rb | 2 + app/helpers/analysis_jobs_helper.rb | 2 + app/helpers/analysis_scripts_helper.rb | 2 + app/models/analysis_item.rb | 18 ++++ app/models/analysis_job.rb | 33 ++++++++ app/models/analysis_script.rb | 22 +++++ app/models/user.rb | 4 +- app/serializers/analysis_item_serializer.rb | 10 +++ app/serializers/analysis_job_serializer.rb | 8 ++ app/serializers/analysis_script_serializer.rb | 6 ++ app/views/analysis_items/_form.html.erb | 49 +++++++++++ app/views/analysis_items/edit.html.erb | 6 ++ app/views/analysis_items/index.html.erb | 37 +++++++++ app/views/analysis_items/new.html.erb | 5 ++ app/views/analysis_items/show.html.erb | 45 ++++++++++ app/views/analysis_jobs/_form.html.erb | 61 ++++++++++++++ app/views/analysis_jobs/edit.html.erb | 6 ++ app/views/analysis_jobs/index.html.erb | 43 ++++++++++ app/views/analysis_jobs/new.html.erb | 5 ++ app/views/analysis_jobs/show.html.erb | 60 ++++++++++++++ app/views/analysis_scripts/_form.html.erb | 41 +++++++++ app/views/analysis_scripts/edit.html.erb | 6 ++ app/views/analysis_scripts/index.html.erb | 33 ++++++++ app/views/analysis_scripts/new.html.erb | 5 ++ app/views/analysis_scripts/show.html.erb | 35 ++++++++ lib/external/analysis_runner.rb | 6 +- lib/modules/byte_range.rb | 73 ++++++++++++++++ 37 files changed, 882 insertions(+), 7 deletions(-) create mode 100644 app/assets/stylesheets/analysis_items.css.scss create mode 100644 app/assets/stylesheets/analysis_jobs.css.scss create mode 100644 app/assets/stylesheets/analysis_scripts.css.scss create mode 100644 app/controllers/analysis_items_controller.rb create mode 100644 app/controllers/analysis_jobs_controller.rb create mode 100644 app/controllers/analysis_scripts_controller.rb create mode 100644 app/helpers/analysis_items_helper.rb create mode 100644 app/helpers/analysis_jobs_helper.rb create mode 100644 app/helpers/analysis_scripts_helper.rb create mode 100644 app/models/analysis_item.rb create mode 100644 app/models/analysis_job.rb create mode 100644 app/models/analysis_script.rb create mode 100644 app/serializers/analysis_item_serializer.rb create mode 100644 app/serializers/analysis_job_serializer.rb create mode 100644 app/serializers/analysis_script_serializer.rb create mode 100644 app/views/analysis_items/_form.html.erb create mode 100644 app/views/analysis_items/edit.html.erb create mode 100644 app/views/analysis_items/index.html.erb create mode 100644 app/views/analysis_items/new.html.erb create mode 100644 app/views/analysis_items/show.html.erb create mode 100644 app/views/analysis_jobs/_form.html.erb create mode 100644 app/views/analysis_jobs/edit.html.erb create mode 100644 app/views/analysis_jobs/index.html.erb create mode 100644 app/views/analysis_jobs/new.html.erb create mode 100644 app/views/analysis_jobs/show.html.erb create mode 100644 app/views/analysis_scripts/_form.html.erb create mode 100644 app/views/analysis_scripts/edit.html.erb create mode 100644 app/views/analysis_scripts/index.html.erb create mode 100644 app/views/analysis_scripts/new.html.erb create mode 100644 app/views/analysis_scripts/show.html.erb create mode 100644 lib/modules/byte_range.rb diff --git a/app/assets/stylesheets/analysis_items.css.scss b/app/assets/stylesheets/analysis_items.css.scss new file mode 100644 index 00000000..15180d72 --- /dev/null +++ b/app/assets/stylesheets/analysis_items.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the AnalysisItems controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/analysis_jobs.css.scss b/app/assets/stylesheets/analysis_jobs.css.scss new file mode 100644 index 00000000..69569d65 --- /dev/null +++ b/app/assets/stylesheets/analysis_jobs.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the AnalysisJobs controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/analysis_scripts.css.scss b/app/assets/stylesheets/analysis_scripts.css.scss new file mode 100644 index 00000000..2bef8043 --- /dev/null +++ b/app/assets/stylesheets/analysis_scripts.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the AnalysisScripts controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/analysis_items_controller.rb b/app/controllers/analysis_items_controller.rb new file mode 100644 index 00000000..a5c17b37 --- /dev/null +++ b/app/controllers/analysis_items_controller.rb @@ -0,0 +1,83 @@ +class AnalysisItemsController < ApplicationController + # GET /analysis_items + # GET /analysis_items.json + def index + @analysis_items = AnalysisItem.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @analysis_items } + end + end + + # GET /analysis_items/1 + # GET /analysis_items/1.json + def show + @analysis_item = AnalysisItem.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @analysis_item } + end + end + + # GET /analysis_items/new + # GET /analysis_items/new.json + def new + @analysis_item = AnalysisItem.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @analysis_item } + end + end + + # GET /analysis_items/1/edit + def edit + @analysis_item = AnalysisItem.find(params[:id]) + end + + # POST /analysis_items + # POST /analysis_items.json + def create + @analysis_item = AnalysisItem.new(params[:analysis_item]) + + respond_to do |format| + if @analysis_item.save + format.html { redirect_to @analysis_item, notice: 'Analysis item was successfully created.' } + format.json { render json: @analysis_item, status: :created, location: @analysis_item } + else + format.html { render action: "new" } + format.json { render json: @analysis_item.errors, status: :unprocessable_entity } + end + end + end + + # PUT /analysis_items/1 + # PUT /analysis_items/1.json + def update + @analysis_item = AnalysisItem.find(params[:id]) + + respond_to do |format| + if @analysis_item.update_attributes(params[:analysis_item]) + format.html { redirect_to @analysis_item, notice: 'Analysis item was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @analysis_item.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /analysis_items/1 + # DELETE /analysis_items/1.json + def destroy + @analysis_item = AnalysisItem.find(params[:id]) + @analysis_item.destroy + + respond_to do |format| + format.html { redirect_to analysis_items_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/analysis_jobs_controller.rb b/app/controllers/analysis_jobs_controller.rb new file mode 100644 index 00000000..33dbedae --- /dev/null +++ b/app/controllers/analysis_jobs_controller.rb @@ -0,0 +1,83 @@ +class AnalysisJobsController < ApplicationController + # GET /analysis_jobs + # GET /analysis_jobs.json + def index + @analysis_jobs = AnalysisJob.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @analysis_jobs } + end + end + + # GET /analysis_jobs/1 + # GET /analysis_jobs/1.json + def show + @analysis_job = AnalysisJob.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @analysis_job } + end + end + + # GET /analysis_jobs/new + # GET /analysis_jobs/new.json + def new + @analysis_job = AnalysisJob.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @analysis_job } + end + end + + # GET /analysis_jobs/1/edit + def edit + @analysis_job = AnalysisJob.find(params[:id]) + end + + # POST /analysis_jobs + # POST /analysis_jobs.json + def create + @analysis_job = AnalysisJob.new(params[:analysis_job]) + + respond_to do |format| + if @analysis_job.save + format.html { redirect_to @analysis_job, notice: 'Analysis job was successfully created.' } + format.json { render json: @analysis_job, status: :created, location: @analysis_job } + else + format.html { render action: "new" } + format.json { render json: @analysis_job.errors, status: :unprocessable_entity } + end + end + end + + # PUT /analysis_jobs/1 + # PUT /analysis_jobs/1.json + def update + @analysis_job = AnalysisJob.find(params[:id]) + + respond_to do |format| + if @analysis_job.update_attributes(params[:analysis_job]) + format.html { redirect_to @analysis_job, notice: 'Analysis job was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @analysis_job.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /analysis_jobs/1 + # DELETE /analysis_jobs/1.json + def destroy + @analysis_job = AnalysisJob.find(params[:id]) + @analysis_job.destroy + + respond_to do |format| + format.html { redirect_to analysis_jobs_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/analysis_scripts_controller.rb b/app/controllers/analysis_scripts_controller.rb new file mode 100644 index 00000000..7a151fbb --- /dev/null +++ b/app/controllers/analysis_scripts_controller.rb @@ -0,0 +1,83 @@ +class AnalysisScriptsController < ApplicationController + # GET /analysis_scripts + # GET /analysis_scripts.json + def index + @analysis_scripts = AnalysisScript.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @analysis_scripts } + end + end + + # GET /analysis_scripts/1 + # GET /analysis_scripts/1.json + def show + @analysis_script = AnalysisScript.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @analysis_script } + end + end + + # GET /analysis_scripts/new + # GET /analysis_scripts/new.json + def new + @analysis_script = AnalysisScript.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @analysis_script } + end + end + + # GET /analysis_scripts/1/edit + def edit + @analysis_script = AnalysisScript.find(params[:id]) + end + + # POST /analysis_scripts + # POST /analysis_scripts.json + def create + @analysis_script = AnalysisScript.new(params[:analysis_script]) + + respond_to do |format| + if @analysis_script.save + format.html { redirect_to @analysis_script, notice: 'Analysis script was successfully created.' } + format.json { render json: @analysis_script, status: :created, location: @analysis_script } + else + format.html { render action: "new" } + format.json { render json: @analysis_script.errors, status: :unprocessable_entity } + end + end + end + + # PUT /analysis_scripts/1 + # PUT /analysis_scripts/1.json + def update + @analysis_script = AnalysisScript.find(params[:id]) + + respond_to do |format| + if @analysis_script.update_attributes(params[:analysis_script]) + format.html { redirect_to @analysis_script, notice: 'Analysis script was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @analysis_script.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /analysis_scripts/1 + # DELETE /analysis_scripts/1.json + def destroy + @analysis_script = AnalysisScript.find(params[:id]) + @analysis_script.destroy + + respond_to do |format| + format.html { redirect_to analysis_scripts_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/api/callbacks_controller.rb b/app/controllers/api/callbacks_controller.rb index 2f1d7562..1fe5f51f 100644 --- a/app/controllers/api/callbacks_controller.rb +++ b/app/controllers/api/callbacks_controller.rb @@ -14,6 +14,7 @@ class Api::CallbacksController < Devise::OmniauthCallbacksController # good info about the omniauth flow # http://www.arailsdemo.com/posts/18 + # oauth example # see https://gist.github.com/993566 # END NOTES diff --git a/app/controllers/api/sessions_controller.rb b/app/controllers/api/sessions_controller.rb index 67d1ece1..f24c621c 100644 --- a/app/controllers/api/sessions_controller.rb +++ b/app/controllers/api/sessions_controller.rb @@ -68,6 +68,8 @@ def ping end end + private + def self.login_info(current_user, user, provider_id) { :response => 'ok', :user_id => user.id, diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8cbe0078..09ffcbdc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -27,8 +27,6 @@ def render_csv(filename = nil) private - - #def set_stamper # User.stamper = current_user if user_signed_in? #end diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 0e235962..b070070a 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -3,6 +3,9 @@ class MediaController < ApplicationController include FileCacher, Mime + # http byte range - doesn't seem to be quite right... :( + #include ByteRange + #respond_to :xml, :json, :html, :png, :ogg, :oga, :webm, :webma, :mp3 def index diff --git a/app/helpers/analysis_items_helper.rb b/app/helpers/analysis_items_helper.rb new file mode 100644 index 00000000..08c56ca5 --- /dev/null +++ b/app/helpers/analysis_items_helper.rb @@ -0,0 +1,2 @@ +module AnalysisItemsHelper +end diff --git a/app/helpers/analysis_jobs_helper.rb b/app/helpers/analysis_jobs_helper.rb new file mode 100644 index 00000000..8ed5dd34 --- /dev/null +++ b/app/helpers/analysis_jobs_helper.rb @@ -0,0 +1,2 @@ +module AnalysisJobsHelper +end diff --git a/app/helpers/analysis_scripts_helper.rb b/app/helpers/analysis_scripts_helper.rb new file mode 100644 index 00000000..e415507f --- /dev/null +++ b/app/helpers/analysis_scripts_helper.rb @@ -0,0 +1,2 @@ +module AnalysisScriptsHelper +end diff --git a/app/models/analysis_item.rb b/app/models/analysis_item.rb new file mode 100644 index 00000000..ca147995 --- /dev/null +++ b/app/models/analysis_item.rb @@ -0,0 +1,18 @@ +class AnalysisItem < ActiveRecord::Base + # relations + belongs_to :audio_recording + belongs_to :analysis_job + + # attr + attr_accessible :offset_end_seconds, :offset_start_seconds, :status, :worker_info, :worker_run_details, :worker_started_utc + + accepts_nested_attributes_for :analysis_job, :audio_recording + + # validations + validates :offset_start_seconds, :presence => true, :numericality => true + validates :offset_end_seconds, :presence => true, :numericality => true + validates :audio_recording_id, :presence => true + # documentation for timeliness: https://github.com/adzap/validates_timeliness + validates :worker_started_utc, :timeliness => { :type => :datetime, :allow_blank => true } + validates :status, :inclusion => { :in => [:ready, :running, :complete, :error] } +end diff --git a/app/models/analysis_job.rb b/app/models/analysis_job.rb new file mode 100644 index 00000000..bbcb7075 --- /dev/null +++ b/app/models/analysis_job.rb @@ -0,0 +1,33 @@ +class AnalysisJob < ActiveRecord::Base + # flex store + store :notes + + # relations + belongs_to :saved_search + + # attr + attr_accessible :data_set_identifier, :description, :name, :notes, + :script_description, :script_display_name, :script_extra_data, :script_name, + :script_settings, :script_version, + :process_new + + accepts_nested_attributes_for :saved_search + + # userstamp + stampable + belongs_to :user, :class_name => 'User', :foreign_key => :creator_id + + # validations + validates :name, :presence => true, :length => { :minimum => 2, :maximum => 100 }, :uniqueness => { :case_sensitive => false } + validates :script_name, :presence => true + validates :script_settings, :presence => true + validates :script_version, :presence => true + validates :script_display_name, :presence => true + validates :process_new, :inclusion => { :in => [true, false] } + validate :data_set_cannot_process_new + + # custom validation methods + def data_set_cannot_process_new + errors.add(:level, "An analysis job that references a data set cannot process new recordings.") if self.data_set_identifier && self.process_new + end +end diff --git a/app/models/analysis_script.rb b/app/models/analysis_script.rb new file mode 100644 index 00000000..edf46257 --- /dev/null +++ b/app/models/analysis_script.rb @@ -0,0 +1,22 @@ +class AnalysisScript < ActiveRecord::Base + # flex store + store :notes + + # attr + attr_accessible :description, :display_name, :extra_data, :name, :settings, :version, :notes, :verified + + # userstamp + stampable + belongs_to :user, :class_name => 'User', :foreign_key => :creator_id + acts_as_paranoid + validates_as_paranoid + + # validations + validates :name, :presence => true, :length => { :minimum => 2, :maximum => 100 }, :uniqueness => { :case_sensitive => false } + validates :display_name, :presence => true + validates :settings, :presence => true + validates :version, :presence => true + validates :display_name, :presence => true + validates :verified, :inclusion => { :in => [true, false] } + +end diff --git a/app/models/user.rb b/app/models/user.rb index 2775a9fc..c8d20a5c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,9 +1,9 @@ class User < ActiveRecord::Base # Include devise modules. - # :registerable, :rememberable, :recoverable, + # :registerable,:rememberable, devise :confirmable, :omniauthable, :token_authenticatable, :trackable, :database_authenticatable, :lockable, - :validatable, :timeoutable + :validatable, :timeoutable, :recoverable # Setup accessible (or protected) attributes for your model attr_accessible :display_name, :email, :password, :admin diff --git a/app/serializers/analysis_item_serializer.rb b/app/serializers/analysis_item_serializer.rb new file mode 100644 index 00000000..03671eaa --- /dev/null +++ b/app/serializers/analysis_item_serializer.rb @@ -0,0 +1,10 @@ + +class AnalysisItemSerializer < ActiveModel::Serializer + attributes :id, :worker_info, :worker_started_utc, :worker_run_details, :status, :offset_start_seconds, :offset_end_seconds + + #has_one :audio_recording + + #has_one :analysis_job + +end + diff --git a/app/serializers/analysis_job_serializer.rb b/app/serializers/analysis_job_serializer.rb new file mode 100644 index 00000000..806113cc --- /dev/null +++ b/app/serializers/analysis_job_serializer.rb @@ -0,0 +1,8 @@ + +class AnalysisJobSerializer < ActiveModel::Serializer + attributes :id, :name, :description, :notes, :script_name, :script_version, :script_description, :script_settings, :script_display_name, :script_extra_data, :data_set_identifier + + #has_one :saved_search + +end + diff --git a/app/serializers/analysis_script_serializer.rb b/app/serializers/analysis_script_serializer.rb new file mode 100644 index 00000000..1b542728 --- /dev/null +++ b/app/serializers/analysis_script_serializer.rb @@ -0,0 +1,6 @@ + +class AnalysisScriptSerializer < ActiveModel::Serializer + attributes :id, :name, :version, :description, :settings, :display_name, :extra_data + +end + diff --git a/app/views/analysis_items/_form.html.erb b/app/views/analysis_items/_form.html.erb new file mode 100644 index 00000000..295be6b6 --- /dev/null +++ b/app/views/analysis_items/_form.html.erb @@ -0,0 +1,49 @@ +<%= form_for(@analysis_item) do |f| %> + <% if @analysis_item.errors.any? %> +
+

<%= pluralize(@analysis_item.errors.count, "error") %> prohibited this analysis_item from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :worker_info %>
+ <%= f.text_field :worker_info %> +
+
+ <%= f.label :worker_started_utc %>
+ <%= f.datetime_select :worker_started_utc %> +
+
+ <%= f.label :worker_run_details %>
+ <%= f.text_area :worker_run_details %> +
+
+ <%= f.label :status %>
+ <%= f.text_field :status %> +
+
+ <%= f.label :offset_start_seconds %>
+ <%= f.text_field :offset_start_seconds %> +
+
+ <%= f.label :offset_end_seconds %>
+ <%= f.text_field :offset_end_seconds %> +
+
+ <%= f.label :audio_recording %>
+ <%= f.text_field :audio_recording %> +
+
+ <%= f.label :analysis_job %>
+ <%= f.text_field :analysis_job %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/analysis_items/edit.html.erb b/app/views/analysis_items/edit.html.erb new file mode 100644 index 00000000..2f89981a --- /dev/null +++ b/app/views/analysis_items/edit.html.erb @@ -0,0 +1,6 @@ +

Editing analysis_item

+ +<%= render 'form' %> + +<%= link_to 'Show', @analysis_item %> | +<%= link_to 'Back', analysis_items_path %> diff --git a/app/views/analysis_items/index.html.erb b/app/views/analysis_items/index.html.erb new file mode 100644 index 00000000..adb3ce04 --- /dev/null +++ b/app/views/analysis_items/index.html.erb @@ -0,0 +1,37 @@ +

Listing analysis_items

+ + + + + + + + + + + + + + + + +<% @analysis_items.each do |analysis_item| %> + + + + + + + + + + + + + +<% end %> +
Worker infoWorker started utcWorker run detailsStatusOffset start secondsOffset end secondsAudio recordingAnalysis job
<%= analysis_item.worker_info %><%= analysis_item.worker_started_utc %><%= analysis_item.worker_run_details %><%= analysis_item.status %><%= analysis_item.offset_start_seconds %><%= analysis_item.offset_end_seconds %><%= analysis_item.audio_recording %><%= analysis_item.analysis_job %><%= link_to 'Show', analysis_item %><%= link_to 'Edit', edit_analysis_item_path(analysis_item) %><%= link_to 'Destroy', analysis_item, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Analysis item', new_analysis_item_path %> diff --git a/app/views/analysis_items/new.html.erb b/app/views/analysis_items/new.html.erb new file mode 100644 index 00000000..eeb8b0b4 --- /dev/null +++ b/app/views/analysis_items/new.html.erb @@ -0,0 +1,5 @@ +

New analysis_item

+ +<%= render 'form' %> + +<%= link_to 'Back', analysis_items_path %> diff --git a/app/views/analysis_items/show.html.erb b/app/views/analysis_items/show.html.erb new file mode 100644 index 00000000..6bb6dd0b --- /dev/null +++ b/app/views/analysis_items/show.html.erb @@ -0,0 +1,45 @@ +

<%= notice %>

+ +

+ Worker info: + <%= @analysis_item.worker_info %> +

+ +

+ Worker started utc: + <%= @analysis_item.worker_started_utc %> +

+ +

+ Worker run details: + <%= @analysis_item.worker_run_details %> +

+ +

+ Status: + <%= @analysis_item.status %> +

+ +

+ Offset start seconds: + <%= @analysis_item.offset_start_seconds %> +

+ +

+ Offset end seconds: + <%= @analysis_item.offset_end_seconds %> +

+ +

+ Audio recording: + <%= @analysis_item.audio_recording %> +

+ +

+ Analysis job: + <%= @analysis_item.analysis_job %> +

+ + +<%= link_to 'Edit', edit_analysis_item_path(@analysis_item) %> | +<%= link_to 'Back', analysis_items_path %> diff --git a/app/views/analysis_jobs/_form.html.erb b/app/views/analysis_jobs/_form.html.erb new file mode 100644 index 00000000..4d8b5403 --- /dev/null +++ b/app/views/analysis_jobs/_form.html.erb @@ -0,0 +1,61 @@ +<%= form_for(@analysis_job) do |f| %> + <% if @analysis_job.errors.any? %> +
+

<%= pluralize(@analysis_job.errors.count, "error") %> prohibited this analysis_job from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :description %>
+ <%= f.text_field :description %> +
+
+ <%= f.label :notes %>
+ <%= f.text_area :notes %> +
+
+ <%= f.label :script_name %>
+ <%= f.text_field :script_name %> +
+
+ <%= f.label :script_version %>
+ <%= f.text_field :script_version %> +
+
+ <%= f.label :script_description %>
+ <%= f.text_field :script_description %> +
+
+ <%= f.label :script_settings %>
+ <%= f.text_field :script_settings %> +
+
+ <%= f.label :script_display_name %>
+ <%= f.text_field :script_display_name %> +
+
+ <%= f.label :script_extra_data %>
+ <%= f.text_area :script_extra_data %> +
+
+ <%= f.label :data_set_identifier %>
+ <%= f.text_field :data_set_identifier %> +
+
+ <%= f.label :saved_search %>
+ <%= f.text_field :saved_search %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/analysis_jobs/edit.html.erb b/app/views/analysis_jobs/edit.html.erb new file mode 100644 index 00000000..2cdd3f3c --- /dev/null +++ b/app/views/analysis_jobs/edit.html.erb @@ -0,0 +1,6 @@ +

Editing analysis_job

+ +<%= render 'form' %> + +<%= link_to 'Show', @analysis_job %> | +<%= link_to 'Back', analysis_jobs_path %> diff --git a/app/views/analysis_jobs/index.html.erb b/app/views/analysis_jobs/index.html.erb new file mode 100644 index 00000000..603e6b5e --- /dev/null +++ b/app/views/analysis_jobs/index.html.erb @@ -0,0 +1,43 @@ +

Listing analysis_jobs

+ + + + + + + + + + + + + + + + + + + +<% @analysis_jobs.each do |analysis_job| %> + + + + + + + + + + + + + + + + +<% end %> +
NameDescriptionNotesScript nameScript versionScript descriptionScript settingsScript display nameScript extra dataDatat set identifierSaved search
<%= analysis_job.name %><%= analysis_job.description %><%= analysis_job.notes %><%= analysis_job.script_name %><%= analysis_job.script_version %><%= analysis_job.script_description %><%= analysis_job.script_settings %><%= analysis_job.script_display_name %><%= analysis_job.script_extra_data %><%= analysis_job.data_set_identifier %><%= analysis_job.saved_search %><%= link_to 'Show', analysis_job %><%= link_to 'Edit', edit_analysis_job_path(analysis_job) %><%= link_to 'Destroy', analysis_job, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Analysis job', new_analysis_job_path %> diff --git a/app/views/analysis_jobs/new.html.erb b/app/views/analysis_jobs/new.html.erb new file mode 100644 index 00000000..800900e3 --- /dev/null +++ b/app/views/analysis_jobs/new.html.erb @@ -0,0 +1,5 @@ +

New analysis_job

+ +<%= render 'form' %> + +<%= link_to 'Back', analysis_jobs_path %> diff --git a/app/views/analysis_jobs/show.html.erb b/app/views/analysis_jobs/show.html.erb new file mode 100644 index 00000000..3475ce2f --- /dev/null +++ b/app/views/analysis_jobs/show.html.erb @@ -0,0 +1,60 @@ +

<%= notice %>

+ +

+ Name: + <%= @analysis_job.name %> +

+ +

+ Description: + <%= @analysis_job.description %> +

+ +

+ Notes: + <%= @analysis_job.notes %> +

+ +

+ Script name: + <%= @analysis_job.script_name %> +

+ +

+ Script version: + <%= @analysis_job.script_version %> +

+ +

+ Script description: + <%= @analysis_job.script_description %> +

+ +

+ Script settings: + <%= @analysis_job.script_settings %> +

+ +

+ Script display name: + <%= @analysis_job.script_display_name %> +

+ +

+ Script extra data: + <%= @analysis_job.script_extra_data %> +

+ +

+ Datat set identifier: + <%= @analysis_job.data_set_identifier %> +

+ +

+ Saved search: + <%= @analysis_job.saved_search %> +

+ + +<%= link_to 'Edit', edit_analysis_job_path(@analysis_job) %> | +<%= link_to 'Back', analysis_jobs_path %> diff --git a/app/views/analysis_scripts/_form.html.erb b/app/views/analysis_scripts/_form.html.erb new file mode 100644 index 00000000..8ffa9513 --- /dev/null +++ b/app/views/analysis_scripts/_form.html.erb @@ -0,0 +1,41 @@ +<%= form_for(@analysis_script) do |f| %> + <% if @analysis_script.errors.any? %> +
+

<%= pluralize(@analysis_script.errors.count, "error") %> prohibited this analysis_script from being saved:

+ + +
+ <% end %> + +
+ <%= f.label :name %>
+ <%= f.text_field :name %> +
+
+ <%= f.label :version %>
+ <%= f.text_field :version %> +
+
+ <%= f.label :description %>
+ <%= f.text_field :description %> +
+
+ <%= f.label :settings %>
+ <%= f.text_field :settings %> +
+
+ <%= f.label :display_name %>
+ <%= f.text_field :display_name %> +
+
+ <%= f.label :extra_data %>
+ <%= f.text_area :extra_data %> +
+
+ <%= f.submit %> +
+<% end %> diff --git a/app/views/analysis_scripts/edit.html.erb b/app/views/analysis_scripts/edit.html.erb new file mode 100644 index 00000000..4e2acf72 --- /dev/null +++ b/app/views/analysis_scripts/edit.html.erb @@ -0,0 +1,6 @@ +

Editing analysis_script

+ +<%= render 'form' %> + +<%= link_to 'Show', @analysis_script %> | +<%= link_to 'Back', analysis_scripts_path %> diff --git a/app/views/analysis_scripts/index.html.erb b/app/views/analysis_scripts/index.html.erb new file mode 100644 index 00000000..65d14de7 --- /dev/null +++ b/app/views/analysis_scripts/index.html.erb @@ -0,0 +1,33 @@ +

Listing analysis_scripts

+ + + + + + + + + + + + + + +<% @analysis_scripts.each do |analysis_script| %> + + + + + + + + + + + +<% end %> +
NameVersionDescriptionSettingsDisplay nameExtra data
<%= analysis_script.name %><%= analysis_script.version %><%= analysis_script.description %><%= analysis_script.settings %><%= analysis_script.display_name %><%= analysis_script.extra_data %><%= link_to 'Show', analysis_script %><%= link_to 'Edit', edit_analysis_script_path(analysis_script) %><%= link_to 'Destroy', analysis_script, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Analysis script', new_analysis_script_path %> diff --git a/app/views/analysis_scripts/new.html.erb b/app/views/analysis_scripts/new.html.erb new file mode 100644 index 00000000..4df1e1f1 --- /dev/null +++ b/app/views/analysis_scripts/new.html.erb @@ -0,0 +1,5 @@ +

New analysis_script

+ +<%= render 'form' %> + +<%= link_to 'Back', analysis_scripts_path %> diff --git a/app/views/analysis_scripts/show.html.erb b/app/views/analysis_scripts/show.html.erb new file mode 100644 index 00000000..76df2c59 --- /dev/null +++ b/app/views/analysis_scripts/show.html.erb @@ -0,0 +1,35 @@ +

<%= notice %>

+ +

+ Name: + <%= @analysis_script.name %> +

+ +

+ Version: + <%= @analysis_script.version %> +

+ +

+ Description: + <%= @analysis_script.description %> +

+ +

+ Settings: + <%= @analysis_script.settings %> +

+ +

+ Display name: + <%= @analysis_script.display_name %> +

+ +

+ Extra data: + <%= @analysis_script.extra_data %> +

+ + +<%= link_to 'Edit', edit_analysis_script_path(@analysis_script) %> | +<%= link_to 'Back', analysis_scripts_path %> diff --git a/lib/external/analysis_runner.rb b/lib/external/analysis_runner.rb index 548c972d..823a591c 100644 --- a/lib/external/analysis_runner.rb +++ b/lib/external/analysis_runner.rb @@ -76,16 +76,16 @@ def run_once_file(file_path) Trollop::die :login_email, 'must be given' if opts[:login_email].nil? Trollop::die :login_password, 'must be given' if opts[:login_password].nil? -analysisRunner = AnalysisRunner::Runner.new( +analysis_runner = AnalysisRunner::Runner.new( 'localhost', 3000, '/media/', '/media/', '/media/', opts[:base_dir], opts[:analysis_script]) # run the script for a directory if opts[:dir] - analysisRunner.run_once_dir opts[:dir] + analysis_runner.run_once_dir opts[:dir] end # run the script for a single file if opts[:file] - analysisRunner.run_once_file opts[:file] + analysis_runner.run_once_file opts[:file] end \ No newline at end of file diff --git a/lib/modules/byte_range.rb b/lib/modules/byte_range.rb new file mode 100644 index 00000000..44ebaa1e --- /dev/null +++ b/lib/modules/byte_range.rb @@ -0,0 +1,73 @@ +# from +# http://code.google.com/p/http-byte-range/source/browse/trunk/plugins/byte_range/lib/byte_range.rb +# MIT license: http://code.google.com/p/http-byte-range/source/browse/trunk/plugins/byte_range/MIT-LICENSE +module ByteRange + def self.included(base) + base.send :include, InstanceMethods + base.class_eval do + after_filter :byte_range + end + end + + module InstanceMethods + protected + def byte_range + ranges = request.env['HTTP_RANGE'] + if ranges + response.headers['Accept-Ranges'] = 'bytes' + response.headers['Status'] = '206' + content_range = 'bytes ' + range = split_ranges(ranges).first + content_range << range.to_s + content_range << "/#{response.headers['Content-Length']}" + if response.body.respond_to?(:length) + response.body = response.body[range.first, range.read_length] + else + response.body = get_data_from_stream(range, response.body) + end + response.headers['Content-Range'] = content_range + response.headers['Content-Length'] = range.read_length + else + response.headers['Accept-Ranges'] = 'bytes' + end + end + + def split_ranges(ranges) + ranges.split(/,/).map {|range| HttpByteRangeSpecifier.new(range)} + end + + def get_data_from_stream(range, rails_stream) + count = 0 + out = StringIO.new + rails_stream.call(nil, out) while out.length < range.last + out.seek(range.first, IO::SEEK_SET) + out.read(range.read_length) + end + end + + class HttpByteRangeSpecifier + attr_reader :first, :last + + def initialize(range) + @first, @last = parse(range) + end + + def read_length + @last - @first + 1 + end + + def to_s + if @first && @last + "#@first-#@last" + end + end + + protected + def parse(range) + case range + when /(\d+)-(\d+)/ + return $1.to_i, $2.to_i + end + end + end +end \ No newline at end of file