This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from logging import Logger | |
from gooddata_sdk import GoodDataSdk | |
from analytics.credentials import GoodDataCredentials | |
class GoodDataAnalytics: | |
def __init__(self, logger: Logger, credentials: GoodDataCredentials): | |
self.logger = logger | |
self.host = credentials.host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with deals as (select id, created_date, to_json("item") as item_json from input_stage.airtable_crm_deals), | |
final as ( | |
select | |
id, | |
CAST(json_extract_path_text(item_json, 'Name') as VARCHAR) as name, | |
CAST(json_extract_path_text(item_json, 'Stage') as VARCHAR) as stage, | |
CAST(json_extract_path_text(item_json, 'Amount') as NUMERIC) as amount, | |
CAST(json_extract_path_text(item_json, 'Details') as VARCHAR) as details, | |
CAST(json_extract_path_text(item_json, 'Close Probability') as NUMERIC) as close_probability, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run extract and load | |
on: | |
push: | |
schedule: | |
- cron: "0 2 * * *" | |
workflow_dispatch: | |
jobs: | |
run_extract_load: | |
runs-on: ubuntu-latest | |
steps: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT ( | |
SELECT {metric/gd_revenue} WHERE ( | |
SELECT {metric/revenue_top_10} BY {label/customers.customer_id} ALL OTHER | |
) > 0 | |
) / {metric/gd_revenue} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT {metric/gd_revenue} WHERE TOP(10%) OF ({metric/gd_revenue}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT (SUM({fact/price} * {fact/quantity})) WHERE {label/order_status} = "Delivered" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with customer_group as ( | |
SELECT customer_id, sum(revenue) AS revenue_sum | |
FROM {{ metrics.calculate( | |
metric('revenue'), | |
grain='day', | |
dimensions=['customer_id'] | |
) }} | |
GROUP BY customer_id | |
), | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- name: revenue | |
label: Revenue | |
model: ref('revenue_all') | |
calculation_method: sum | |
expression: price * quantity | |
timestamp: date | |
time_grains: [day, week, month, quarter, year] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
predictions = predict_model(best, data=report_data) | |
print(predictions.head()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT RUNAVG({fact/close}) ROWS BETWEEN 20 PRECEDING AND CURRENT ROW |
NewerOlder