---
title: Pulse Score Calculation - Done
slug: pulse-score-calculation-done
createdAt: 2025-02-12T01:22:59.339Z
---

This outlines the procedure for calculating the "Pulse" score, a composite satisfaction metric, each time a survey response is submitted.

# Input

The function receives three inputs representing the survey response data:

- `faceRatings`: `Array<number | null>`
  - An array of numeric values representing responses to the face-rating questions (up to 10 questions).
  - Each element corresponds to a single question and can have one of the following values:
    - `100`: Positive (Happy Face)
    - `50`: Neutral (Meh Face)
    - `0`: Negative (Unhappy Face)
    - `-1`: N/A (Circle with Dash)
    - `null`: Question was not answered.
- `npsScore`: `number`
  - An integer between 0 and 10 (inclusive), representing the respondent's answer to the "Would you refer" (NPS) question.
- `comments`: `Array<string>`
  - An array of strings, representing any comments provided by the respondent.
  - The array can be empty (no comments) or contain one or more strings.

# Output

- `pulseScore`: `number`
  - A floating-point number between 0 and 100 (inclusive), representing the overall satisfaction percentage (the Pulse score).

# Calculating Pulse Score (Individual Response)

## Calculation Steps

Note only calculate based on Score 0-100. Do not include N/A or null questions in calculations.&#x20;

1. **Calculate Face Score:**
   - Initialize `faceSum = 0`.
   - Initialize `faceCount = 0`.
   - Iterate through the `faceRatings` array:
     - For each `rating` in `faceRatings`:
       - If `rating !== null`:
         - `faceSum += rating`
         - `faceCount++`
   - If `faceCount > 0`:
     - `faceScore = faceSum / faceCount`
   - Else:
     - `faceScore = 0`  // Handle cases where no face-rating questions were answered.
2. **Calculate NPS Score (0-100 Scale):**
   - Convert the raw `npsScore` to a 0-100 scale (`npsScore100`) based on the following mapping:

     ```javascript
     switch (npsScore) {
         case 0: case 1: case 2: case 3: case 4: case 5: case 6:
             npsScore100 = 0;
             break;
         case 7: case 8:
             npsScore100 = 50;
             break;
         case 9: case 10:
             npsScore100 = 100;
             break;
         default:
             npsScore100 = 0; // Or handle invalid input appropriately.
     }
     ```
3. **Calculate Comment Sentiment Score:**
   - Initialize `commentSentimentScore = 0`.
   - Initialize `commentCount = 0`.
   - If `comments.length > 0`:  // Check if comments array is not empty
     - Iterate through the `comments` array:
       - For each `comment` in `comments`:
         - `sentiment = analyzeSentiment(comment)`  // Call external sentiment analysis function
         - If `sentiment !== null`: // Check if sentiment analysis was successful
           - `commentSentimentScore += sentiment`
           - `commentCount++`
     - If `commentCount > 0`:
       - `commentSentimentScore = commentSentimentScore / commentCount`
4. **Calculate Overall Pulse Score (with Re-weighting):**
   - **Initial Weights:**
     - `wf = 0.4`  // Face Rating weight
     - `wn = 0.4`  // NPS weight
     - `wc = 0.2`  // Comment Sentiment weight
   - **Handle Missing Comment Sentiment (Re-weighting):**
     - If `commentCount === 0`:  // No comments or sentiment analysis failed
       - `wc = 0`
       - `newWf = wf / (wf + wn)`
       - `newWn = wn / (wf + wn)`
     - Else:
       - `newWf = wf`
       - `newWn = wn`
   - **Final Calculation:**
     - `pulseScore = (newWf * faceScore) + (newWn * npsScore100) + (wc * commentSentimentScore)`
   - **Return&#x20;**`pulseScore`

## Sentinment Analysis Prompt

```none
You are tasked with analyzing customer sentiment of a comment associated with a survey question. Your goal is to provide a sentiment score between 0 and 100, where 0 represents extremely negative sentiment, 50 represents neutral sentiment, and 100 represents extremely positive sentiment.

Here is the customer comment you need to analyze:

<suvrey-question>
   <question>How satisfied are you with the speed at which our helpdesk team responds to your requests?</question>
   <answer>Happy Face</answer> 
   <comment>
      {{comment}}
   </comment>
</suvrey-question>

Carefully read and consider the comment above. Pay attention to the words used, the overall tone, and any specific positive or negative expressions.

To determine the sentiment score, follow these guidelines:
1. Identify key positive and negative words or phrases
2. Consider the overall context and tone of the comment
3. Evaluate any specific complaints or praises
4. Assess the intensity of the sentiment expressed

Before providing the final score, explain your reasoning for the sentiment analysis. Consider the following questions in your justification:
- What specific words or phrases influenced your analysis?
- Is the overall tone primarily positive, negative, or neutral?
- Are there any mixed sentiments present?
- How intense is the sentiment expressed?

Provide your justification and final score in the following format:

<justification>
[Write your reasoning here, explaining how you arrived at the sentiment score]
</justification>

<score>
[Provide only the numeric score between 0 and 100, or null if sentiment cannot be determined]
</score>

Remember, if the sentiment cannot be determined from the given comment, return null as the score.
```

## Javascript Calculation

```javascript
function calculatePulseScore(faceRatings, npsScore, comments) {

    // 1. Calculate Face Score
    let faceSum = 0;
    let faceCount = 0;
    for (const rating of faceRatings) {
        if (rating !== null) {
            faceSum += rating;
            faceCount++;
        }
    }
    const faceScore = faceCount > 0 ? faceSum / faceCount : 0;

    // 2. Calculate NPS Score
    let npsScore100;
    switch (npsScore) {
        case 0: case 1: case 2: case 3: case 4: case 5: case 6:
            npsScore100 = 0;
            break;
        case 7: case 8:
            npsScore100 = 50;
            break;
        case 9: case 10:
            npsScore100 = 100;
            break;
        default:
            npsScore100 = 0; // Handle invalid input
    }

    // 3. Calculate Comment Sentiment Score
    let commentSentimentScore = 0;
    let commentCount = 0;
    if (comments.length > 0) {
        for (const comment of comments) {
            const sentiment = analyzeSentiment(comment); // Assume this function exists
            if (sentiment !== null) {
                commentSentimentScore += sentiment;
                commentCount++;
            }
        }
        commentSentimentScore = commentCount > 0 ? commentSentimentScore / commentCount : 0;
    }

    // 4. Calculate Overall Pulse Score (with Re-weighting)
    const wf = 0.4;
    const wn = 0.4;
    let wc = 0.2;
    let newWf, newWn;

    if (commentCount === 0) {
        wc = 0;
        newWf = wf / (wf + wn);
        newWn = wn / (wf + wn);
    } else {
        newWf = wf;
        newWn = wn;
    }

    const pulseScore = (newWf * faceScore) + (newWn * npsScore100) + (wc * commentSentimentScore);

    return pulseScore;
}
```



# Calculating Pulse Score (Aggregate)

To calculate an aggregated Pulse Score for a group (e.g., a company, department, or team), we use a simple arithmetic mean of all individual Pulse Scores.&#x20;

## Formula

The aggregated Pulse Score is calculated as:&#x20;

:::BlockQuote
Aggregated Pulse = Sum of all individual Pulse Scores / Number of respondents&#x20;
:::

Or more simply:&#x20;

:::BlockQuote
Aggregated Pulse = (Pulse₁ + Pulse₂ + ... + Pulseₙ) / n&#x20;
:::

Where n is the total number of respondents.

### Example

A team of 5 people with the following individual Pulse Scores:

- Person A: 75
- Person B: 82
- Person C: 68
- Person D: 90
- Person E: 71

**Calculation**

:::BlockQuote
Aggregated Pulse: (75 + 82 + 68 + 90 + 71) / 5 = 77.2 -> Rounded = 77
:::

## Important Notes

1. **Incomplete or Missing Responses**: The aggregation only includes actual responses. Respondents who did not complete the survey are not counted in the calculation.
2. **Rounding**: Display the final Aggregated Pulse Score rounded to a whole number.

