Skip to content

Commit

Permalink
Stuff media files into their own table
Browse files Browse the repository at this point in the history
  • Loading branch information
HD Moore committed Dec 28, 2012
1 parent 65579c3 commit 62d6590
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 73 deletions.
2 changes: 1 addition & 1 deletion app/controllers/analyze_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def resource
cpath = nil
cdata = "File not found"

res = DialResult.find(params[:result_id])
res = DialResultMedium.where(:dial_result_id => params[:result_id].to_i).first

if res
case params[:type]
Expand Down
36 changes: 14 additions & 22 deletions app/controllers/dial_results_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ def view
:per_page => 30
)

if(@dial_results)
@call_results = {
:Timeout => DialResult.count(:conditions =>['dial_job_id = ? and completed = ?', params[:id], false]),
:Busy => DialResult.count(:conditions =>['dial_job_id = ? and busy = ?', params[:id], true]),
:Answered => DialResult.count(:conditions =>['dial_job_id = ? and completed = ?', params[:id], true]),
}
unless @dial_results and @dial_results.length > 0
redirect_to :action => :index
return
end
@call_results = {
:Timeout => DialResult.count(:conditions =>['dial_job_id = ? and completed = ?', params[:id], false]),
:Busy => DialResult.count(:conditions =>['dial_job_id = ? and busy = ?', params[:id], true]),
:Answered => DialResult.count(:conditions =>['dial_job_id = ? and completed = ?', params[:id], true]),
}

respond_to do |format|
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @dial_results }
end
Expand All @@ -98,6 +100,11 @@ def view
def show
@dial_result = DialResult.find(params[:id])

unless @dial_result
redirect_to :action => :index
return
end

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @dial_result }
Expand Down Expand Up @@ -159,23 +166,8 @@ def update
def purge

@job = DialJob.find(params[:id])
@job.dial_results.each do |r|
r.destroy
end
@job.destroy

dir = nil
jid = @job.id
dfd = Dir.new(WarVOX::Config.data_path)
dfd.entries.each do |ent|
j,m = ent.split('-', 2)
if (m and j == jid)
dir = File.join(WarVOX::Config.data_path, ent)
end
end

FileUtils.rm_rf(dir) if dir

respond_to do |format|
format.html { redirect_to :action => 'index' }
format.xml { head :ok }
Expand Down
2 changes: 1 addition & 1 deletion app/models/dial_job.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DialJob < ActiveRecord::Base
attr_accessor :range_file

has_many :dial_results
has_many :dial_results, :dependent => :destroy

validates_presence_of :range, :lines, :seconds
validates_numericality_of :lines, :less_than => 256, :greater_than => 0
Expand Down
12 changes: 11 additions & 1 deletion app/models/dial_result.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DialResult < ActiveRecord::Base
belongs_to :provider
belongs_to :dial_job

has_one :dial_result_medium, :dependent => :delete

has_many :matches, :class_name => 'DialResult', :finder_sql => proc {
'SELECT dial_results.*, ' +
Expand All @@ -21,4 +21,14 @@ class DialResult < ActiveRecord::Base
"dial_results.id != \'#{id}\' " +
'ORDER BY matchscore DESC'
}


def media
DialResultMedium.find_or_create_by_dial_result_id(self[:id])
end

def media_fields
DialResultMedium.columns_hash.keys.reject{|x| x =~ /^id|_id$/}
end

end
3 changes: 3 additions & 0 deletions app/models/dial_result_medium.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class DialResultMedium < ActiveRecord::Base
belongs_to :dial_result
end
6 changes: 4 additions & 2 deletions bin/analyze_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
#

inp = ARGV.shift || exit(0)
$0 = "warvox(analyzer): #{inp}"
num = ARGV.shift || exit(0)

$0 = "warvox(analyzer): #{inp} #{num}"

$stdout.write(
Marshal.dump(
WarVOX::Jobs::CallAnalysis.new(
0
).analyze_call(
inp
inp, num
)
)
)
11 changes: 6 additions & 5 deletions bin/export_audio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def usage
if(not job)
$stderr.puts "Listing all available jobs"
$stderr.puts "=========================="
DialJob.find(:all).each do |j|
DialJob.all.each do |j|
puts "#{j.id}\t#{j.started_at} --> #{j.completed_at}"
end
exit
Expand All @@ -51,13 +51,14 @@ def usage

begin
cnt = 0
job = DialJob.find(job.to_i)
job.dial_results.each do |r|
DialResult.where(:dial_job_id => job.to_i).find_each do |r|
next if not r.number
next if r.audio.to_s.length == 0
m = r.media
next if not m
next if m.audio.to_s.length == 0
out = ::File.join(dir, "#{r.number}.raw")
::File.open(out, "wb") do |fd|
fd.write( r.audio )
fd.write( m.audio )
end
cnt += 1
end
Expand Down
71 changes: 71 additions & 0 deletions db/migrate/20121228171549_initial_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class InitialSchema < ActiveRecord::Migration
def up

# Require the intarray extension
execute("CREATE EXTENSION IF NOT EXISTS intarray")

create_table "dial_jobs" do |t|
t.timestamps
t.text "range"
t.integer "seconds"
t.integer "lines"
t.text "status"
t.integer "progress"
t.datetime "started_at"
t.datetime "completed_at"
t.boolean "processed"
t.text "cid_mask"
end

create_table "dial_results" do |t|
t.timestamps
t.text "number"
t.integer "dial_job_id"
t.integer "provider_id"
t.boolean "completed"
t.boolean "busy"
t.integer "seconds"
t.integer "ringtime"
t.boolean "processed"
t.datetime "processed_at"
t.text "cid"
t.float "peak_freq"
t.text "peak_freq_data"
t.text "sig_data"
t.text "line_type"
t.text "notes"
t.text "signatures"
t.integer "fprint", :array => true
end

create_table "dial_result_media" do |t|
t.integer "dial_result_id"
t.binary "audio"
t.binary "mp3"
t.binary "png_big"
t.binary "png_big_dots"
t.binary "png_big_freq"
t.binary "png_sig"
t.binary "png_sig_freq"
end

create_table "providers" do |t|
t.timestamps
t.text "name"
t.text "host"
t.integer "port"
t.text "user"
t.text "pass"
t.integer "lines"
t.boolean "enabled"
end

end

def down
remove_table "providers"
remove_table "dial_result_media"
remove_table "dial_results"
remove_table "dial_jobs"
end
end
38 changes: 20 additions & 18 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20110801000003) do
ActiveRecord::Schema.define(:version => 20121228171549) do

# Require the intarray extension
execute "CREATE EXTENSION IF NOT EXISTS intarray"
add_extension "intarray"

create_table "dial_jobs", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "range"
t.integer "seconds"
t.integer "lines"
Expand All @@ -25,23 +26,31 @@
t.datetime "started_at"
t.datetime "completed_at"
t.boolean "processed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "cid_mask"
end

create_table "dial_result_media", :force => true do |t|
t.integer "dial_result_id"
t.binary "audio"
t.binary "mp3"
t.binary "png_big"
t.binary "png_big_dots"
t.binary "png_big_freq"
t.binary "png_sig"
t.binary "png_sig_freq"
end

create_table "dial_results", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "number"
t.integer "dial_job_id"
t.integer "provider_id"
t.boolean "completed"
t.boolean "busy"
t.integer "seconds"
t.integer "ringtime"
t.text "rawfile"
t.boolean "processed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "processed_at"
t.text "cid"
t.float "peak_freq"
Expand All @@ -50,25 +59,18 @@
t.text "line_type"
t.text "notes"
t.text "signatures"
t.integer "fprint", :array => true
t.binary "audio"
t.binary "mp3"
t.binary "png_big"
t.binary "png_big_dots"
t.binary "png_big_freq"
t.binary "png_sig"
t.binary "png_sig_freq"
t.integer "fprint", :array => true
end

create_table "providers", :force => true do |t|
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "name"
t.text "host"
t.integer "port"
t.text "user"
t.text "pass"
t.integer "lines"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "enabled"
end

Expand Down
Loading

0 comments on commit 62d6590

Please sign in to comment.