Skip to content

Commit

Permalink
upgrading package
Browse files Browse the repository at this point in the history
  • Loading branch information
deemount committed Mar 21, 2024
1 parent 632a81a commit 39f2463
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ gobpmnCounter is a tool for counting the elements, shapes and egdes present in a

## Wiki

The [documentation](https://github.com/deemount/gobpmnCounter/wiki) is now written in the wiki of the respective module
Read the [documentation](https://github.com/deemount/gobpmnCounter/wiki)

**Start here** [gobpmn](https://github.com/deemount/gobpmn)

Expand Down
1 change: 1 addition & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package gobpmn_counter
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/deemount/gobpmnCounter

go 1.21.7

require github.com/deemount/gobpmnReflection v0.0.0-20240311195407-66268668805a
require github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/deemount/gobpmnReflection v0.0.0-20240311195407-66268668805a h1:NSd968TGgWy0m8tPU+nxPzzWHkWpnGU1Hk9bHDJ/yhs=
github.com/deemount/gobpmnReflection v0.0.0-20240311195407-66268668805a/go.mod h1:NhbSOQE5lfqYvNkZXsm6xWTq3Wpy5xBPaERNqM/0OgI=
github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d h1:yQY4ikw/HuvVlPu3hGc0X8gntQnSbLqMnUw/nHRRCKU=
github.com/deemount/gobpmnReflection v0.0.0-20240315112013-036495e4c08d/go.mod h1:j8WCmdzEkTq/FVsWJAdoPtjTiRryLZp/WjOLcIqtt5c=
96 changes: 82 additions & 14 deletions quantities.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ import (
gobpmn_reflection "github.com/deemount/gobpmnReflection"
)

// Quantities ...
// Quantities holds all the quantities of the BPMN elements
// in the BPMN model. It is used to count the number of elements
type Quantities struct {
Process int
Participant int
Message int
StartEvent int
EndEvent int
// How many processes are in the BPMN model
Process int
// How many participants are in the BPMN model
// This will be counted by the number of pools
Participant int
// How many messages are in the BPMN model
// This will be counted by the number of edges
// and if the string contains the word "Message"
Message int
// How many elements are in the BPMN model
ComplexGateway int
EventBasedGateway int
ExclusiveGateway int
InclusiveGateway int
ParallelGateway int
// How many events are in the BPMN model
BoundaryEvent int
EndEvent int
IntermediateCatchEvent int
IntermediateThrowEvent int
StartEvent int
// How many tasks are in the BPMN model
BusinessRuleTask int
ManualTask int
ReceiveTask int
Expand All @@ -23,19 +41,28 @@ type Quantities struct {
ServiceTask int
Task int
UserTask int
Flow int
Shape int
Edge int
Words map[int][]string
// How many flows are in the BPMN model
// This will be counted by the number of edges
// and if the string contains a preposition, like
// "From" or "To"
Flow int
// How many shapes and edges are in the BPMN model
Shape int
Edge int
// How many words are in the BPMN model
Words map[int][]string
}

// In ...
// In is a copy of the reflection package, but with the
// ability to count the number of elements in the BPMN model.
func (q *Quantities) In(p interface{}) *Quantities {

ref := gobpmn_reflection.New(p)
ref.Interface().Allocate().Maps().Assign()

switch true {

// If the BPMN model is a pool and has embedded structs
case len(ref.Anonym) > 0:
for _, field := range ref.Anonym {
n := ref.Temporary.FieldByName(field)
Expand All @@ -49,24 +76,36 @@ func (q *Quantities) In(p interface{}) *Quantities {
}
}
}

// If the BPMN model is not a pool and has no embedded structs
case len(ref.Anonym) == 0:
for _, field := range ref.Rflct {
q.countProcess(field)
q.countElements(field)
}
}

// Count the number of words in the BPMN model
q.countWords()

return q

}

/*
* @private
* @pprivate
*/

// countPool ...
// countPool counts the number of processes and participants in the BPMN model.
// A pool is structured as a process and has participants and messages.
// Ruleset:
// - If the field contains the word "Pool" and the reflection field contains the word "Process"
// then it is a process.
// - If the field contains the word "Pool" and the reflection field contains the word "ID"
// then it is a participant.
//
// Note:
// The word "Pool" is case insensitive.
func (q *Quantities) countPool(field, reflectionField string) {
if strings.ToLower(field) == "pool" {
if strings.Contains(reflectionField, "Process") {
Expand Down Expand Up @@ -96,16 +135,43 @@ func (q *Quantities) countProcess(field string) {
}
}

// countElements ...
// countElements counts all the elements in the BPMN model
// and increments the counter for each element.
// Ruleset:
// - If the field contains one of the words below and without the word "From"
// then it is an element.
// - If the field contains the word from one of the words below
func (q *Quantities) countElements(field string) {

if utils.After(field, "From") == "" {

switch true {

// events
case strings.Contains(field, "StartEvent"):
q.StartEvent++
case strings.Contains(field, "BoundaryEvent"):
q.BoundaryEvent++
case strings.Contains(field, "IntermediateCatchEvent"):
q.IntermediateCatchEvent++
case strings.Contains(field, "IntermediateThrowEvent"):
q.IntermediateThrowEvent++
case strings.Contains(field, "EndEvent"):
q.EndEvent++

// gateways
case strings.Contains(field, "ComplexGateway"):
q.ComplexGateway++
case strings.Contains(field, "EventBasedGateway"):
q.EventBasedGateway++
case strings.Contains(field, "ExclusiveGateway"):
q.ExclusiveGateway++
case strings.Contains(field, "InclusiveGateway"):
q.InclusiveGateway++
case strings.Contains(field, "ParallelGateway"):
q.ParallelGateway++

// tasks
case strings.Contains(field, "BusinessRuleTask"):
q.BusinessRuleTask++
case strings.Contains(field, "ManualTask"):
Expand All @@ -122,8 +188,10 @@ func (q *Quantities) countElements(field string) {
q.Task++
case strings.Contains(field, "UserTask"):
q.UserTask++

}

// each element in the switch has a shape
q.Shape++

}
Expand Down
1 change: 1 addition & 0 deletions quantities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package gobpmn_counter_test

0 comments on commit 39f2463

Please sign in to comment.