Skip to content

Instantly share code, notes, and snippets.

View patrikbraborec's full-sized avatar

Patrik Braborec patrikbraborec

View GitHub Profile
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
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,
name: Run extract and load
on:
push:
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
jobs:
run_extract_load:
runs-on: ubuntu-latest
steps:
SELECT (
SELECT {metric/gd_revenue} WHERE (
SELECT {metric/revenue_top_10} BY {label/customers.customer_id} ALL OTHER
) > 0
) / {metric/gd_revenue}
SELECT {metric/gd_revenue} WHERE TOP(10%) OF ({metric/gd_revenue})
SELECT (SUM({fact/price} * {fact/quantity})) WHERE {label/order_status} = "Delivered"
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
),
- name: revenue
label: Revenue
model: ref('revenue_all')
calculation_method: sum
expression: price * quantity
timestamp: date
time_grains: [day, week, month, quarter, year]
predictions = predict_model(best, data=report_data)
print(predictions.head())
SELECT RUNAVG({fact/close}) ROWS BETWEEN 20 PRECEDING AND CURRENT ROW