Module: MiGA::Dataset::Result

Includes:
Common::WithResult, Base
Included in:
MiGA::Dataset
Defined in:
lib/miga/dataset/result.rb

Overview

Helper module including specific functions to add dataset results

Instance Method Summary collapse

Methods included from Common::WithResult

#add_result, #each_result, #get_result, #next_task, #recalculate_tasks, #result, #result_dirs, #results

Instance Method Details

#cleanup_distances!Object

Clean-up all the stored distances, removing values for datasets no longer in the project as reference datasets.



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/miga/dataset/result.rb', line 138

def cleanup_distances!
  r = get_result(:distances)
  return if r.nil?

  require 'miga/sqlite'
  ref = project.datasets.select(&:ref?).select(&:active?).map(&:name)
  %i[haai_db aai_db ani_db].each do |db_type|
    db = r.file_path(db_type)
    next if db.nil? || !File.size?(db)

    sqlite_db = MiGA::SQLite.new(db)
    table = db_type[-6..-4]
    val = sqlite_db.run("select seq2 from #{table}")
    next if val.empty?

    (val.map(&:first) - ref).each do |extra|
      sqlite_db.run("delete from #{table} where seq2=?", extra)
    end
  end
end

#done_preprocessing?(save = false) ⇒ Boolean

Are all the dataset-specific tasks done? Passes save to #add_result

Returns:

  • (Boolean)


86
87
88
# File 'lib/miga/dataset/result.rb', line 86

def done_preprocessing?(save = false)
  !first_preprocessing(save).nil? && next_preprocessing(save).nil?
end

#first_preprocessing(save = false) ⇒ Object

Returns the key symbol of the first registered result (sorted by the execution order). This typically corresponds to the result used as the initial input. Passes save to #add_result.



70
71
72
73
74
# File 'lib/miga/dataset/result.rb', line 70

def first_preprocessing(save = false)
  @first_processing ||= @@PREPROCESSING_TASKS.find do |t|
    !add_result(t, save).nil?
  end
end

#ignore_task?(task) ⇒ Boolean

Should I ignore task for this dataset?

Returns:

  • (Boolean)


24
25
26
# File 'lib/miga/dataset/result.rb', line 24

def ignore_task?(task)
  why_ignore(task) != :execute
end

#next_preprocessing(save = false) ⇒ Object

Returns the key symbol of the next task that needs to be executed or nil. Passes save to #add_result.



79
80
81
82
# File 'lib/miga/dataset/result.rb', line 79

def next_preprocessing(save = false)
  first_preprocessing(save) if save
  next_task(nil, save)
end

#profile_advance(save = false) ⇒ Object

Returns an array indicating the stage of each task (sorted by execution order). The values are integers:

  • 0 for an undefined result (a task before the initial input).

  • 1 for a registered result (a completed task).

  • 2 for a queued result (a task yet to be executed).

It passes save to #add_result



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/miga/dataset/result.rb', line 97

def profile_advance(save = false)
  first_task = first_preprocessing(save)
  return Array.new(@@PREPROCESSING_TASKS.size, 0) if first_task.nil?

  adv = []
  state = 0
  next_task = next_preprocessing(save)
  @@PREPROCESSING_TASKS.each do |task|
    state = 1 if first_task == task
    state = 2 if !next_task.nil? && next_task == task
    adv << state
  end
  adv
end

#result_baseObject

Return the basename for results



18
19
20
# File 'lib/miga/dataset/result.rb', line 18

def result_base
  name
end

#result_status(task) ⇒ Object

Returns the status of task. The status values are symbols:

  • -: the task is upstream from the initial input

  • ignore_*: the task is to be ignored, see codes in #why_ignore

  • complete: a task with registered results

  • pending: a task queued to be performed



125
126
127
128
129
130
131
132
133
# File 'lib/miga/dataset/result.rb', line 125

def result_status(task)
  reason = why_ignore(task)
  case reason
  when :upstream; :-
  when :execute; :pending
  when :complete; :complete
  else; :"ignore_#{reason}"
  end
end

#results_statusObject

Returns a Hash with tasks as key and status as value. See result_status for possible values



115
116
117
# File 'lib/miga/dataset/result.rb', line 115

def results_status
  Hash[@@PREPROCESSING_TASKS.map { |task| [task, result_status(task)] }]
end

#why_ignore(task) ⇒ Object

Return a code explaining why a task is ignored. The values are symbols:

  • empty: the dataset has no data

  • inactive: the dataset is inactive

  • upstream: the task is upstream from dataset’s input

  • force: forced to ignore by metadata

  • project: incompatible project

  • noref: incompatible dataset, only for reference

  • multi: incompatible dataset, only for multi

  • nonmulti: incompatible dataset, only for nonmulti

  • complete: the task is already complete

  • execute: do not ignore, execute the task



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/miga/dataset/result.rb', line 41

def why_ignore(task)
  if !get_result(task).nil?
    :complete
  elsif !active?
    :inactive
  elsif first_preprocessing.nil?
    :empty
  elsif @@PREPROCESSING_TASKS.index(task) <
        @@PREPROCESSING_TASKS.index(first_preprocessing)
    :upstream
  elsif !["run_#{task}"].nil?
    ["run_#{task}"] ? :execute : :force
  elsif task == :taxonomy && project.option(:ref_project).nil?
    :project
  elsif @@_EXCLUDE_NOREF_TASKS_H[task] && !ref?
    :noref
  elsif @@_ONLY_MULTI_TASKS_H[task] && !multi?
    :multi
  elsif @@_ONLY_NONMULTI_TASKS_H[task] && !nonmulti?
    :nonmulti
  else
    :execute
  end
end