Class: Debci::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/debci/graph.rb

Overview

This class represents different data charts for a specific suite and architecture.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, suite, architecture) ⇒ Graph

Returns a new instance of Graph



13
14
15
16
17
18
# File 'lib/debci/graph.rb', line 13

def initialize(repository, suite, architecture)
  @repository = repository
  @suite = suite
  @architecture = architecture
  @data = get_data
end

Instance Attribute Details

#dateObject

Returns the value of attribute date



11
12
13
# File 'lib/debci/graph.rb', line 11

def date
  @date
end

#failObject

Returns the value of attribute fail



11
12
13
# File 'lib/debci/graph.rb', line 11

def fail
  @fail
end

#passObject

Returns the value of attribute pass



11
12
13
# File 'lib/debci/graph.rb', line 11

def pass
  @pass
end

#pass_percentageObject

Returns the value of attribute pass_percentage



11
12
13
# File 'lib/debci/graph.rb', line 11

def pass_percentage
  @pass_percentage
end

#tmpfailObject

Returns the value of attribute tmpfail



11
12
13
# File 'lib/debci/graph.rb', line 11

def tmpfail
  @tmpfail
end

#totalObject

Returns the value of attribute total



11
12
13
# File 'lib/debci/graph.rb', line 11

def total
  @total
end

Instance Method Details

#current_value(field) ⇒ Object

Returns the value of the last data entry for the specified field



21
22
23
24
# File 'lib/debci/graph.rb', line 21

def current_value(field)
  data = @data.send(field)
  data[-1] || 0
end

#get_dataObject

Read the status data



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/debci/graph.rb', line 34

def get_data
  data = @repository.status_history(@suite, @architecture)

  return unless data

  entries = self

  entries.date = data.map { |entry| Time.parse(entry['date'] + ' UTC') }
  entries.pass = data.map { |entry| entry['pass'] }
  entries.fail = data.map { |entry| entry['fail'] }
  entries.tmpfail = data.map { |entry| entry['tmpfail'] ? entry['tmpfail'] : 0 }
  entries.total = data.map { |entry| entry['total'] }
  entries.pass_percentage = data.map { |entry| entry['pass'].to_f / entry['total'].to_f }

  entries
end

#previous_value(field) ⇒ Object

Returns the value of the second to last data entry for the specified field



28
29
30
31
# File 'lib/debci/graph.rb', line 28

def previous_value(field)
  data = @data.send(field)
  data[-2] || 0
end