Skip to content

Commit cfb391a

Browse files
committed
Added additional concepts and relations to be more compliant with WRROC
1 parent dd7fd6c commit cfb391a

2 files changed

Lines changed: 268 additions & 1 deletion

File tree

RO-Crate-REPRESENTATION.md

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Structured of generated RO-Crates using `treecript.rocrate`
2+
3+
As `treecript` gathers timeseries of metrics, the first, naïve approach,
4+
has been describing each one of the metrics of each one of the sampling events,
5+
using next classes.
6+
7+
```mermaid
8+
flowchart LR
9+
A[ActivateAction]
10+
P[PropertyValue]
11+
E[EventSeries]
12+
I["`InstantaneousEvent
13+
Event`"]
14+
O[OrganizeAction]
15+
S[SoftwareApplication]
16+
C[ControlAction]
17+
H[HowToStep]
18+
19+
click A href "https://schema.org/ActivateAction" "ActivateAction" _blank
20+
click P href "https://schema.org/PropertyValue" "PropertyValue" _blank
21+
click E href "https://schema.org/EventSeries" "EventSeries" _blank
22+
click I href "https://schema.org/InstantaneousEvent" "InstantaneousEvent" _blank
23+
click O href "https://schema.org/OrganizeAction" "OrganizeAction" _blank
24+
click S href "https://schema.org/SoftwareApplication" "SoftwareApplication" _blank
25+
click C href "https://schema.org/ControlAction" "ControlAction" _blank
26+
click H href "https://schema.org/HowToStep" "HowToStep" _blank
27+
28+
A -->|resourceUsage| P
29+
A -->|subjectOf| E
30+
A -->|instrument| S
31+
32+
E --> |about| A
33+
E -->|subEvent+| I
34+
35+
I -->|superEvent| E
36+
I -->|source| A
37+
I -->|data+| P
38+
39+
O -->|result| A
40+
O -->|instrument| S
41+
O -->|object*| C
42+
43+
C -->|object| A
44+
C -->|instrument| H
45+
46+
H -->|workExample| S
47+
```
48+
49+
The description of the metrics using [PropertyValue](https://schema.org/PropertyValue) uses next ontological terms and units:
50+
51+
```json
52+
"PID": {
53+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#pid",
54+
"unitCode": None,
55+
"additionalType": "Integer",
56+
},
57+
"Virt": {
58+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#virt",
59+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
60+
"additionalType": "Integer",
61+
},
62+
"Res": {
63+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#res",
64+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
65+
"additionalType": "Integer",
66+
},
67+
"CPU": {
68+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#cpu",
69+
"unitCode": "http://qudt.org/vocab/unit/PERCENT",
70+
"additionalType": "Float",
71+
},
72+
"Memory": {
73+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#memory",
74+
"unitCode": "http://qudt.org/vocab/unit/PERCENT",
75+
"additionalType": "Float",
76+
},
77+
"TCP Connections": {
78+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#tcp_connections",
79+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
80+
"additionalType": "Integer",
81+
},
82+
"Thread Count": {
83+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#thread_count",
84+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
85+
"additionalType": "Integer",
86+
},
87+
"User": {
88+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#user",
89+
"unitCode": "http://qudt.org/vocab/unit/SEC",
90+
"additionalType": "Float",
91+
},
92+
"System": {
93+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#system",
94+
"unitCode": "http://qudt.org/vocab/unit/SEC",
95+
"additionalType": "Float",
96+
},
97+
"Children_User": {
98+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#children_user",
99+
"unitCode": "http://qudt.org/vocab/unit/SEC",
100+
"additionalType": "Float",
101+
},
102+
"Children_System": {
103+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#children_system",
104+
"unitCode": "http://qudt.org/vocab/unit/SEC",
105+
"additionalType": "Float",
106+
},
107+
"IO": {
108+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#io",
109+
"unitCode": "http://qudt.org/vocab/unit/SEC",
110+
"additionalType": "Float",
111+
},
112+
"uss": {
113+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#uss",
114+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
115+
"additionalType": "Integer",
116+
},
117+
"swap": {
118+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#swap",
119+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
120+
"additionalType": "Integer",
121+
},
122+
"processor_num": {
123+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#processor_num",
124+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
125+
"additionalType": "Integer",
126+
},
127+
"core_num": {
128+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#core_num",
129+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
130+
"additionalType": "Integer",
131+
},
132+
"cpu_num": {
133+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#cpu_num",
134+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
135+
"additionalType": "Integer",
136+
},
137+
"processor_ids": {
138+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#processor_ids",
139+
"unitCode": None,
140+
"additionalType": "String",
141+
},
142+
"core_ids": {
143+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#core_ids",
144+
"unitCode": None,
145+
"additionalType": "String",
146+
},
147+
"cpu_ids": {
148+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#cpu_ids",
149+
"unitCode": None,
150+
"additionalType": "String",
151+
},
152+
"process_status": {
153+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#process_status",
154+
"unitCode": None,
155+
"additionalType": "String",
156+
},
157+
"read_count": {
158+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#read_count",
159+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
160+
"additionalType": "Integer",
161+
},
162+
"write_count": {
163+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#write_count",
164+
"unitCode": "http://qudt.org/vocab/unit/CountingUnit",
165+
"additionalType": "Integer",
166+
},
167+
"read_bytes": {
168+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#read_bytes",
169+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
170+
"additionalType": "Integer",
171+
},
172+
"write_bytes": {
173+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#write_bytes",
174+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
175+
"additionalType": "Integer",
176+
},
177+
"read_chars": {
178+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#read_chars",
179+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
180+
"additionalType": "Integer",
181+
},
182+
"write_chars": {
183+
"propertyID": "https://w3id.org/ro/terms/treecript-metrics#write_chars",
184+
"unitCode": "http://qudt.org/vocab/unit/BYTE",
185+
"additionalType": "Integer",
186+
},
187+
```
188+
189+
but this approach generates an RO-Crate 100-fold the size of the original CSV files with the metrics.
190+
191+
You can try the translation first installing treecript,
192+
capturing metrics from an execution and then translating gathered metrics to RO-Crate.
193+
194+
```bash
195+
python3 -mvenv TREECRIPT
196+
TREECRIPT/bin/pip install --upgrade pip wheel
197+
TREECRIPT/bin/pip install 'treecript [analytics,docker] @ git+https://github.com/inab/treecript.git@exec'
198+
source TREECRIPT/bin/activate
199+
200+
# Let's try with an example from the source distribution
201+
# the generated RO-Crate weights more than 670MB!!!
202+
git clone https://github.com/inab/treecript.git
203+
python -m treecript.rocrate --as-directory /tmp/rocrate_as_directory treecript/sample-series/Wetlab2Variations_metrics/2025_05_20-02_19-14001/
204+
```

treecript/rocrate.py

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import logging
2424
import pathlib
2525

26-
from typing import TYPE_CHECKING
26+
from typing import (
27+
cast,
28+
TYPE_CHECKING,
29+
)
2730

2831
if TYPE_CHECKING:
2932
from typing import (
@@ -37,6 +40,8 @@
3740

3841
import pandas.core.series
3942

43+
from pandas import isna as pandas_isna
44+
4045
import rocrate.model.creativework
4146
import rocrate.model.contextentity
4247
import rocrate.rocrate
@@ -268,6 +273,64 @@ def activate_action(wrroc: "rocrate.rocrate.ROCrate", pid_row: "pandas.core.seri
268273
pid_metric = create_property_value(wrroc, "PID", pid_row.PID)
269274
action.append_to("resourceUsage", pid_metric, compact=True)
270275

276+
organize_action = rocrate.model.contextentity.ContextEntity(
277+
wrroc,
278+
"#" + pid_row.node + "_organize",
279+
properties={
280+
"@type": "OrganizeAction",
281+
"name": "Run of " + " ".join(pid_row.full_command),
282+
"startTime": start_action,
283+
},
284+
)
285+
286+
wrroc.add(organize_action)
287+
organize_action.append_to("result", action, compact=True)
288+
289+
assert len(pid_row.full_command) > 0
290+
software_application = rocrate.model.contextentity.ContextEntity(
291+
wrroc,
292+
"#" + pid_row.node + "_software_application",
293+
properties={
294+
"@type": "SoftwareApplication",
295+
"name": pid_row.full_command[0],
296+
},
297+
)
298+
wrroc.add(software_application)
299+
organize_action.append_to("instrument", software_application, compact=True)
300+
action.append_to("instrument", software_application, compact=True)
301+
302+
# Try registering this control action with its parent (if exists)
303+
control_action = rocrate.model.contextentity.ContextEntity(
304+
wrroc,
305+
"#" + pid_row.node + "_control_action",
306+
properties={
307+
"@type": "ControlAction",
308+
"name": "Orchestrate " + " ".join(pid_row.full_command),
309+
},
310+
)
311+
wrroc.add(control_action)
312+
control_action.append_to("object", action, compact=True)
313+
314+
howto_step = rocrate.model.contextentity.ContextEntity(
315+
wrroc,
316+
"#" + pid_row.node + "_howto_step",
317+
properties={
318+
"@type": "HowToStep",
319+
},
320+
)
321+
wrroc.add(howto_step)
322+
howto_step.append_to("workExample", software_application, compact=True)
323+
control_action.append_to("instrument", howto_step, compact=True)
324+
325+
326+
if not pandas_isna(pid_row.parent):
327+
parent_organize_action = cast(
328+
"Optional[rocrate.model.contextentity.ContextEntity]",
329+
wrroc.dereference("#" + pid_row.parent + "_organize")
330+
)
331+
if parent_organize_action is not None:
332+
parent_organize_action.append_to("object", control_action, compact=True)
333+
271334
action_series = rocrate.model.contextentity.ContextEntity(
272335
wrroc,
273336
"#series_" + pid_row.node,

0 commit comments

Comments
 (0)