added r script not releasable code yet
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,5 +1,8 @@
|
|||||||
|
.env
|
||||||
**/*.pyc
|
**/*.pyc
|
||||||
.coverage
|
.coverage
|
||||||
htmlcov
|
htmlcov
|
||||||
**/.DS_Store
|
**/.DS_Store
|
||||||
**/*.log
|
**/*.log
|
||||||
|
|
||||||
|
.codegpt
|
7
LICENSE
7
LICENSE
@ -1,13 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022 ArjanCodes and Mark Todisco
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
The above copyright notice and this permission notice shall be included in all
|
||||||
copies or substantial portions of the Software.
|
copies or substantial portions of the Software.
|
||||||
|
8
main.py
8
main.py
@ -3,15 +3,19 @@ from dash import Dash
|
|||||||
from dash_bootstrap_components.themes import BOOTSTRAP
|
from dash_bootstrap_components.themes import BOOTSTRAP
|
||||||
|
|
||||||
from src.components.layout import create_layout
|
from src.components.layout import create_layout
|
||||||
from src.data.loader_gz import load_transaction_data
|
from src.data.loader_gz import load_spc_data
|
||||||
from json import load
|
from json import load
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
config_file = "./config.json"
|
config_file = "./config.json"
|
||||||
|
|
||||||
with open(config_file) as config_f:
|
with open(config_file) as config_f:
|
||||||
config=load(config_f)
|
config=load(config_f)
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
print(os.getenv("MY_ENV_VAR"))
|
||||||
# load the data and create the data manager
|
# load the data and create the data manager
|
||||||
data = load_transaction_data(config["DATA_PATH"])
|
data = load_transaction_data(config["DATA_PATH"])
|
||||||
|
|
||||||
|
17
poetry.lock
generated
17
poetry.lock
generated
@ -744,6 +744,21 @@ files = [
|
|||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
six = ">=1.5"
|
six = ">=1.5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "python-dotenv"
|
||||||
|
version = "1.0.0"
|
||||||
|
description = "Read key-value pairs from a .env file and set them as environment variables"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
files = [
|
||||||
|
{file = "python-dotenv-1.0.0.tar.gz", hash = "sha256:a8df96034aae6d2d50a4ebe8216326c61c3eb64836776504fcca410e5937a3ba"},
|
||||||
|
{file = "python_dotenv-1.0.0-py3-none-any.whl", hash = "sha256:f5971a9226b701070a4bf2c38c89e5a3f0d64de8debda981d1db98583009122a"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
cli = ["click (>=5.0)"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pytz"
|
name = "pytz"
|
||||||
version = "2023.3.post1"
|
version = "2023.3.post1"
|
||||||
@ -915,4 +930,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "aec3b7eae4106cf6a3129ef080da73c29c6c87cdce2ad8daa07863e6530a583b"
|
content-hash = "7f3e66382a8e3dfd6c4b32282eb27fa714b79e8aa2ddbf66a6adfdae0e127732"
|
||||||
|
@ -13,6 +13,7 @@ pydantic = "^2.5.3"
|
|||||||
dash-bootstrap-components = "^1.5.0"
|
dash-bootstrap-components = "^1.5.0"
|
||||||
pandas = "^2.1.4"
|
pandas = "^2.1.4"
|
||||||
dash-daq = "^0.5.0"
|
dash-daq = "^0.5.0"
|
||||||
|
python-dotenv = "^1.0.0"
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
|
48
src/components/data_table.py
Normal file
48
src/components/data_table.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import plotly.express as px
|
||||||
|
from dash import Dash, dcc, html
|
||||||
|
from dash.dependencies import Input, Output
|
||||||
|
|
||||||
|
from ..data.loader import DataSchema
|
||||||
|
from . import ids
|
||||||
|
|
||||||
|
|
||||||
|
def render(app: Dash, data: pd.DataFrame) -> html.Div:
|
||||||
|
@app.callback(
|
||||||
|
Output(ids.BAR_CHART, "children"),
|
||||||
|
[
|
||||||
|
Input(ids.YEAR_DROPDOWN, "value"),
|
||||||
|
Input(ids.MONTH_DROPDOWN, "value"),
|
||||||
|
Input(ids.CATEGORY_DROPDOWN, "value"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def update_bar_chart(
|
||||||
|
years: list[str], months: list[str], categories: list[str]
|
||||||
|
) -> html.Div:
|
||||||
|
filtered_data = data.query(
|
||||||
|
"year in @years and month in @months and category in @categories"
|
||||||
|
)
|
||||||
|
|
||||||
|
if filtered_data.shape[0] == 0:
|
||||||
|
return html.Div("No data selected.", id=ids.BAR_CHART)
|
||||||
|
|
||||||
|
def create_pivot_table() -> pd.DataFrame:
|
||||||
|
pt = filtered_data.pivot_table(
|
||||||
|
values=DataSchema.AMOUNT,
|
||||||
|
index=[DataSchema.CATEGORY],
|
||||||
|
aggfunc="sum",
|
||||||
|
fill_value=0,
|
||||||
|
dropna=False,
|
||||||
|
)
|
||||||
|
return pt.reset_index().sort_values(DataSchema.AMOUNT, ascending=False)
|
||||||
|
|
||||||
|
fig = px.bar(
|
||||||
|
create_pivot_table(),
|
||||||
|
x=DataSchema.CATEGORY,
|
||||||
|
y=DataSchema.AMOUNT,
|
||||||
|
color=DataSchema.CATEGORY,
|
||||||
|
)
|
||||||
|
|
||||||
|
return html.Div(dcc.Graph(figure=fig), id=ids.BAR_CHART)
|
||||||
|
|
||||||
|
return html.Div(id=ids.BAR_CHART)
|
@ -1,5 +1,6 @@
|
|||||||
BAR_CHART = "bar-chart"
|
BAR_CHART = "bar-chart"
|
||||||
PIE_CHART = "pie-chart"
|
PIE_CHART = "pie-chart"
|
||||||
|
DATA_TABLE = "data-table"
|
||||||
|
|
||||||
SELECT_ALL_CATEGORIES_BUTTON = "select-all-categories-button"
|
SELECT_ALL_CATEGORIES_BUTTON = "select-all-categories-button"
|
||||||
CATEGORY_DROPDOWN = "category-dropdown"
|
CATEGORY_DROPDOWN = "category-dropdown"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
class DataSchema:
|
class DataSchema:
|
||||||
AMOUNT = "amount"
|
AMOUNT = "amount"
|
||||||
CATEGORY = "category"
|
CATEGORY = "category"
|
||||||
@ -8,8 +7,17 @@ class DataSchema:
|
|||||||
MONTH = "month"
|
MONTH = "month"
|
||||||
YEAR = "year"
|
YEAR = "year"
|
||||||
|
|
||||||
|
class SPC_Schema:
|
||||||
|
FC = "FC"
|
||||||
|
Category1 = "Category1"
|
||||||
|
Category2 = "Category2"
|
||||||
|
Category3 = "Category3"
|
||||||
|
Batch = "Batch"
|
||||||
|
Lot = "Lot"
|
||||||
|
DateTime = "DateTime"
|
||||||
|
Value = "Value"
|
||||||
|
|
||||||
def load_transaction_data(path: str) -> pd.DataFrame:
|
def load_spc_data(path: str) -> pd.DataFrame:
|
||||||
# load the data from the CSV file
|
# load the data from the CSV file
|
||||||
data = pd.read_csv(
|
data = pd.read_csv(
|
||||||
path,
|
path,
|
||||||
|
3
src/data/statistic_ver.R
Normal file
3
src/data/statistic_ver.R
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
library("ggplot2")
|
||||||
|
|
||||||
|
read.csv("data\\")
|
11
tools/stat_check.R
Normal file
11
tools/stat_check.R
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
library(tidyverse)
|
||||||
|
library(lubridate
|
||||||
|
)
|
||||||
|
print("Hello")
|
||||||
|
|
||||||
|
setwd("~/code/2024-dash_v1/data")
|
||||||
|
data <- read.csv("transactions.csv.gz")
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
print("Goodbye")
|
Reference in New Issue
Block a user