# core/converters/report.converter.ts

> 24 lines of code and 6 definitions.

Tree: GovLab Patterns
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/patterns#file-patterns-core-converters-report-converter-ts
Source text: https://banes-lab.com/source/patterns/core/converters/report.converter.ts.txt

Listed in [core/converters](https://banes-lab.com/api/source/patterns/core/converters.md), after [core/converters/page.converter.ts](https://banes-lab.com/source/patterns/core/converters/page.converter.ts.md) and before [core/converters/walk.converter.ts](https://banes-lab.com/source/patterns/core/converters/walk.converter.ts.md).

## Definitions

- `toReport` (lexical_declaration, line 20, exported)
- `coverageOf` (lexical_declaration, line 8)
- `graphToDict` (lexical_declaration, line 16, exported)
- `COVERAGE_SEP` (lexical_declaration, line 6)
- `cells` (lexical_declaration, line 9)
- `filled` (lexical_declaration, line 12)

## Contained in

- [core/converters](https://banes-lab.com/anatomy/patterns/folder-patterns-core-converters.md)

## Used by

- [core/pipelines/record.pipeline.ts](https://banes-lab.com/source/patterns/core/pipelines/record.pipeline.ts.md)
- [core/pipelines/snapshot.pipeline.ts](https://banes-lab.com/source/patterns/core/pipelines/snapshot.pipeline.ts.md)

## Linked from

- [core/converters](https://banes-lab.com/anatomy/patterns/folder-patterns-core-converters.md)
- [core/pipelines](https://banes-lab.com/anatomy/patterns/folder-patterns-core-pipelines.md)

## Source

```typescript
import type { AnalyzeReport, AnalyzeResult, Coverage } from "#types/record.types";
import type { AnalysisGraph } from "#core/models/graph.model";
import type { Finding } from "#types/finding.types";
import type { GraphDict } from "#types/graph.types";

const COVERAGE_SEP = "␟";

const coverageOf = function coverageOf(findings: readonly Finding[]): Coverage {
    const cells = new Set(
        findings.map((finding) => `${finding.coordinate.ontology}${COVERAGE_SEP}${finding.coordinate.analysis}`),
    );
    const filled = [...cells].sort((a, b) => a.localeCompare(b)).map((cell) => cell.split(COVERAGE_SEP));
    return { counts: { filled: cells.size, findings: findings.length }, filled };
};

export const graphToDict = function graphToDict(graph: AnalysisGraph): GraphDict {
    return { edges: graph.nodes.reduce((sum, node) => sum + node.inputs.length, 0), nodes: [...graph.nodes] };
};

export const toReport = function toReport(records: number, result: AnalyzeResult): AnalyzeReport {
    return {
        coverage: coverageOf(result.findings),
        findings: result.findings,
        graph: graphToDict(result.graph),
        headline: { fields: result.schema.length, findings: result.findings.length, records },
        schema: result.schema,
    };
};
```
