> ## Documentation Index
> Fetch the complete documentation index at: https://www.studyfetch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Data Analyst

> An AI chatbot that allows educators to ask questions about student usage, performance, and recommendations

## Overview

The Data Analyst component is an AI-powered chatbot designed specifically for educators. It provides intelligent insights into student engagement, performance metrics, and learning patterns. Educators can ask natural language questions about their students' study habits, identify areas where students may need additional support, and receive personalized recommendations to improve learning outcomes.

## Creating a Data Analyst Component

<CodeGroup>
  ```javascript JavaScript theme={null}
  import StudyfetchSDK from '@studyfetch/sdk';

  const client = new StudyfetchSDK({
    apiKey: 'your-api-key',
    baseURL: 'https://studyfetchapi.com',
  });

  const dataAnalystComponent = await client.v1.components.create({
    name: 'Student Performance Analyst',
    type: 'data-analyst',
    config: {
      materials: ['mat-123', 'mat-456'], // Course materials with student activity data
      folders: ['folder-789'],
      model: 'gpt-4o-mini-2024-07-18',
      systemPrompt: 'You are an AI assistant for educators. Help analyze student usage patterns, performance metrics, and provide actionable recommendations to improve learning outcomes. Focus on identifying struggling students, engagement trends, and suggesting personalized interventions.',
      temperature: 0.3, // Lower temperature for more precise analysis
      maxTokens: 4096
    }
  });

  console.log('Data Analyst component created:', dataAnalystComponent._id);
  ```

  ```python Python theme={null}
  from studyfetch_sdk import StudyfetchSDK

  client = StudyfetchSDK(
      api_key="your-api-key",
      base_url="https://studyfetchapi.com",
  )

  data_analyst_component = client.v1.components.create(
      name="Student Performance Analyst",
      type="data-analyst",
      config={
          "materials": ["mat-123", "mat-456"],  # Course materials with student activity data
          "folders": ["folder-789"],
          "model": "gpt-4o-mini-2024-07-18",
          "systemPrompt": "You are an AI assistant for educators. Help analyze student usage patterns, performance metrics, and provide actionable recommendations to improve learning outcomes. Focus on identifying struggling students, engagement trends, and suggesting personalized interventions.",
          "temperature": 0.3,  # Lower temperature for more precise analysis
          "maxTokens": 4096
      }
  )

  print(f"Data Analyst component created: {data_analyst_component._id}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.components.ComponentResponse;
  import com.studyfetch.javasdk.models.v1.components.ComponentCreateParams;
  import java.util.List;

  public class CreateDataAnalystComponent {
      public static void main(String[] args) {
          StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
              .fromEnv()
              .baseUrl("https://studyfetchapi.com")
              .build();

          ComponentCreateParams params = ComponentCreateParams.builder()
              .name("Student Performance Analyst")
              .type(ComponentCreateParams.Type.DATA_ANALYST)
              .config(ComponentCreateParams.Config.DataAnalystConfigDto.builder()
                  .materials(List.of("mat-123", "mat-456")) // Course materials with student activity data
                  .folders(List.of("folder-789"))
                  .model("gpt-4o-mini-2024-07-18")
                  .systemPrompt("You are an AI assistant for educators. Help analyze student usage patterns, performance metrics, and provide actionable recommendations to improve learning outcomes. Focus on identifying struggling students, engagement trends, and suggesting personalized interventions.")
                  .temperature(0.3) // Lower temperature for more precise analysis
                  .maxTokens(4096)
                  .build())
              .build();

          ComponentResponse component = client.v1().components().create(params);
          System.out.println("Data Analyst component created: " + component._id());
      }
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Components;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;
  public class CreateDataAnalystComponent
  {
      public static async Task CreateDataAnalyst()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          var dataAnalystComponent = await client.V1.Components.Create(new()
          {
              Name = "Student Performance Analyst",
              Type = StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.Type.DataAnalyst,
              Config = new StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.ConfigProperties.DataAnalystConfigDto()
              {
                  Model = "gemini-2.5-flash",
                  Materials = new List<string> { "mat-123" }
              }
          });

          Console.WriteLine($"Data Analyst component created: {dataAnalystComponent._ID}");
      }
  }
  ```
</CodeGroup>

## Configuration Parameters

<ParamField body="name" type="string" required>
  Name of the data analyst component
</ParamField>

<ParamField body="type" type="string" required>
  Must be `"data-analyst"`
</ParamField>

<ParamField body="config" type="object" required>
  Data analyst configuration object

  <Expandable title="Configuration Properties">
    <ParamField body="materials" type="array" required>
      Array of material IDs containing student activity and performance data
    </ParamField>

    <ParamField body="folders" type="array">
      Array of folder IDs containing course materials with student data
    </ParamField>

    <ParamField body="model" type="string" default="gpt-4o-mini-2024-07-18">
      AI model to use for analysis
    </ParamField>

    <ParamField body="systemPrompt" type="string">
      Custom instructions for the AI assistant (default focuses on student analytics for educators)
    </ParamField>

    <ParamField body="temperature" type="number" default="0.3">
      Controls randomness in responses (0-1, lower is more precise)
    </ParamField>

    <ParamField body="maxTokens" type="integer" default="4096">
      Maximum length of analysis responses
    </ParamField>
  </Expandable>
</ParamField>

## Response

```json theme={null}
{
  "_id": "comp_abc123",
  "name": "Student Performance Analyst",
  "type": "data_analyst",
  "status": "active",
  "config": {
    "materials": ["mat-123", "mat-456"],
    "folders": ["folder-789"],
    "model": "gpt-4o-mini-2024-07-18",
    "systemPrompt": "You are an AI assistant for educators. Help analyze student usage patterns, performance metrics, and provide actionable recommendations to improve learning outcomes. Focus on identifying struggling students, engagement trends, and suggesting personalized interventions.",
    "temperature": 0.3,
    "maxTokens": 4096
  },
  "createdAt": "2024-01-15T10:00:00Z",
  "updatedAt": "2024-01-15T10:00:00Z",
  "organizationId": "org_456def",
  "statistics": {
    "totalSessions": 0,
    "totalAnalyses": 0,
    "averageSessionDuration": null
  }
}
```

## Embedding This Component

Once you've created a Data Analyst component, you can embed it on your website using the embedding API.

### Generate Embed URL

<CodeGroup>
  ```javascript JavaScript theme={null}
  const embedResponse = await client.v1.components.generateEmbed(dataAnalystComponent._id, {
    // User tracking
    userId: 'user-456',
    studentName: 'Jane Smith',  // Student name for display
    groupIds: ['class-101', 'class-102'],
    sessionId: 'session-789',
    
    // Dimensions
    width: '100%',
    height: '700px',
    
    // Token expiry
    expiryHours: 24
  });
  ```

  ```python Python theme={null}
  embed_response = client.v1.components.generateEmbed(
      component_id=data_analyst_component._id,
      userId="user-456",
      student_name="Jane Smith",  # Student name for display
      groupIds=["class-101", "class-102"],
      sessionId="session-789",
      width="100%",
      height="700px",
      expiryHours=24
  )
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedParams;
  import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedResponse;

  StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
      .fromEnv()
      .baseUrl("https://studyfetchapi.com")
      .build();

  ComponentGenerateEmbedParams params = ComponentGenerateEmbedParams.builder()
      .id(dataAnalystComponent._id())
      // User tracking
      .userId("user-456")
      .studentName("Jane Smith")  // Student name for display
      .groupIds(List.of("class-101", "class-102"))
      .sessionId("session-789")
      
      // Dimensions
      .width("100%")
      .height("700px")
      
      // Token expiry
      .expiryHours(24)
      .build();

  ComponentGenerateEmbedResponse embedResponse = client.v1().components()
      .generateEmbed(params);
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Components;
  using System;
  using System.Collections.Generic;
  using System.Threading.Tasks;

  public class GenerateDataAnalystEmbed
  {
      public static async Task GenerateEmbed()
      {
          var client = new StudyfetchSDKClient()
          {
              APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
              BaseUrl = new Uri("https://studyfetchapi.com")
          };

          var embedResponse = await client.V1.Components.GenerateEmbed(new()
          {
              ID = "component_123abc", // Replace with your component ID
              UserID = "user-456",
              StudentName = "Jane Smith",  // Student name for display
              GroupIDs = new List<string> { "class-101", "class-102" },
              Width = "100%",
              Height = "600px"
          });

          Console.WriteLine($"Embed URL: {embedResponse.EmbedURL}");
          Console.WriteLine($"Token: {embedResponse.Token}");
      }
  }
  ```
</CodeGroup>

### Embed in Your HTML

```html theme={null}
<iframe 
  src="https://embed.studyfetch.com/component/comp_abc123?token=..."
  width="100%"
  height="700px"
  frameborder="0"
  allow="clipboard-write"
  style="border: 1px solid #e5e5e5; border-radius: 8px;">
</iframe>
```
