Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Task 5 — Multi-Sector Pipeline Stability Report

Objective

Create an advanced pipeline-analysis function named:

ReportForInvalidPipelines(...)

Each source pipeline must first be divided into a configurable number of equal sectors.

Every sector has its own stability level.

The function must then produce a detailed report describing:

  • every value below its sector stability level
  • how far each invalid value is below that level
  • the source pipeline
  • the source sector
  • fully stable sectors
  • sectors containing two or more unstable values
  • values whose stability deficit is greater than a global critical threshold

Input

The function has four input arguments:

1. pipelines
2. sector counts
3. sector stability levels
4. critical deficit

Argument 1 — Pipelines

The first argument is:

[][]int

The provided data contains six pipelines.

Pipeline 1

[]int{
    37, 92, 61, 28,
    55, 78, 10, 91,
    64, 84, 56, 73,
    29, 19, 49, 88,
}

Length:

16

Pipeline 2

[]int{
    64, 35, 46, 78,
    52, 23, 97, 12,
    61, 41, 85, 70,
    99, 54, 16, 68,
}

Length:

16

Pipeline 3

[]int{
    15, 58, 91, 37,
    67, 74, 29, 50,
    84, 63, 95, 12,
    39, 68, 27, 72,
    44, 10, 81, 90,
    80, 36, 79, 43,
}

Length:

24

Pipeline 4

[]int{
    25, 61, 92, 34,
    47, 83, 52, 64,
    11, 70, 86, 59,
    28, 65, 49, 40,
    99, 74, 53, 80,
    63, 82, 30, 72,
}

Length:

24

Pipeline 5

[]int{
    58, 33, 47, 91,
    29, 72, 56, 39,
    61, 87, 64, 49,
    88, 72, 44, 61,
    57, 55, 69, 95,
}

Length:

20

Pipeline 6

[]int{
    48, 92, 65, 44,
    41, 59, 40, 90,
    77, 55, 33, 68,
    19, 84, 61, 43,
    12, 81, 74, 56,
}

Length:

20

Argument 2 — Sector Counts

The second argument is:

[]int

There must be exactly one sector count for every source pipeline.

Allowed sector counts depend on pipeline length.

16-Element Pipeline

Allowed:

2
4

20-Element Pipeline

Allowed:

4
5

24-Element Pipeline

Allowed:

3
4
6

These configurations guarantee equal-size sectors.

Sector Size

For a pipeline with:

N elements

divided into:

S sectors

each sector contains:

N / S

values.

For example:

16 elements / 4 sectors = 4 values per sector

Argument 3 — Stability Configuration

The third argument is:

[][]int

There must be one inner stability slice for every pipeline.

The number of stability values inside that slice must equal the number of sectors selected for that pipeline.

For example:

sectorCounts[0] = 2

requires:

len(stability[0]) == 2

If:

stability[0] = []int{50, 70}

then:

Sector 1 stability = 50
Sector 2 stability = 70

Argument 4 — Critical Deficit

The fourth argument is a single integer.

It defines when an unstable value should also be classified as critically below its required stability level.

For example:

criticalDeficit = 15

means a value is critical when:

stability - value > 15

Case 1

Sector counts:

[]int{
    2,
    4,
    3,
    6,
    4,
    5,
}

Stability configuration:

[][]int{
    {50, 70},
    {60, 70, 40, 65},
    {40, 60, 50},
    {60, 40, 50, 70, 60, 70},
    {50, 40, 40, 50},
    {40, 30, 50, 70, 60},
}

Critical deficit:

15

Case 1 Sector Mapping

Pipeline 1

Length:

16

Sector count:

2

Each sector contains:

8 values

Stability levels:

Sector 1 -> 50
Sector 2 -> 70

Pipeline 2

Length:

16

Sector count:

4

Each sector contains:

4 values

Stability levels:

Sector 1 -> 60
Sector 2 -> 70
Sector 3 -> 40
Sector 4 -> 65

Pipeline 3

Length:

24

Sector count:

3

Each sector contains:

8 values

Stability levels:

40
60
50

Pipeline 4

Length:

24

Sector count:

6

Each sector contains:

4 values

Stability levels:

60
40
50
70
60
70

Pipeline 5

Length:

20

Sector count:

4

Each sector contains:

5 values

Stability levels:

50
40
40
50

Pipeline 6

Length:

20

Sector count:

5

Each sector contains:

4 values

Stability levels:

40
30
50
70
60

Case 2

Sector counts:

[]int{
    4,
    2,
    6,
    3,
    5,
    4,
}

Stability configuration:

[][]int{
    {60, 70, 40, 65},
    {50, 70},
    {60, 40, 50, 70, 60, 70},
    {40, 60, 50},
    {50, 40, 40, 50, 70},
    {40, 30, 50, 70},
}

Critical deficit:

20

Sector Processing

For every pipeline:

  1. determine its sector count
  2. calculate sector size
  3. divide the pipeline into consecutive sectors
  4. retrieve the stability level for each sector
  5. analyze every value

Sector membership is based on original position.

Do not sort the pipeline before dividing it.

Stability Rule

A value is stable when:

value >= stability

A value is unstable when:

value < stability

Stability Deficit

For an unstable value:

deficit = stability - value

For example:

stability = 60
value     = 37

produces:

deficit = 23

Critical Instability

An unstable value is also critical when:

deficit > criticalDeficit

For:

criticalDeficit = 15

a deficit of:

16

is critical.

A deficit of exactly:

15

is not critical because the original task requires values below the stability level by more than the configured amount.

Suggested Result Model

Use structured output.

For example:

type InvalidValue struct {
    Value       int
    Stability   int
    Deficit     int
    Critical    bool
    SourceIndex int
}

A sector result can be:

type SectorReport struct {
    SectorIndex        int
    Stability          int
    InvalidValues      []InvalidValue
    FullyStable        bool
    MultipleFailures   bool
}

A pipeline result can be:

type PipelineReport struct {
    PipelineIndex int
    SectorCount   int
    SectorSize    int
    Sectors       []SectorReport
}

The complete result can be:

type StabilityReport struct {
    CriticalDeficit int
    Pipelines       []PipelineReport
}

The exact naming may be changed.

Fully Stable Sector

A sector is fully stable when every value satisfies:

value >= stability

Therefore:

FullyStable = true

only when:

len(InvalidValues) == 0

Sector with Multiple Failures

The task requires reporting sectors containing:

2 or more values below stability

Therefore:

MultipleFailures = len(InvalidValues) >= 2

Invalid Value Report

Every unstable value must preserve enough information to identify:

  • its numeric value
  • required stability
  • deficit
  • pipeline
  • sector
  • optionally its original source index

For example:

InvalidValue{
    Value:       37,
    Stability:   60,
    Deficit:     23,
    Critical:    true,
    SourceIndex: 0,
}

Validation

The following relationships must be validated.

Pipeline Count

len(pipelines) == len(sectorCounts)

Stability Configuration Count

len(pipelines) == len(stability)

Valid Sector Count

The sector count must be allowed for the corresponding pipeline length.

Equal Sector Division

The pipeline length must be evenly divisible by the requested sector count.

Stability Count Per Pipeline

For every pipeline i:

len(stability[i]) == sectorCounts[i]

Critical Deficit

The critical deficit should not be negative.

Invalid Configuration Example

A 16-element pipeline cannot be configured with:

3 sectors

under the original task rules.

Likewise:

sectorCount = 4
stability values = {50, 60}

is invalid because four sectors require four stability levels.

Requirements

The function must report:

  1. every value below its stability level
  2. the deficit for every unstable value
  3. the source pipeline
  4. the source sector
  5. every fully stable sector
  6. every sector with two or more unstable values
  7. every value whose deficit exceeds the critical threshold

Testing

The original task requires:

  1. testing Case 1
  2. testing Case 2
  3. creating one additional example using different values

Additional useful tests include:

  • all sectors stable
  • all sectors unstable
  • one invalid value in a sector
  • exactly two invalid values
  • deficit exactly equal to critical threshold
  • deficit one greater than critical threshold
  • invalid sector configuration
  • mismatched stability configuration
  • negative critical deficit

Source Data Difference

The original task initially lists one set of values for pipelines 5 and 6, then its Case 1 and Case 2 examples use slightly different values in those pipelines.

For example, the initial pipeline data includes values such as:

Pipeline 5: ... 27, 55 ...
Pipeline 6: ... 34, 11 ...

while the later executable cases use:

Pipeline 5: ... 57, 55 ...
Pipeline 6: ... 44, 41 ...

The two case definitions should therefore be treated as their own explicit test inputs rather than assumed to be identical to the earlier introductory dataset.

Implementation Notes

This task extends Task 4.

Task 4 uses:

one threshold per pipeline

Task 5 uses:

one or more sectors per pipeline
+
one threshold per sector
+
a global critical-deficit threshold

A clean processing model is:

Validate configuration
        ↓
For each pipeline
        ↓
Divide into sectors
        ↓
Resolve sector stability
        ↓
Analyze values
        ↓
Build sector report
        ↓
Build pipeline report
        ↓
Return complete report

Avoid creating separate processing code for 16-element, 20-element, and 24-element pipelines.

Their allowed sector counts differ, but the analysis algorithm itself should remain generic.

Scalionix Docs

Keyboard Shortcuts

Navigate the documentation without leaving the keyboard.
Navigation
Previous subject
←
Next subject
→
Previous subsection
Alt + ↑
Next subsection
Alt + ↓
Interface
Documentation Home
Ctrl + Enter
Search
Alt + Q
Open shortcuts
?
Close dialog
Esc
Scalionix Docs

Search Documentation