ruby-xes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ module XES
2
+ # Trace represents "trace" element of XES.
3
+ class Trace
4
+ include TraceAttributeAccessor
5
+
6
+ # @return [Array<Attribute>]
7
+ # attributes of the trace element
8
+ attr_accessor :attributes
9
+
10
+ # @return [Array<Event>]
11
+ # events included in the trace element
12
+ attr_accessor :events
13
+
14
+ # Create a XES trace.
15
+ #
16
+ # @param events [Array<Event>]
17
+ # events included in the trace element
18
+ def initialize(attributes=[], events=[])
19
+ @attributes = attributes
20
+ @events = events
21
+ end
22
+
23
+ # Return true if the element is formattable.
24
+ #
25
+ # @return [Boolean]
26
+ # true if the element is formattable
27
+ def formattable?
28
+ @events.any? {|event| event.formattable?}
29
+ end
30
+
31
+ # Format as a XML element.
32
+ #
33
+ # @return [REXML::Element]
34
+ # XML element
35
+ # @raise FormatError
36
+ def format
37
+ raise FormatError.new(self) unless formattable?
38
+
39
+ REXML::Element.new("trace").tap do |trace|
40
+ @attributes.each {|attribute| trace.elements << attribute.format if attribute.formattable?}
41
+ @events.each {|event| trace.elements << event.format if event.formattable?}
42
+ end
43
+ end
44
+
45
+ # @api private
46
+ def ==(other)
47
+ return false unless other.kind_of?(self.class)
48
+ @attributes == other.attributes and @events == other.events
49
+ end
50
+ alias :eql? :"=="
51
+
52
+ # @api private
53
+ def hash
54
+ @attributes.hash + @events.hash
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ module XES
2
+ # version of ruby-xes
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,24 @@
1
+ # -*- ruby -*-
2
+ # -*- encoding: utf-8 -*-
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'xes/version'
6
+
7
+ Gem::Specification.new do |gem|
8
+ gem.name = "ruby-xes"
9
+ gem.version = XES::VERSION
10
+ gem.authors = ["Keita Yamaguchi"]
11
+ gem.email = ["keita.yamaguchi@gmail.com"]
12
+ gem.description = "ruby-xes is a library for generating XES event log."
13
+ gem.summary = "ruby-xes is a library for generating XES event log."
14
+ gem.homepage = "https://github.com/pione/ruby-xes"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "bacon"
22
+ gem.add_development_dependency "yard", "~> 0.8.5"
23
+ gem.add_development_dependency "redcarpet"
24
+ end
@@ -0,0 +1,150 @@
1
+ require 'xes'
2
+
3
+ describe "XES::Attribute" do
4
+ it "should equal" do
5
+ XES::Attribute.new("string", "concept:name", "A").should ==
6
+ XES::Attribute.new("string", "concept:name", "A")
7
+ end
8
+
9
+ it 'should not equal' do
10
+ XES::Attribute.new("string", "concept:name", "A").should !=
11
+ XES::Attribute.new("string", "concept:name", "B")
12
+ end
13
+
14
+ it 'should make string attribute' do
15
+ XES.string("concept:name", "A").should ==
16
+ XES::Attribute.new("string", "concept:name", "A")
17
+ end
18
+
19
+ it 'should make date attribute' do
20
+ Time.now.tap do |time|
21
+ XES.date("time:timestamp", time).should ==
22
+ XES::Attribute.new("date", "time:timestamp", time)
23
+ end
24
+ end
25
+
26
+ it 'should make int attribute' do
27
+ XES.int("counter", 123).should ==
28
+ XES::Attribute.new("int", "counter", 123)
29
+ end
30
+
31
+ it 'should make float attribute' do
32
+ XES.float("counter", 0.123).should ==
33
+ XES::Attribute.new("float", "counter", 0.123)
34
+ end
35
+
36
+ it 'should make boolean attribute' do
37
+ XES.boolean("truth", true).should ==
38
+ XES::Attribute.new("boolean", "truth", true)
39
+ end
40
+
41
+ it 'should make id attribute' do
42
+ XES.id("identity:id", "123").should ==
43
+ XES::Attribute.new("id", "identity:id", "123")
44
+ end
45
+
46
+ it 'should get the type' do
47
+ XES::Attribute.new("string", "concept:name", "A").type.should == "string"
48
+ end
49
+
50
+ it 'should get the key' do
51
+ XES::Attribute.new("string", "concept:name", "A").key.should == "concept:name"
52
+ end
53
+
54
+ it 'should get the value' do
55
+ XES::Attribute.new("string", "concept:name", "A").value.should == "A"
56
+ end
57
+
58
+ it 'should get meta attributes' do
59
+ XES::Attribute.new("string", "concept:name", "A").tap do |x|
60
+ x.meta << XES::Attribute.new("string", "meta", "1")
61
+ end.meta.should == [XES::Attribute.new("string", "meta", "1")]
62
+ end
63
+
64
+ it 'should get identity:id' do
65
+ XES::Attribute.new("string", "concept:name", "A").tap do |x|
66
+ x.meta << XES::Attribute.new("id", "identity:id", "123456")
67
+ end.identity_id.should == "123456"
68
+ end
69
+
70
+ it 'should set identity:id' do
71
+ XES::Attribute.new("string", "concept:name", "A").tap do |x|
72
+ x.identity_id = "test"
73
+ end.identity_id.should == "test"
74
+ end
75
+
76
+ it "should get cost:amount" do
77
+ XES.string("concept:name", "A").tap do |x|
78
+ x.meta << XES.float("cost:amount", 0.123)
79
+ end.cost_amount.should == 0.123
80
+ end
81
+
82
+ it "should set cost:amount" do
83
+ XES.string("concept:name", "A").tap do |x|
84
+ x.cost_amount = 0.123
85
+ end.cost_amount.should == 0.123
86
+ end
87
+
88
+ it "should get cost:driver" do
89
+ XES.string("concept:name", "A").tap do |x|
90
+ x.meta << XES.string("cost:driver", "xyz123")
91
+ end.cost_driver.should == "xyz123"
92
+ end
93
+
94
+ it "should set cost:driver" do
95
+ XES.string("concept:name", "A").tap do |x|
96
+ x.cost_driver = "xyz123"
97
+ end.cost_driver.should == "xyz123"
98
+ end
99
+
100
+ it "should get cost:type" do
101
+ XES.string("concept:name", "A").tap do |x|
102
+ x.meta << XES.string("cost:type", "Fixed Overhead")
103
+ end.cost_type.should == "Fixed Overhead"
104
+ end
105
+
106
+ it "should set cost:driver" do
107
+ XES.string("concept:name", "A").tap do |x|
108
+ x.cost_type = "Fixed Overhead"
109
+ end.cost_type.should == "Fixed Overhead"
110
+ end
111
+
112
+ it 'should format string attribute as XML' do
113
+ XES.string("concept:name", "A").format.to_s.should ==
114
+ "<string key='concept:name' value='A'/>"
115
+ end
116
+
117
+ it 'should format date attribute as XML' do
118
+ Time.now.tap do |time|
119
+ XES.date("time:timestamp", time).format.to_s.should ==
120
+ "<date key='time:timestamp' value='%s'/>" % time.iso8601
121
+ end
122
+ end
123
+
124
+ it 'should format int attribute as XML' do
125
+ XES.int("counter", 123).format.to_s.should ==
126
+ "<int key='counter' value='123'/>"
127
+ end
128
+
129
+ it 'should format float attribute as XML' do
130
+ XES.float("counter", 0.123).format.to_s.should ==
131
+ "<float key='counter' value='0.123'/>"
132
+ end
133
+
134
+ it 'should format boolean attribute as XML' do
135
+ XES.boolean("truth", true).format.to_s.should ==
136
+ "<boolean key='truth' value='true'/>"
137
+ end
138
+
139
+ it 'should format id attribute as XML' do
140
+ XES.id("identity:id", "123456").format.to_s.should ==
141
+ "<id key='identity:id' value='123456'/>"
142
+ end
143
+
144
+ it 'should format attribute with meta attribute as XML' do
145
+ XES.string("concept:name", "A").tap do |x|
146
+ x.identity_id = "123456"
147
+ end.format.to_s.should ==
148
+ "<string key='concept:name' value='A'><id key='identity:id' value='123456'/></string>"
149
+ end
150
+ end
@@ -0,0 +1,26 @@
1
+ require 'xes'
2
+
3
+ describe "XES::Classifier" do
4
+ it "should equal" do
5
+ XES::Classifier.new("Event Name", "concept:name").should ==
6
+ XES::Classifier.new("Event Name", "concept:name")
7
+ end
8
+
9
+ it "should not equal" do
10
+ XES::Classifier.new("Event Name", "concept:name").should !=
11
+ XES::Classifier.new("Resource", "org:resource")
12
+ end
13
+
14
+ it "should get the name" do
15
+ XES::Classifier.new("Event Name", "concept:name").name.should == "Event Name"
16
+ end
17
+
18
+ it "should get the keys" do
19
+ XES::Classifier.new("Event Name", "concept:name").keys.should == "concept:name"
20
+ end
21
+
22
+ it "should format as XML element" do
23
+ XES::Classifier.new("Event Name", "concept:name").format.to_s.should ==
24
+ "<classifier keys='concept:name' name='Event Name'/>"
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ require 'xes'
2
+
3
+ describe "XES::Document" do
4
+ it "should equal" do
5
+ XES::Document.new.should == XES::Document.new
6
+ end
7
+
8
+ it "should formattable" do
9
+ XES::Document.new.tap do |doc|
10
+ doc.log = XES::Log.new.tap do |log|
11
+ log.traces << XES::Trace.new.tap do |trace|
12
+ trace.events << XES::Event.new.tap do |event|
13
+ event.attributes << XES.string("concept:name", "test")
14
+ end
15
+ end
16
+ end
17
+ end.should.formattable
18
+ end
19
+ end
@@ -0,0 +1,102 @@
1
+ require 'xes'
2
+
3
+ describe "XES::Event" do
4
+ it "should equal" do
5
+ XES::Event.new([XES.string("concept:name", "A")]).should ==
6
+ XES::Event.new([XES.string("concept:name", "A")])
7
+ end
8
+
9
+ it "should get concept:name" do
10
+ XES::Event.new([XES.string("concept:name", "A")]).concept_name.should == "A"
11
+ end
12
+
13
+ it "should set concept:name" do
14
+ XES::Event.new.tap{|x| x.concept_name = "A"}.concept_name.should == "A"
15
+ end
16
+
17
+ it "should get lifecycle:transition" do
18
+ XES::Event.new([XES.string("lifecycle:transition", "start")]).lifecycle_transition.should == "start"
19
+ end
20
+
21
+ it "should set lifecycle:transition" do
22
+ XES::Event.new.tap{|x| x.lifecycle_transition = "start"}.lifecycle_transition.should == "start"
23
+ end
24
+
25
+ it "should get org:resource" do
26
+ XES::Event.new([XES.string("org:resource", "A")]).org_resource.should == "A"
27
+ end
28
+
29
+ it "should set org:resource" do
30
+ XES::Event.new.tap{|x| x.org_resource = "A"}.org_resource.should == "A"
31
+ end
32
+
33
+ it "should get org:role" do
34
+ XES::Event.new([XES.string("org:role", "A")]).org_role.should == "A"
35
+ end
36
+
37
+ it "should set org:role" do
38
+ XES::Event.new.tap{|x| x.org_role = "A"}.org_role.should == "A"
39
+ end
40
+
41
+ it "should get org:group" do
42
+ XES::Event.new([XES.string("org:group", "A")]).org_group.should == "A"
43
+ end
44
+
45
+ it "should set org:group" do
46
+ XES::Event.new.tap{|x| x.org_group = "A"}.org_group.should == "A"
47
+ end
48
+
49
+ it "should get time:timestamp" do
50
+ Time.now.tap do |time|
51
+ XES::Event.new([XES.date("time:timestamp", time)]).time_timestamp.should == time
52
+ end
53
+ end
54
+
55
+ it "should set time:timestamp" do
56
+ Time.now.tap do |time|
57
+ XES::Event.new.tap{|x| x.time_timestamp = time}.time_timestamp.should == time
58
+ end
59
+ end
60
+
61
+ it "should get semantic:modelReference" do
62
+ XES::Event.new([XES.string("semantic:modelReference", "A")]).semantic_modelReference.should == "A"
63
+ end
64
+
65
+ it "should set semantic:modelReference" do
66
+ XES::Event.new.tap{|x| x.semantic_modelReference = "A"}.semantic_modelReference.should == "A"
67
+ end
68
+
69
+ it "should get identity:id" do
70
+ XES::Event.new([XES.id("identity:id", "A")]).identity_id.should == "A"
71
+ end
72
+
73
+ it "should set identity:id" do
74
+ XES::Event.new.tap{|x| x.identity_id = "123456"}.identity_id.should == "123456"
75
+ end
76
+
77
+ it "should get cost:total" do
78
+ XES::Event.new([XES.float("cost:total", 0.123)]).cost_total.should == 0.123
79
+ end
80
+
81
+ it "should set cost:total" do
82
+ XES::Event.new.tap{|x| x.cost_total = 0.123}.cost_total.should == 0.123
83
+ end
84
+
85
+ it "should get cost:currency" do
86
+ XES::Event.new([XES.string("cost:currency", "AUD")]).cost_currency.should == "AUD"
87
+ end
88
+
89
+ it "should set cost:total" do
90
+ XES::Event.new.tap{|x| x.cost_currency = "AUD"}.cost_currency.should == "AUD"
91
+ end
92
+
93
+ it "should get attributes" do
94
+ XES::Event.new([XES.string("concept:name", "A")]).attributes.should ==
95
+ [XES.string("concept:name", "A")]
96
+ end
97
+
98
+ it "should format as XML" do
99
+ XES::Event.new([XES.string("concept:name", "A")]).format.to_s.should ==
100
+ "<event><string key='concept:name' value='A'/></event>"
101
+ end
102
+ end
@@ -0,0 +1,34 @@
1
+ require 'xes'
2
+
3
+ describe "XES::Extension" do
4
+ it "should equal" do
5
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext").should ==
6
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext")
7
+ end
8
+
9
+ it "shoud not equal" do
10
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext").should !=
11
+ XES::Extension.new("Identity", "identity", "http://www.xes-standard.org/identity.xesext")
12
+ end
13
+
14
+ it "should get the name" do
15
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext").name.should == "Concept"
16
+ end
17
+
18
+ it "should get the prefix" do
19
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext").prefix.should == "concept"
20
+ end
21
+
22
+ it "should be formattable" do
23
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext").should.formattable
24
+ end
25
+
26
+ it "should be not formattable" do
27
+ XES::Extension.new("Concept", "concept", nil).should.not.formattable
28
+ end
29
+
30
+ it "should get the uri" do
31
+ XES::Extension.new("Concept", "concept", "http://www.xes-standard.org/concept.xesext").uri.should ==
32
+ "http://www.xes-standard.org/concept.xesext"
33
+ end
34
+ end
@@ -0,0 +1,131 @@
1
+ require 'xes'
2
+
3
+ describe "XES::Global" do
4
+ it "should equal" do
5
+ XES::Global.event.should == XES::Global.event
6
+ end
7
+
8
+ it "should not equal" do
9
+ XES::Global.event.should != XES::Global.trace
10
+ end
11
+
12
+ it "should get the scope" do
13
+ XES::Global.event.scope.should == "event"
14
+ end
15
+
16
+ it "should get the attributes" do
17
+ XES::Global.event.tap do |global|
18
+ global.attributes << XES.string("concept:name", "__INVALID__")
19
+ end.attributes.should == [XES.string("concept:name", "__INVALID__")]
20
+ end
21
+
22
+ it "should set and get concept:name of event global" do
23
+ XES::Global.event.tap do |global|
24
+ global.concept_name = "A"
25
+ end.concept_name.should == "A"
26
+ end
27
+
28
+ it "should set and get concept:instance of event global" do
29
+ XES::Global.event.tap do |global|
30
+ global.concept_instance = "A"
31
+ end.concept_instance.should == "A"
32
+ end
33
+
34
+ it "should set and get lifecycle:transition of event global" do
35
+ XES::Global.event.tap do |global|
36
+ global.lifecycle_transition = "complete"
37
+ end.lifecycle_transition.should == "complete"
38
+ end
39
+
40
+ it "should set and get org:resource of event global" do
41
+ XES::Global.event.tap do |global|
42
+ global.org_resource = "A"
43
+ end.org_resource.should == "A"
44
+ end
45
+
46
+ it "should set and get org:role of event global" do
47
+ XES::Global.event.tap do |global|
48
+ global.org_role = "A"
49
+ end.org_role.should == "A"
50
+ end
51
+
52
+ it "should set and get org:group of event global" do
53
+ XES::Global.event.tap do |global|
54
+ global.org_group = "A"
55
+ end.org_group.should == "A"
56
+ end
57
+
58
+ it "should set and get time:timestamp of event global" do
59
+ Time.now.tap do |time|
60
+ XES::Global.event.tap do |global|
61
+ global.time_timestamp = time
62
+ end.time_timestamp.should == time
63
+ end
64
+ end
65
+
66
+ it "should set and get semantic:modelReference of event global" do
67
+ XES::Global.event.tap do |global|
68
+ global.semantic_modelReference = "A"
69
+ end.semantic_modelReference.should == "A"
70
+ end
71
+
72
+ it "should set and get identity:id of event global" do
73
+ XES::Global.event.tap do |global|
74
+ global.identity_id = "A"
75
+ end.identity_id.should == "A"
76
+ end
77
+
78
+ it "should set and get cost:total of event global" do
79
+ XES::Global.event.tap do |global|
80
+ global.cost_total = 0.123
81
+ end.cost_total.should == 0.123
82
+ end
83
+
84
+ it "should set and get cost:currency of event global" do
85
+ XES::Global.event.tap do |global|
86
+ global.cost_currency = "A"
87
+ end.cost_currency.should == "A"
88
+ end
89
+
90
+ it "should set and get concept:name of trace global" do
91
+ XES::Global.trace.tap do |global|
92
+ global.concept_name = "A"
93
+ end.concept_name.should == "A"
94
+ end
95
+
96
+ it "should set and get semantic:modelReference of trace global" do
97
+ XES::Global.trace.tap do |global|
98
+ global.semantic_modelReference = "A"
99
+ end.semantic_modelReference.should == "A"
100
+ end
101
+
102
+ it "should set and get identity:id of trace global" do
103
+ XES::Global.trace.tap do |global|
104
+ global.identity_id = "A"
105
+ end.identity_id.should == "A"
106
+ end
107
+
108
+ it "should set and get cost:total of trace global" do
109
+ XES::Global.trace.tap do |global|
110
+ global.cost_total = 0.123
111
+ end.cost_total.should == 0.123
112
+ end
113
+
114
+ it "should set and get cost:currency of trace global" do
115
+ XES::Global.trace.tap do |global|
116
+ global.cost_currency = "A"
117
+ end.cost_currency.should == "A"
118
+ end
119
+
120
+ it "should format event global as XML element" do
121
+ XES::Global.event.tap do |global|
122
+ global.concept_name = "A"
123
+ end.format.to_s.should == "<global scope='event'><string key='concept:name' value='A'/></global>"
124
+ end
125
+
126
+ it "should format trace global as XML element" do
127
+ XES::Global.trace.tap do |global|
128
+ global.concept_name = "A"
129
+ end.format.to_s.should == "<global scope='trace'><string key='concept:name' value='A'/></global>"
130
+ end
131
+ end