Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Statistics needed in getReport2() #77

Closed
set92 opened this issue Mar 22, 2022 · 5 comments
Closed

[Bug] Statistics needed in getReport2() #77

set92 opened this issue Mar 22, 2022 · 5 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@set92
Copy link

set92 commented Mar 22, 2022

I would call it a bug but maybe is mandatory for some weird thing. But when I call to getReport2() without statistics block it returns an error.

p:\programdata\anaconda3\lib\site-packages\aanalytics2\aanalytics2.py in getReport2(self, request, limit, n_results, allowRemoteLoad, useCache, useResultsCache, includeOberonXml, includePredictiveObjects, returnsNone, countRepeatInstances, ignoreZeroes, rsid, resolveColumns, save, returnClass)
   2720             dataRequest["statistics"]["ignoreZeroes"] = True
   2721         else:
-> 2722             dataRequest["statistics"]["ignoreZeroes"] = False
   2723         ### Request data
   2724         if self.loggingEnabled:

KeyError: 'statistics'

My json file (modified just in case) is this one, in which I don't have the statistics block.

jsn = """{
    "rsid": "id1",
    "globalFilters": [
        {
            "type": "segment",
            "segmentId": "s21_59c218..."
        },
        {
            "type": "dateRange",
            "dateRange": "2022-01-01T00:00:00.000/2022-02-01T00:00:00.000"
        }
    ],
    "metricContainer": {
        "metrics": [
            {
                "columnId": "0",
                "id": "metrics/visitors"
            },
            {
                "columnId": "2",
                "id": "metrics/visitors",
                "filters": [
                    "0"
                ]
            }
        ],
        "metricFilters": [
            {
                "id": "0",
                "type": "segment",
                "segmentId": "s21_59c218..."
            }
        ]
    },
    "dimension": "variables/daterangeday",
    "settings": {
        "countRepeatInstances": true,
        "includeAnnotations": false,
        "dimensionSort": "asc"
    }
}"""
jsn = json.loads(jsn)

The fix is easy, since I only have to add a random one like this one at the end.

,
    "statistics": {
        "functions": [
            "col-max",
            "col-min"
        ]
    }

But in general, I don't want the statistics but the filteredTotals and totals from summaryData (which I already have), not the col-max and col-min.

Also, with getReport() I could send the json as string, but now I need to parse it with json.loads() before using getReport2(), is not a problem because this way I can modify more stuff, but just in case you wanted to maintain the same behavior in both calls.

Thanks for the library and the new version 😄

@pitchmuc pitchmuc self-assigned this Mar 22, 2022
@pitchmuc pitchmuc added the bug Something isn't working label Mar 22, 2022
@pitchmuc
Copy link
Owner

Thanks for providing this, probably miss to test that case.
I can probably fix that so you do not have to add a statistics key.

I will do a fix this week.

Some questions as you tested the new version :)
Do you use the RequestCreator and do you find the Workspace class returned by the result better than the old getReport result ?

@set92
Copy link
Author

set92 commented Mar 22, 2022

Tbh I'm using the simplest things. Basically in my company there is some department of analytics that generates this type of reports for business, CEOs, etc... And, although I'm not certain why me xD, I'm doing the automatization of those reports, my normal job is data scientist but the guy who tend to do this job manually doesn't know how to program in python, so he creates the segments in Adobe Analytics and send me the JSONs, which I use to call the API, join the dataframes and put them in BigQuery to use datastudio as tool of visualization for business.

Therefore, I don't use RequestCreator, and there are some differences with the new method (like dict vs params, n_result vs n_results or the need to parse it as json), but in general are pretty similar, I like that know I can check the summaryData, which is useful when I'm doing monthly calls and then I have the mean of the data in the summaryData instead of needing to do another call, which will delay the rest of the calls, so I'm trying to do few and big calls, instead of small and many calls to not have problems with the limitations of the API xD.

@pitchmuc
Copy link
Owner

thanks, appreciate the feedback.
I was not scrupulous enough for the parameters (n_results vs n_result), I will try to support both via kwargs, so you can change the method easily.
Normally, you can pass a dict for the request, not mandatory have a JSON.
It may be badly documented.

@pitchmuc pitchmuc added the enhancement New feature or request label Mar 22, 2022
@pitchmuc
Copy link
Owner

The new release should fix this @set92.
Let me know if it works for you to get it to version 0.3.1.post2

I will add the kwargs supports later with another release.

@set92
Copy link
Author

set92 commented Mar 22, 2022

Works, thanks :D

@set92 set92 closed this as completed Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants