# Aiflow
1. mermaid graph
https://mermaid.live/ (可放大)
https://mermaid-js.github.io/docs/mermaid-live-editor-beta/
https://drive.google.com/file/d/1Fqj0xVScPnfuSBBw5Vx0zaJqtGi-D3_3/view?usp=sharing
```mermaid
flowchart LR;
A[airflow] --> D
D[dags] --> L[lego]
L --> S1[src]
S1 --> E1[etl.py]
E1 --> ar(["extract_games : 提取時間區間的遊戲(不重複)"])
E1 --> as([transform_docs2summary : ])
L --> L1[LegoSource.md] -->at{{Lego mongo資料庫}}
L --> R1[README.md] --> au{{Lego mysql資料庫}}
L --> E2[etl_dag.py]
D --> Re[report]
Re --> C1[crud]
C1 --> M1[mongo]
M1 --> O1[order.py] --> av([get_interval_orders_4report : 取得時間區間資訊])
O1 --> aw([get_interval_unique_parents : 取得時間區間不重複之parents])
C1 --> M2[mysql]
M2 --> P[parent.py] --> ax([get_not_test_parents : 取得非測試之parents])
Re --> S2[src]
S2 --> Re1[report.py] --> ay(["collect_playtime_n_round_by_parent : "])
Re1 --> E3[etl_dag.py] --> az{{收集playtime和局數}}
Re1 --> Re2[report_example_variable.json] --> ba{{USE_CREATETIME : 是否使用createtime撈資料}}
D --> T1[tracker]
T1 --> C2[crud]
C2 --> M3[mongo] --> a[order.py]
a --> bb([get_by_bettime : 使用bettime撈取時間區間之資料])
a --> bc([get_by_createtime : 使用createtime撈取時間區間之資料])
a --> bd([get_specific_bettype_hedge : 取得某個tabletype的資料])
C2 --> M4[mysql] --> b[game.py]
b --> be([get_info : 取得所有gamecode的遊戲名稱])
C2 --> c[agent.py] --> bf([get_info : 去的所有非測試之parent的ssid, parent_name, owner_name和parent的currency])
C2 --> d[summary.py] --> bg(["get_newAB3_summary : 取得new-AB3之總碼量,總局數,玩家數和net_win(不含測試(總)代理)"])
d --> bh(["get_lego_summary : 取得lego之總碼量,總局數,玩家數和net_win(不含測試(總)代理)"])
d --> bi(["get_game_owner_summary_by_code : 取得各owner的碼量,net_win,局數和玩家數"])
d --> bj(["get_one_time_users : 取得最近七天只玩一天的玩家"])
d --> bk(["get_lotto_date : 取得全部(或各genre)的總碼量和玩家數"])
d --> bl(["get_game_top_owner_by_code : 根據gametype範圍取得時間區間內前十名遊戲之owner,碼量"])
d --> bm(["get_game_month_by_code : 根據gametype和gamecode取得遊戲一個月的碼量,net_win,局數和玩家數"])
d --> bn(["get_game_by_code : 根據gametype和gamecode取得遊戲的碼量,net_win,局數和玩家數"])
d --> bo(["get_game_pre_month : 根據brand,gid(,currency)取得前一個月的總碼量,局數和遊玩天數"])
d --> bp(["get_game_yesterday : 根據brand,gid取得總碼量,局數(和幣別)取得總碼量,局數(和幣別)"])
d --> bq(["get_date_top_game : 根據brand,game_code(,幣別)取得排名,總碼量,局數(和幣別)"])
d --> br(["get_gametype : 根據brand,game_type(,幣別)[時間區間是今天,昨天或上個月]取得總碼量,局數(和幣別)"])
d --> bs(["get_owner_pre_month : 根據brand,oid,game_code(,幣別)取得上個月總碼量,局數(,幣別)"])
d --> bt(["get_owner_yesterday : 根據brand,oid,game_code(,幣別)取得昨日總碼量,局數(,幣別)"])
d --> bu(["get_date_top_owner : 根據brand,owner(,幣別)取得前五名的排名,總碼量,局數(和幣別)"])
d --> bv(["get_registered_user_count : 根據幣別list,oidlist,排除部分uid取得各uid的註冊賬號時間(非首遊時間)"])
d --> bw(["get_played_registered_user_count : 根據brand,currencys,game_code取得該日日期,玩家數和owner"])
d --> bx(["get_daily_of_currencys : 根據brand,cyrrencys,game_codes取得時間區間內各幣別的總碼量,net_win,玩家數,局數和幣別"])
d --> by(["get_daily_by_currency : 根據brand,currency,game_codes和day_opt取得總碼量,net_win,遊玩日數和局數"])
d --> bz(["get_daily : 根據brand,currencys,game_codes和day_opt取得總碼量,net_win,玩家數和局數"])
C2 --> e[user.py]
e --> ca(["get_news_with_high_net_win_n_game : 取得時間區間內各遊戲和玩家的owner,parent,account,userid,game_name_tw,bets,rounds和net_win(net_win需大於net_win_threshold)"])
e --> cb(["get_news_with_high_net_win : 與get_news_with_high_net_win_n_game雷同,但這個是根據玩家全加總"])
T1 --> f[README.md] --> cc{{說明tracker這個文件夾的程式所做的事情}}
T1 --> g[alert_high_bet_high_win_sport.py] --> cd{{"分別警示高碼量和高吐錢低碼量的註單(sport)"}}
T1 --> cs[alert_high_bet_n_high_win_motivation.py] --> ct{{"警示高碼量和高吐錢的註單(motivation)"}}
T1 --> h[daily_summary_champ.py] --> ce{{ }}
T1 --> i[daily_summary_cl.py] --> cf{{ }}
T1 --> j[daily_summary_cq9.py] --> cg{{ }}
T1 --> k[daily_summary_lego.py] --> ch{{ }}
T1 --> l[daily_summary_venus.py] --> ci{{ }}
T1 --> m[hourly_alert_on_new_players.py] --> cj{{警示高net_win的新玩家}}
T1 --> n[on_specify_hedge.py] --> ck{{ }}
T1 --> o[tmp_daily_summary_newAB3.py] --> cl{{ }}
T1 --> p[tracker_champ_example_variable.json] --> cm{{看README.md}}
T1 --> q[tracker_cl_example_variable.json] --> cm
T1 --> r[tracker_pro_example_variable.json] --> cm
T1 --> s[tracker_venus_example_variable.json] --> cm
D --> U[util_example]
U --> t[da_api.py]
U --> u[google_dag.py] --> cn{{上傳文件到google drive}}
U --> v[google_sheet_dag.py]
U --> w[team_plus_dag.py] --> co{{傳訊息到Team+}}
D --> U1[utils]
U1 --> C[connection]
C --> x[champ_api.py]
C --> y[da_api.py]
C --> z[google.py]
C --> aa[google_oauth_json_generator.py]
C --> ab[mysql.py] --> cp{{連線mysql}}
C --> ac[team_plus.py]
U1 --> ad[README.md]
U1 --> ae[define_example_variable.json]
U1 --> af[tools.py ]
af --> cq([get_excel_timestamp : 轉換成timestamp])
af --> cr([teamplus_message : 傳送訊息到Team+])
D --> S(schemas)
S --> ag[__init__.py]
S --> ah[agent.py]
S --> ai[alert.py]
S --> aj[game.py]
S --> ak[msg.py]
S --> al[player.py]
S --> am[sales.py]
S --> an[task.py]
S --> ao[token.py]
S --> ap[user.py]
S --> aq[util.py]
```
2. C4 Model
* C4 Model將架構圖分成四塊,分別是上下文(Context)、容器(Container)、組件(Component)和代碼(Code)。


* Context
這個階段主要是將各種使用者/角色需要使用的功能畫出來,並不會有技術名詞貨實作的相關做法
目標受眾:軟件開發團隊內外的所有人,包括技術人員和非技術人員

```mermaid
flowchart TB
subgraph Airflow[Airflow]
h1[-Airflow專案-]:::folder
d1[程式主要文件夾]:::folder
end
Airflow:::folder
subgraph dags[dags]
h2[-Airflow執行之dags-]:::folder
d2[文件夾內包含analysis,dicator,lego,<br>report,tracker的執行]:::folder
end
dags:::folder
subgraph tests[tests]
h3[-dags程式之測試檔案-]:::folder
d3[文件夾內包含dags<br>所執行之專案測試程式]:::folder
end
tests:::folder
Airflow --> dags
Airflow --> tests
%% Element type definitions
classDef folder fill:#1168bd
classDef instruction fill:#999999
```
* Container
放大說明包含什麼專案或簡單交代專案在做什麼事情
目標受眾:軟件開發團隊內外的技術人員;包括軟件架構師、開發人員和運營/支持人員

```mermaid
flowchart TB
subgraph Airflow[Airflow]
h1[-Airflow專案-]:::folder
d1[程式主要文件夾]:::folder
end
Airflow:::folder
subgraph dags[dags]
direction TB
subgraph Analysis[analysis]
direction LR
h2[Container:python and json]:::instruction
d2[分析]:::instruction
end
Analysis:::instruction
subgraph Dicator[Dicator]
direction LR
h3[Container: python]:::instruction
d3[寫入資料庫]:::instruction
end
Dicator:::instruction
subgraph tracker[tracker]
direction LR
h4[Container: python and json]:::instruction
d4[alert to telegram or team+]:::instruction
end
tracker:::instruction
subgraph lego[lego]
direction LR
h5[Container: python]:::instruction
d5[lego專案]:::instruction
end
lego:::instruction
subgraph report[report]
direction LR
h6[Container: python and json]:::instruction
d6[報表]:::instruction
end
report:::instruction
end
dags:::folder
Airflow --> dags
%% Element type definitions
classDef folder fill:#1168bd
classDef instruction fill:#999999
classDef small_folder fill:#222222
```
* Component
再放大Container的內容,描述每個元件
目標受眾:軟件架構師和開發人員

```mermaid
flowchart TB
subgraph Airflow[Airflow]
h1[-Airflow專案-]:::folder
d1[程式主要文件夾]:::folder
end
Airflow:::folder
subgraph dags[dags]
direction TB
subgraph Analysis[analysis]
subgraph betWinStatistics[bet_win_statistics.py]
direction LR
c_analysis1[Component: python]:::small_folder
analysis1[Transform bet/win statistics]:::small_folder
end
betWinStatistics:::small_folder
subgraph gradingGames[grading_games.py]
direction LR
c_analysis2[Component: python]:::small_folder
analysis2[First step: get basic summary for resources<br>Second step: grab duration info, and get <br>one shot info base on each game's basic summary<br>Third step: find vips situation under each game.<br>Final step: grading each game by resources]:::small_folder
end
gradingGames:::small_folder
subgraph gradingOwner[grading_owner.py]
direction LR
c_analysis3[Component: python]:::small_folder
analysis3[First step: get basic summary for resources<br>Second step: grab duration info, and get <br>one shot info base on each owner's basic summary<br>Third step: find vips situation under each owner<br>Final step: grading each owner by resources]:::small_folder
end
gradingOwner:::small_folder
end
Analysis:::instruction
subgraph Dicator[Dicator]
subgraph transformRTPRecord[transform_rtp_record.py]
direction LR
c_dicator1[Component: python]:::small_folder
dicator1[Transform rtp record from mongo to mysql]:::small_folder
end
transformRTPRecord:::small_folder
end
Dicator:::instruction
subgraph Tracker[Tracker]
subgraph Alert_highBET_highWIN_sport[alert_high_bet_high_win_sport.py]
direction LR
c_tracker1[Component: python]:::small_folder
tracker1[Alert when high bet or high win sport]:::small_folder
end
Alert_highBET_highWIN_sport:::small_folder
subgraph Alert_highBET_N_highWIN_motivation[alert_high_bet_n_high_win_motivation.py]
direction LR
c_tracker2[Component: python]:::small_folder
tracker2[Alert when high bet and high win motivation]:::small_folder
end
Alert_highBET_N_highWIN_motivation:::small_folder
subgraph dailySummaryChamp[daily_summary_champ.py]
direction LR
c_tracker3[Component: python]:::small_folder
tracker3[Get addition info from champland API, <br>and send summary to team+ and store to DA-API]:::small_folder
end
dailySummaryChamp:::small_folder
subgraph dailySummaryCL[daily_summary_cl.py]
direction LR
c_tracker4[Component: python]:::small_folder
tracker4[Send summary to team+ and store to DA-API]:::small_folder
end
dailySummaryCL:::small_folder
subgraph dailySummaryCQ9[daily_summary_cq9.py]
direction LR
c_tracker5[Component: python]:::small_folder
tracker5[Send summary to team+ and store to DA-API]:::small_folder
end
dailySummaryCQ9:::small_folder
subgraph dailySummaryLego[daily_summary_lego.py]
direction LR
c_tracker6[Component: python]:::small_folder
tracker6[Send summary to team+ and store to DA-API]:::small_folder
end
dailySummaryLego:::small_folder
subgraph dailySummaryVenus[daily_summary_venus.py]
direction LR
c_tracker7[Component: python]:::small_folder
tracker7[Send summary to team+ and store to DA-API]:::small_folder
end
dailySummaryVenus:::small_folder
subgraph hourlyAlertOnNewPlayers[hourly_alert_on_new_players.py]
direction LR
c_tracker8[Component: python]:::small_folder
tracker8[Send alert to team+ and broadcast via API]:::small_folder
end
hourlyAlertOnNewPlayers:::small_folder
subgraph notifyBettypeRatio[notify_bettype_ratio.py]
direction LR
c_tracker9[Component: python]:::small_folder
tracker9[Notify Motivation bettype ratio]:::small_folder
end
notifyBettypeRatio:::small_folder
subgraph onSpecifyHedge[on_specify_hedge.py]
direction LR
c_tracker10[Component: python]:::small_folder
tracker10[CA01 specific bettype hedge status and send alert to team+]:::small_folder
end
onSpecifyHedge:::small_folder
subgraph tmpDailySummaryNewAB3[tmp_daily_summary_newAB3.py]
direction LR
c_tracker11[Component: python]:::small_folder
tracker11["new AB3 summary(*)"]:::small_folder
end
tmpDailySummaryNewAB3:::small_folder
end
Tracker:::instruction
subgraph lego[lego]
subgraph LegoSource[LegoSource.md]
direction LR
c_lego1[Component: markdown]:::small_folder
lego1[lego mongo order]:::small_folder
end
LegoSource:::small_folder
subgraph README_[README.md]
direction LR
c_lego2[Component: markdown]:::small_folder
lego2["lego mysql(maria) order"]:::small_folder
end
README_:::small_folder
subgraph etlDag_[etl_dag.py]
direction LR
c_lego3[Component: python]:::small_folder
lego3[Lego-QTech ETL]:::small_folder
end
etlDag_:::small_folder
end
lego:::instruction
subgraph report[report]
subgraph etlDag_2[etl_dag.py]
direction LR
c_report1[Component: python]:::small_folder
report1[Report ETL]:::small_folder
end
etlDag_2:::small_folder
end
report:::instruction
end
dags:::folder
Airflow --> dags
%% Element type definitions
classDef folder fill:#1168bd
classDef instruction fill:#999999
classDef small_folder fill:#666666
```
* Code
目標受眾:軟件架構師和開發人員

* analysis
* bet_win_statistics.py(*)
1. [流程圖](https://docs.google.com/drawings/d/1ufaBhlgDdoBSMNv7BMYiEVJUIUxIV8Ik2k4pEo14hdU/edit)
* grading_games.py
1.
* grading_owner.py
1.
* dicator
* transform_rtp_record.py
1. [流程圖](https://docs.google.com/drawings/d/1rBoCcGI45FoH0Scs2E906KlTFxajlHgaYb-6HnnjXMM/edit)
* tracker
* alert_high_bet_high_win_sport.py
1. [流程圖1](https://docs.google.com/drawings/d/1Az2r9ym0Z1CSzI7U6ERbLZlgvDKv-IwMuDSPZH8e0DM/edit)
2. [流程圖2](https://docs.google.com/drawings/d/1DEL7c1mgbFFg0iJnhfrI_uEM2CgQHEJYhw1-cskgN-g/edit)
* alert_high_bet_n_high_win_motivation.py
1. [流程圖1](https://docs.google.com/drawings/d/17kgA1tTivchskMrz6x_BeZRUo57qgCJaoA4-PTHhaCo/edit)
2. [流程圖2](https://docs.google.com/drawings/d/10sOQLg5rNmOpgaPg8-Rb4kc3B4ltuNeGn9mCtsfA5W4/edit)
* daily_summary_champ.py
1. [流程圖](https://docs.google.com/drawings/d/1QjXQbuU64-s_lgWCzjHVyVFvXSrz45T06m7vsMdSsm0/edit)
* daily_summary_cl.py
1. [流程圖]
* daily_summary_cq9.py
1. [流程圖](https://docs.google.com/drawings/d/16tCoTfuSFBA6-jIr0SQYzefRurLO-r_aaCePmmPpUow/edit)
* daily_summary_lego.py
1. [流程圖]
* daily_summary_venus.py
1. [流程圖]
* hourly_alert_on_new_players.py
1. [流程圖]
* notify_bettype_ratio.py
1. [流程圖]
* on_specify_hedge.py
1. [流程圖]
* tmp_daily_summary_newAB3.py
1. [流程圖]
* lego
* etl_dag.py
1. [流程圖]
* report
* etl_dag.py
1. [流程圖]
<!-- 3. ER Model(實體聯絡模型)

<!-- ## 參考資料
* https://c4model.com/ (C4 Model作者提供的網站)
* https://stevenjhu.com/2022/04/28/othertools%E5%B7%A5%E7%A8%8B%E5%B8%AB%E7%95%AB%E5%9C%96-c4-model-%E8%BB%9F%E9%AB%94%E7%B3%BB%E7%B5%B1%E5%BB%BA%E6%A8%A1%E7%9A%84%E5%9C%96%E5%BD%A2%E8%A1%A8%E7%A4%BA%E6%8A%80%E5%B7%A7/
* https://lukemerrett.com/building-c4-diagrams-in-mermaid/
* https://zh.wikipedia.org/zh-tw/ER%E6%A8%A1%E5%9E%8B -->