import pandas as pd
import os
import json

# Paths to key files
jp1_file = "/home/hieutt50/projects/DSOL/CustomerDocument/уВ╖уВЩуГзуГХуВЩф╕Ашжз/1.2 JP1шинхоЪщаЕчЫо.xlsx"
screen_file = "/home/hieutt50/projects/DSOL/CustomerDocument/чФ╗щЭвшиншиИч╖и/01_хЕ▒щАЪ/02_чФ╗щЭвщБ╖чз╗хЫ│/01.01.02.02.07_чФ╗щЭвщБ╖чз╗хЫ│_х╖еф║ЛцГЕха▒ц╡БщАЪ-я╝вя╝пчК╢ц│БхЗ║хКЫщГихИЖ.xls"
soap_file = "/home/hieutt50/projects/DSOL/CustomerDocument/IFф╗ХцзШцЫ╕(уВвуГ│уГПуВЩуГ│уГИуВЩуГл)/ч╡▒хРИHHC/01.03.03-06_SOAP FaultуВдуГ│уВ┐уГХуВзуГ╝уВ╣щЫ╗цЦЗ.xlsx"

samples = {}

# 1. JP1 Sample
try:
    print("Sampling JP1...")
    df = pd.read_excel(jp1_file, sheet_name=0, header=None, nrows=20)
    # Find a row with meaningful data (not just headers)
    # Looking for a row with a job path
    sample_rows = []
    for i in range(len(df)):
        row_str = df.iloc[i].to_string(index=False)
        if "/batch/" in row_str:
            sample_rows.append(df.iloc[i].dropna().tolist())
    
    samples["JP1"] = sample_rows[:3] if sample_rows else "No direct job rows found in first 20 lines"
except Exception as e:
    samples["JP1"] = str(e)

# 2. Screen Sample
try:
    print("Sampling Screen...")
    # Screen files are often visual, so let's just get the text content of the first few rows
    df = pd.read_excel(screen_file, sheet_name=0, header=None, nrows=10)
    # Get non-empty cells
    cells = []
    for i in range(len(df)):
        row_vals = [str(x) for x in df.iloc[i].dropna().tolist() if str(x) != 'nan']
        if row_vals:
            cells.append(f"Row {i}: {', '.join(row_vals)}")
    samples["Screen"] = cells
except Exception as e:
    samples["Screen"] = str(e)

# 3. SOAP Sample
try:
    print("Sampling SOAP...")
    df = pd.read_excel(soap_file, sheet_name=0, header=None, nrows=20)
    # Look for parameter definitions
    soap_data = []
    for i in range(len(df)):
        row_vals = [str(x) for x in df.iloc[i].dropna().tolist()]
        if row_vals:
            soap_data.append(f"Row {i}: {', '.join(row_vals)}")
    samples["SOAP"] = soap_data
except Exception as e:
    samples["SOAP"] = str(e)

print(json.dumps(samples, indent=2, ensure_ascii=False))
