Refactor join conditions in dash_app
fix is weekday issue, making fridays a weekend update ERD
This commit is contained in:
@@ -11,3 +11,4 @@ CONFLICT = 9
|
|||||||
MOVE_FILE_ERROR = 10
|
MOVE_FILE_ERROR = 10
|
||||||
DUPLICATE_RESOLUTION_ERROR = 11
|
DUPLICATE_RESOLUTION_ERROR = 11
|
||||||
UNIQUE_ID_NOT_FOUND = 12
|
UNIQUE_ID_NOT_FOUND = 12
|
||||||
|
NO_DATA_PRODUCED = 13
|
||||||
+3
-3
@@ -14,9 +14,9 @@ scheduled_transactions = pl.read_parquet('data/warehouse/scheduled_transactions.
|
|||||||
transactions = pl.read_parquet('data/warehouse/transactions.parquet')
|
transactions = pl.read_parquet('data/warehouse/transactions.parquet')
|
||||||
|
|
||||||
# Join transactions with accounts, categories, and payees to create a master DataFrame
|
# Join transactions with accounts, categories, and payees to create a master DataFrame
|
||||||
master_df = transactions.join(categories, left_on='category_id', right_on='id', suffix='_category')\
|
master_df = transactions.join(categories, left_on='category_id', right_on='category_id', suffix='_category')\
|
||||||
.join(accounts, left_on='account_id', right_on='id', suffix='_account')\
|
.join(accounts, left_on='account_id', right_on='account_id', suffix='_account')\
|
||||||
.join(payees, left_on='payee_id', right_on='id', suffix='_payee')\
|
.join(payees, left_on='payee_id', right_on='payee_id', suffix='_payee')\
|
||||||
.join(dates, left_on='transaction_date', right_on='date_id', suffix='_date')\
|
.join(dates, left_on='transaction_date', right_on='date_id', suffix='_date')\
|
||||||
|
|
||||||
# Create aggregations
|
# Create aggregations
|
||||||
|
|||||||
+15
-6
@@ -34,23 +34,29 @@ erDiagram
|
|||||||
}
|
}
|
||||||
|
|
||||||
DATES {
|
DATES {
|
||||||
int date_id
|
string date_id
|
||||||
string date
|
date date
|
||||||
int year
|
int year
|
||||||
int month
|
int month
|
||||||
int day
|
int day
|
||||||
|
boolean is_weekday
|
||||||
|
int weekday
|
||||||
}
|
}
|
||||||
|
|
||||||
TRANSACTIONS {
|
TRANSACTIONS {
|
||||||
int transaction_id
|
str transaction_id
|
||||||
int account_id
|
int account_id
|
||||||
int category_id
|
int category_id
|
||||||
int payee_id
|
int payee_id
|
||||||
int date_id
|
int transaction_date
|
||||||
decimal amount
|
decimal amount
|
||||||
boolean cleared
|
boolean cleared
|
||||||
boolean approved
|
boolean approved
|
||||||
boolean deleted
|
boolean deleted
|
||||||
|
string memo
|
||||||
|
string flag_color
|
||||||
|
str transfer_account_id
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SCHEDULED_TRANSACTIONS {
|
SCHEDULED_TRANSACTIONS {
|
||||||
@@ -58,10 +64,14 @@ erDiagram
|
|||||||
int account_id
|
int account_id
|
||||||
int category_id
|
int category_id
|
||||||
int payee_id
|
int payee_id
|
||||||
int date_id
|
str date_first
|
||||||
|
str date_next
|
||||||
decimal amount
|
decimal amount
|
||||||
string frequency
|
string frequency
|
||||||
boolean deleted
|
boolean deleted
|
||||||
|
text memo
|
||||||
|
string flag_color
|
||||||
|
str transfer_account_id
|
||||||
}
|
}
|
||||||
|
|
||||||
TRANSACTIONS ||--o{ ACCOUNTS : "belongs to"
|
TRANSACTIONS ||--o{ ACCOUNTS : "belongs to"
|
||||||
@@ -73,4 +83,3 @@ erDiagram
|
|||||||
SCHEDULED_TRANSACTIONS ||--o{ PAYEES : "belongs to"
|
SCHEDULED_TRANSACTIONS ||--o{ PAYEES : "belongs to"
|
||||||
SCHEDULED_TRANSACTIONS ||--o{ DATES : "scheduled on"
|
SCHEDULED_TRANSACTIONS ||--o{ DATES : "scheduled on"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import logging.config
|
|||||||
import logging.handlers
|
import logging.handlers
|
||||||
|
|
||||||
import config.exit_codes as ec
|
import config.exit_codes as ec
|
||||||
#from dash_app import app
|
|
||||||
from pipeline.pipeline_main import pipeline_main
|
from pipeline.pipeline_main import pipeline_main
|
||||||
|
|
||||||
def set_up_logging():
|
def set_up_logging():
|
||||||
@@ -58,7 +57,15 @@ config['BUDGET_ID'] = BUDGET_ID
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
pipeline_main(config)
|
pipeline_main(config)
|
||||||
# app.run() #debug=True)
|
|
||||||
|
# Check if the data was successfully created
|
||||||
|
data_exists = os.path.exists('data/processed') and os.listdir('data/processed')
|
||||||
|
if data_exists:
|
||||||
|
from dash_app import app
|
||||||
|
app.run() # debug=True
|
||||||
|
else:
|
||||||
|
logging.error('Data pipeline did not produce any data. Dash app will not run.')
|
||||||
|
sys.exit(ec.NO_DATA_PRODUCED)
|
||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
exit_code = e.code
|
exit_code = e.code
|
||||||
if exit_code == ec.SUCCESS:
|
if exit_code == ec.SUCCESS:
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ class DimDate(Dimensions):
|
|||||||
try:
|
try:
|
||||||
# Create a new column to indicate if the date is a weekday or weekend
|
# Create a new column to indicate if the date is a weekday or weekend
|
||||||
dates_df = dates_df.with_columns([
|
dates_df = dates_df.with_columns([
|
||||||
(pl.col('weekday') < 5).alias('is_weekday') # True for weekdays (Monday to Friday), False for weekends (Saturday and Sunday)
|
(pl.col('weekday') < 6).alias('is_weekday') # True for weekdays (Monday to Friday), False for weekends (Saturday and Sunday)
|
||||||
])
|
])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to create a new column to indicate if the date is a weekday or weekend: {e}")
|
logging.error(f"Failed to create a new column to indicate if the date is a weekday or weekend: {e}")
|
||||||
|
|||||||
Reference in New Issue
Block a user