# Laporan Kinerja Pipeline — Disbunak Kalsel

## Overview
Pak Edi frequently produces Laporan Kinerja (Performance Report) for:
- **Bidang Peternakan dan Kesehatan Hewan** (Triwulan I, II, III, IV)
- **BIB Banjarbaru** (Triwulan I, II, III, IV)
- Other UPTD/institutions under Disbunak

## Document Structure — Two Distinct Formats

> **IMPORTANT**: There are TWO different Laporan Kinerja formats used at Disbunak. Always confirm which institution before building.

---

### FORMAT A — Bidang Peternakan dan Kesehatan Hewan

**Used for:** Pak Edi's own laporan (Bidang Peternakan). Standard SAKIP format.

#### BAB I — PENDAHULUAN
  Latar Belakang (3–4 paragraphs, deep analysis)
  Maksud dan Tujuan
  Sasaran, Output, Outcome

#### BAB II — PERENCANAAN DAN REALISASI KINERJA
  Perjanjian Kinerja Tahun 2026 → **Tabel 1** (2 rows: produksi + PHMS/ASUH)
  Realisasi Kinerja → **Tabel 2** (same 2 rows with realization numbers)
  Realisasi Anggaran → **Tabel 3** (if data available)

#### BAB III — AKUNTABILITAS KINERJA
  Analisis dan Evaluasi Kinerja:
  1. Analisis Capaian Produksi (mini heading, 3–4 body paras)
  2. Analisis Pengendalian Penyakit Hewan
  3. Analisis Kesehatan Masyarakat Veteriner
  4. Target dan Realisasi Rencana Aksi Kinerja

#### BAB IV — PENUTUP
  Kesimpulan (3–4 paragraphs)
  Tanggapan Atasan Langsung → Tabel options (1–6)
  Tanda tangan: Ka. Dinas (kiri) | Kabid (kanan)

---

### FORMAT B — UPT BIB Banjarbaru

**Used for:** BIB Banjarbaru (Kepala: drh. Sasongko Nugroho). Follows reference DOC exactly.

#### BAB I — PENDAHULUAN
  Latar Belakang (includes: dasar pergub, tupoksi/fungsi lengkap)
  **Maksud dan Tujuan** (Maksud + Tujuan bullets)
  **Sasaran, Output, Outcome, Benefit, Impact** (each as separate sub-section)

#### BAB II — PERENCANAAN KINERJA
  Perjanjian Kinerja → **Tabel 1 PK** (kinerja utama + IKU + target)
  Sub Bagian Tata Usaha: list all 15 sub-kegiatan (bullet list)
  Seksi Pengkajian & Seksi Produksi: sub-kegiatan listed

#### BAB III — AKUNTABILITAS KINERJA
  Realisasi Kinerja → **Tabel 2 IKU** (target vs realizasi TW)
  Perbandingan dengan tahun sebelumnya → **Tabel 3** (tahun n vs tahun n-1)
  **Evaluasi dan Analisis Kinerja:**
  - A. Sub Bagian Tata Usaha (analysis bullets, one per IKU)
  - B. Seksi Pengkajian dan Pemeliharaan (bullet list: perawatan bull, pengendalian penyakit, pakan, pelayanan teknis)
  - C. Seksi Produksi dan Distribusi (analysis + supporting factors)

#### BAB IV — PENUTUP
  Kesimpulan (3 paragraphs)
  Rencana Tindak Lanjut (bullet list)
  Tanggapan Atasan Langsung → Tabel options
  Tanda tangan: Ka. Dinas (kiri, date Mar 2026) | Ka. BIB (kanan)

---

### Format Specifications (BOTH formats)
| Element | Specification |
|---------|---------------|
| Font | Arial 12pt throughout (body + tables) |
| BAB heading | **Centered**, bold, 14pt, color (22,50,61) |
| Sub-chapter heading | **Left aligned**, bold, 12pt |
| Mini heading | Left aligned, bold, 11pt |
| Body paragraph | Justify, first-line indent **1.5 cm** |
| Table | Keep together — no page-break-split (`cantSplit` XML) |

## Data Sources

### LAKIN CSV from Google Sheets
URL: `https://docs.google.com/spreadsheets/d/18IPrWDVqsL7ASvllOfIwfPSpF_hADdSXvootQ050FKw/...`
Pak Edi exports as CSV and sends via Telegram.

### CSV Parsing Notes
- Date in CSV is report period, NOT current date
- If "Hambatan/Upaya/Tindak Lanjut" cells are empty → write generic narrative
- For akumulatif (cumulative TW): use sheet for end-of-period month

## Build Scripts

### Run
```bash
/home/ubuntu/venv_rra/bin/python3 build_tw1.py   # Bidang TW1
/home/ubuntu/venv_rra/bin/python3 build_tw2.py   # Bidang TW2
/home/ubuntu/venv_rra/bin/python3 build_bib_tw1.py  # BIB TW1
/home/ubuntu/venv_rra/bin/python3 build_bib_tw2.py  # BIB TW2 (needs CSV update)
```

### Python Environment
- venv: `/home/ubuntu/venv_rra/`
- Package: `python-docx`

### Key Scripts
| File | Purpose |
|------|---------|
| `/home/ubuntu/build_bib.py` | Shared `build_bib()` function — generates BIB laporan |
| `/home/ubuntu/build_bib_tw1.py` | BIB TW1 wrapper (calls `build_bib()`) |
| `/home/ubuntu/build_bib_tw2.py` | BIB TW2 wrapper (calls `build_bib()`) |
| `/home/ubuntu/build_laporan_base.py` | Base script for Bidang Peternakan laporan |

## Key Data Points

### Bidang Peternakan TW1 (Mar CSV)
| Indikator | Target | Realisasi TW I | Capaian |
|-----------|--------|----------------|---------|
| Produksi Daging | 141.147t | 35.287t | 25.0% |
| Produksi Telur | 157.752t | 39.438t | 25.0% |
| Produksi Susu | 97t | 24t | 25.0% |
| PHMS | 85% | 21.24% | 25.0% thd target |
| ASUH | 100% | 24.99% | 25.0% thd target |

### Bidang Peternakan TW2 (Jun CSV, akumulatif Jan-Jun)
| Indikator | Target | Realisasi TW II | Capaian |
|-----------|--------|-----------------|---------|
| Produksi Daging | 141.147t | 70.574t | 50.0% |
| Produksi Telur | 157.752t | 78.876t | 50.0% |
| Produksi Susu | 97t | 49t | 50.5% |
| PHMS | 85% | 42.48% | 50.0% thd target |
| ASUH | 100% | 49.98% | 50.0% thd target |
| Pagu | Rp3.631.894.900 | Rp1.665.339.108 | 45.85% |
| Fisik | 100% | 54.73% | 54.73% |
| Catatan Atasan | "Sudah baik dan agar lebih ditingkatkan" | | |

### BIB Banjarbaru TW1 (Mar CSV)
| IKU | Target | Realisasi TW I | Capaian |
|-----|--------|----------------|---------|
| Kegiatan tepat waktu | 100% | 0.25% | 25.00% |
| Kepatuhan administrasi | 100 | 1.00 | **100.00%** |
| IKM layanan | 96.4 | 1.00 | **96.40%** |
| Semen beku SNI | 100.000 dosis | 19.700 dosis | **19.70%** |
| Benih sesuai ketentuan | 100% | 0.25% | 25.00% |
| Semen beku hidup | 100% | 0.25% | 25.00% |
| Bibit sesuai SNI | 100% | 0.25% | 25.00% |

### BIB TW2 (Jun 2026) — Data belum ada
Estimasi saat ini: ~40.000 dosis (40%). **HARUS diupdate** begitu CSV Juni diterima dari Pak Sasongko.

### BIB Perbandingan TW I 2025 vs 2026
| IKU | TW I 2025 | TW I 2026 |
|-----|-----------|-----------|
| Kepatuhan Adm. | 25% | 25% |
| Produksi SNI | **19.10%** | **19.70%** |

> **Note:** CSV BIB Mar 2026 has empty Hambatan/Upaya/Tindak Lanjut cells — write generic narrative for these sections.

> **IMPORTANT**: Program name is **OPRE** (Optimalisasi Reproduksi), NOT SIKOMANDAN. SIKOMANDAN is for Dinas, not BIB.

## Output Path
```
/home/ubuntu/kantor/LAPORAN KINERJA TW1 2026 - [Institution].docx
/home/ubuntu/kantor/LAPORAN KINERJA TW2 2026 - [Institution].docx
```

## Common Names
| Institution | Leader | NIP |
|------------|--------|-----|
| Dinas (Ka. Dinas) | drh. Suparmi, M.S | 196809111995032003 |
| Bidang Peternakan (Kabid) | drh. Edi Santosa | 197409182008031001 |
| BIB Banjarbaru (Ka. BIB) | drh. Sasongko Nugroho | 197905232008031002 |

## Extracting Text from Old .DOC Files (Binary .doc, not .docx)

Old BIB laporan files come as `.doc` (Binary format, not XML). Use `olefile` + raw byte extraction:

```bash
/home/ubuntu/venv_rra/bin/pip install olefile

/home/ubuntu/venv_rra/bin/python3 << 'PYEOF'
import olefile, re
path = '/path/to/file.doc'
ole = olefile.OleFileIO(path)
data = ole.openstream('WordDocument').read()

text_chunks = []
current = []
for b in data:
    # Printable ASCII + tab/lf/cr
    if 32 <= b <= 126 or b in (9, 10, 13):
        current.append(chr(b))
    else:
        if len(current) > 3:
            chunk = ''.join(current).strip()
            if chunk:
                text_chunks.append(chunk)
        current = []

full = re.sub(r' +', ' ', ' '.join(text_chunks))
# Stop at PAGE \* MERGEFORMAT or other field codes (binary garbage follows)
idx = full.find('PAGE \\* MERGEFORMAT')
if idx > 0:
    full = full[:idx]
print(full)
PYEOF
```

> **Critical**: The `.doc` format stores text as raw bytes in the `WordDocument` stream — no encoding markers needed. Printable ASCII (32–126) + tab/lf/cr = readable content. Binary control bytes act as delimiters. Binary garbage (JPEG thumbnails, OLE embeddings) appear after the readable text — stop at field codes like `PAGE \* MERGEFORMAT` or garbled sequences like `GG66 uuuuaaauu`.
> **Warning**: Do NOT use `antiword`, `catdoc`, or `libreoffice` — none are installed. Use olefile only.
