lua scripting - milsoft utility solutions · lua categories • .lua - modify elements • .elua -...
TRANSCRIPT
Lua Scripting
Purpose
• Explain basic editing techniques • Reduce anxiety • Provide examples of scripts • Inspire • Prove that one need not be a CS major to
work with LUA
Lua Categories
• .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts
Where to start ?
• Begin modifying ELUA’s – Simple – Useful by many for daily business
• Templates – Some labeled “templates” exist – Think of exisBng ELUA scripts as templates
ExisBng ELUA scripts
• Archive folder to shorten list
• Use exisBng as template ideas.
• Be Careful! Turning too many “on” will slow model.
Simple 5 step modificaBon process
• Open Script Manager and select “Lua Fields” tab
• Double click ELUA to modify • “Save as” and rename as you see fit • Modify code • AcBvate Script
ModificaBon example outline
• Goal: Create a field that displays the next Upline device from any element.
• Step one: find ELUA that performs similar funcBon. – Upline Transformer Equipment? – Upline Transformer KVA?
ModificaBon Example code review -‐-‐Upline Transformer KVA.Elua -‐-‐ BEGIN META DATA -‐-‐<luaelemenXield> -‐-‐ <name>Upline Transformer KVA</name> This is the name of the field created -‐-‐ <type>stringTypeEnum</type> -‐-‐ <category>fieldCategoryGeneral</category> -‐-‐ <geXuncBon>UplineTransformerKVA</geXuncBon> This sets the funcBon name below -‐-‐ <seXuncBon></seXuncBon> -‐-‐</luaelemenXield> -‐-‐ END META DATA funcBon UplineTransformerKVA( element ) This must match funcBon name above
local parent = GetParent( element ) This selects the parent of the element while parent ~= nil do This creates loop, moves up connecBvity tree if GetElementField( parent, 'Type' ) == 'Transformer' then Selects type of element we are interested in local kva = GetElementField( parent, "Transformer Base Kva" ) Sets the value “kva” to field value if not kva then kva = 0.0 end return kva Returns value from “kva” field to new field end parent = GetParent( parent ) Selects parent of current selecBon (loop) if parent == nil then return 'none' end If parent does not exist, terminate loop end
end
Green boxes: Items must be modified Red text: funcBon explained on right (Blue text)
Modified code example -‐-‐ BEGIN META DATA -‐-‐<luaelemenXield> -‐-‐ <name>Upline Dev Equip</name> -‐-‐ <type>stringTypeEnum</type> -‐-‐ <category>fieldCategoryGeneral</category> -‐-‐ <geXuncBon>UplineDevice</geXuncBon> -‐-‐ <seXuncBon></seXuncBon> -‐-‐</luaelemenXield> -‐-‐ END META DATA funcBon UplineDevice( element )
local parent = GetParent( element ) while parent ~= nil do if GetElementField( parent, 'Type' ) == 'Device' then local kva = GetElementField( parent, "Device Equipment" ) if not kva then kva = 0.0 end return kva end parent = GetParent( parent ) if parent == nil then return 'none' end end
end
Items in Red: Must change Items in Green: Should change
Modified code result
Selected line secBons
ResulBng fields
What else could we have returned? • Element name • Device capacity • Map name • Any field from the device
How is this useful?
• Assists with finding errors – Three phase transformers feeding only single phase customers – “Upline transformer phasing”
• External table manager – ELUA fields mapped to external tables – Example – “Upline OCR” connected to blink data from AMI
Where to find field names?
• Complete lists – Lua editor, right side – Element:getElementField – Element:setElementField
Data loss correcBon
• Data Loss: Line segments out of posiBon
• Create 4 ELUA fields – Parent X – Parent Y – Child X2 – Child Y2
Line segment connected but not proper X and Y
Data loss correcBon
• Data loss: line secBons lost equipment data • Create ELUA to return “parent equipment” • Use global editor to correct
– Example: If #2 ACSR parent, Then likely #2ACSR child. For all “parent equipment”= #2ACSR then edit set
Mapping ELUA field to external tables
• Create fields in Ext. Tables
• Match to ELUA in “WindMil Field”
• ELUA is then available to mapping
• ConnecBon to AMI
LUA Scripts
• There are many available by default
• Support has several more
• ApplicaBons can be very specific
Useful LUA scripts
• “From File” Scripts – highly useful for bulk changes – Good candidates for modificaBon
• Modify data – Copy data – alter WindMil fields to ext. table fields
Updateable uBliBes
• All former updateable uBliBes moved to LUA • Highly useful Scripts
– Rephase elements in file – Apply reliability indexes
• Some former uBliBes are difficult to find – Call support if unable to locate
ImporBng SQL load data
• Update from last year • Concept –
– Load data stored in External tables – Link CIS, AMI and WindMil data together – Create “loadview” table – Lua script imports this table to populate Calculated load directly
Progress
• IniBal phase in development – Export from SQL to flaXile – LUA imports flat file directly to calculated load
• Second phase – Move load to consumer external table in SQL – LUA imports directly from external table field