ruby-xes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +16 -0
- data/lib/xes.rb +18 -0
- data/lib/xes/attribute-accessor.rb +121 -0
- data/lib/xes/attribute.rb +201 -0
- data/lib/xes/classifier.rb +63 -0
- data/lib/xes/document.rb +48 -0
- data/lib/xes/event.rb +50 -0
- data/lib/xes/extension.rb +73 -0
- data/lib/xes/format-error.rb +15 -0
- data/lib/xes/global.rb +75 -0
- data/lib/xes/log.rb +158 -0
- data/lib/xes/trace.rb +57 -0
- data/lib/xes/version.rb +4 -0
- data/ruby-xes.gemspec +24 -0
- data/test/spec_attribute.rb +150 -0
- data/test/spec_classifier.rb +26 -0
- data/test/spec_document.rb +19 -0
- data/test/spec_event.rb +102 -0
- data/test/spec_extension.rb +34 -0
- data/test/spec_global.rb +131 -0
- data/test/spec_log.rb +90 -0
- data/test/spec_trace.rb +113 -0
- metadata +128 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 NaU Data Institute Inc. and contributors.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# ruby-xes
|
2
|
+
|
3
|
+
ruby-xes is a Ruby library for generating XES event log.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install ruby-xes
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'xes'
|
13
|
+
|
14
|
+
XES::Document.new.tap do |doc|
|
15
|
+
doc.log = XES::Log.new.tap do |log|
|
16
|
+
log.traces << XES::Trace.new.tap do |trace|
|
17
|
+
trace.events << XES::Event.new.tap do |event|
|
18
|
+
event.attributes << XES.string("concept:name", "test")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end.format
|
23
|
+
```
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
32
|
+
|
33
|
+
## Licence
|
34
|
+
|
35
|
+
ruby-xes is free software distributed under MIT licence.
|
36
|
+
|
37
|
+
## Links
|
38
|
+
|
39
|
+
* [PIONE project homepage](http://pione.github.io/)
|
40
|
+
* [repository on github](https://github.com/pione/pione)
|
41
|
+
* [XES](http://www.xes-standard.org/start)
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc 'Test specs'
|
4
|
+
task 'test' do
|
5
|
+
sh "bundle exec bacon -a"
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Generate API document'
|
9
|
+
task 'html' do
|
10
|
+
sh "bundle exec yard doc -o html --hide-void-return --no-api"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Show undocumented function list'
|
14
|
+
task 'html:undoc' do
|
15
|
+
sh "bundle exec yard stats --list-undoc --no-api --compact"
|
16
|
+
end
|
data/lib/xes.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "rexml/document"
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
require "xes/version"
|
5
|
+
require "xes/format-error"
|
6
|
+
require "xes/attribute-accessor"
|
7
|
+
require "xes/extension"
|
8
|
+
require "xes/classifier"
|
9
|
+
require "xes/attribute"
|
10
|
+
require "xes/global"
|
11
|
+
require "xes/event"
|
12
|
+
require "xes/trace"
|
13
|
+
require "xes/log"
|
14
|
+
require "xes/document"
|
15
|
+
|
16
|
+
# XES is a module for genereting XES event log.
|
17
|
+
module XES
|
18
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module XES
|
2
|
+
# AttributeAccessor provides attribute accessors of standard extensions.
|
3
|
+
module AttributeAccessor
|
4
|
+
# Define an attribute accessor.
|
5
|
+
#
|
6
|
+
# @param name [String]
|
7
|
+
# attribute name
|
8
|
+
# @param type [String]
|
9
|
+
# attribute type
|
10
|
+
# @return [void]
|
11
|
+
def define_attribute(name, type)
|
12
|
+
_name = name.gsub(":", "_")
|
13
|
+
|
14
|
+
define_method(_name) do
|
15
|
+
var = instance_variables.include?(:@meta) ? :@meta : :@attributes
|
16
|
+
instance_variable_get(var).find do |attribute|
|
17
|
+
attribute.key == name
|
18
|
+
end.tap{|x| return x.value if x}
|
19
|
+
end
|
20
|
+
|
21
|
+
define_method("%s=" % _name) do |value|
|
22
|
+
var = instance_variables.include?(:@meta) ? :@meta : :@attributes
|
23
|
+
instance_variable_get(var).tap do |attributes|
|
24
|
+
if elt = __send__(_name)
|
25
|
+
attributes.delete(elt)
|
26
|
+
end
|
27
|
+
attributes << XES.send(type, name, value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# EventAttributeAccessor provides attribute accessors for event or event global element.
|
34
|
+
module EventAttributeAccessor
|
35
|
+
extend AttributeAccessor
|
36
|
+
|
37
|
+
# @!attribute [rw] concept_name
|
38
|
+
# @return [String]
|
39
|
+
# the value of attribute "concept:name"
|
40
|
+
define_attribute "concept:name", "string"
|
41
|
+
|
42
|
+
# @!attribute [rw] concept_instance
|
43
|
+
# @return [String]
|
44
|
+
# the value of attribute "concept:instance"
|
45
|
+
define_attribute "concept:instance", "string"
|
46
|
+
|
47
|
+
# @!attribute [rw] lifecycle_transition
|
48
|
+
# @return [String]
|
49
|
+
# the value of attribute "lifecycle:transition"
|
50
|
+
define_attribute "lifecycle:transition", "string"
|
51
|
+
|
52
|
+
# @!attribute [rw] org_resource
|
53
|
+
# @return [String]
|
54
|
+
# the value of attribute "org:resource"
|
55
|
+
define_attribute "org:resource", "string"
|
56
|
+
|
57
|
+
# @!attribute [rw] org_role
|
58
|
+
# @return [String]
|
59
|
+
# the value of attribute "org:role"
|
60
|
+
define_attribute "org:role", "string"
|
61
|
+
|
62
|
+
# @!attribute [rw] org_group
|
63
|
+
# @return [String]
|
64
|
+
# the value of attribute "org:group"
|
65
|
+
define_attribute "org:group", "string"
|
66
|
+
|
67
|
+
# @!attribute [rw] time_timestamp
|
68
|
+
# @return [Time,String]
|
69
|
+
# the value of attribute "time:timestamp"
|
70
|
+
define_attribute "time:timestamp", "date"
|
71
|
+
|
72
|
+
# @!attribute [rw] semantic_modelReference
|
73
|
+
# @return [String]
|
74
|
+
# the value of attribute "semantic:modelReference"
|
75
|
+
define_attribute "semantic:modelReference", "string"
|
76
|
+
|
77
|
+
# @!attribute [rw] identity_id
|
78
|
+
# @return [String]
|
79
|
+
# the value of attribute "identity:id"
|
80
|
+
define_attribute "identity:id", "id"
|
81
|
+
|
82
|
+
# @!attribute [rw] cost_total
|
83
|
+
# @return [Float]
|
84
|
+
# the value of attribute "cost:total"
|
85
|
+
define_attribute "cost:total", "float"
|
86
|
+
|
87
|
+
# @!attribute [rw] cost_currency
|
88
|
+
# @return [String]
|
89
|
+
# the value of attribute "cost:currency"
|
90
|
+
define_attribute "cost:currency", "string"
|
91
|
+
end
|
92
|
+
|
93
|
+
# TraceAttributeAccessor provides attribute accessors for trace or trace global element.
|
94
|
+
module TraceAttributeAccessor
|
95
|
+
extend AttributeAccessor
|
96
|
+
# @!attribute [rw] concept_name
|
97
|
+
# @return [String]
|
98
|
+
# the value of attribute "concept:name"
|
99
|
+
define_attribute "concept:name", "string"
|
100
|
+
|
101
|
+
# @!attribute [rw] semantic_modelReference
|
102
|
+
# @return [String]
|
103
|
+
# the value of attribute "semantic:modelReference"
|
104
|
+
define_attribute "semantic:modelReference", "string"
|
105
|
+
|
106
|
+
# @!attribute [rw] identity_id
|
107
|
+
# @return [String]
|
108
|
+
# the value of attribute "identity:id"
|
109
|
+
define_attribute "identity:id", "id"
|
110
|
+
|
111
|
+
# @!attribute [rw] cost:total
|
112
|
+
# @return [Float]
|
113
|
+
# the value of attribute "cost:total"
|
114
|
+
define_attribute "cost:total", "float"
|
115
|
+
|
116
|
+
# @!attribute [rw] cost_currency
|
117
|
+
# @return [String]
|
118
|
+
# the value of attribute "cost:currency"
|
119
|
+
define_attribute "cost:currency", "string"
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
module XES
|
2
|
+
# Attribute represents attribute of XES.
|
3
|
+
class Attribute
|
4
|
+
extend AttributeAccessor
|
5
|
+
|
6
|
+
# @!attribute [rw] semantic_modelReference
|
7
|
+
# @return [String]
|
8
|
+
# the value of meta attribute "semantic:modelReference"
|
9
|
+
define_attribute "semantic:modelReference", "string"
|
10
|
+
|
11
|
+
# @!attribute [rw] identity_id
|
12
|
+
# @return [String]
|
13
|
+
# the value of meta attribute "identity:id"
|
14
|
+
define_attribute "identity:id", "id"
|
15
|
+
|
16
|
+
# @!attribute [rw] cost_amount
|
17
|
+
# @return [Float]
|
18
|
+
# the value of meta attribute "cost:amount"
|
19
|
+
define_attribute "cost:amount", "float"
|
20
|
+
|
21
|
+
# @!attribute [rw] cost_driver
|
22
|
+
# @return [String]
|
23
|
+
# the value of meta attribute "cost:driver"
|
24
|
+
define_attribute "cost:driver", "string"
|
25
|
+
|
26
|
+
# @!attribute [rw] cost_type
|
27
|
+
# @return [String]
|
28
|
+
# the value of meta attribute "cost:type"
|
29
|
+
define_attribute "cost:type", "string"
|
30
|
+
|
31
|
+
# @return [String]
|
32
|
+
# attribute type
|
33
|
+
attr_reader :type
|
34
|
+
|
35
|
+
# @return [String]
|
36
|
+
# attribute name
|
37
|
+
attr_accessor :key
|
38
|
+
|
39
|
+
# @return [String]
|
40
|
+
# attribute value
|
41
|
+
attr_accessor :value
|
42
|
+
|
43
|
+
# @return [Meta]
|
44
|
+
# attribute meta attributes
|
45
|
+
attr_accessor :meta
|
46
|
+
|
47
|
+
# @param type [String]
|
48
|
+
# attribute type
|
49
|
+
# @param key [String]
|
50
|
+
# attribute name
|
51
|
+
# @param value [String]
|
52
|
+
# attribute value
|
53
|
+
# @param meta [Array<Attribute>]
|
54
|
+
# meta attributes
|
55
|
+
def initialize(type, key, value, meta=[])
|
56
|
+
@type = type
|
57
|
+
@key = key
|
58
|
+
@value = value
|
59
|
+
@meta = meta
|
60
|
+
end
|
61
|
+
|
62
|
+
# Return true if the element is formattable.
|
63
|
+
#
|
64
|
+
# @return [Boolean]
|
65
|
+
# true if the element is formattable
|
66
|
+
def formattable?
|
67
|
+
not(@type.nil? or @key.nil? or @value.nil? or @meta.nil?)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Format as a XML element.
|
71
|
+
def format
|
72
|
+
raise FormatError.new(self) unless formattable?
|
73
|
+
|
74
|
+
REXML::Element.new(type).tap do |attribute|
|
75
|
+
attribute.attributes["key"] = @key
|
76
|
+
attribute.attributes["value"] = format_value
|
77
|
+
meta.each {|m| attribute.elements << m.format if m.formattable?}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# @api private
|
82
|
+
def ==(other)
|
83
|
+
return false unless other.kind_of?(self.class)
|
84
|
+
@type == other.type and @key == other.key and @value == other.value and @meta == other.meta
|
85
|
+
end
|
86
|
+
alias :eql? :"=="
|
87
|
+
|
88
|
+
# @api private
|
89
|
+
def hash
|
90
|
+
@type.hash + @key.hash + @value.hash
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
# Format the value.
|
96
|
+
#
|
97
|
+
# @return [String]
|
98
|
+
def format_value
|
99
|
+
case @type
|
100
|
+
when "string"
|
101
|
+
@value
|
102
|
+
when "date"
|
103
|
+
@value.kind_of?(Time) ? @value.iso8601(3) : @value
|
104
|
+
when "int"
|
105
|
+
@value.kind_of?(Integer) ? @value : @value.to_i
|
106
|
+
when "float"
|
107
|
+
@value.kind_of?(Float) ? @value : @value.to_f
|
108
|
+
when "boolean"
|
109
|
+
@value
|
110
|
+
when "id"
|
111
|
+
@value
|
112
|
+
end.to_s
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class << self
|
117
|
+
# Return string attribute object.
|
118
|
+
#
|
119
|
+
# @param key [String]
|
120
|
+
# attribute name
|
121
|
+
# @param value [Object]
|
122
|
+
# attribute value
|
123
|
+
# @param meta [Array<Attribute>]
|
124
|
+
# meta attributes
|
125
|
+
# @return [Attribute]
|
126
|
+
# string attribute
|
127
|
+
def string(key, value, meta=[])
|
128
|
+
Attribute.new("string", key, value, meta)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Return date attribute object.
|
132
|
+
#
|
133
|
+
# @param key [String]
|
134
|
+
# attribute name
|
135
|
+
# @param value [Object]
|
136
|
+
# attribute value
|
137
|
+
# @param meta [Array<Attribute>]
|
138
|
+
# meta attributes
|
139
|
+
# @return [Attribute]
|
140
|
+
# date attribute
|
141
|
+
def date(key, value, meta=[])
|
142
|
+
Attribute.new("date", key, value, meta)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Return int attribute object.
|
146
|
+
#
|
147
|
+
# @param key [String]
|
148
|
+
# attribute name
|
149
|
+
# @param value [Object]
|
150
|
+
# attribute value
|
151
|
+
# @param meta [Array<Attribute>]
|
152
|
+
# meta attributes
|
153
|
+
# @return [Attribute]
|
154
|
+
# int attribute
|
155
|
+
def int(key, value, meta=[])
|
156
|
+
Attribute.new("int", key, value, meta)
|
157
|
+
end
|
158
|
+
|
159
|
+
# Return float attribute object.
|
160
|
+
#
|
161
|
+
# @param key [String]
|
162
|
+
# attribute name
|
163
|
+
# @param value [Object]
|
164
|
+
# attribute value
|
165
|
+
# @param meta [Array<Attribute>]
|
166
|
+
# meta attributes
|
167
|
+
# @return [Attribute]
|
168
|
+
# float attribute
|
169
|
+
def float(key, value, meta=[])
|
170
|
+
Attribute.new("float", key, value, meta)
|
171
|
+
end
|
172
|
+
|
173
|
+
# Return boolean attribute object.
|
174
|
+
#
|
175
|
+
# @param key [String]
|
176
|
+
# attribute name
|
177
|
+
# @param value [Object]
|
178
|
+
# attribute value
|
179
|
+
# @param meta [Array<Attribute>]
|
180
|
+
# meta attributes
|
181
|
+
# @return [Attribute]
|
182
|
+
# boolean attribute
|
183
|
+
def boolean(key, value, meta=[])
|
184
|
+
Attribute.new("boolean", key, value, meta)
|
185
|
+
end
|
186
|
+
|
187
|
+
# Return id attribute object.
|
188
|
+
#
|
189
|
+
# @param key [String]
|
190
|
+
# attribute name
|
191
|
+
# @param value [Object]
|
192
|
+
# attribute value
|
193
|
+
# @param meta [Array<Attribute>]
|
194
|
+
# meta attributes
|
195
|
+
# @return [Attribute]
|
196
|
+
# id attribute
|
197
|
+
def id(key, value, meta=[])
|
198
|
+
Attribute.new("id", key, value, meta)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|