Anonymous

Changes

From KIproBatt Wiki
import from DevWiki
-- creates an overview over a process chain
-- Module:SMW
local p = {}

function p.GetProcessesGraph()
local process_types = {"LabProcess:OSL9a645a64b15442398ad3c057e1b64d87", "LabProcess:OSL4c1f7444e389471a8250f53407191735"}
local result = p.GetProcesses(process_types)
--mw.logObject(result)

local d = mw.html.create( 'div' )
d:attr( 'class', 'graphviz' )
local g = [[
digraph G {
rankdir=LR
]]
for id,process in pairs(result) do
--mw.logObject(process)
local nodes = ""
local edges = ""
for obj_id, obj in pairs(process['objects']) do
nodes = nodes .. '"' .. obj_id .. '" [label="' .. obj['local_id'] .. '"];'
if (obj['successor_object'] ~= nil) then
for succ_id, succ in pairs(obj['successor_object']) do
edges = edges .. '"' .. obj_id .. '" -> "' .. succ .. '";'
end
end
end
g = g .. [[
subgraph cluster_]] .. id:gsub(":","_") .. [[ {
node [style=filled];
label = "]] .. process['label'] .. [[";
color=blue;
]] .. nodes .. [[

}
]] .. edges .. [[

]]
end
g = g .. [[
}]]
d:wikitext(g)
mw.logObject(d)
return tostring( d )

end

function p.GetProcesses(process_types)

local results = {}

for key,process_type in pairs(process_types) do
results[process_type] = {}
results[process_type]['objects'] = {}
result = p.GetOutputs(process_type)
if (result ~= nil) then
for index, obj in pairs(result) do
--mw.logObject(obj['id'])
results[process_type]['objects'][obj['id']] = obj
end
end
end

local process_type_query = "[[" .. table.concat(process_types, "]] OR [[") .. "]]"
process_type_query = process_type_query .. " |?Display title of#-=label |?#-=process_type |?HasId#-=id |format=plain"
--mw.logObject(process_type_query)
local process_type_infos = mw.smw.ask( process_type_query )
for key,process_type_info in pairs(process_type_infos) do
--mw.logObject(process_type_info)
process_type = process_type_info['process_type']
if (process_type ~= nil) then
for k,v in pairs(process_type_info) do
if (k ~= "process_type") then results[process_type][k] = v end
end
end
end

return results
end

function p.GetOutputs(process_type)
--mw.logObject(obj)
-- please note the unlinking of properties 'page authors', and mainlabel '?' by using the #- operator
-- note also: unlinking via parameter link is not supported at this point
--local process_type = "LabProcess:OSL9a645a64b15442398ad3c057e1b64d87"
local query = "[[Category:LabProcessOutput]] [[-HasObject.IsInstanceOf::" .. process_type .. "]] |?#-=id |?HasId#-=local_id |?-HasPredecessor#-=successor_param |?-HasPredecessor.IsProcessParameterOf#-=successor_subprocess |?-HasPredecessor.IsObjectParameterOf#-=successor_object |?-HasPredecessor.IsProcessParameterOf.IsSubprocessOf#-=successor_process |format=plain"
local result = mw.smw.ask( query )
return result
end

return p
Bots, bulkpusher, Bureaucrats, checkuser, filepusher, Interface administrators, oversight, pusher, rdfioadministrator, rdfiocurator, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Editors (Semantic MediaWiki), Administrators
5,444

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.