diff --git a/.gitignore b/.gitignore index 7ad52b6..4851fa6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ +.env **/*.pyc .coverage htmlcov **/.DS_Store -**/*.log \ No newline at end of file +**/*.log + +.codegpt \ No newline at end of file diff --git a/LICENSE b/LICENSE index ec68112..d4679ec 100644 --- a/LICENSE +++ b/LICENSE @@ -1,13 +1,6 @@ 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 copies or substantial portions of the Software. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/data/spc_data_full.csv b/data/spc_data_full.csv index ad4f064..a5d06fc 100644 --- a/data/spc_data_full.csv +++ b/data/spc_data_full.csv @@ -651,4 +651,4 @@ Batch,Speed,BatchQty,Para1Tgt,Para1,Para2Tgt,Para2,Para3,Para4,Para5,Para6,Para7 650,98,121,0.421,0.432,312,312,314,51747,1549,0.43525,312.75,26510,872,0.433,315.75,964,0.443,317.5,1113,56.25,32.49266862,49.7005988,2.857142857,0.5,0.22,0.824601367,21 651,98,25,0.421,0.424,313,315,306,42278,1433,0.424,307.25,19901,854,0.426,307.5,709,0.431,304,1046,61.68333333,37.33955659,68.13186813,2.923976608,0.27,0.69,0.700471698,22 652,88,17,0.429,0.44425,311,318,314,50548,1496,0.4435,311.75,24853,864,0.4465,315.25,772,0.4475,313,1330,47.5,26.15384615,54.54545455,3.281334051,0.46,0.91,0.74715262,20 -653,90,95,0.421,0.42675,311,311,296,42970,1354,0.4245,294.25,19676,770,0.427,301,691,0.4275,287.5,1040,52.5,31.88073394,56.81818182,2.099580084,0.49,0.8,0.555288462,19 \ No newline at end of file +653,90,95,0.421,0.42675,311,311,296,42970,1354,0.4245,294.25,19676,770,0.427,301,691,0.4275,287.5,1040,52.5,31.88073394,56.81818182,2.099580084,0.49,0.8,0.555288462,19 diff --git a/main.py b/main.py index c4a2d00..d9e2bbb 100644 --- a/main.py +++ b/main.py @@ -3,15 +3,19 @@ from dash import Dash from dash_bootstrap_components.themes import BOOTSTRAP 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 +import os +from dotenv import load_dotenv +load_dotenv() config_file = "./config.json" + with open(config_file) as config_f: config=load(config_f) def main() -> None: - + print(os.getenv("MY_ENV_VAR")) # load the data and create the data manager data = load_transaction_data(config["DATA_PATH"]) diff --git a/poetry.lock b/poetry.lock index a4a7daa..e483c5f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -744,6 +744,21 @@ files = [ [package.dependencies] 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]] name = "pytz" version = "2023.3.post1" @@ -915,4 +930,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "aec3b7eae4106cf6a3129ef080da73c29c6c87cdce2ad8daa07863e6530a583b" +content-hash = "7f3e66382a8e3dfd6c4b32282eb27fa714b79e8aa2ddbf66a6adfdae0e127732" diff --git a/pyproject.toml b/pyproject.toml index 507672b..e7357c2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ pydantic = "^2.5.3" dash-bootstrap-components = "^1.5.0" pandas = "^2.1.4" dash-daq = "^0.5.0" +python-dotenv = "^1.0.0" [build-system] diff --git a/src/components/data_table.py b/src/components/data_table.py new file mode 100644 index 0000000..dfa2e49 --- /dev/null +++ b/src/components/data_table.py @@ -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) diff --git a/src/components/ids.py b/src/components/ids.py index c02bc18..22a44ea 100644 --- a/src/components/ids.py +++ b/src/components/ids.py @@ -1,5 +1,6 @@ BAR_CHART = "bar-chart" PIE_CHART = "pie-chart" +DATA_TABLE = "data-table" SELECT_ALL_CATEGORIES_BUTTON = "select-all-categories-button" CATEGORY_DROPDOWN = "category-dropdown" diff --git a/src/data/loader_gz.py b/src/data/loader_gz.py index 2f3e2a7..27a5aea 100644 --- a/src/data/loader_gz.py +++ b/src/data/loader_gz.py @@ -1,6 +1,5 @@ import pandas as pd - class DataSchema: AMOUNT = "amount" CATEGORY = "category" @@ -8,8 +7,17 @@ class DataSchema: MONTH = "month" 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 data = pd.read_csv( path, diff --git a/src/data/statistic_ver.R b/src/data/statistic_ver.R new file mode 100644 index 0000000..2dfa92f --- /dev/null +++ b/src/data/statistic_ver.R @@ -0,0 +1,3 @@ +library("ggplot2") + +read.csv("data\\") \ No newline at end of file diff --git a/test b/test deleted file mode 100644 index 0ddf2ba..0000000 --- a/test +++ /dev/null @@ -1 +0,0 @@ -i diff --git a/test1 b/test1 deleted file mode 100644 index 0ddf2ba..0000000 --- a/test1 +++ /dev/null @@ -1 +0,0 @@ -i diff --git a/tools/stat_check.R b/tools/stat_check.R new file mode 100644 index 0000000..851ef0b --- /dev/null +++ b/tools/stat_check.R @@ -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")