Class: Vangrail::Judgement

Inherits:
Struct
  • Object
show all
Defined in:
lib/vangrail/judgement.rb

Overview

What to do with a posterior, and what the numbers were.

A Result answers "did a rail stop this". A Judgement answers a different question: given everything that ran, how likely is it that this text is an attack, and is that likely enough to act on. The two are not interchangeable and the second is the one an operator can set a policy against.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def action
  @action
end

#bitsObject

Returns the value of attribute bits

Returns:

  • (Object)

    the current value of bits



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def bits
  @bits
end

#certainObject

Returns the value of attribute certain

Returns:

  • (Object)

    the current value of certain



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def certain
  @certain
end

#contributionsObject

Returns the value of attribute contributions

Returns:

  • (Object)

    the current value of contributions



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def contributions
  @contributions
end

#originObject

Returns the value of attribute origin

Returns:

  • (Object)

    the current value of origin



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def origin
  @origin
end

#posteriorObject

Returns the value of attribute posterior

Returns:

  • (Object)

    the current value of posterior



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def posterior
  @posterior
end

#priorObject

Returns the value of attribute prior

Returns:

  • (Object)

    the current value of prior



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def prior
  @prior
end

#sideObject

Returns the value of attribute side

Returns:

  • (Object)

    the current value of side



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def side
  @side
end

#skippedObject

Rails not run because the action was already settled: no remaining evidence could have changed it. Different in kind from a rail that could not run, which is why this is a separate field from certain?.



12
13
14
# File 'lib/vangrail/judgement.rb', line 12

def skipped
  @skipped
end

Instance Method Details

#allow?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/vangrail/judgement.rb', line 22

def allow?
  action == :allow
end

#block?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/vangrail/judgement.rb', line 14

def block?
  action == :block
end

#certain?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/vangrail/judgement.rb', line 26

def certain?
  certain
end

#channelObject



49
50
51
# File 'lib/vangrail/judgement.rb', line 49

def channel
  origin&.channel
end

#factorObject

How far the evidence moved the odds, as a multiplier. Bits are the honest unit and this is the readable one.



38
39
40
# File 'lib/vangrail/judgement.rb', line 38

def factor
  2**bits
end

#firedObject

The rails that fired, most telling first, which is what a person reading a flagged page wants before anything else.



32
33
34
# File 'lib/vangrail/judgement.rb', line 32

def fired
  contributions.select { |c| c[:fired] }.sort_by { |c| -c[:bits] }
end

#review?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/vangrail/judgement.rb', line 18

def review?
  action == :review
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vangrail/judgement.rb', line 53

def to_h
  {
    'side' => side.to_s,
    'origin' => origin&.to_s,
    'channel' => channel&.to_s,
    'prior' => prior,
    'posterior' => posterior.round(6),
    'bits' => bits.round(2),
    'action' => action.to_s,
    'certain' => certain?,
    'fired' => fired.map { |c| { 'rail' => c[:rail], 'bits' => c[:bits].round(2) } },
    'skipped' => (skipped unless skipped.empty?),
  }.compact
end

#to_sObject



68
69
70
71
72
73
74
# File 'lib/vangrail/judgement.rb', line 68

def to_s
  parts = [format('%<action>s p=%<posterior>.4f (prior %<prior>g, %<bits>+.1f bits)',
                  action: action, posterior: posterior, prior: prior, bits: bits)]
  parts << "fired: #{fired.map { |c| c[:rail] }.join(', ')}" unless fired.empty?
  parts << 'uncertain' unless certain?
  parts.join(' ')
end