commit
a642eef7c4
4
.env
4
.env
|
|
@ -1,9 +1,11 @@
|
||||||
# MySQL Database Configuration
|
# MySQL Database Configuration
|
||||||
|
DB_CONNECTION=mysql
|
||||||
DB_HOST=localhost
|
DB_HOST=localhost
|
||||||
DB_PORT=3306
|
DB_PORT=3306
|
||||||
DB_USER=root
|
DB_USER=root
|
||||||
DB_PASSWORD=""
|
DB_PASSWORD=
|
||||||
DB_NAME=deteksi_pmk
|
DB_NAME=deteksi_pmk
|
||||||
|
|
||||||
# Flask Configuration
|
# Flask Configuration
|
||||||
FLASK_SECRET=deteksi-pmk-secret-key-2026
|
FLASK_SECRET=deteksi-pmk-secret-key-2026
|
||||||
|
FLASK_DEBUG=1
|
||||||
|
|
@ -232,7 +232,7 @@ expert_diseases
|
||||||
-- Aturan forward chaining (5 aturan)
|
-- Aturan forward chaining (5 aturan)
|
||||||
expert_rules
|
expert_rules
|
||||||
id INT AUTO_INCREMENT PK
|
id INT AUTO_INCREMENT PK
|
||||||
code VARCHAR(20) UNIQUE -- FC01–FC04
|
code VARCHAR(20) UNIQUE -- FC01–FC05
|
||||||
symptom_codes TEXT -- JSON array of symptom codes
|
symptom_codes TEXT -- JSON array of symptom codes
|
||||||
result_disease_code VARCHAR(10) FK → expert_diseases.code
|
result_disease_code VARCHAR(10) FK → expert_diseases.code
|
||||||
description TEXT
|
description TEXT
|
||||||
|
|
@ -262,12 +262,12 @@ expert_rules_expert_symptoms
|
||||||
- P03 = PMK_LAKTASI (gejala ambing)
|
- P03 = PMK_LAKTASI (gejala ambing)
|
||||||
- P05 = PMK_AKUT_GENERAL (gejala umum berat)
|
- P05 = PMK_AKUT_GENERAL (gejala umum berat)
|
||||||
|
|
||||||
**4 Aturan (FC01–FC04):**
|
**5 Aturan (FC01–FC05):**
|
||||||
|
|
||||||
- FC01 → P01 (oral): [G01, G02, G03, G04, G11, G18, G19, G20, G21]
|
- FC01 → P01 (oral): [G01, G02, G03, G04, G11, G18, G19, G20, G21]
|
||||||
- FC02 → P02 (podal): [G01, G02, G05, G06, G15, G22, G23, G24, G25]
|
- FC02 → P02 (podal): [G01, G02, G05, G06, G15, G22, G23, G24, G25]
|
||||||
- FC03 → P03 (laktasi): [G01, G02, G07, G08, G09, G26, G27]
|
- FC03 → P03 (laktasi): [G01, G02, G07, G08, G09, G26, G27]
|
||||||
- FC04 → P05 (akut umum): [G01, G02, G03, G04, G05, G06, G07, G09, G11, G12, G14, G18, G20, G22, G23, G24, G26]
|
- FC05 → P05 (akut umum): [G01, G02, G03, G04, G05, G06, G07, G09, G11, G12, G14, G18, G20, G22, G23, G24, G26]
|
||||||
|
|
||||||
> **Auto-check gejala dari hasil deteksi gambar** (di `app.py:pmk_to_symptoms`):
|
> **Auto-check gejala dari hasil deteksi gambar** (di `app.py:pmk_to_symptoms`):
|
||||||
> Mapping ini digunakan saat redirect ke expert system via mode=image. Hanya gejala spesifik body part yang diikutkan (tanpa gejala umum):
|
> Mapping ini digunakan saat redirect ke expert system via mode=image. Hanya gejala spesifik body part yang diikutkan (tanpa gejala umum):
|
||||||
|
|
|
||||||
4
app.py
4
app.py
|
|
@ -838,7 +838,7 @@ def expert_system_page():
|
||||||
|
|
||||||
# Jika ada hasil prediksi berbasis image processing sebelumnya, tambahkan ke konteks
|
# Jika ada hasil prediksi berbasis image processing sebelumnya, tambahkan ke konteks
|
||||||
last_prediction = session.get('last_prediction', {})
|
last_prediction = session.get('last_prediction', {})
|
||||||
upload_images = session.get('upload_images_data', [])
|
upload_images = session.get('upload_images_data', []) if use_image_context else []
|
||||||
image_info = None
|
image_info = None
|
||||||
if use_image_context and last_prediction.get('source') == 'image_processing':
|
if use_image_context and last_prediction.get('source') == 'image_processing':
|
||||||
image_info = {
|
image_info = {
|
||||||
|
|
@ -866,7 +866,7 @@ def expert_system_page():
|
||||||
|
|
||||||
# Ambil informasi gambar dari session jika hasil sebelumnya berasal dari image processing
|
# Ambil informasi gambar dari session jika hasil sebelumnya berasal dari image processing
|
||||||
last_prediction = session.get('last_prediction', {})
|
last_prediction = session.get('last_prediction', {})
|
||||||
upload_images = session.get('upload_images_data', [])
|
upload_images = session.get('upload_images_data', []) if use_image_context else []
|
||||||
image_info = None
|
image_info = None
|
||||||
if use_image_context and last_prediction.get('source') == 'image_processing':
|
if use_image_context and last_prediction.get('source') == 'image_processing':
|
||||||
image_info = {
|
image_info = {
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ class ForwardChaining:
|
||||||
matched_rules = stats['matched_rules']
|
matched_rules = stats['matched_rules']
|
||||||
avg_coverage = stats['coverage_sum'] / matched_rules if matched_rules else 0.0
|
avg_coverage = stats['coverage_sum'] / matched_rules if matched_rules else 0.0
|
||||||
support_ratio = matched_rules / total_rules
|
support_ratio = matched_rules / total_rules
|
||||||
evidence_strength = min(stats['best_matched_count'] / 4.0, 1.0)
|
evidence_strength = stats['best_matched_count'] / max(len(self.kb.gejala), 1)
|
||||||
exact_bonus = 0.10 if stats['exact_rules'] > 0 else 0.0
|
exact_bonus = 0.10 if stats['exact_rules'] > 0 else 0.0
|
||||||
|
|
||||||
combined_score = (
|
combined_score = (
|
||||||
|
|
@ -180,7 +180,7 @@ class ForwardChaining:
|
||||||
combined_score = min(combined_score, 0.99)
|
combined_score = min(combined_score, 0.99)
|
||||||
|
|
||||||
if combined_score >= min_score_threshold:
|
if combined_score >= min_score_threshold:
|
||||||
self.hasil[penyakit] = combined_score
|
self.hasil[penyakit] = (combined_score, stats['best_matched_count'])
|
||||||
|
|
||||||
self.disease_evidence = disease_evidence
|
self.disease_evidence = disease_evidence
|
||||||
|
|
||||||
|
|
@ -203,7 +203,7 @@ class ForwardChaining:
|
||||||
}
|
}
|
||||||
|
|
||||||
# Urutkan hasil dari yang paling cocok
|
# Urutkan hasil dari yang paling cocok
|
||||||
hasil_urut = sorted(hasil_inferensi.items(), key=lambda x: x[1], reverse=True)
|
hasil_urut = sorted(hasil_inferensi.items(), key=lambda x: (x[1][0], x[1][1]), reverse=True)
|
||||||
|
|
||||||
# Pemetaan tingkat keparahan
|
# Pemetaan tingkat keparahan
|
||||||
severity_map = {
|
severity_map = {
|
||||||
|
|
@ -214,7 +214,7 @@ class ForwardChaining:
|
||||||
}
|
}
|
||||||
|
|
||||||
diagnosis = []
|
diagnosis = []
|
||||||
for kode_penyakit, score in hasil_urut:
|
for kode_penyakit, (score, _matched_count) in hasil_urut:
|
||||||
penyakit = self.kb.penyakit[kode_penyakit]
|
penyakit = self.kb.penyakit[kode_penyakit]
|
||||||
relevant_aliases = DISEASE_ALIAS_MAP.get(kode_penyakit, {kode_penyakit})
|
relevant_aliases = DISEASE_ALIAS_MAP.get(kode_penyakit, {kode_penyakit})
|
||||||
evidence_rules = [rule for rule in self.matched_rules if rule['hasil'] in relevant_aliases]
|
evidence_rules = [rule for rule in self.matched_rules if rule['hasil'] in relevant_aliases]
|
||||||
|
|
@ -237,7 +237,7 @@ class ForwardChaining:
|
||||||
'semua_diagnosis': diagnosis # Will be populated after all diagnosis generated
|
'semua_diagnosis': diagnosis # Will be populated after all diagnosis generated
|
||||||
})
|
})
|
||||||
|
|
||||||
filtered_diagnosis = diagnosis[:1]
|
filtered_diagnosis = diagnosis[:5]
|
||||||
|
|
||||||
# Isi daftar hasil untuk ditampilkan ke pengguna
|
# Isi daftar hasil untuk ditampilkan ke pengguna
|
||||||
for diag in filtered_diagnosis:
|
for diag in filtered_diagnosis:
|
||||||
|
|
|
||||||
|
|
@ -273,7 +273,7 @@ DEFAULT_EXPERT_RULES = [
|
||||||
'display_order': 3,
|
'display_order': 3,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'code': 'FC04',
|
'code': 'FC05',
|
||||||
'symptom_codes': ['G01', 'G02', 'G03', 'G04', 'G05', 'G06', 'G07', 'G09', 'G11', 'G12', 'G14', 'G18', 'G20', 'G22', 'G23', 'G24', 'G26'],
|
'symptom_codes': ['G01', 'G02', 'G03', 'G04', 'G05', 'G06', 'G07', 'G09', 'G11', 'G12', 'G14', 'G18', 'G20', 'G22', 'G23', 'G24', 'G26'],
|
||||||
'result_disease_code': 'P04',
|
'result_disease_code': 'P04',
|
||||||
'description': 'PMK akut: demam, air liur berlebihan, luka mulut, nyeri setelah lepuh pecah, lepuh kaki/kuku, lepuh puting, produksi susu menurun, nafsu makan turun, lesu, lepuh moncong, luka meluas, edema/radang, bengkak celah kuku, telapak kaki longgar, dan puting retak',
|
'description': 'PMK akut: demam, air liur berlebihan, luka mulut, nyeri setelah lepuh pecah, lepuh kaki/kuku, lepuh puting, produksi susu menurun, nafsu makan turun, lesu, lepuh moncong, luka meluas, edema/radang, bengkak celah kuku, telapak kaki longgar, dan puting retak',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue