cjapy 0.2.3__tar.gz → 0.2.3.post1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/PKG-INFO +1 -1
- cjapy-0.2.3.post1/cjapy/__version__.py +1 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/requestCreator.py +185 -29
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy.egg-info/PKG-INFO +1 -1
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/releases.md +5 -1
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/requestCreator.md +45 -1
- cjapy-0.2.3/cjapy/__version__.py +0 -1
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/LICENSE +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/README.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/__init__.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/cjapy.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/config.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/configs.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/connector.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/projects.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/token_provider.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy/workspace.py +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy.egg-info/SOURCES.txt +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy.egg-info/dependency_links.txt +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy.egg-info/requires.txt +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/cjapy.egg-info/top_level.txt +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/authenticating_without_config_json.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/cja.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/getting_started.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/logging.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/main.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/projects.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/docs/workspace.md +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/pyproject.toml +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/requirements.txt +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/setup.cfg +0 -0
- {cjapy-0.2.3 → cjapy-0.2.3.post1}/setup.py +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.3-1"
|
|
@@ -2,6 +2,7 @@ from copy import deepcopy
|
|
|
2
2
|
import datetime
|
|
3
3
|
import json
|
|
4
4
|
from time import time
|
|
5
|
+
from typing import Union
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class RequestCreator:
|
|
@@ -99,18 +100,130 @@ class RequestCreator:
|
|
|
99
100
|
def __str__(self):
|
|
100
101
|
return json.dumps(self.__request, indent=4)
|
|
101
102
|
|
|
102
|
-
def addMetric(
|
|
103
|
+
def addMetric(
|
|
104
|
+
self,
|
|
105
|
+
metricId: str = None,
|
|
106
|
+
attributionModel: str = None,
|
|
107
|
+
lookbackWindow: Union[int, str] = 30,
|
|
108
|
+
lookbackGranularity: str = "day",
|
|
109
|
+
**kwargs
|
|
110
|
+
) -> None:
|
|
103
111
|
"""
|
|
104
112
|
Add a metric to the template.
|
|
105
113
|
Arguments:
|
|
106
114
|
metricId : REQUIRED : The metric to add
|
|
115
|
+
attributionModel : OPTIONAL : The attribution model to use (e.g., "lastTouch", "firstTouch", "linear", "participation", "sameTouch", "uShaped", "jShaped", "reverseJShaped", "timeDecay", "positionBased", "algorithmic")
|
|
116
|
+
lookbackWindow : OPTIONAL : The lookback window (number of minutes, hours, days, weeks, months, quarters, "session", or "person"). Assumes 30 if not specified.
|
|
117
|
+
lookbackGranularity : OPTIONAL : The granularity of the lookback window (minute, hour, day, week, month, quarter). Defaults to "day".
|
|
118
|
+
**kwargs : Additional model-specific parameters. For "timeDecay" (assumes 1 week): halfLifeNumPeriods, halfLifeGranularity, for "positionBased": firstWeight, middleWeight, lastWeight.
|
|
107
119
|
"""
|
|
108
120
|
if metricId is None:
|
|
109
121
|
raise ValueError("Require a metric ID")
|
|
122
|
+
|
|
123
|
+
if attributionModel and attributionModel not in ["lastTouch", "firstTouch", "linear", "participation", "sameTouch", "uShaped", "jShaped", "reverseJShaped", "timeDecay", "positionBased", "algorithmic"]:
|
|
124
|
+
raise ValueError("Invalid attribution model")
|
|
125
|
+
|
|
126
|
+
if attributionModel and lookbackGranularity not in ["minute", "hour", "day", "week", "month", "quarter"]:
|
|
127
|
+
raise ValueError("Invalid lookbackGranularity. Valid values are: 'minute', 'hour', 'day', 'week', 'month', 'quarter'")
|
|
128
|
+
|
|
110
129
|
columnId = self.__metricCount
|
|
111
130
|
addMetric = {"columnId": str(columnId), "id": metricId}
|
|
112
131
|
if columnId == 0:
|
|
113
132
|
addMetric["sort"] = "desc"
|
|
133
|
+
|
|
134
|
+
if attributionModel:
|
|
135
|
+
# Handle sameTouch separately
|
|
136
|
+
if attributionModel == "sameTouch":
|
|
137
|
+
allocationModel = {
|
|
138
|
+
"func": "allocation-instance"
|
|
139
|
+
}
|
|
140
|
+
else:
|
|
141
|
+
allocationModel = {
|
|
142
|
+
"func": f"allocation-{attributionModel}"
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
# Validate lookback window
|
|
146
|
+
if lookbackWindow is not None and attributionModel != "sameTouch":
|
|
147
|
+
if isinstance(lookbackWindow, int):
|
|
148
|
+
if lookbackWindow <= 0:
|
|
149
|
+
raise ValueError("lookbackWindow must be positive")
|
|
150
|
+
|
|
151
|
+
# Default lookback granularity to days if not specified
|
|
152
|
+
lookbackGranularity = kwargs.get('lookbackGranularity', lookbackGranularity)
|
|
153
|
+
|
|
154
|
+
max_lookback = {
|
|
155
|
+
'minute': 129600,
|
|
156
|
+
'hour': 2160,
|
|
157
|
+
'day': 90,
|
|
158
|
+
'week': 12,
|
|
159
|
+
'month': 3,
|
|
160
|
+
'quarter': 1
|
|
161
|
+
}.get(lookbackGranularity, 90)
|
|
162
|
+
|
|
163
|
+
if lookbackWindow > max_lookback:
|
|
164
|
+
raise ValueError(f"lookbackWindow of {lookbackWindow} exceeds maximum for {lookbackGranularity} granularity")
|
|
165
|
+
|
|
166
|
+
if attributionModel not in ["lastTouch", "firstTouch"] or lookbackWindow != "session":
|
|
167
|
+
allocationModel["lookbackExpiration"] = {
|
|
168
|
+
"func": "allocation-lookbackPeriod",
|
|
169
|
+
"granularity": lookbackGranularity,
|
|
170
|
+
"numPeriods": lookbackWindow
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
addMetric["lookback"] = {
|
|
174
|
+
"func": "min-months",
|
|
175
|
+
"granularity": lookbackGranularity,
|
|
176
|
+
"numPeriods": lookbackWindow
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if attributionModel in ["lastTouch", "firstTouch"]:
|
|
180
|
+
allocationModel["expiration"] = {
|
|
181
|
+
"context": "visitors",
|
|
182
|
+
"func": "allocation-container"
|
|
183
|
+
}
|
|
184
|
+
else:
|
|
185
|
+
allocationModel["context"] = "visitors"
|
|
186
|
+
|
|
187
|
+
elif lookbackWindow == "session":
|
|
188
|
+
if attributionModel in ["lastTouch", "firstTouch"]:
|
|
189
|
+
allocationModel["expiration"] = {
|
|
190
|
+
"context": "sessions",
|
|
191
|
+
"func": "allocation-container"
|
|
192
|
+
}
|
|
193
|
+
else:
|
|
194
|
+
allocationModel["context"] = "sessions"
|
|
195
|
+
elif lookbackWindow == "person":
|
|
196
|
+
if attributionModel not in ["lastTouch", "firstTouch"]:
|
|
197
|
+
allocationModel["context"] = "visitors"
|
|
198
|
+
else:
|
|
199
|
+
raise ValueError("lookbackWindow must be a positive integer or 'session' or 'person'")
|
|
200
|
+
|
|
201
|
+
if attributionModel in ["lastTouch", "firstTouch"]:
|
|
202
|
+
allocationModel["expiration"] = {
|
|
203
|
+
"context": allocationModel.get("expiration", {}).get("context", "visitors"),
|
|
204
|
+
"func": "allocation-container"
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if attributionModel == "timeDecay":
|
|
208
|
+
halfLifeNumPeriods = kwargs.get("halfLifeNumPeriods", 1)
|
|
209
|
+
halfLifeGranularity = kwargs.get("halfLifeGranularity", "week")
|
|
210
|
+
if halfLifeNumPeriods is None or halfLifeGranularity not in ["minute", "hour", "day", "week", "month"]:
|
|
211
|
+
raise ValueError("For 'timeDecay', both 'halfLifeNumPeriods' and 'halfLifeGranularity' are required and granularity must be 'minute', 'hour', 'day', 'week', or 'month'")
|
|
212
|
+
allocationModel["halfLifeGranularity"] = halfLifeGranularity
|
|
213
|
+
allocationModel["halfLifeNumPeriods"] = halfLifeNumPeriods
|
|
214
|
+
|
|
215
|
+
if attributionModel == "positionBased":
|
|
216
|
+
firstWeight = kwargs.get("firstWeight")
|
|
217
|
+
middleWeight = kwargs.get("middleWeight")
|
|
218
|
+
lastWeight = kwargs.get("lastWeight")
|
|
219
|
+
if firstWeight is None or middleWeight is None or lastWeight is None:
|
|
220
|
+
raise ValueError("For 'positionBased', 'firstWeight', 'middleWeight', and 'lastWeight' are required")
|
|
221
|
+
allocationModel["firstWeight"] = firstWeight
|
|
222
|
+
allocationModel["middleWeight"] = middleWeight
|
|
223
|
+
allocationModel["lastWeight"] = lastWeight
|
|
224
|
+
|
|
225
|
+
addMetric["allocationModel"] = allocationModel
|
|
226
|
+
|
|
114
227
|
self.__request["metricContainer"]["metrics"].append(addMetric)
|
|
115
228
|
self.__metricCount += 1
|
|
116
229
|
|
|
@@ -336,47 +449,90 @@ class RequestCreator:
|
|
|
336
449
|
raise ValueError("A dataView ID must be passed")
|
|
337
450
|
self.__request["dataId"] = dataViewId
|
|
338
451
|
|
|
339
|
-
def addGlobalFilter(self, filterId: str = None) -> None:
|
|
452
|
+
def addGlobalFilter(self, filterId: str = None, adHocFilter: dict = None) -> None:
|
|
340
453
|
"""
|
|
341
454
|
Add a global filter to the report.
|
|
342
|
-
NOTE
|
|
455
|
+
NOTE: You need to have a dateRange filter at least in the global report.
|
|
456
|
+
|
|
343
457
|
Arguments:
|
|
344
|
-
filterId :
|
|
345
|
-
|
|
458
|
+
filterId : OPTIONAL : The filter to add to the global filter.
|
|
459
|
+
Example :
|
|
346
460
|
"s2120430124uf03102jd8021" -> segment
|
|
347
461
|
"2020-01-01T00:00:00.000/2020-02-01T00:00:00.000" -> dateRange
|
|
462
|
+
adHocFilter : OPTIONAL : A dictionary representing the ad-hoc filter.
|
|
348
463
|
"""
|
|
349
|
-
if filterId
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
464
|
+
if not filterId and not adHocFilter:
|
|
465
|
+
raise ValueError("You must supply either a filterId or an adHocFilter.")
|
|
466
|
+
if filterId and adHocFilter:
|
|
467
|
+
raise ValueError("You cannot supply both a filterId and an adHocFilter.")
|
|
468
|
+
|
|
469
|
+
if filterId:
|
|
470
|
+
if filterId.startswith("s") and "@AdobeOrg" in filterId:
|
|
471
|
+
filter = {
|
|
472
|
+
"type": "segment",
|
|
473
|
+
"segmentId": filterId,
|
|
474
|
+
}
|
|
475
|
+
elif filterId.startswith("20") and "/20" in filterId:
|
|
476
|
+
filter = {
|
|
477
|
+
"type": "dateRange",
|
|
478
|
+
"dateRange": filterId,
|
|
479
|
+
}
|
|
480
|
+
elif ":::" in filterId:
|
|
481
|
+
dimension, itemId = filterId.split(":::")
|
|
482
|
+
filter = {
|
|
483
|
+
"type": "breakdown",
|
|
484
|
+
"dimension": dimension,
|
|
485
|
+
"itemId": itemId,
|
|
486
|
+
}
|
|
487
|
+
else:
|
|
488
|
+
filter = {
|
|
489
|
+
"type": "segment",
|
|
490
|
+
"segmentId": filterId,
|
|
491
|
+
}
|
|
492
|
+
else:
|
|
371
493
|
filter = {
|
|
372
|
-
"type":
|
|
373
|
-
"
|
|
494
|
+
"type": "segment",
|
|
495
|
+
"segmentDefinition": adHocFilter
|
|
374
496
|
}
|
|
497
|
+
|
|
375
498
|
### incrementing the count for globalFilter
|
|
376
499
|
self.__globalFiltersCount += 1
|
|
377
500
|
### adding to the globalFilter list
|
|
378
501
|
self.__request["globalFilters"].append(filter)
|
|
379
502
|
|
|
503
|
+
def setDateRange(self, start_date: Union[str], end_date: Union[str]) -> None:
|
|
504
|
+
"""
|
|
505
|
+
Set the date range for the request.
|
|
506
|
+
Arguments:
|
|
507
|
+
start_date : REQUIRED : The start date for the report in 'YYYY-MM-DD' format or datetime object.
|
|
508
|
+
end_date : REQUIRED : The end date for the report in 'YYYY-MM-DD' format or datetime object.
|
|
509
|
+
"""
|
|
510
|
+
def ensure_datetime_format(date: Union[str], is_start: bool) -> str:
|
|
511
|
+
if isinstance(date, str):
|
|
512
|
+
date = datetime.datetime.fromisoformat(date)
|
|
513
|
+
if date.time() == datetime.datetime.min.time():
|
|
514
|
+
if is_start:
|
|
515
|
+
return date.strftime('%Y-%m-%dT00:00:00.000')
|
|
516
|
+
else:
|
|
517
|
+
return date.strftime('%Y-%m-%dT23:59:59.999')
|
|
518
|
+
return date.strftime('%Y-%m-%dT%H:%M:%S.000')
|
|
519
|
+
|
|
520
|
+
start_date_str = ensure_datetime_format(start_date, is_start=True)
|
|
521
|
+
end_date_str = ensure_datetime_format(end_date, is_start=False)
|
|
522
|
+
date_range = f"{start_date_str}/{end_date_str}"
|
|
523
|
+
|
|
524
|
+
# Update global filters with the new date range
|
|
525
|
+
date_range_filter = {
|
|
526
|
+
"type": "dateRange",
|
|
527
|
+
"dateRange": date_range
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
# Remove any existing dateRange filters before adding the new one
|
|
531
|
+
self.__request["globalFilters"] = [
|
|
532
|
+
f for f in self.__request["globalFilters"] if f["type"] != "dateRange"
|
|
533
|
+
]
|
|
534
|
+
self.__request["globalFilters"].append(date_range_filter)
|
|
535
|
+
|
|
380
536
|
def updateDateRange(
|
|
381
537
|
self,
|
|
382
538
|
dateRange: str = None,
|
|
@@ -13,7 +13,11 @@ Patch:
|
|
|
13
13
|
* Fixing some edge cases of `findComponentUsage`
|
|
14
14
|
* Adding more parameters for `createDataView` methods
|
|
15
15
|
* Fixing `updateCalculatedMetric`
|
|
16
|
-
* Fixing the `setSearch
|
|
16
|
+
* Fixing the `setSearch`\
|
|
17
|
+
Patch:
|
|
18
|
+
* adding attribution model possibility to addMetric in `RequestCreator`
|
|
19
|
+
* adding `setDateRange` method in `RequestCreator`
|
|
20
|
+
* supporting adhoc filter in `RequestCreator`
|
|
17
21
|
|
|
18
22
|
## 0.2.1
|
|
19
23
|
|
|
@@ -75,6 +75,44 @@ We will review the different methods available via the object.
|
|
|
75
75
|
|
|
76
76
|
* `addMetric()`
|
|
77
77
|
Add a metric to the Request.
|
|
78
|
+
Arguments:
|
|
79
|
+
* metricId : REQUIRED : The metric to add
|
|
80
|
+
* attributionModel : OPTIONAL : The attribution model to use (e.g., "lastTouch", "firstTouch", "linear", "participation", "sameTouch", "uShaped", "jShaped", "reverseJShaped", "timeDecay", "positionBased", "algorithmic")
|
|
81
|
+
* lookbackWindow : OPTIONAL : The lookback window (number of minutes, hours, days, weeks, months, quarters, "session", or "person"). Assumes 30 if not specified.
|
|
82
|
+
* lookbackGranularity : OPTIONAL : The granularity of the lookback window (minute, hour, day, week, month, quarter). Defaults to "day".
|
|
83
|
+
* **kwargs : Additional model-specific parameters. For "timeDecay" (assumes 1 week): halfLifeNumPeriods, halfLifeGranularity; for "positionBased": firstWeight, middleWeight, lastWeight.
|
|
84
|
+
|
|
85
|
+
The `addMetric` method also supports various attribution models. For example, the `sameTouch` model is defined without a lookback window, while other models like `lastTouch` and `firstTouch` can have lookback windows and expiration settings. The `timeDecay` model allows specifying half-life periods and granularity, with defaults to 1 week if not provided.
|
|
86
|
+
|
|
87
|
+
Examples:
|
|
88
|
+
```python
|
|
89
|
+
# Adding a simple metric
|
|
90
|
+
myRequest.addMetric("metrics/orders")
|
|
91
|
+
|
|
92
|
+
# Adding a metric with an attribution model
|
|
93
|
+
myRequest.addMetric("metrics/orders", attributionModel="lastTouch", lookbackWindow=30)
|
|
94
|
+
|
|
95
|
+
# Adding a metric with a custom attribution model
|
|
96
|
+
myRequest.addMetric(
|
|
97
|
+
"metrics/orders",
|
|
98
|
+
attributionModel="timeDecay",
|
|
99
|
+
lookbackWindow=60,
|
|
100
|
+
halfLifeNumPeriods=1,
|
|
101
|
+
halfLifeGranularity="week"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
# Adding a metric with position-based attribution model
|
|
105
|
+
myRequest.addMetric(
|
|
106
|
+
"metrics/orders",
|
|
107
|
+
attributionModel="positionBased",
|
|
108
|
+
lookbackWindow=30,
|
|
109
|
+
firstWeight=30,
|
|
110
|
+
middleWeight=20,
|
|
111
|
+
lastWeight=50
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
# Adding a metric with sameTouch attribution model
|
|
115
|
+
myRequest.addMetric("metrics/orders", attributionModel="sameTouch")
|
|
78
116
|
|
|
79
117
|
* `addGlobalFilter()`
|
|
80
118
|
Add a global filter to the report.
|
|
@@ -131,6 +169,12 @@ We will review the different methods available via the object.
|
|
|
131
169
|
* filterId : REQUIRED : The filter to add.
|
|
132
170
|
when breakdown, use the following format for the value "dimension:::itemId"
|
|
133
171
|
|
|
172
|
+
* `setDateRange()`
|
|
173
|
+
Set the date range for the request.
|
|
174
|
+
Arguments:
|
|
175
|
+
* start_date : REQUIRED : The start date for the report in 'YYYY-MM-DD' format or datetime object.
|
|
176
|
+
* end_date : REQUIRED : The end date for the report in 'YYYY-MM-DD' format or datetime object.
|
|
177
|
+
|
|
134
178
|
* `updateDateRange()`
|
|
135
179
|
Update the dateRange filter on the globalFilter list
|
|
136
180
|
One of the 3 elements specified below is required.
|
|
@@ -167,4 +211,4 @@ This can help you derive other dates if needed.
|
|
|
167
211
|
|
|
168
212
|
### search
|
|
169
213
|
|
|
170
|
-
`search` attribute is a boolean defining if search has been set for the dimension.
|
|
214
|
+
`search` attribute is a boolean defining if search has been set for the dimension.
|
cjapy-0.2.3/cjapy/__version__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.3"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|