from pprint import pprint
from ADFmentor import ADFMentor
import os

questions = """
Topic: Azure Data Factory – API CSV to SQL Pipelines

Objective

Design and implement two Azure Data Factory pipelines that retrieve CSV customer data from an HTTP API and load it into an Azure SQL Database.
The first pipeline handles a single CSV file, while the second pipeline dynamically processes multiple CSV files from an API folder.

Requirements
Part 1 — Static API CSV Pipeline

Create a pipeline named API_Customers_To_SQL.

The pipeline must retrieve a CSV file from an HTTP API endpoint.

Use a Copy activity to move data from the API source to Azure SQL Database.

Configure the source:

Use DelimitedTextSource.

Use HttpReadSettings for API access.

Skip the first row (header).

Configure the sink:

Use AzureSqlSink.

Set writeBatchSize = 1000.

Use datasets:

HTTP dataset for the CSV source.

Azure SQL dataset for the destination table.

Add a pipeline parameter:

apiUrl (string)

Use dynamic content so the HTTP dataset reads the CSV file using the apiUrl parameter.

Ensure the pipeline successfully loads the customer data into the SQL table.


Part-2: Azure Data Factory – Binary File Copy and SQL Execution Pipeline

Reads binary files (PDFs) from a source Azure Blob Storage container.

Copies them to an output folder in the same Blob Storage.

Executes a SQL Server stored procedure for each file processed.

Triggers a Web Activity after all files are processed.

Task Instructions:

Pipeline Analysis:

Review the provided ARM template for the pipeline.

Identify the activities in order of execution and their dependencies.

Explain the purpose of each activity (Lookup1, ForEach1, Copy data1, Stored procedure1, Web1).

Dataset Configuration:

Describe the source (pdfs) and sink (Binary1) datasets.

Identify the linked service used for both datasets.

Explain the role of the container (traveling) and folder path (output).

Pipeline Execution:

Explain what happens if Lookup1 is skipped.

Explain how ForEach1 handles multiple files from the pdfs dataset.

Describe how the pipeline ensures that the SQL stored procedure runs after each file is copied.

Practical Task:

Modify the pipeline to filter only PDF files larger than 1 MB before copying.

Add error handling in Copy data1 so that failed copies are logged to a separate container called error-logs.

Update Web1 to send a POST request with the number of successfully processed files to a sample URL (https://example.com/pipeline-status).

Optional Bonus Task:

Implement a parameterized folder path for the sink dataset so that files can be copied to output/YYYY/MM/DD dynamically based on the pipeline run date.

Deliverables:

Screenshot or export of the modified pipeline JSON/ARM template.

A brief explanation of how each modification works.

A sample run showing PDF files copied to the output folder and stored procedure executed.

"""

prompt = """You are evaluating an Azure Data Factory pipeline submission. Assess the following:

    CORRECTNESS (70 points):
    - Does the pipeline correctly copy CSV files from Blob Storage to SQL Database?
    - Are GetMetadata, Filter, ForEach, and Copy activities configured properly?
    - Is the activity dependency chain correct?
    - Does it handle multiple files?

    BEST PRACTICES (10 points):
    - Proper use of parameterization
    - Efficient pipeline design
    - Clear naming conventions
    - Appropriate use of linked services and datasets

    PERFORMANCE (10 points):
    - Is ForEach set to parallel (isSequential: false)?
    - Efficient data movement patterns

    REQUIREMENTS ALIGNMENT (10 points):
    - Does it include all required activities (GetMetadata, Filter, ForEach, Copy, notification)?
    - Are parameters defined for sourceFolder and targetTable?

    Provide a score out of 100 and concise feedback (50-75 words)."""


current_dir = os.path.dirname(os.path.abspath(__file__))

mentor = ADFMentor(api_key="AIzaSyBET8k0Ipdfk7fqhylWSzEp_Y4Q0avygZY", model_name="gemini-2.5-flash-lite")

results = mentor.evaluate(
    answer_path=os.path.join(current_dir, "Answers.zip"),
    questions=questions,
    prompt=prompt,
)

print(results['feedback'])
print(f"Score: {results['score']}")

if results.get('task_mapping'):
    print("\nTask Mapping:")
    for task in results['task_mapping']:
        print(f"  File: {task['file']}")
        print(f"  Task: {task['identified_task']}")
        print(f"  Score: {task['score']}")
        print(f"  Feedback: {task['feedback']}")
        print()