Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -339,7 +339,7 @@ with st.container():
|
|
| 339 |
# RIGHT — LOGO
|
| 340 |
with col3:
|
| 341 |
try:
|
| 342 |
-
st.image("pln.png", width=
|
| 343 |
except:
|
| 344 |
st.write("") # Jika logo tidak ditemukan, kosongkan
|
| 345 |
|
|
@@ -358,6 +358,12 @@ import plotly.graph_objects as go
|
|
| 358 |
import numpy as np
|
| 359 |
import pandas as pd
|
| 360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
# =================== OBJECTIVE 1 - Company Reporting Activity (Polar Bar Chart) ===================
|
| 362 |
st.markdown(
|
| 363 |
"""
|
|
@@ -446,19 +452,16 @@ if 'temuan_kode_distrik' in df_local.columns:
|
|
| 446 |
]
|
| 447 |
pln_color = "#FFD700" # Kuning PLN
|
| 448 |
|
| 449 |
-
def
|
| 450 |
colors = []
|
| 451 |
-
names = []
|
| 452 |
blue_idx = 0
|
| 453 |
for company in df['nama_perusahaan']:
|
| 454 |
if 'PLN' in str(company).upper():
|
| 455 |
colors.append(pln_color)
|
| 456 |
-
names.append(company)
|
| 457 |
else:
|
| 458 |
colors.append(pastel_blues[blue_idx % len(pastel_blues)])
|
| 459 |
-
names.append(company)
|
| 460 |
blue_idx += 1
|
| 461 |
-
return colors
|
| 462 |
|
| 463 |
# Fungsi untuk membuat polar bar chart
|
| 464 |
def create_polar_bar_chart(df, area_name):
|
|
@@ -469,7 +472,7 @@ if 'temuan_kode_distrik' in df_local.columns:
|
|
| 469 |
df = df.sort_values('avg_monthly_ratio', ascending=True)
|
| 470 |
companies = df['nama_perusahaan'].tolist()
|
| 471 |
ratios = df['avg_monthly_ratio'].tolist()
|
| 472 |
-
colors
|
| 473 |
|
| 474 |
# Hitung total temuan untuk menghitung sudut (proporsi)
|
| 475 |
total_findings = df_local[df_local['Area_Type'] == area_name].groupby('nama_perusahaan').size()
|
|
@@ -489,7 +492,7 @@ if 'temuan_kode_distrik' in df_local.columns:
|
|
| 489 |
|
| 490 |
fig = go.Figure()
|
| 491 |
|
| 492 |
-
# Tambahkan satu trace untuk setiap perusahaan agar muncul di legend
|
| 493 |
for i, (comp, ratio, color, angle) in enumerate(zip(companies, ratios, colors, angles)):
|
| 494 |
fig.add_trace(go.Barpolar(
|
| 495 |
r=[ratio],
|
|
@@ -511,15 +514,17 @@ if 'temuan_kode_distrik' in df_local.columns:
|
|
| 511 |
bgcolor="white",
|
| 512 |
radialaxis=dict(
|
| 513 |
visible=True,
|
| 514 |
-
tickfont=dict(size=9),
|
| 515 |
-
gridcolor='
|
| 516 |
-
title=dict(text='Avg Finding/Person', font=dict(size=10))
|
| 517 |
),
|
| 518 |
angularaxis=dict(
|
| 519 |
visible=True,
|
| 520 |
direction='clockwise',
|
| 521 |
-
tickfont=dict(size=9, color="white"),
|
| 522 |
-
showline=False
|
|
|
|
|
|
|
| 523 |
),
|
| 524 |
),
|
| 525 |
showlegend=True, # 🔥 Aktifkan legend
|
|
@@ -1060,6 +1065,7 @@ with col_3d:
|
|
| 1060 |
####OBJECTIVE 4
|
| 1061 |
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1062 |
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
|
|
|
| 1063 |
try:
|
| 1064 |
from wordcloud import WordCloud
|
| 1065 |
import matplotlib.pyplot as plt
|
|
@@ -1067,7 +1073,7 @@ try:
|
|
| 1067 |
except ImportError:
|
| 1068 |
WORDCLOUD_AVAILABLE = False
|
| 1069 |
|
| 1070 |
-
st.markdown("<h3 class='section-title'>4.
|
| 1071 |
unsafe_allow_html=True)
|
| 1072 |
|
| 1073 |
if WORDCLOUD_AVAILABLE:
|
|
@@ -1103,8 +1109,8 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1103 |
|
| 1104 |
# === HIGH RESOLUTION WORDCLOUD ===
|
| 1105 |
wordcloud = WordCloud(
|
| 1106 |
-
width=
|
| 1107 |
-
height=
|
| 1108 |
background_color='white',
|
| 1109 |
colormap='viridis',
|
| 1110 |
max_words=1000,
|
|
@@ -1112,7 +1118,7 @@ if WORDCLOUD_AVAILABLE:
|
|
| 1112 |
).generate(text)
|
| 1113 |
|
| 1114 |
# === SMALL BUT SHARP OUTPUT ===
|
| 1115 |
-
fig, ax = plt.subplots(figsize=(
|
| 1116 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 1117 |
ax.axis('off')
|
| 1118 |
plt.tight_layout()
|
|
|
|
| 339 |
# RIGHT — LOGO
|
| 340 |
with col3:
|
| 341 |
try:
|
| 342 |
+
st.image("pln.png", width=120) # Sesuaikan width sesuai kebutuhan
|
| 343 |
except:
|
| 344 |
st.write("") # Jika logo tidak ditemukan, kosongkan
|
| 345 |
|
|
|
|
| 358 |
import numpy as np
|
| 359 |
import pandas as pd
|
| 360 |
|
| 361 |
+
# =================== OBJECTIVE 1 - Company Reporting Activity (Polar Bar Chart) ===================
|
| 362 |
+
import streamlit as st
|
| 363 |
+
import plotly.graph_objects as go
|
| 364 |
+
import numpy as np
|
| 365 |
+
import pandas as pd
|
| 366 |
+
|
| 367 |
# =================== OBJECTIVE 1 - Company Reporting Activity (Polar Bar Chart) ===================
|
| 368 |
st.markdown(
|
| 369 |
"""
|
|
|
|
| 452 |
]
|
| 453 |
pln_color = "#FFD700" # Kuning PLN
|
| 454 |
|
| 455 |
+
def assign_colors(df):
|
| 456 |
colors = []
|
|
|
|
| 457 |
blue_idx = 0
|
| 458 |
for company in df['nama_perusahaan']:
|
| 459 |
if 'PLN' in str(company).upper():
|
| 460 |
colors.append(pln_color)
|
|
|
|
| 461 |
else:
|
| 462 |
colors.append(pastel_blues[blue_idx % len(pastel_blues)])
|
|
|
|
| 463 |
blue_idx += 1
|
| 464 |
+
return colors
|
| 465 |
|
| 466 |
# Fungsi untuk membuat polar bar chart
|
| 467 |
def create_polar_bar_chart(df, area_name):
|
|
|
|
| 472 |
df = df.sort_values('avg_monthly_ratio', ascending=True)
|
| 473 |
companies = df['nama_perusahaan'].tolist()
|
| 474 |
ratios = df['avg_monthly_ratio'].tolist()
|
| 475 |
+
colors = assign_colors(df)
|
| 476 |
|
| 477 |
# Hitung total temuan untuk menghitung sudut (proporsi)
|
| 478 |
total_findings = df_local[df_local['Area_Type'] == area_name].groupby('nama_perusahaan').size()
|
|
|
|
| 492 |
|
| 493 |
fig = go.Figure()
|
| 494 |
|
| 495 |
+
# 🔥 Tambahkan satu trace untuk setiap perusahaan agar muncul di legend
|
| 496 |
for i, (comp, ratio, color, angle) in enumerate(zip(companies, ratios, colors, angles)):
|
| 497 |
fig.add_trace(go.Barpolar(
|
| 498 |
r=[ratio],
|
|
|
|
| 514 |
bgcolor="white",
|
| 515 |
radialaxis=dict(
|
| 516 |
visible=True,
|
| 517 |
+
tickfont=dict(size=9, color="white"), # 🔥 Warna angka radial jadi putih
|
| 518 |
+
gridcolor='lightgray',
|
| 519 |
+
title=dict(text='Avg Finding/Person', font=dict(size=10, color="white")) # 🔥 Warna judul radial
|
| 520 |
),
|
| 521 |
angularaxis=dict(
|
| 522 |
visible=True,
|
| 523 |
direction='clockwise',
|
| 524 |
+
tickfont=dict(size=9, color="white"), # 🔥 Warna angka derajat jadi putih
|
| 525 |
+
showline=False,
|
| 526 |
+
linecolor="white", # 🔥 Warna garis derajat jadi putih
|
| 527 |
+
gridcolor="rgba(255,255,255,0.2)" # 🔥 Warna grid derajat jadi transparan putih
|
| 528 |
),
|
| 529 |
),
|
| 530 |
showlegend=True, # 🔥 Aktifkan legend
|
|
|
|
| 1065 |
####OBJECTIVE 4
|
| 1066 |
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1067 |
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1068 |
+
# ================= WORDCLOUD (HIGH QUALITY) ==================
|
| 1069 |
try:
|
| 1070 |
from wordcloud import WordCloud
|
| 1071 |
import matplotlib.pyplot as plt
|
|
|
|
| 1073 |
except ImportError:
|
| 1074 |
WORDCLOUD_AVAILABLE = False
|
| 1075 |
|
| 1076 |
+
st.markdown("<h3 class='section-title'>4. Most Frequent Unsafe Cases</h3>",
|
| 1077 |
unsafe_allow_html=True)
|
| 1078 |
|
| 1079 |
if WORDCLOUD_AVAILABLE:
|
|
|
|
| 1109 |
|
| 1110 |
# === HIGH RESOLUTION WORDCLOUD ===
|
| 1111 |
wordcloud = WordCloud(
|
| 1112 |
+
width=1600, # resolusi besar agar HD
|
| 1113 |
+
height=800,
|
| 1114 |
background_color='white',
|
| 1115 |
colormap='viridis',
|
| 1116 |
max_words=1000,
|
|
|
|
| 1118 |
).generate(text)
|
| 1119 |
|
| 1120 |
# === SMALL BUT SHARP OUTPUT ===
|
| 1121 |
+
fig, ax = plt.subplots(figsize=(3, 2), dpi=200)
|
| 1122 |
ax.imshow(wordcloud, interpolation='bilinear')
|
| 1123 |
ax.axis('off')
|
| 1124 |
plt.tight_layout()
|