Skip to content

Commit

Permalink
Added completions pivot table for data prior to Oct 4 change
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan-moore-97 committed Oct 12, 2023
1 parent 0c93518 commit c8f9312
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
11 changes: 7 additions & 4 deletions gdrive/analytics_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def run_analytics_task(start_date: datetime, end_date: datetime):
sheets_id = export(analytics_df, start_date, end_date)
do_analytics_export_post_processing(analytics_df, sheets_id=sheets_id)
except Exception as e:
log.error(e.args)
log.error(e)


async def list_accounts_task():
Expand Down Expand Up @@ -127,7 +127,7 @@ def export(
"""
filename_str = get_filename(date_of_report, end_date)
analytics_folder_id = drive_client.create_folder(
"Google Analytics", parent_id=settings.ROOT_DIRECTORY
"Google Analytics", parent_id=settings.ANALYTICS_ROOT
)

# We have to do this in multiple steps with more than one client because the Sheets API
Expand Down Expand Up @@ -156,11 +156,14 @@ def do_analytics_export_post_processing(df: pd.DataFrame, sheets_id: str):
page1 = "Rekrewt Pivot Table - First Visit"
page2 = "Rekrewt Pivot Table - Sessions"
page3 = "GSA Use Pivot Table"
page4 = "Completions"

new_sheet_name_to_id = sheets_client.add_new_pages([page1, page2, page3], sheets_id)
new_sheet_name_to_id = sheets_client.add_new_pages(
[page1, page2, page3, page4], sheets_id
)
log.info("Added %s pages to %s" % (len(new_sheet_name_to_id.keys()), sheets_id))
sheets_client.do_create_pivot_tables(
df, (page1, page2, page3), new_sheet_name_to_id, sheets_id
df, (page1, page2, page3, page4), new_sheet_name_to_id, sheets_id
)


Expand Down
5 changes: 4 additions & 1 deletion gdrive/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
LOG_LEVEL = os.getenv("LOG_LEVEL", logging.getLevelName(logging.INFO))

ANALYTICS = os.getenv("ANALYTICS", False)
ANALYTICS_PROPERTY_ID = os.getenv("ANALYTICS_PROPERTY_ID", 377091467)

SCOPES = [
"https://www.googleapis.com/auth/analytics",
Expand All @@ -27,6 +26,8 @@
ROOT_DIRECTORY = ""
CODE_NAMES = None
CREDENTIALS = None
ANALYTICS_ROOT = None
ANALYTICS_PROPERTY_ID = None

ES_HOST = os.getenv("ES_HOST")
ES_PORT = os.getenv("ES_PORT")
Expand All @@ -49,6 +50,8 @@
log.info("Loading credentials from creds file")
config = json.load(file)
CREDENTIALS = config["credentials"]
ANALYTICS_ROOT = config["analytics_root"]
ANALYTICS_PROPERTY_ID = config["analytics_property_id"]
ROOT_DIRECTORY = config["root_directory"]
CODE_NAMES = config["code_names"]
SHEETS_ID = config["sheets_id"]
Expand Down
56 changes: 56 additions & 0 deletions gdrive/sheets_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def do_create_pivot_tables(
"Added pivot table to %s (%s)" % (page_names[2], names_to_id[page_names[2]])
)

create_feedback_pt(sheets_id, names_to_id[page_names[3]], col_dict)
log.info(
"Added pivot table to %s (%s)" % (page_names[3], names_to_id[page_names[3]])
)

update_cell_value(sheets_id, page_names[0], "A17", "Total First Visits")
update_cell_value(
sheets_id,
Expand Down Expand Up @@ -550,6 +555,57 @@ def create_clicks_pt(sheets_id, page_id, col_dict):
)


def create_feedback_pt(sheets_id, page_id, col_dict):
add_pivot_tables(
sheets_id,
page_id,
(
{
"pivotTable": {
"source": {
"sheetId": 0,
},
"rows": [
{
"sourceColumnOffset": col_dict["eventName"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
{
"sourceColumnOffset": col_dict["eventCount"],
"showTotals": True,
"sortOrder": "ASCENDING",
},
],
"filterSpecs": [
{
"filterCriteria": {
"condition": {
"type": "TEXT_CONTAINS",
"values": [
{
"userEnteredValue": "feedback",
}
],
},
"visibleByDefault": True,
},
"columnOffsetIndex": col_dict["linkUrl"],
},
],
"values": [
{
"summarizeFunction": "SUM",
"sourceColumnOffset": col_dict["eventCount"],
}
],
"valueLayout": "HORIZONTAL",
}
}
),
)


def upload_participant(
first,
last,
Expand Down

0 comments on commit c8f9312

Please sign in to comment.