This file contains hidden or 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 flask import request | |
from jsonschema import validate, FormatChecker, exceptions | |
data = request.json | |
# Define the schema to check | |
check_schema = { | |
"type": "object", | |
"properties": { | |
"name": {"type": "string"}, |
This file contains hidden or 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
import random | |
def esimate_pi(n: int) -> float: | |
n_points_in_circle = 0 | |
for _ in range(n): | |
x = random.uniform(0, 1) | |
y = random.uniform(0, 1) | |
# don't need to square root: | |
# if r < 1 then sqrt(r) < 1 | |
# if r > 1 then sqrt(r) > 1 |
This file contains hidden or 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 python:3.8-slim-buster | |
WORKDIR /app | |
COPY requirements.txt requirements.txt | |
RUN pip3 install -r requirements.txt | |
COPY src/ . | |
CMD ["python3", "app.py"] |
This file contains hidden or 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 flask import Flask, jsonify, request | |
# This code is typically imported from a separate python module | |
# e.g. from ml_model.predict import predict_result (from folder.pythonfile import function) | |
# ============ | |
import pickle | |
def predict_result(transaction_id): | |
with open("model.pkl", "rb") as file: | |
model = pickle.load(file) |
This file contains hidden or 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
{%- macro dbt_greatest(cols, dummy_val="'1/1/1900'") -%} | |
-- Returns null if all arguments are null | |
{%- if cols is not iterable and (cols is not string and cols is not mapping) -%} | |
{{ exceptions.raise_compiler_error( | |
"Argument invalid... dbt_greatest() expects argument format (['col1', 'col2'], 'dummy_val')" | |
) | |
}} | |
{% endif %} |
This file contains hidden or 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 | |
product_id, | |
{{ dbt_utils.pivot( | |
'month', | |
dbt_utils.get_column_values(ref('product_sales'), 'month'), | |
then_value='amount' | |
) }} | |
from {{ ref('product_sales') }} | |
group by product_id |
This file contains hidden or 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
{% snapshot product_sales_snapshot %} | |
{{ config( | |
tags = ['hourly', 'product'], -- we can use these for airflow orchestration | |
target_schema = 'product', | |
unique_key = 'product_sale_id', | |
strategy = 'check', | |
check_cols = 'all', | |
) | |
}} |
This file contains hidden or 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 | |
coalesce( | |
try_to_date(freeflow_sale_date), | |
try_to_date(freeflow_sale_date, 'DD Mon YYYY'), -- 19 September 2020 | |
try_to_date(freeflow_sale_date, 'DD/MM/YYYY'), -- 14/12/2020 | |
try_to_date(freeflow_sale_date, 'YYYY/MM/DD') -- 2020/12/08 | |
) as sale_date | |
from product_sales |
This file contains hidden or 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 to_pivot as ( | |
select | |
product_id, | |
month, | |
amount | |
from product_sales | |
) | |
select * | |
from to_pivot |
This file contains hidden or 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 | |
iff(p.status in ('open', 'active'), 'active', i.status) as clean_status, | |
iff(clean_status = 'active', true, false) as is_active | |
from product_sales p |
NewerOlder