def GetConfiguration()

in render-wallboard.py [0:0]


def GetConfiguration(WallboardName):
    global LastRun,ConfigTimeout,DDBTableName,Logger,Table,Settings,Cells,Thresholds,AgentStates,Calculations,DataSources
    
    #
    # We only want to retrieve the configuration for the wallboard if we haven't
    # retrieved it recently or it hasn't previously been loaded.
    #
    GetConfig = False
    if WallboardName not in Settings:
        LastRun = time.time()
        GetConfig = True
        Logger.debug("No config loaded for "+WallboardName+" - retrieving")
    else:
        Logger.debug("Last run at "+str(LastRun)+", timeout is "+str(ConfigTimeout)+", now is "+str(time.time()))
    
        if time.time() > LastRun+ConfigTimeout:
            LastRun = time.time()
            GetConfig = True
            Logger.debug("  Wallboard config needs refreshing")
        else:
            Logger.debug("  Within timeout period - no config refresh")
    
    if not GetConfig: return(True)

    #
    # All relevant wallboard information (how it is to be formatted, threshold
    # details, etc.) all have a primary partition key of the name of the
    # wallboard.
    #
    try:
        Response = Table.query(KeyConditionExpression=Key("Identifier").eq(WallboardName))
    except ClientError as e:
        Logger.error("DynamoDB error: "+e.response["Error"]["Message"])
        return(False)

    if len(Response["Items"]) == 0:
        Logger.error("Did not get any configuration for wallboard "+WallboardName)
        return(False)

    LocalSettings     = DefaultSettings.copy()
    LocalThresholds   = {}
    LocalCells        = {}
    LocalAgentStates  = {}
    LocalCalculations = {}
    LocalDataSources  = {}
    for Item in Response["Items"]:
        if Item["RecordType"] == "Settings":
            for Config in Item:
                LocalSettings[Config] = Item[Config]
        elif Item["RecordType"][:11] == "Calculation":
            if "Formula" not in Item:
                Logger.warning("Formula not set for "+Item["RecordType"]+" in wallboard " +WallboardName+" - ignored")
                continue
            LocalCalculations[Item["Name"]] = Item["Formula"]
        elif Item["RecordType"][:4] == "Cell":
            if "Address" not in Item:
                Logger.warning("Cell address not set for "+Item["RecordType"]+" in wallboard "+WallboardName+" - ignored")
                continue
            LocalCells[Item["Address"]] = Item
        elif Item["RecordType"][:9] == "Threshold":
            if "Name" not in Item:
                Logger.warning("Threshold name not set for "+Item["RecordType"]+" in wallboard "+WallboardName+" - ignored")
                continue
            LocalThresholds[Item["Name"]] = Item
        elif Item["RecordType"][:10] == "AgentState":
            if "StateName" not in Item:
                Logger.warning("Agent state name not set for "+Item["RecordType"]+" in wallboard "+WallboardName+" - ignored")
                continue
            LocalAgentStates[Item["StateName"]] = Item["BackgroundColour"]
        elif Item["RecordType"][:10] == "DataSource":
            if "Name" not in Item:
                Logger.warning("Data source reference not set for "+Item["RecordType"]+" in wallboard "+WallboardName+" - ignored")
                continue
            
            Metric = Item["Reference"].split(":")[2]
            if Metric not in MetricUnitMapping: continue # Ignore non real-time metrics
            LocalDataSources[Item["Name"]] = Item["Reference"]

    Settings[WallboardName]     = LocalSettings
    Cells[WallboardName]        = LocalCells
    Thresholds[WallboardName]   = LocalThresholds
    AgentStates[WallboardName]  = LocalAgentStates
    Calculations[WallboardName] = LocalCalculations
    DataSources[WallboardName]  = LocalDataSources
    
    return(True)