added r script not releasable code yet

This commit is contained in:
2025-08-24 21:28:33 +02:00
parent d77c51cc81
commit 017f9fbf2e
14 changed files with 101 additions and 16 deletions

View 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)

View File

@ -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"

View File

@ -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,

3
src/data/statistic_ver.R Normal file
View File

@ -0,0 +1,3 @@
library("ggplot2")
read.csv("data\\")