Module:Solab1

From solab
Revision as of 12:42, 29 November 2019 by Gio (talk | contribs) (Created page with " local subString, lenString = mw.ustring.sub, mw.ustring.len local p = {} local url = require "Module:URL" local util = require "Module:Utility" local split = util.split...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Solab1/doc

 local subString, lenString = mw.ustring.sub, mw.ustring.len
 local p = {}
 local url = require "Module:URL"
 local util = require "Module:Utility"
 local split = util.split
 local comp = util.comp
 local subString, lenString = mw.ustring.sub, mw.ustring.len
 local gm = string.gmatch

 function p.Company(frame)
    local fields ={'Name',
                   'Cat',
                   'Product',
                   'products',
                   'Technology',
                   'Homepage',
                   'streetAddress',
                   'has_location_city','city',
                   'has_location_country', 'country',
                   'has_coordinates',
                   'Photo',
                   'logo',
                   'ticker'}
    r= ''
    r = r..'\n{|class="wikitable sortable"\n!Name!!Value\n'

    for key, nam in pairs(fields) do 
     local val = frame.args[nam]
     if val == nil and nam == 'Name' then
        r = r..'|-\n|'..nam..'|| [[Name::'.. mw.title.getCurrentTitle().text ..']]\n'
     elseif val ~= nil and (nam == 'Product' or nam == 'Technology' or nam == 'products')  then
       val = split(val, ',') 
       val_list = ''
       for y,x in ipairs(val) do
              val_list  = val_list .. '[['..nam..'::'..x..']],'
       end
       r = r..'|-\n|[['..nam..']]||'..val_list..'\n' 
     elseif val ~= nil and  (nam == 'Photo'  or nam == 'logo')  then
       r = r..'|-\n|'..nam..'||[[File:'..val..'| 150px ]]\n'
     elseif val == nil and  nam == 'Cat' then
        r = r..'|-\n|'..nam..'|| [[Cat::Solar]]\n' 
     elseif val ~= nil and (nam == 'has_location_city' or nam == 'city') then
         --r = r..'|-\n|[[Property:'..nam..']]||[['..nam..'::'..val..']]\n'
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'
          hsc = 'Has location country'
          hasc =  'Has coordinates'
          format = 'format=list'
          link  = 'link=none'
          co    = '?Country'
          coord = '?Coordinates'
          local hscv=frame:preprocess("{{#show: "..val.."|"..co.."|"..link.."|"..format.."}}")
          local hsco=frame:preprocess("{{#show: "..val.."|"..coord.."|"..link.."|"..format.."}}")
          if frame.args['has_location_country'] == nil then
             r = r..'|-\n|[[Property:'..hsc..']]||[['..hsc..'::'..hscv..']]\n' 
          end
          if frame.args['has_coordinates'] == nil then
              r = r..'|-\n|[[Property:'..hasc..']]||[['..hasc..'::'..hsco..']]\n'
          end
    elseif val ~= nil and nam == 'has_location_country' then
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'

    elseif val ~= nil and nam == 'has_coordinates' then
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'
          --r = r..'|-\n|[[Property:'..nam..']]||[['..nam..'::'..val..']]\n'

    elseif val ~= nil and  nam == 'ticker' then
             r = r..'|-\n|[[Property:'..nam..']]||[['..nam..'::'..val..']]\n'
             local grap=frame:preprocess("{{#stockchart: ticker="..val.."}}")
             r = r..'|-\n|[['..nam..']]||'..grap..'\n'
                  urlin = 'https://www.google.com/finance?q=' .. val 
             r = r..'|-\n|google.com/finance||'..url._url(urlin,urlin)..'\n'
     elseif val ~= nil then

     r = r..'|-\n|'..nam..'||[['..nam..'::'..val..']]\n'
    end 
     end
    r=r..'|}\n'

    local man=frame:preprocess("{{#ask: [[HasManufacturer::{{PAGENAME}}]] |?Category }}")

    r = r .. man ..'\n'
    return r
end

function p.Event(frame)
    local t={}   
    local fields ={'Title',
                   'Cat',
                   'Start_date',
                   'End_date',
                   'Homepage',
                   'has_location_city',
                   'has_location_country',
                   'has_coordinates',
                   'Photo'
                   }

    r = ''
    r = r..'\n{|class="wikitable sortable"\n!Name!!Value\n'
 
    for key, nam in pairs(fields)  do 
     local val  = frame.args[nam]
     if val == nil and  nam == 'Name' then
        r = r..'|-\n|'..nam..'|| [[Name::'.. mw.title.getCurrentTitle().text ..']]\n'
     elseif val ~= nil and (nam == 'Product' or nam == 'Technology')  then
      val  =  split( val, ',' ) 
      val_list = ''
      for y,x in ipairs(val)  do
       val_list  = val_list .. '[['..nam..'::'..x..']],'
       end
        r = r..'|-\n|[['..nam..']]||'..val_list..'\n' 
     elseif val ~= nil and  nam == 'Photo' then
        r = r..'|-\n|'..nam..'|Poster||[[File:'..val..'| 150px ]]\n'
     elseif val == nil and  nam == 'Cat' then
        r = r..'|-\n|'..nam..'|| [[Cat::Solar]]\n' 

     elseif val ~= nil and nam == 'has_location_city' then
         r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'
          hsc = 'Has location country'
          hasc =  'Has coordinates'
          format = 'format=list'
          link  = 'link=none'
          co    = '?Country'
          coord = '?Coordinates'

          local hscv=frame:preprocess("{{#show: "..val.."|"..co.."|"..link.."|"..format.."}}")
          local hsco=frame:preprocess("{{#show: "..val.."|"..coord.."|"..link.."|"..format.."}}")
           if frame.args['has_location_country'] == nil then
             r = r..'|-\n|[[Property:'..hsc..'|Country]]||[['..hsc..'::'..hscv..']]\n' 
           end
           if frame.args['has_coordinates'] == nil then
              r = r..'|-\n|[[Property:'..hasc..'|GEO]]||[['..hasc..'::'..hsco..']]\n' 
           end

     elseif val ~= nil and nam == 'has_location_country' then
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'
     
    elseif val ~= nil and nam == 'has_coordinates' then
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'

     elseif val ~= nil then
     r = r..'|-\n|'..nam..'||[['..nam..'::'..val..']]\n'
    end 
     end
    r=r..'|}\n'
    return r
end



function p.Panel(frame)
    local t={}   
    local fields =
{'Name', 
                  'Material', 
                  'Product',
                  'Homepage',
                  'Producer',
                  'Photo',
'Pmax',
'Vmpp',
'Impp',
'Voc',
'Isc',
'Max. over current rating',
'Power tolerance',
'Max. system voltage',
'Solar panel efficiency',
'Weight',
'Maximum_Reverse_Current',
 'COP',
 'Eta',
 'ticker' }

    r = ''
    r = r..'\n{|class="wikitable sortable"\n!name!!value\n'

    for key, nam in pairs(fields)  do 
     local val  = frame.args[nam]
     if val ~= nil and nam == 'Product' then
      val  =  split( val, ',' ) 
      val_list = ''
      for y,x in ipairs(val)  do
       val_list  = val_list .. '[['..nam..'::'..x..']],'
       end
        r = r..'|-\n|[['..nam..']]||'..val_list..'\n'
     elseif val ~= nil and nam == 'Photo' then
        r = r..'|-\n|'..nam..'||[[File:'..val..'| 150px ]]\n' 
        r = r..'|-\n|'.. 'Electrical data' ..'||[['..'STC' ..']]\n' 
     elseif val ~= nil and  nam == 'Producer' then
        r = r..'|-\n|'..nam..'||[[hasManufacturer::'..val..']]\n' 
     elseif val ~= nil then
     r = r..'|-\n|'..nam..'|| [['..nam..'::'..val..']]\n'
     else
     r = r..'|-\n|[['..nam..']]|| [['..nam..'::'..'??'..']]\n'
    end 
     end
    r=r..'|}\n'
    return r
end


function p.Plant(frame)
local fields ={'Name',
                   'Cat',
                   'Product',
                   'Power',
                   'products',
                   'Technology',
                   'Homepage',
                   'has_location_city','city',
                   'has_location_country', 'country',
                   'has_coordinates',
                   'Photo',
                   'Owner',
                    'Developer',
                   'logo',
                   'ticker'}

    r= ''
    r = r..'\n{|class="wikitable sortable"\n!Name!!Value\n'

    for key, nam in pairs(fields) do 
     local val = frame.args[nam]
     if val == nil and nam == 'Name' then
        r = r..'|-\n|'..nam..'|| [[Name::'.. mw.title.getCurrentTitle().text ..']]\n'
     elseif val ~= nil and (nam == 'Product' or nam == 'Technology' or nam == 'products')  then
       val = split(val, ',') 
       val_list = ''
       for y,x in ipairs(val) do
              val_list  = val_list .. '[['..nam..'::'..x..']],'
       end
       r = r..'|-\n|[['..nam..']]||'..val_list..'\n' 
     elseif val ~= nil and  (nam == 'Photo'  or nam == 'logo')  then
       r = r..'|-\n|'..nam..'||[[File:'..val..'| 150px ]]\n'
     elseif val == nil and  nam == 'Cat' then
        r = r..'|-\n|'..nam..'|| [[Cat::Solar]]\n' 
     elseif val ~= nil and (nam == 'has_location_city' or nam == 'city') then
         --r = r..'|-\n|[[Property:'..nam..']]||[['..nam..'::'..val..']]\n'
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'
          hsc = 'Has location country'
          hasc =  'Has coordinates'
          format = 'format=list'
          link  = 'link=none'
          co    = '?Country'
          coord = '?Coordinates'
          local hscv=frame:preprocess("{{#show: "..val.."|"..co.."|"..link.."|"..format.."}}")
          local hsco=frame:preprocess("{{#show: "..val.."|"..coord.."|"..link.."|"..format.."}}")
          if frame.args['has_location_country'] == nil then
             r = r..'|-\n|[[Property:'..hsc..']]||[['..hsc..'::'..hscv..']]\n' 
          end
          if frame.args['has_coordinates'] == nil then
              r = r..'|-\n|[[Property:'..hasc..']]||[['..hasc..'::'..hsco..']]\n'
          end
    elseif val ~= nil and nam == 'has_location_country' then
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'

    elseif val ~= nil and nam == 'has_coordinates' then
          r = r..'|-\n|[[Property:'..nam..'|'..nam..']]||[['..nam..'::'..val..']]\n'
          --r = r..'|-\n|[[Property:'..nam..']]||[['..nam..'::'..val..']]\n'

    elseif val ~= nil and  nam == 'ticker' then
             r = r..'|-\n|[[Property:'..nam..']]||[['..nam..'::'..val..']]\n'
             local grap=frame:preprocess("{{#stockchart: ticker="..val.."}}")
             r = r..'|-\n|[['..nam..']]||'..grap..'\n'
                  urlin = 'https://www.google.com/finance?q=' .. val 
             r = r..'|-\n|google.com/finance||'..url._url(urlin,urlin)..'\n'
     elseif val ~= nil then

     r = r..'|-\n|'..nam..'||[['..nam..'::'..val..']]\n'
    end 
     end
    r=r..'|}\n'
    return r
end



function p.In(frame)
    local t={}
    for n,v in frame:argumentPairs() do table.insert (t,{n,v}) end
    table.sort (t,comp)
    tot = 0
    r = '{|class="wikitable sortable"\n!name!!value\n'
    for i,nv in ipairs(t) do 
    r = r..'|-\n|'..nv[1]..'||[['..nv[1]..'::'..nv[2]..']]\n' 
    end
    r=r..'|}\n'
    return r
end

function p.Out(frame)
    local t={}
    for n,v in frame:argumentPairs() do table.insert (t,{n,v}) end
    table.sort (t,comp)
    tot = 0
    r = '{|class="wikitable sortable"\n!name!!value\n'
    for i,nv in ipairs(t) do 
    r = r..'|-\n|'..nv[1]..'||'..nv[2]..'\n' 
    tot = tot + nv[2]
    end
    r = r..'|-\n|'..'Tot'..'||'..tot..'\n'
    r=r..'|}\n'
    return r
end
return p