Exemple #1
0
def getCmdResponse(TS, data, logger):
    presModel = data["vqlCmdResponse"]["layoutStatus"]["applicationPresModel"]

    zonesWithWorksheet = utils.selectWorksheetCmdResponse(presModel, logger)
    dataFull = utils.getDataFullCmdResponse(presModel, TS.dataSegments)
    output = []
    for selectedZone in zonesWithWorksheet:
        frameData = utils.getWorksheetCmdResponse(selectedZone, dataFull)

        if frameData is None:
            continue

        df = pd.DataFrame.from_dict(frameData, orient="index").fillna(0).T

        output.append(
            TableauWorksheet(
                scraper=TS,
                originalData=data,
                originalInfo={},
                worksheetName=selectedZone["worksheet"],
                dataFrame=df,
                dataFull=utils.getDataFullCmdResponse(presModel,
                                                      TS.dataSegments),
                cmdResponse=True,
            ))
    return TableauWorkbook(scraper=TS,
                           originalData=data,
                           originalInfo={},
                           data=output,
                           cmdResponse=True)
Exemple #2
0
def getWorksheetCmdResponse(TS, data, worksheetName):
    presModel = data["vqlCmdResponse"]["layoutStatus"]["applicationPresModel"]
    zonesWithWorksheet = [
        t for t in utils.listWorksheetCmdResponse(presModel)
        if t["worksheet"] == worksheetName
    ]
    if len(zonesWithWorksheet) == 0:
        zonesWithWorksheet = [
            t for t in utils.listWorksheetStoryPoint(presModel)
            if t["worksheet"] == worksheetName
        ]
    if len(zonesWithWorksheet) == 0:
        return TableauWorksheet(
            scraper=TS,
            originalData=data,
            originalInfo={},
            worksheetName=worksheetName,
            dataFrame=pd.DataFrame(),
            dataFull=utils.getDataFullCmdResponse(presModel, TS.dataSegments),
            cmdResponse=True,
        )

    selectedZone = zonesWithWorksheet[0]

    dataFull = utils.getDataFullCmdResponse(presModel, TS.dataSegments)
    frameData = utils.getWorksheetCmdResponse(selectedZone, dataFull)

    if frameData is None:
        return TableauWorksheet(
            scraper=TS,
            originalData=data,
            originalInfo={},
            worksheetName=worksheetName,
            dataFrame=pd.DataFrame(),
            dataFull=utils.getDataFullCmdResponse(presModel, TS.dataSegments),
            cmdResponse=True,
        )

    df = pd.DataFrame.from_dict(frameData, orient="index").fillna(0).T

    return TableauWorksheet(
        scraper=TS,
        originalData=data,
        originalInfo={},
        worksheetName=selectedZone["worksheet"],
        dataFrame=df,
        dataFull=utils.getDataFullCmdResponse(presModel, TS.dataSegments),
        cmdResponse=True,
    )
Exemple #3
0
def getWorksheetDownloadCmdResponse(TS, data):
    table = data["vqlCmdResponse"]["cmdResultList"][0]["commandReturn"][
        "underlyingDataTable"]
    dataFull = utils.getDataFullCmdResponse(
        {}, TS.dataSegments, table["dataDictionary"]["dataSegments"])
    frameData = utils.getWorksheetDownloadCmdResponse(
        dataFull, table["underlyingDataTableColumns"])
    df = pd.DataFrame.from_dict(frameData, orient="index").fillna(0).T
    return df
Exemple #4
0
def test_getDataFullCmdResponse():
    presModel = vqlCmdResponse["vqlCmdResponse"]["layoutStatus"]["applicationPresModel"]
    dataFull = utils.getDataFullCmdResponse(presModel, {})
    assert len(dataFull.keys()) == 2
    assert "cstring" in dataFull
    assert "real" in dataFull
    assert len(dataFull["cstring"]) == 9
    assert len(dataFull["real"]) == 5
    assert dataFull["cstring"] == ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
    assert dataFull["real"] == [1, 2, 3, 4, 5]
Exemple #5
0
def test_getWorksheetCmdResponse():
    presModel = vqlCmdResponse["vqlCmdResponse"]["layoutStatus"]["applicationPresModel"]
    dataFull = utils.getDataFullCmdResponse(presModel, {})
    worksheet = utils.listWorksheetCmdResponse(presModel)[0]
    frameData = utils.getWorksheetCmdResponse(worksheet, dataFull)
    assert len(frameData.keys()) == 2
    assert "[FIELD1]-value" in frameData
    assert "[FIELD2]-alias" in frameData
    assert len(frameData["[FIELD1]-value"]) == 4
    assert len(frameData["[FIELD2]-alias"]) == 4
    assert frameData["[FIELD1]-value"] == ["2", "3", "4", "5"]
    assert frameData["[FIELD2]-alias"] == ["6", "7", "8", "9"]
Exemple #6
0
def test_getDataCmdResponse():
    presModel = vqlCmdResponse["vqlCmdResponse"]["layoutStatus"][
        "applicationPresModel"]
    dataFull = utils.getDataFullCmdResponse(presModel, {})
    indicesInfo = utils.getIndicesInfoVqlResponse(presModel, "[WORKSHEET1]")
    frameData = utils.getDataCmdResponse(dataFull, indicesInfo)
    assert len(frameData.keys()) == 2
    assert "[FIELD1]-value" in frameData
    assert "[FIELD2]-alias" in frameData
    assert len(frameData["[FIELD1]-value"]) == 4
    assert len(frameData["[FIELD2]-alias"]) == 4
    assert frameData["[FIELD1]-value"] == ["2", "3", "4", "5"]
    assert frameData["[FIELD2]-alias"] == ["6", "7", "8", "9"]