Skip to content

Commit

Permalink
Merge pull request #59 from TeoMeWhy/feat/dota
Browse files Browse the repository at this point in the history
Feat/dota
  • Loading branch information
TeoCalvo authored Aug 17, 2023
2 parents 8085f61 + 3ea123a commit d08b5d5
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 6 deletions.
53 changes: 53 additions & 0 deletions src/03.silver/dota/feature_store/etl/players.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SELECT
'{date}' AS dtReference,
idPlayer,
count(distinct idMatch) AS nrFrequency,
avg(flWin) AS avgWin,
COALESCE(avg(nrCampsStacked),0) AS avgCampsStacked,
COALESCE(avg(nrCreepsStacked),0) AS avgCreepsStacked,
COALESCE(avg(nrKills),0) AS avgKills,
COALESCE(avg(nrAssist),0) AS avgAssist,
COALESCE(avg(nrDeaths),0) AS avgDeaths,
COALESCE(avg(nrDenies),0) AS avgDenies,
COALESCE(avg(flFirstbloodClaimed),0) AS avgFirstbloodClaimed,
COALESCE(avg(nrGold),0) AS avgGold,
COALESCE(avg(nrGoldMinute),0) AS avgGoldMinute,
COALESCE(avg(nrGoldSpent),0) AS avgGoldSpent,
COALESCE(avg(nrHeroDamage),0) AS avgHeroDamage,
COALESCE(avg(nrHeroHealing),0) AS avgHeroHealing,
COALESCE(avg(nrLastHits),0) AS avgLastHits,
COALESCE(avg(nrLevel),0) AS avgLevel,
COALESCE(avg(nrNetWorth),0) AS avgNetWorth,
COALESCE(avg(nrRoshansKilled),0) AS avgRoshansKilled,
COALESCE(avg(nrRunePicks),0) AS avgRunePicks,
COALESCE(avg(nrStunsSec),0) AS avgStunsSec,
COALESCE(avg(pctTeamfightParticipation),0) AS avgtTeamfightParticipation,
COALESCE(avg(nrTowerDamage),0) AS avgTowerDamage,
COALESCE(avg(nrTowerKilled),0) AS avgTowerKilled,
COALESCE(avg(nrXpMinute),0) AS avgXpMinute,
COALESCE(avg(nrTotalGold),0) AS avgTotalGold,
COALESCE(avg(nrTotalXp),0) AS avgTotalXp,
COALESCE(avg(nrKillsMinute),0) AS avgKillsMinute,
COALESCE(avg(nrKDA),0) AS avgKDA,
COALESCE(avg(nrNeutralKills),0) AS avgNeutralKills,
COALESCE(avg(nrTowerKills),0) AS avgTowerKills,
COALESCE(avg(nrCourierKills),0) AS avgCourierKills,
COALESCE(avg(nrLaneKills),0) AS avgLaneKills,
COALESCE(avg(nrHeroKills),0) AS avgHeroKills,
COALESCE(avg(nrObserverKills),0) AS avgObserverKills,
COALESCE(avg(nrSentryKills),0) AS avgSentryKills,
COALESCE(avg(nrRoshansKills),0) AS avgRoshansKills,
COALESCE(avg(nrNecronomiconKills),0) AS avgNecronomiconKills,
COALESCE(avg(nrAncientKills),0) AS avgAncientKills,
COALESCE(avg(nrBuybackCount),0) AS avgBuybackCount,
COALESCE(avg(nrObserverUses),0) AS avgObserverUses,
COALESCE(avg(nrSentryUses),0) AS avgSentryUses,
COALESCE(avg(pctLaneEfficiency),0) AS avgLaneEfficiency,
COALESCE(avg(nrPurchaseTps),0) AS avgPurchaseTps

FROM silver.dota.matches_players

WHERE dtMatch >= '{date}' - INTERVAL {window} DAY
AND dtMatch < '{date}'

GROUP BY dtReference, idPlayer
46 changes: 46 additions & 0 deletions src/03.silver/dota/feature_store/fs_ingestao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Databricks notebook source
import sys

sys.path.insert(0, '../../../lib/')

import dbtools
import dttools
from databricks import feature_store

table = dbutils.widgets.get('table') # parametro
window_time = int(dbutils.widgets.get('window')) # parametro

fs_name = f'dota_{table}_{window_time}'
database = 'feature_store'
fs_full_name = f'{database}.{fs_name}'
description = dbutils.widgets.get('description') # parametro
id_fields = dbutils.widgets.get('id_fields').split(',') # parametro
partition_fields = dbutils.widgets.get('partition_fields').split(',') # parametro

date_start = dbutils.widgets.get('date_start') # parametro
date_stop = dbutils.widgets.get('date_stop') # parametro
monthly = 'monthly' if dbutils.widgets.get('monthly') == 'True' else 'daily' # parametro
dates = dttools.date_range(date_start, date_stop, period=monthly)

query = dbtools.import_query(f'etl/{table}.sql')

fs = feature_store.FeatureStoreClient()

# COMMAND ----------

fl_table_exists = dbtools.table_exists(spark=spark, database=database, table=fs_name)

for i in dates:
print(i)
df = spark.sql(query.format(date=i, window=window_time))

if not fl_table_exists:
fs.create_table(name=fs_full_name,
primary_keys=id_fields,
partition_columns=partition_fields,
description=description,
schema=df.schema)

fl_table_exists = True

fs.write_table(name=fs_full_name, df=df, mode='merge')
87 changes: 81 additions & 6 deletions src/06.workflows/data4u_dota.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"source": "GIT"
},
"existing_cluster_id": "0523-124114-7ef5b8u0",
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {},
"notification_settings": {
Expand All @@ -40,7 +40,7 @@
},
"source": "GIT"
},
"existing_cluster_id": "0523-124114-7ef5b8u0",
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
Expand All @@ -55,7 +55,7 @@
"notebook_path": "src/01.raw/dota/pos_collect",
"source": "GIT"
},
"existing_cluster_id": "0523-124114-7ef5b8u0",
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
Expand All @@ -74,7 +74,7 @@
},
"source": "GIT"
},
"existing_cluster_id": "0523-124114-7ef5b8u0",
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
Expand All @@ -93,7 +93,7 @@
},
"source": "GIT"
},
"existing_cluster_id": "0523-124114-7ef5b8u0",
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
Expand All @@ -111,7 +111,82 @@
},
"source": "GIT"
},
"existing_cluster_id": "0523-124114-7ef5b8u0",
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
{
"task_key": "fs_players_30",
"depends_on": [
{
"task_key": "silver_matches_players"
}
],
"notebook_task": {
"notebook_path": "src/03.silver/dota/feature_store/fs_ingestao",
"base_parameters": {
"table": "players",
"window": "30",
"description": "Feature Store de jogadores profissionais com suas estatísticas sumarizadas (D30)",
"id_fields": "dtReference,idPlayer",
"partition_fields": "dtReference",
"date_start": "{{start_date}}",
"date_stop": "{{start_date}}",
"monthly": "False"
},
"source": "GIT"
},
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
{
"task_key": "fs_players_90",
"depends_on": [
{
"task_key": "silver_matches_players"
}
],
"notebook_task": {
"notebook_path": "src/03.silver/dota/feature_store/fs_ingestao",
"base_parameters": {
"table": "players",
"window": "90",
"description": "Feature Store de jogadores profissionais com suas estatísticas sumarizadas (D90)",
"id_fields": "dtReference,idPlayer",
"partition_fields": "dtReference",
"date_start": "{{start_date}}",
"date_stop": "{{start_date}}",
"monthly": "False"
},
"source": "GIT"
},
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
},
{
"task_key": "fs_players_180",
"depends_on": [
{
"task_key": "silver_matches_players"
}
],
"notebook_task": {
"notebook_path": "src/03.silver/dota/feature_store/fs_ingestao",
"base_parameters": {
"table": "players",
"window": "180",
"description": "Feature Store de jogadores profissionais com suas estatísticas sumarizadas (D180)",
"id_fields": "dtReference,idPlayer",
"partition_fields": "dtReference",
"date_start": "{{start_date}}",
"date_stop": "{{start_date}}",
"monthly": "False"
},
"source": "GIT"
},
"existing_cluster_id": "0809-155233-nc569ju7",
"timeout_seconds": 0,
"email_notifications": {}
}
Expand Down

0 comments on commit d08b5d5

Please sign in to comment.