reflekt 1.0.2 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/{Accessor.rb → accessor.rb} +0 -0
- data/lib/{Execution.rb → action.rb} +12 -12
- data/lib/action_stack.rb +44 -0
- data/lib/{Clone.rb → clone.rb} +4 -4
- data/lib/{Config.rb → config.rb} +1 -1
- data/lib/{Control.rb → control.rb} +14 -12
- data/lib/experiment.rb +81 -0
- data/lib/{Meta.rb → meta.rb} +5 -5
- data/lib/meta/{ArrayMeta.rb → array_meta.rb} +1 -1
- data/lib/meta/{BooleanMeta.rb → boolean_meta.rb} +1 -1
- data/lib/meta/{FloatMeta.rb → float_meta.rb} +1 -1
- data/lib/meta/{IntegerMeta.rb → integer_meta.rb} +1 -1
- data/lib/meta/{NullMeta.rb → null_meta.rb} +2 -2
- data/lib/meta/{StringMeta.rb → string_meta.rb} +1 -1
- data/lib/{MetaBuilder.rb → meta_builder.rb} +2 -2
- data/lib/reflection.rb +148 -0
- data/lib/{Reflekt.rb → reflekt.rb} +42 -42
- data/lib/{Renderer.rb → renderer.rb} +0 -0
- data/lib/{Rule.rb → rule.rb} +1 -1
- data/lib/{RuleSet.rb → rule_set.rb} +3 -3
- data/lib/{Aggregator.rb → rule_set_aggregator.rb} +27 -18
- data/lib/rules/{ArrayRule.rb → array_rule.rb} +1 -1
- data/lib/rules/{BooleanRule.rb → boolean_rule.rb} +1 -1
- data/lib/rules/{FloatRule.rb → float_rule.rb} +1 -1
- data/lib/rules/{IntegerRule.rb → integer_rule.rb} +1 -1
- data/lib/rules/{NullRule.rb → null_rule.rb} +3 -6
- data/lib/rules/{StringRule.rb → string_rule.rb} +1 -1
- data/lib/web/bundle.js +2 -2
- data/lib/web/package-lock.json +3 -3
- data/lib/web/package.json +1 -1
- data/lib/web/server.js +5 -5
- metadata +30 -29
- data/lib/Reflection.rb +0 -193
- data/lib/ShadowStack.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f733fd18e6885b020065ce5e52e352caf9bcdc38f3459ab4d322d4b1c7870e
|
4
|
+
data.tar.gz: 8715db31d91effbb04ba99a6b79f973bfd17ebd1c1976328d186c344cb7c2edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbbd92db72d16a5e0fe31d526e820c8844b4ca514ee7eb85360e5a4e9d05dacd685c2a5af1f233653af0cd506f7c48cf46b16195975c5fe64ab5b6c43b633f74
|
7
|
+
data.tar.gz: af79125c63aae1e1437d133ae66d5a6fbd313baaf60295d864528f0388a2ba9c6b6d7d9ada8c8319f963db0c2dc8c40d6446d727ca0fdc3af80f64fa5d073cb5
|
File without changes
|
@@ -1,13 +1,13 @@
|
|
1
1
|
################################################################################
|
2
|
-
# A shadow
|
2
|
+
# A shadow action.
|
3
3
|
#
|
4
4
|
# @hierachy
|
5
|
-
# 1.
|
5
|
+
# 1. Action <- YOU ARE HERE
|
6
6
|
# 2. Reflection
|
7
7
|
# 3. Meta
|
8
8
|
################################################################################
|
9
9
|
|
10
|
-
class
|
10
|
+
class Action
|
11
11
|
|
12
12
|
attr_accessor :unique_id
|
13
13
|
attr_accessor :caller_object
|
@@ -19,17 +19,17 @@ class Execution
|
|
19
19
|
attr_accessor :parent
|
20
20
|
attr_accessor :child
|
21
21
|
attr_accessor :control
|
22
|
-
attr_accessor :
|
22
|
+
attr_accessor :experiments
|
23
23
|
attr_accessor :is_reflecting
|
24
24
|
attr_accessor :is_base
|
25
25
|
|
26
26
|
##
|
27
|
-
# Create
|
27
|
+
# Create Action.
|
28
28
|
#
|
29
29
|
# @param object [Object] The calling object.
|
30
30
|
# @param method [Symbol] The calling method.
|
31
|
-
# @param reflect_amount [Integer] The number of
|
32
|
-
# @param stack [
|
31
|
+
# @param reflect_amount [Integer] The number of experiments to create per action.
|
32
|
+
# @param stack [ActionStack] The shadow action call stack.
|
33
33
|
##
|
34
34
|
def initialize(caller_object, method, reflect_amount, stack)
|
35
35
|
|
@@ -51,7 +51,7 @@ class Execution
|
|
51
51
|
|
52
52
|
# Reflections.
|
53
53
|
@control = nil
|
54
|
-
@
|
54
|
+
@experiments = Array.new(reflect_amount)
|
55
55
|
|
56
56
|
# State.
|
57
57
|
if @stack.peek() == nil
|
@@ -64,12 +64,12 @@ class Execution
|
|
64
64
|
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
@
|
67
|
+
def has_empty_experiments?
|
68
|
+
@experiments.include? nil
|
69
69
|
end
|
70
70
|
|
71
71
|
##
|
72
|
-
# Is the
|
72
|
+
# Is the Action currently reflecting methods?
|
73
73
|
##
|
74
74
|
def is_reflecting?
|
75
75
|
@is_reflecting
|
@@ -79,7 +79,7 @@ class Execution
|
|
79
79
|
if is_reflecting?
|
80
80
|
return false
|
81
81
|
end
|
82
|
-
if
|
82
|
+
if has_empty_experiments?
|
83
83
|
return false
|
84
84
|
end
|
85
85
|
return true
|
data/lib/action_stack.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Track the actions in a shadow call stack.
|
3
|
+
#
|
4
|
+
# @pattern Stack
|
5
|
+
################################################################################
|
6
|
+
|
7
|
+
class ActionStack
|
8
|
+
|
9
|
+
def initialize()
|
10
|
+
@bottom = nil
|
11
|
+
@top = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def peek()
|
15
|
+
@top
|
16
|
+
end
|
17
|
+
|
18
|
+
def base()
|
19
|
+
@bottom
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Place Action at the top of stack.
|
24
|
+
#
|
25
|
+
# @param action [Action] The action to place.
|
26
|
+
# @return [Action] The placed action.
|
27
|
+
##
|
28
|
+
def push(action)
|
29
|
+
|
30
|
+
# Place first action at bottom of stack.
|
31
|
+
if @bottom.nil?
|
32
|
+
@bottom = action
|
33
|
+
# Connect subsequent actions to each other.
|
34
|
+
else
|
35
|
+
@top.parent = action
|
36
|
+
action.child = @top
|
37
|
+
end
|
38
|
+
|
39
|
+
# Place action at top of stack.
|
40
|
+
@top = action
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/{Clone.rb → clone.rb}
RENAMED
@@ -7,17 +7,17 @@
|
|
7
7
|
# on object, not indirectly through clone which results in "undefined method".
|
8
8
|
#
|
9
9
|
# @hierachy
|
10
|
-
# 1.
|
10
|
+
# 1. Action
|
11
11
|
# 2. Reflection
|
12
12
|
# 3. Clone <- YOU ARE HERE
|
13
13
|
################################################################################
|
14
14
|
|
15
15
|
class Clone
|
16
16
|
|
17
|
-
def initialize(
|
17
|
+
def initialize(action)
|
18
18
|
|
19
|
-
# Clone the
|
20
|
-
@caller_object_clone =
|
19
|
+
# Clone the action's calling object.
|
20
|
+
@caller_object_clone = action.caller_object.clone
|
21
21
|
|
22
22
|
# TODO: Clone any other instances that this clone references.
|
23
23
|
# TODO: Replace clone's references to these new instances.
|
data/lib/{Config.rb → config.rb}
RENAMED
@@ -2,13 +2,13 @@
|
|
2
2
|
# A shapshot of real data.
|
3
3
|
#
|
4
4
|
# @note
|
5
|
-
# A control's @number
|
5
|
+
# A control's @number will always be 0.
|
6
6
|
#
|
7
7
|
# @nomenclature
|
8
8
|
# args, inputs/output and meta represent different stages of a value.
|
9
9
|
#
|
10
10
|
# @hierachy
|
11
|
-
# 1.
|
11
|
+
# 1. Action
|
12
12
|
# 2. Control <- YOU ARE HERE
|
13
13
|
# 3. Meta
|
14
14
|
#
|
@@ -18,43 +18,45 @@
|
|
18
18
|
# - :error [Symbol] The control reflection produces a system error.
|
19
19
|
################################################################################
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
require_relative 'reflection'
|
22
|
+
require_relative 'meta_builder'
|
23
23
|
|
24
24
|
class Control < Reflection
|
25
25
|
|
26
26
|
##
|
27
27
|
# Reflect on a method.
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# Create a shadow action.
|
30
30
|
# @param *args [Dynamic] The method's arguments.
|
31
31
|
##
|
32
32
|
def reflect(*args)
|
33
33
|
|
34
|
-
# Get
|
34
|
+
# Get trained rule sets.
|
35
35
|
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
36
36
|
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
37
37
|
|
38
|
+
# Fail when no trained rule sets.
|
39
|
+
if input_rule_sets.nil?
|
40
|
+
@status = :fail
|
41
|
+
end
|
42
|
+
|
38
43
|
# When arguments exist.
|
39
44
|
unless args.size == 0
|
40
45
|
|
41
|
-
#
|
46
|
+
# Validate arguments against trained rule sets.
|
42
47
|
unless input_rule_sets.nil?
|
43
|
-
|
44
|
-
# Validate arguments against aggregated rule sets.
|
45
48
|
unless @aggregator.test_inputs(args, input_rule_sets)
|
46
49
|
@status = :fail
|
47
50
|
end
|
48
|
-
|
49
51
|
end
|
50
52
|
|
51
53
|
# Create metadata for each argument.
|
52
|
-
# TODO: Create metadata for other inputs such as
|
54
|
+
# TODO: Create metadata for other inputs such as instance variables.
|
53
55
|
@inputs = MetaBuilder.create_many(args)
|
54
56
|
|
55
57
|
end
|
56
58
|
|
57
|
-
# Action method with
|
59
|
+
# Action method with real arguments.
|
58
60
|
begin
|
59
61
|
|
60
62
|
# Run reflection.
|
data/lib/experiment.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
################################################################################
|
2
|
+
# A snapshot of random data.
|
3
|
+
#
|
4
|
+
# @note
|
5
|
+
# A reflection's random values are generated from aggregated control rule sets.
|
6
|
+
#
|
7
|
+
# @nomenclature
|
8
|
+
# args, inputs/output and meta represent different stages of a value.
|
9
|
+
#
|
10
|
+
# @hierachy
|
11
|
+
# 1. Action
|
12
|
+
# 2. Experiment <- YOU ARE HERE
|
13
|
+
# 3. Meta
|
14
|
+
#
|
15
|
+
# @status
|
16
|
+
# - :pass [Symbol] The reflection passes the rules.
|
17
|
+
# - :fail [Symbol] The reflection fails the rules or produces a system error.
|
18
|
+
# - :error [Symbol] The control reflection produces a system error.
|
19
|
+
################################################################################
|
20
|
+
|
21
|
+
require_relative 'reflection'
|
22
|
+
require_relative 'meta_builder'
|
23
|
+
|
24
|
+
class Experiment < Reflection
|
25
|
+
|
26
|
+
##
|
27
|
+
# Reflect on a method.
|
28
|
+
#
|
29
|
+
# Create a shadow action.
|
30
|
+
# @param *args [Dynamic] The method's arguments.
|
31
|
+
##
|
32
|
+
def reflect(*args)
|
33
|
+
|
34
|
+
# Get aggregated rule sets.
|
35
|
+
input_rule_sets = @aggregator.get_input_rule_sets(@klass, @method)
|
36
|
+
output_rule_set = @aggregator.get_output_rule_set(@klass, @method)
|
37
|
+
|
38
|
+
# Fail when no trained rule sets.
|
39
|
+
if input_rule_sets.nil?
|
40
|
+
@status = :fail
|
41
|
+
end
|
42
|
+
|
43
|
+
# When arguments exist.
|
44
|
+
unless args.size == 0
|
45
|
+
|
46
|
+
# Create random arguments from aggregated rule sets.
|
47
|
+
unless input_rule_sets.nil?
|
48
|
+
args = randomize(args, input_rule_sets)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create metadata for each argument.
|
52
|
+
# TODO: Create metadata for other inputs such as instance variables.
|
53
|
+
@inputs = MetaBuilder.create_many(args)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
# Action method with random arguments.
|
58
|
+
begin
|
59
|
+
|
60
|
+
# Run reflection.
|
61
|
+
output = @clone.send(@method, *args)
|
62
|
+
@output = MetaBuilder.create(output)
|
63
|
+
|
64
|
+
# Validate output against aggregated control rule sets.
|
65
|
+
unless output_rule_set.nil?
|
66
|
+
unless @aggregator.test_output(output, output_rule_set)
|
67
|
+
@status = :fail
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# When a system error occurs.
|
72
|
+
rescue StandardError => message
|
73
|
+
|
74
|
+
@status = :fail
|
75
|
+
@message = message
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
data/lib/{Meta.rb → meta.rb}
RENAMED
@@ -5,7 +5,7 @@
|
|
5
5
|
# @see lib/meta for each meta.
|
6
6
|
#
|
7
7
|
# @hierachy
|
8
|
-
# 1.
|
8
|
+
# 1. Action
|
9
9
|
# 2. Reflection
|
10
10
|
# 3. Meta <- YOU ARE HERE
|
11
11
|
################################################################################
|
@@ -16,7 +16,7 @@ class Meta
|
|
16
16
|
# Each meta defines its type.
|
17
17
|
##
|
18
18
|
def initialize()
|
19
|
-
@type =
|
19
|
+
@type = :null
|
20
20
|
end
|
21
21
|
|
22
22
|
##
|
@@ -28,12 +28,12 @@ class Meta
|
|
28
28
|
end
|
29
29
|
|
30
30
|
##
|
31
|
-
# Each meta serializes metadata.
|
32
|
-
#
|
33
31
|
# @return [Hash]
|
34
32
|
##
|
35
33
|
def serialize()
|
36
|
-
{
|
34
|
+
{
|
35
|
+
:type => @type
|
36
|
+
}
|
37
37
|
end
|
38
38
|
|
39
39
|
##############################################################################
|
@@ -5,12 +5,12 @@
|
|
5
5
|
# A "null" value on serialized "inputs" and "output" also becomes a NullMeta.
|
6
6
|
#
|
7
7
|
# @hierachy
|
8
|
-
# 1.
|
8
|
+
# 1. Action
|
9
9
|
# 2. Reflection
|
10
10
|
# 3. Meta <- YOU ARE HERE
|
11
11
|
################################################################################
|
12
12
|
|
13
|
-
|
13
|
+
require_relative '../meta'
|
14
14
|
|
15
15
|
class NullMeta < Meta
|
16
16
|
|
@@ -5,9 +5,9 @@
|
|
5
5
|
# @see lib/meta for each meta.
|
6
6
|
################################################################################
|
7
7
|
|
8
|
-
|
8
|
+
require_relative 'meta'
|
9
9
|
# Require all meta.
|
10
|
-
Dir[File.join(__dir__, 'meta', '*.rb')].each { |file|
|
10
|
+
Dir[File.join(__dir__, 'meta', '*.rb')].each { |file| require_relative file }
|
11
11
|
|
12
12
|
class MetaBuilder
|
13
13
|
|
data/lib/reflection.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
################################################################################
|
2
|
+
# A snapshot of real or random data.
|
3
|
+
#
|
4
|
+
# @pattern Abstract class
|
5
|
+
#
|
6
|
+
# @nomenclature
|
7
|
+
# args, inputs/output and meta represent different stages of a value.
|
8
|
+
#
|
9
|
+
# @hierachy
|
10
|
+
# 1. Action
|
11
|
+
# 2. Reflection <- YOU ARE HERE
|
12
|
+
# 3. Meta
|
13
|
+
#
|
14
|
+
# @status
|
15
|
+
# - :pass [Symbol] The reflection passes the rules.
|
16
|
+
# - :fail [Symbol] The reflection fails the rules or produces a system error.
|
17
|
+
# - :error [Symbol] The control reflection produces a system error.
|
18
|
+
################################################################################
|
19
|
+
|
20
|
+
require_relative 'clone'
|
21
|
+
require_relative 'meta_builder'
|
22
|
+
|
23
|
+
class Reflection
|
24
|
+
|
25
|
+
attr_reader :status
|
26
|
+
|
27
|
+
##
|
28
|
+
# Create a reflection.
|
29
|
+
#
|
30
|
+
# @param action [Action] The Action that created this Reflection.
|
31
|
+
# @param number [Integer] Multiple Reflections can be created per Action.
|
32
|
+
# @param aggregator [RuleSetAggregator] The aggregated RuleSet for this class/method.
|
33
|
+
##
|
34
|
+
def initialize(action, number, aggregator)
|
35
|
+
|
36
|
+
@action = action
|
37
|
+
@unique_id = action.unique_id + number
|
38
|
+
@number = number
|
39
|
+
|
40
|
+
# Dependency.
|
41
|
+
@aggregator = aggregator
|
42
|
+
|
43
|
+
# Caller.
|
44
|
+
@klass = action.klass
|
45
|
+
@method = action.method
|
46
|
+
|
47
|
+
# Metadata.
|
48
|
+
@inputs = nil
|
49
|
+
@output = nil
|
50
|
+
|
51
|
+
# Clone the action's calling object.
|
52
|
+
# TODO: Abstract away into Clone class.
|
53
|
+
@clone = action.caller_object.clone
|
54
|
+
|
55
|
+
# Result.
|
56
|
+
@status = :pass
|
57
|
+
@time = Time.now.to_i
|
58
|
+
@message = nil
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Reflect on a method.
|
64
|
+
#
|
65
|
+
# Create a shadow action.
|
66
|
+
# @param *args [Dynamic] The method's arguments.
|
67
|
+
##
|
68
|
+
def reflect(*args)
|
69
|
+
# Implemented by Control and Experiment.
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Create random values for each argument from control reflections.
|
74
|
+
#
|
75
|
+
# @param args [Dynamic] The arguments to mirror random values for.
|
76
|
+
# @param input_rule_sets [Array] Aggregated rule sets for each argument.
|
77
|
+
#
|
78
|
+
# @return [Dynamic] Random arguments.
|
79
|
+
##
|
80
|
+
def randomize(args, input_rule_sets)
|
81
|
+
|
82
|
+
random_args = []
|
83
|
+
|
84
|
+
args.each_with_index do |arg, arg_num|
|
85
|
+
|
86
|
+
# Get a random rule in the rule set.
|
87
|
+
rules = input_rule_sets[arg_num].rules
|
88
|
+
agg_rule = rules[rules.keys.sample]
|
89
|
+
|
90
|
+
# Create a random value that follows that rule.
|
91
|
+
random_args << agg_rule.random()
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
return random_args
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# Get the results of the reflection.
|
101
|
+
#
|
102
|
+
# @keys
|
103
|
+
# - eid [Integer] Execution ID
|
104
|
+
# - aid [Integer] Action ID
|
105
|
+
# - rid [Integer] Reflection ID
|
106
|
+
# - num [Integer] Reflection number
|
107
|
+
#
|
108
|
+
# @return [Hash] Reflection metadata.
|
109
|
+
##
|
110
|
+
def serialize()
|
111
|
+
|
112
|
+
# Create execution ID from the ID of the first action in the ActionStack.
|
113
|
+
execution_id = @action.unique_id
|
114
|
+
unless @action.base.nil?
|
115
|
+
execution_id = @action.base.unique_id
|
116
|
+
end
|
117
|
+
|
118
|
+
# Build reflection.
|
119
|
+
reflection = {
|
120
|
+
:eid => execution_id,
|
121
|
+
:aid => @action.unique_id,
|
122
|
+
:rid => @unique_id,
|
123
|
+
:num => @number,
|
124
|
+
:time => @time,
|
125
|
+
:class => @klass,
|
126
|
+
:method => @method,
|
127
|
+
:status => @status,
|
128
|
+
:message => @message,
|
129
|
+
:inputs => nil,
|
130
|
+
:output => nil,
|
131
|
+
}
|
132
|
+
|
133
|
+
unless @inputs.nil?
|
134
|
+
reflection[:inputs] = []
|
135
|
+
@inputs.each do |meta|
|
136
|
+
reflection[:inputs] << meta.serialize()
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
unless @output.nil?
|
141
|
+
reflection[:output] = @output.serialize()
|
142
|
+
end
|
143
|
+
|
144
|
+
return reflection
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|