lua scripting - milsoft utility solutions · lua categories • .lua - modify elements • .elua -...

21
Lua Scripting

Upload: vuongdieu

Post on 10-Dec-2018

387 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

Lua Scripting

Page 2: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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

Page 3: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

Lua Categories

•  .LUA - Modify elements •  .ELUA - Create Fields •  .PLUM - Automatic scripts

Page 4: Lua Scripting - Milsoft Utility Solutions · 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  

Page 5: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

ExisBng  ELUA  scripts  

•  Archive  folder  to  shorten  list  

•  Use  exisBng  as  template  ideas.  

•  Be  Careful!  Turning  too  many  “on”  will  slow  model.  

Page 6: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 7: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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?  

Page 8: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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)  

Page 9: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 10: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 11: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 12: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

Where  to  find  field  names?  

•  Complete  lists  –  Lua  editor,  right  side  – Element:getElementField  – Element:setElementField  

Page 13: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 14: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 15: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 16: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

LUA  Scripts  

•  There  are  many  available  by  default  

•  Support  has  several  more  

•  ApplicaBons  can  be  very  specific  

Page 17: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 18: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 19: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 20: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

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  

Page 21: Lua Scripting - Milsoft Utility Solutions · Lua Categories • .LUA - Modify elements • .ELUA - Create Fields • .PLUM - Automatic scripts

QuesBons?  

Eric  Jung  SouthEastern  IL  Electric  CooperaBve  

[email protected]