# NordaBiz Data Quality Report

Wygeneruj raport jakości danych firm w katalogu NordaBiz.

## Kroki do wykonania:

### 1. Podsumowanie ogólne
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '=== RAPORT JAKOŚCI DANYCH ===' as header;
SELECT NOW() as data_raportu;

SELECT '--- OGÓLNE ---' as section;
SELECT 'Łącznie firm: ' || COUNT(*) FROM companies;
SELECT 'Aktywnych: ' || COUNT(*) FROM companies WHERE status = 'active';
SELECT 'Nieaktywnych: ' || COUNT(*) FROM companies WHERE status != 'active' OR status IS NULL;
"
```

### 2. Kompletność danych kontaktowych
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- DANE KONTAKTOWE ---' as section;
SELECT 'Z emailem: ' || COUNT(*) FROM companies WHERE email IS NOT NULL AND email != '';
SELECT 'Z telefonem: ' || COUNT(*) FROM companies WHERE phone IS NOT NULL AND phone != '';
SELECT 'Ze stroną www: ' || COUNT(*) FROM companies WHERE website IS NOT NULL AND website != '';
SELECT 'Z pełnym adresem: ' || COUNT(*) FROM companies
  WHERE address_street IS NOT NULL AND address_city IS NOT NULL AND address_postal IS NOT NULL;
"
```

### 3. Dane rejestrowe
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- DANE REJESTROWE ---' as section;
SELECT 'Z NIP: ' || COUNT(*) FROM companies WHERE nip IS NOT NULL AND nip != '';
SELECT 'Z REGON: ' || COUNT(*) FROM companies WHERE regon IS NOT NULL AND regon != '';
SELECT 'Z KRS: ' || COUNT(*) FROM companies WHERE krs IS NOT NULL AND krs != '';
"
```

### 4. Jakość opisów
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- OPISY ---' as section;
SELECT 'Z krótkim opisem: ' || COUNT(*) FROM companies WHERE description_short IS NOT NULL AND description_short != '';
SELECT 'Z pełnym opisem: ' || COUNT(*) FROM companies WHERE description_full IS NOT NULL AND description_full != '';
SELECT 'Śr. długość krótkiego opisu: ' || ROUND(AVG(LENGTH(description_short))::numeric, 0) || ' znaków'
  FROM companies WHERE description_short IS NOT NULL;
"
```

### 5. Rozkład kategorii
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- KATEGORIE ---' as section;
SELECT c.name as kategoria, COUNT(*) as liczba
FROM companies co
LEFT JOIN categories c ON co.category_id = c.id
GROUP BY c.name
ORDER BY liczba DESC;
"
```

### 6. Poziomy jakości danych
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- POZIOMY JAKOŚCI ---' as section;
SELECT
  COALESCE(data_quality, 'brak') as poziom,
  COUNT(*) as liczba
FROM companies
GROUP BY data_quality
ORDER BY liczba DESC;
"
```

### 7. Firmy wymagające uzupełnienia
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- WYMAGAJĄ UZUPEŁNIENIA ---' as section;
SELECT slug, legal_name,
  CASE
    WHEN email IS NULL OR email = '' THEN 'brak email'
    WHEN website IS NULL OR website = '' THEN 'brak www'
    WHEN description_short IS NULL OR description_short = '' THEN 'brak opisu'
    ELSE 'inne'
  END as problem
FROM companies
WHERE email IS NULL OR email = ''
   OR website IS NULL OR website = ''
   OR description_short IS NULL OR description_short = ''
LIMIT 20;
"
```

### 8. Ostatnio aktualizowane
```bash
docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz -c "
SELECT '--- OSTATNIE AKTUALIZACJE ---' as section;
SELECT slug, legal_name, DATE(updated_at) as ostatnia_aktualizacja
FROM companies
ORDER BY updated_at DESC
LIMIT 10;
"
```

## Output:
Wygeneruj raport w formacie markdown z tabelami:

### Podsumowanie kompletności danych

| Pole | Wypełnione | Procent |
|------|------------|---------|
| Email | X/80 | X% |
| Telefon | X/80 | X% |
| Strona www | X/80 | X% |
| NIP | X/80 | X% |
| Opis | X/80 | X% |

### Rekomendacje
- Lista firm wymagających uzupełnienia danych
- Sugestie poprawy jakości

## Uwagi:
- Cel: 100% kompletność podstawowych danych
- Priorytet: email > telefon > www > opis
- Weryfikuj dane przez oficjalne źródła (CEIDG, KRS)
- DEV: `docker exec nordabiz-postgres psql -U nordabiz_app -d nordabiz`
- PROD: `ssh maciejpi@10.22.68.249 "sudo -u postgres psql -d nordabiz"`
