Files changed (3) hide show
  1. .gitignore +2 -5
  2. README.md +0 -10
  3. SPC_System/spc_engine.py +0 -122
.gitignore CHANGED
@@ -1,7 +1,4 @@
1
  data/
2
- *.ipynb
3
  *.csv
4
- *.xlsx
5
- *.json
6
- charts/*.png
7
- charts_compare/*.png
 
1
  data/
2
+ test.ipynb
3
  *.csv
4
+ *.xlsx
 
 
 
README.md CHANGED
@@ -12,13 +12,3 @@ short_description: This space is created to compare the test data
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
15
-
16
- <h1>Added new SPC system</h1>
17
- <h2>To check this out in your local environment</h2>
18
-
19
- <ul>
20
- <li>Keep the input file in the same folder</li>
21
- <li>Key in the input file in the terminal</li>
22
- <li>Run the <code>spc_engine.py</code></li>
23
- <li>This will generate all the graphs inside the <code>charts</code> folder</li>
24
- </ul>
 
12
  ---
13
 
14
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
SPC_System/spc_engine.py DELETED
@@ -1,122 +0,0 @@
1
- import pandas as pd
2
- import matplotlib.pyplot as plt
3
- import numpy as np
4
- import os
5
-
6
- # --------- Load three datasets ----------
7
- df_t1 = pd.read_excel("tester#1.xlsx")
8
- df_t2 = pd.read_excel("tester#2.xlsx")
9
- df_gold = pd.read_excel("Golden_Data.xlsx")
10
-
11
- # --------- Get parameter list ----------
12
- df_new = df_gold.head(3).dropna(axis=1, how="all")
13
- df_param = df_new.drop(["T_TIME", "SITE_NUM"], axis=1)
14
- parameters = list(df_param.columns)
15
-
16
- # --------- Build master dictionary ----------
17
- data = {
18
- param: {
19
- "Tester1": pd.to_numeric(df_t1[param].iloc[3:], errors="coerce").dropna().tolist(),
20
- "Tester2": pd.to_numeric(df_t2[param].iloc[3:], errors="coerce").dropna().tolist(),
21
- "Golden": pd.to_numeric(df_gold[param].iloc[3:], errors="coerce").dropna().tolist(),
22
- "LimitL": df_new[param].iloc[1],
23
- "LimitU": df_new[param].iloc[2],
24
- "Unit": df_new[param].iloc[0]
25
- }
26
- for param in parameters
27
- }
28
-
29
- # --------- Plot comparison SPC ----------
30
- os.makedirs("./charts_compare", exist_ok=True)
31
-
32
- for param in parameters:
33
-
34
- t1 = np.array(data[param]["Tester1"])
35
- t2 = np.array(data[param]["Tester2"])
36
- gold = np.array(data[param]["Golden"])
37
-
38
- limit_l = data[param]["LimitL"]
39
- limit_u = data[param]["LimitU"]
40
- unit = data[param]["Unit"]
41
-
42
- # Golden reference control band
43
- mean = gold.mean()
44
- t1_mean = t1.mean()
45
- t2_mean = t2.mean()
46
- std = gold.std(ddof=1)
47
- UCL = mean + 3 * std
48
- LCL = mean - 3 * std
49
-
50
- # ---- Fix max length ----
51
- max_len = max(len(t1), len(t2), len(gold))
52
- xaxis = np.arange(1, max_len + 1)
53
-
54
- # ---- Correlation ----
55
- min_len_t1 = min(len(t1), len(gold))
56
- min_len_t2 = min(len(t2), len(gold))
57
-
58
- corr_t1 = np.corrcoef(t1[:min_len_t1], gold[:min_len_t1])[0,1]
59
- corr_t2 = np.corrcoef(t2[:min_len_t2], gold[:min_len_t2])[0,1]
60
- corr_t1_t2 = np.corrcoef(t1[:min_len_t1], t2[:min_len_t2])[0,1]
61
-
62
- # ---- CPK (based on Golden dataset) ----
63
- cpk = min((mean - limit_l) / (3 * std), (limit_u - mean) / (3 * std))
64
-
65
- plt.figure(figsize=(10,6))
66
-
67
- # --- Plot all datasets ---
68
- plt.plot(range(1, len(t1)+1), t1, marker='o', label="Tester #1")
69
- plt.plot(range(1, len(t2)+1), t2, marker='o', label="Tester #2")
70
- plt.plot(range(1, len(gold)+1), gold, marker='o', label="Gold Reference", linewidth=3)
71
-
72
- # --- SPC lines ---
73
- plt.axhline(mean, linestyle='--', color='black', label=f"Mean (Gold)")
74
- plt.axhline(UCL, linestyle='-.', color='red', label="UCL (Mean + 3σ)")
75
- plt.axhline(LCL, linestyle='-.', color='red', label="LCL (Mean – 3σ)")
76
-
77
- # --- Spec Limits ---
78
- plt.axhline(limit_l, linestyle=':', color='orange', label="Lower Spec")
79
- plt.axhline(limit_u, linestyle=':', color='orange', label="Upper Spec")
80
-
81
- # ---- Fix X-axis ----
82
- # plt.xticks(np.arange(1, max_len + 1, step=1))
83
- # plt.xlim(1, max_len)
84
-
85
- # ---- Fix X-axis with whole numbers + padding ----
86
- max_len = max(len(t1), len(t2), len(gold))
87
-
88
- plt.xticks(np.arange(1, max_len + 1, 1)) # whole numbers
89
- plt.xlim(0, max_len + 1) # space before 1 and after last point
90
-
91
-
92
- # ---- Add CPK + Correlation text box ----
93
- textstr = (
94
- f"Gold Mean = {mean:.4f}\n"
95
- f"Std Dev = {std:.4f}\n"
96
- f"CPK = {cpk:.4f}\n"
97
- f"Corr T1–Gold = {corr_t1:.4f}\n"
98
- f"Corr T2–Gold = {corr_t2:.4f}\n"
99
- f"Corr T1-T2 = {corr_t1_t2:.4f}\n"
100
- f"Tester#1 Mean = {t1_mean:.4f}\n"
101
- f"Tester#2 Mean = {t2_mean:4f}\n"
102
- )
103
-
104
- plt.gca().text(
105
- 0.02, 0.98, textstr,
106
- transform=plt.gca().transAxes,
107
- fontsize=10,
108
- verticalalignment='top',
109
- bbox=dict(boxstyle="round,pad=0.4", facecolor="white", alpha=0.8)
110
- )
111
-
112
- # Labels
113
- plt.title(f"SPC Comparison - {param} ({unit})")
114
- plt.xlabel("Sample Index")
115
- plt.ylabel(f"Value ({unit})")
116
- plt.grid(True)
117
- plt.legend()
118
- plt.tight_layout()
119
-
120
- # Save chart
121
- plt.savefig(f"./charts_compare/SPC_compare_{param}.png", dpi=300)
122
- plt.close()