Module:VillageTest: Difference between revisions

From RetroMC
Jump to navigation Jump to search
(Disabling memory intensive loggin functions since it causes the module to eat the whole 50mb of memory somehow)
No edit summary
Tag: Manual revert
 
(18 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p =  {}
local VillageTest =  {}
local capiunto = require 'capiunto'
local capiunto = require 'capiunto'
--local externalData = require('externaldata')




Line 21: Line 22:
local debug = 0;
local debug = 0;


function p.debug(frame)
function VillageTest.debug(frame)
     debug = 1;
     debug = 1;
p.main(
VillageTest.main(
     mw.getCurrentFrame():newChild{
     mw.getCurrentFrame():newChild{
         title = "Module:VillageTest",
         title = "Module:VillageTest",
Line 34: Line 35:
end
end


--[[
WE CREATE the TABLES HERE FOR THE MODULE TO STORE STUFF IN
DO NOT REMOVE THE TABLES SINCE THEY SERVE THE PURPOSE OF STORING THE DATA SO THAT
MEDIAWIKI CAN UNLOAD EXTENSIONS FROM MEROY BEFORE WE PROCESS THE DATA


function p.main(frame)
]]
 
local VillagesNameTable = {}
local VillagesUuidTable = {}
local VillagesOwnerTable = {}
 
 
function villagehelper(PV_Input, PV_Name, retval)
        local PV_Input =  PV_Input
        local PV_Name = PV_Name
        local retval = retval
        retval:addHeader(PV_Name)
      -- mw.log(' DATA FOR:  '..PV_Name..':')
                for i, PV_Data in ipairs(PV_Input) do  --[[ For Example: playerVillages.__json.data.member ]]--
                    --mw.log('villagehelper iterations:  '..i)
                    --mw.logObject(PV_Data)
                   
                    if PV_Data ~= nil then
                        if type(PV_Data) == "table" and PV_Data.village then
                            --mw.logObject(PV_Data.village)
                          -- mw.log('SUCCESS: PV_Data is a Table')
                            local PV_Data_Local = PV_Data.village
                       
                            retval:addRow('',PV_Data_Local,'','icr-transparency1 icr-data')
                       
                        elseif type(PV_Data) == "string" or PV_Data == nil then
                          --  mw.logObject(PV_Data)
                            --local PV_Data_Local = 'ERROR: API FAILURE'
                          --  mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                        end
                   
                    elseif PV_Data == nil then
                    --  mw.log('ERROR PV_Data is nil ABORTING')
                        retval:addRow('','API ERROR RETURNING NIL','','icr-transparencry1 icr-data')
                   
                    end
                end
end
 
PV_Data = nil
 
function villagelistprocessor(VP_Input, VP_Name, retval)
        local VP_Input = VP_Input
        local VP_Name = VP_Name
        local retval = retval
 
 
        retval:addHeader(VP_Name)
        for i, VP_Data in ipairs(VP_Input) do
 
            if VP_Data ~= nil then
 
 
            if type(VP_Data) == "table" and VP_Data.name and VP_Data.uuid and VP_Data.owner then
                --local VP_Data_Local = VP_Data.name
                --local VP_UUID_Local = VP_Data.uuid
                --local VP_OWNER_LOCAL = VP_Data.owner
 
                table.insert(VillagesNameTable,VP_Data.name)
 
              -- VillagesTable.name = VP_Data.name
                table.insert(VillagesUuidTable,VP_Data.uuid)
                table.insert(VillagesOwnerTable,VP_Data.owner)
     
 
               
 
                --retval:addRow('Name:',VillagesNameTable,'','icr-transparency1 icr-data')
              -- retval:addRow('UUID',VP_UUID_Local,'','icr-transparency1 icr-data')
              -- retval:addRow('OWNER UUID',VP_OWNER_LOCAL,'','icr-transparency1 icr-data')
             
 
            elseif type(VP_Data) == "string" or VP_Data == nil then
                --mw.logObject(VP_Data)
                mw.log('VP_Data is nil this shouldn\'t be the case')
 
            end
            elseif VP_Data == nil then
                mw.log('ERROR VP_Data is nil ABORTING')
                        retval:addRow('','API ERROR RETURNING NIL','','icr-transparencry1 icr-data')
 
            end
    VP_Data = nil
   
 
    end
end
 
 
 
 
function VillageTest.main(frame)
     local args = frame.args
     local args = frame.args
     local input = preprocessArg(args[1])
     local input = preprocessArg(args[1])
Line 71: Line 167:
         bodyClass = 'icr-DiamondCitizenBodyStyle',
         bodyClass = 'icr-DiamondCitizenBodyStyle',
         topClass = 'icr-title'
         topClass = 'icr-title'
       
     })
     })


     retval:addRow('HOWDY', 'HOWDEE', '', 'icr-transparency1 icr-data')
     :addRow('HOWDY', 'HOWDEE', '', 'icr-transparency1 icr-data')


      
      
     if playerVillages.__json.data then
     if playerVillages.__json.data then


        --table.insert(villagels, "1st layer works")
     
          
          
         function villagehelper(PV_Input, PV_Name)
     
            local PV_Input =  PV_Input
         if infoboxtype == "playervillages" then
            local PV_Name = PV_Name
                villagehelper(playerVillages.__json.data.member, "Member",retval)
            retval:addHeader(PV_Name)
                villagehelper(playerVillages.__json.data.owner, "Owner",retval)
            mw.log(' DATA FOR:  '..PV_Name..':')
                villagehelper(playerVillages.__json.data.assistant, "Assistant",retval)
                    for i, PV_Data in ipairs(PV_Input) do  --[[ For Example: playerVillages.__json.data.member ]]--
        elseif infoboxtype == "villagelist" then
                        --mw.log('villagehelper iterations:  '..i)
 
                        --mw.logObject(PV_Data)
            villagelistprocessor(villagelist, "Villages",retval)
                       
 
                        if PV_Data ~= nil then
            --mw.logObject(VillagesNameTable)
                            if type(PV_Data) == "table" and PV_Data.village then
 
                                mw.logObject(PV_Data.village)
            local NAMEDATA = nil
                                mw.log('SUCCESS: PV_Data is a Table')
            local UUIDDATA = nil
                                local PV_Data_Local = PV_Data.village
 
                           
         
                                retval:addRow('',PV_Data_Local,'','icr-transparency1 icr-data')
          for namenumber, VillagesNameData in ipairs(VillagesNameTable) do
                           
                    if VillagesNameData ~= nil then
                            elseif type(PV_Data) == "string" or PV_Data == nil then
 
                                mw.logObject(PV_Data)
                        NAMEDATA = VillagesNameData
                                --local PV_Data_Local = 'ERROR: API FAILURE'
 
                                mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                        mw.logObject(NAMEDATA)
                            end
 
                        retval:addRow('Name:',NAMEDATA,'','icr-transparency1 icr-data')
 
                          
                          
                        elseif PV_Data == nil then
                            mw.log('ERROR PV_Data is nil ABORTING')
                            retval:addRow('','API ERROR RETURNING NIL','','icr-transparencry1 icr-data')
                          
                          
                        end
                    end
        end
        function villagelistprocessor(VP_Input, VP_Name)
            local VP_Input = VP_Input
            local VP_Name = VP_Name
            retval:addHeader(VP_Name)
            for i, VP_Data in ipairs(VP_Input) do


                if VP_Data ~= nil then


                    end
                 
            end
              --  VillagesNameTable = nil
            --  VillagesNameData = nil
              --  NAMEDATA = nil


                if type(VP_Data) == "table" and VP_Data.name and VP_Data.uuid and VP_Data.owner then
           
                    local VP_Data_Local = VP_Data.name
           
                    local VP_UUID_Local = VP_Data.uuid
            for uuidnumber, VillagesUuidData in ipairs(VillagesUuidTable) do
                    local VP_OWNER_LOCAL = VP_Data.owner
                  --  mw.log("Village Number: "..i)
                    --mw.log("UUID: ")
                    --mw.logObject(VP_Data.uuid,'UUID')
                    --mw.logObject(VP_Data.owner, 'Owner UUID')


                      
                     if VillagesUuidData ~= nil then
                       
                        UUIDDATA = VillagesUuidData


                    retval:addRow('Name:',VP_Data_Local,'','icr-transparency1 icr-data')
                        mw.logObject(UUIDDATA)
                    retval:addRow('UUID',VP_UUID_Local,'','icr-transparency1 icr-data')
                    retval:addRow('OWNER UUID',VP_OWNER_LOCAL,'','icr-transparency1 icr-data')
                  -- mw.logObject(VP_Data.name,'NAME') -- We Printing the VP_Data_Local into console here


                        retval:addRow('Name:',UUIDDATA,'','icr-transparency1 icr-data')
                        retval:addRow('Name:','TEST1','','icr-transparency1 icr-data')
                        retval:addRow('Name:','TEST2','','icr-transparency1 icr-data')
                       


                elseif type(VP_Data) == "string" or VP_Data == nil then
                     end
                     --mw.logObject(VP_Data)
                      
                     mw.log('VP_Data is nil this shouldn\'t be the case')
               
 
            end
                end
          --  VillagesUuidTable = nil
                elseif VP_Data == nil then
        --  VillagesUuidData = nil
                    mw.log('ERROR VP_Data is nil ABORTING')
          -- UUIDDATA = nil
                            retval:addRow('','API ERROR RETURNING NIL','','icr-transparencry1 icr-data')
 
                end
          
          
       
           
 
     
        end
              
        end
   
        if infoboxtype == "playervillages" then
                villagehelper(playerVillages.__json.data.member, "Member")
                villagehelper(playerVillages.__json.data.owner, "Owner")
                villagehelper(playerVillages.__json.data.assistant, "Assistant")
        elseif infoboxtype == "villagelist" then
             --    mw.log('--------------------------------------')
              --  mw.log('|                                              |')
            --  mw.log('|    VILLAGE LIST TESTING    |')
            --  mw.log('|                                              |')
              --  mw.log('--------------------------------------')
            --  mw.logObject(villagelistprocessor(villagelist, "Villages"))
                villagelistprocessor(villagelist, "Villages")
                --mw.logObject(villagelist.__json)
         end
         end


Line 182: Line 258:
     return retval
     return retval
end
end
return p
return VillageTest

Latest revision as of 14:12, 31 January 2025

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

local VillageTest  =  {}
local capiunto = require 'capiunto'
--local externalData = require('externaldata')


--[ Thecow275's WikiStats V2 VIllages MODULE PROTOTYPE ]
--[ Nicknamed: UUID and J-Village Update]

local function preprocessArg(s)
if not s then
    return nil 
end
s = s:match('^%s*(.-)%s*$') --trim whitespace
if s == '' then
    return nil
else
    return s
    end

end

local debug = 0;

function VillageTest.debug(frame)
    debug = 1;
VillageTest.main(
    mw.getCurrentFrame():newChild{
        title = "Module:VillageTest",
        args ={"thecow275","villagelist"}
    
     }
    
    )

end

--[[
WE CREATE the TABLES HERE FOR THE MODULE TO STORE STUFF IN
DO NOT REMOVE THE TABLES SINCE THEY SERVE THE PURPOSE OF STORING THE DATA SO THAT
MEDIAWIKI CAN UNLOAD EXTENSIONS FROM MEROY BEFORE WE PROCESS THE DATA

]]

local VillagesNameTable = {}
local VillagesUuidTable = {}
local VillagesOwnerTable = {}


function villagehelper(PV_Input, PV_Name, retval)
        local PV_Input =  PV_Input
        local PV_Name = PV_Name
        local retval = retval
        retval:addHeader(PV_Name)
       -- mw.log(' DATA FOR:  '..PV_Name..':')
                for i, PV_Data in ipairs(PV_Input) do  --[[ For Example: playerVillages.__json.data.member ]]--
                     --mw.log('villagehelper iterations:  '..i)
                     --mw.logObject(PV_Data)
                     
                    if PV_Data ~= nil then
                        if type(PV_Data) == "table" and PV_Data.village then
                            --mw.logObject(PV_Data.village)
                           -- mw.log('SUCCESS: PV_Data is a Table')
                            local PV_Data_Local = PV_Data.village
                        
                            retval:addRow('',PV_Data_Local,'','icr-transparency1 icr-data')
                        
                        elseif type(PV_Data) == "string" or PV_Data == nil then
                          --  mw.logObject(PV_Data)
                            --local PV_Data_Local = 'ERROR: API FAILURE'
                          --  mw.log('ERROR: PV_Data is a String or nil, Supposed to be a Table')
                        end
                    
                    elseif PV_Data == nil then
                     --   mw.log('ERROR PV_Data is nil ABORTING')
                        retval:addRow('','API ERROR RETURNING NIL','','icr-transparencry1 icr-data')
                    
                    end
                end
end

PV_Data = nil

function villagelistprocessor(VP_Input, VP_Name, retval)
        local VP_Input = VP_Input
        local VP_Name = VP_Name
        local retval = retval


        retval:addHeader(VP_Name)
        for i, VP_Data in ipairs(VP_Input) do

            if VP_Data ~= nil then


            if type(VP_Data) == "table" and VP_Data.name and VP_Data.uuid and VP_Data.owner then
                --local VP_Data_Local = VP_Data.name
                --local VP_UUID_Local = VP_Data.uuid
                --local VP_OWNER_LOCAL = VP_Data.owner

                table.insert(VillagesNameTable,VP_Data.name)

               -- VillagesTable.name = VP_Data.name
                table.insert(VillagesUuidTable,VP_Data.uuid)
                table.insert(VillagesOwnerTable,VP_Data.owner)
      

                

                --retval:addRow('Name:',VillagesNameTable,'','icr-transparency1 icr-data')
               -- retval:addRow('UUID',VP_UUID_Local,'','icr-transparency1 icr-data')
               -- retval:addRow('OWNER UUID',VP_OWNER_LOCAL,'','icr-transparency1 icr-data')
               

            elseif type(VP_Data) == "string" or VP_Data == nil then
                --mw.logObject(VP_Data)
                mw.log('VP_Data is nil this shouldn\'t be the case')

            end
            elseif VP_Data == nil then
                mw.log('ERROR VP_Data is nil ABORTING')
                        retval:addRow('','API ERROR RETURNING NIL','','icr-transparencry1 icr-data')

            end
    VP_Data = nil
    

    end
end




function VillageTest.main(frame)
    local args = frame.args
    local input = preprocessArg(args[1])
    local infoboxtype = preprocessArg(args[2]) -- currently unused will be used whenever I implement more datatypes
    

   if not input then -- CHECK FOR BLANK INPUT
       return 'INPUT ERROR INPUT IS NULL'
    end
   if infoboxtype == "{{{2}}}" then
    infoboxtype = "playervillages"
    
   end

    local uuid = '8fa8f70d-eb7d-4743-b0ad-837cdfb69f4e' --[thecow275]--
    --local uuid = 'b08b6a7a-aada-4787-bb4b-07fc393ad6e5' --[QueenOfAsh]--
    local villagelist = mw.ext.externalData.getExternalData({
        url =  "https://api.retromc.org/api/v1/village/getVillageList",
        format =  'json',
        data = villages
    })
     --mw.log('Village List API')
     --mw.logObject(villagelist.villages)
     --mw.logObject(villagelist.error)

    local playerVillages = mw.ext.externalData.getExternalData({
        url = "https://statistics.retromc.org/api/user_villages?uuid=" .. uuid,
        format = 'json',
        data = url

    })
    
    local retval = capiunto.create({
        top = 'TESTING',
        bodyClass = 'icr-DiamondCitizenBodyStyle',
        topClass = 'icr-title'

        
    })

    :addRow('HOWDY', 'HOWDEE', '', 'icr-transparency1 icr-data')

    
    if playerVillages.__json.data then

       
        
      
        if infoboxtype == "playervillages" then
                villagehelper(playerVillages.__json.data.member, "Member",retval)
                villagehelper(playerVillages.__json.data.owner, "Owner",retval)
                villagehelper(playerVillages.__json.data.assistant, "Assistant",retval)
        elseif infoboxtype == "villagelist" then

            villagelistprocessor(villagelist, "Villages",retval)

            --mw.logObject(VillagesNameTable)

            local NAMEDATA = nil
            local UUIDDATA = nil

          
           for namenumber, VillagesNameData in ipairs(VillagesNameTable) do
                    if VillagesNameData ~= nil then

                        NAMEDATA = VillagesNameData

                        mw.logObject(NAMEDATA)

                        retval:addRow('Name:',NAMEDATA,'','icr-transparency1 icr-data')

                        
                        


                    end
                   
            end
              --  VillagesNameTable = nil
             --   VillagesNameData = nil
              --  NAMEDATA = nil

            
            
            for uuidnumber, VillagesUuidData in ipairs(VillagesUuidTable) do

                    if VillagesUuidData ~= nil then
                        
                        UUIDDATA = VillagesUuidData

                        mw.logObject(UUIDDATA)

                        retval:addRow('Name:',UUIDDATA,'','icr-transparency1 icr-data')
                        retval:addRow('Name:','TEST1','','icr-transparency1 icr-data')
                        retval:addRow('Name:','TEST2','','icr-transparency1 icr-data')
                        

                    end
                    
                
            end
          --  VillagesUuidTable = nil
         --   VillagesUuidData = nil
          --  UUIDDATA = nil
        
            
       
            
     
        end


        
       
            
        
        
        
    end
    --mw.logObject(villagels)
    --mw.logObject(playerVillages.__json.data.member)
    --mw.logObject(member.village)
    --mw.logObject(playerVillages.data)
    --mw.logObject(playerVillages.status)
    --mw.logObject(villagelist.villages)
    return retval
end
return VillageTest