Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better report chart #6

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a751f82
Dark shade ▓
hejny Feb 12, 2024
6b5b4b6
Light shade
hejny Feb 12, 2024
32c3a91
0.32.2
hejny Feb 12, 2024
aaba15f
🆚 Update version in config
hejny Feb 12, 2024
4233bd3
📦 Generating packages
hejny Feb 12, 2024
255029c
📦 Update publish workflow for generated packages
hejny Feb 12, 2024
d882faf
Update promptbook to version 0.32.2 in samples
hejny Feb 12, 2024
91ae239
Fix repeat
hejny Feb 13, 2024
4187899
0.32.3
hejny Feb 13, 2024
4d09a0f
🆚 Update version in config
hejny Feb 13, 2024
5a927e3
📦 Generating packages
hejny Feb 13, 2024
7a0d91d
Update promptbook to version 0.32.3 in samples
hejny Feb 13, 2024
373fdda
Log more when problem in createMarkdownChart
hejny Feb 13, 2024
5efafef
0.32.4
hejny Feb 13, 2024
5bf01ad
🆚 Update version in config
hejny Feb 13, 2024
7aa4de1
📦 Generating packages
hejny Feb 13, 2024
fb98993
Update promptbook to version 0.32.4 in samples
hejny Feb 13, 2024
b912a6b
Fix chart rendering issue in createMarkdownChart
hejny Feb 13, 2024
16960f0
Improve box rendering
hejny Feb 13, 2024
f477477
Fix lint
hejny Feb 13, 2024
3240ee2
📖 Generate reports .report.json -> .report.md
hejny Feb 13, 2024
11c9af7
0.32.5
hejny Feb 13, 2024
9b34471
🆚 Update version in config
hejny Feb 13, 2024
cccdd69
📦 Generating packages
hejny Feb 13, 2024
5702255
Update promptbook to version 0.32.5 in samples
hejny Feb 13, 2024
d4095ac
TODOs
hejny Feb 14, 2024
d89c272
Merge branch 'main' into patch/report-chart
hejny Mar 6, 2024
b09df18
Merge branch 'main' into patch/report-chart
hejny Mar 7, 2024
ad37b5d
TODOs
hejny Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/templates/50-advanced.report.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Trying the language capabilities of GPT models.
| Template | Timeline |
| ------------------------------ | ------------------------------------ |
| Synonym | ████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Sentence with Synonym | ░░░███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Sentence with Synonym | ░░░███░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Sentence without original word | ░░░░░░███░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Comparison | ░░░░░░░░░███████████████████████████ |

Expand All @@ -32,7 +32,7 @@ _Note: Each █ represents 0.295 seconds, width of timeline is 10.61 seconds = 3

| Template | Cost |
| ------------------------------ | ------------------------------------ |
| Synonym | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Synonym | ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Sentence with Synonym | █░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Sentence without original word | █░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ |
| Comparison | ████████████████████████████████████ |
Expand Down
87 changes: 85 additions & 2 deletions src/utils/markdown/createMarkdownChart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,53 @@ describe('how createMarkdownChart works', () => {
);
});

it('should render half-tone boxes', () => {
expect(
createMarkdownChart({
nameHeader: 'Template',
valueHeader: 'Timeline',
items: [
{ title: 'Full', from: 0, to: 10 },
{ title: 'Tiny', from: 4.7, to: 5 },
],
width: 10,
unitName: 'seconds',
}),
).toBe(
spaceTrim(`
| Template | Timeline |
|----------|------------|
| Full | ██████████ |
| Tiny | ░░░░▓░░░░░ |

_Note: Each █ represents 1 seconds, width of timeline is 10 seconds = 10 squares_

`),
);
expect(
createMarkdownChart({
nameHeader: 'Template',
valueHeader: 'Timeline',
items: [
{ title: 'Full', from: 0, to: 10 },
{ title: 'Tiny', from: 5, to: 5.2 },
],
width: 10,
unitName: 'seconds',
}),
).toBe(
spaceTrim(`
| Template | Timeline |
|----------|------------|
| Full | ██████████ |
| Tiny | ░░░░░▓░░░░ |

_Note: Each █ represents 1 seconds, width of timeline is 10 seconds = 10 squares_

`),
);
});

it('should round boxes to nearest whole number', () => {
expect(
createMarkdownChart({
Expand All @@ -51,12 +98,48 @@ describe('how createMarkdownChart works', () => {
| Template | Timeline |
|------------|----------|
| Template 1 | ████ |
| Template 2 | ░░░ |
| Template 3 | ░░██ |
| Template 2 | ░░░ |
| Template 3 | ░██░ |

_Note: Each █ represents 2.55 seconds, width of timeline is 10.2 seconds = 4 squares_

`),
);
});

it('should work in real-life example', () => {
// TODO: !!!! Fix
expect(
createMarkdownChart({
nameHeader: 'Template',
valueHeader: 'Timeline',
items: [
{ title: '🖋 Překlad popisu', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Účel stránek', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Příprava kontaktů', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Příprava odkazů', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Návrh zadání', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Návrh obrázku', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Prompt k obrázku', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Vylepšení názvu', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Claim pro web', from: 1707866836.134, to: 1707866836.134 },
{ title: '🖋 Analýza klíčových slov', from: 1707866836.134, to: 1707866836.134 },
{ title: '📃 Vytvoření obsahu webu', from: 1707866836.134, to: 1707866836.134 },
{ title: '💌 Kontaktní formulář', from: 1707866836.135, to: 1707866836.135 },
],
width: 36,
unitName: 'seconds',
}),
).toBe(
spaceTrim(`

`),
);
});

// TODO: !!!! ## ⌚ Time chart must make sense
});

/**
* TODO: !!!! Make 2 in 1 test mermaid + ASCII chart
*/
29 changes: 26 additions & 3 deletions src/utils/markdown/createMarkdownChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,34 @@ export function createMarkdownChart(options: CreateMarkdownChartOptions): string
const table: Array<Array<string_markdown_text>> = [[nameHeader, valueHeader]];

for (const item of items) {
const before = Math.round((item.from - from) * scale);
const during = Math.round((item.to - item.from) * scale);
const before = Math.floor((item.from - from) * scale);
let duringChar = '█';
let during = Math.round((item.to - item.from) * scale);

if (during === 0) {
duringChar = '▓';
during = 1;
}

const after = width - before - during;

table.push([removeEmojis(item.title).trim(), '░'.repeat(before) + '█'.repeat(during) + '░'.repeat(after)]);
if (before < 0 || during < 0 || after < 0) {
console.error(
'Problem in createMarkdownChart',
{ before, during, after },
{ item, items, table, scale, options },
// <- TODO: Error with extra info
);
throw new Error(
// <- TODO: [🥨] Make some NeverShouldHappenError
'Problem in createMarkdownChart, see more in console',
);
}

table.push([
removeEmojis(item.title).trim(),
'░'.repeat(before) + duringChar.repeat(during) + '░'.repeat(after),
]);
}

const legend = `_Note: Each █ represents ${formatNumber(
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import type { string_version } from './types/typeAliases';
/**
* The version of the Promptbook library
*/
export const PROMPTBOOK_VERSION: string_version = '0.36.4';
export const PROMPTBOOK_VERSION: string_version = '0.36.4';