Skip to content

Commit f923be3

Browse files
authored
Codec-Compare version 0.2.5 (#15)
1 parent a14e57f commit f923be3

24 files changed

Lines changed: 676 additions & 200 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
dist
12
node_modules
23
package-lock.json

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.2.5
4+
5+
- Add support for cross-batch individual source asset filtering.
6+
- Add support for cross-batch batch source asset filtering by tag.
7+
- Add button to set the batch as the reference batch in the batch info panel.
8+
- Add link to view only two batches in the batch info panel.
9+
310
## v0.2.4
411

512
- Add the megapixels field.

assets/demo_batch_some_codec_exp.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
{ "codec": "Name of the codec used to generate this data" },
55
{ "version": "Version of the codec used to generate this data" },
66
{ "time": "Timestamp of when this data was generated" },
7-
{ "source data set": "The origin of the images used as input" },
7+
{ "source_data_set": "The origin of the images used as input" },
8+
{ "source_tags": "Input image tags" },
89
{ "original_path": "The path to the original image" },
910
{ "preview": "The path to the original image preview" },
1011
{ "encoded_path": "The path to the encoded image" },
@@ -17,6 +18,7 @@
1718
"experiment",
1819
"2023-05-22T13:02:15.137053618Z",
1920
"https://testimages.org/sampling/",
21+
"fruits=d040000018&with text=0d88068002",
2022
"/rainbow.png",
2123
"assets/rainbow_q0.webp",
2224
"/rainbow_q50.webp",

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codec_compare",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "Codec performance comparison tool",
55
"publisher": "Google LLC",
66
"author": "Yannis Guyon",
@@ -27,6 +27,7 @@
2727
},
2828
"dependencies": {
2929
"@material/mwc-button": "^0.27.0",
30+
"@material/mwc-checkbox": "^0.27.0",
3031
"@material/mwc-fab": "^0.27.0",
3132
"@material/mwc-icon": "^0.27.0",
3233
"@material/mwc-icon-button": "^0.27.0",

src/batch_merger.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ export function mergeHistograms(histograms: SourceCount[][]): SourceCount[] {
214214
}
215215
}
216216

217-
// Sort by decreasing occurrences.
218-
return Array.from(aggHisto.values()).sort((a, b) => b.count - a.count);
217+
// Sort by name to have a deterministic order that is independent of the
218+
// histogram values which can change depending on the comparison parameters.
219+
return Array.from(aggHisto.values())
220+
.sort(
221+
(a, b) => a.sourceName > b.sourceName ? 1 :
222+
b.sourceName > a.sourceName ? -1 :
223+
0);
219224
}

src/batch_selection.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import {CommonField} from './common_field';
1516
import {Batch} from './entry';
16-
import {dispatch, EventType, listen} from './events';
17-
import {FieldFilter, getFilteredRowIndices} from './filter';
17+
import {FieldFilter} from './filter';
18+
import {getFilteredRowIndices} from './filter_row';
1819
import {MatchedDataPoints} from './matcher';
1920
import {FieldMetricStats, SourceCount} from './metric';
2021

@@ -54,19 +55,11 @@ export class BatchSelection {
5455
}
5556
this.fieldFilters.push(fieldFilter);
5657
}
57-
58-
listen(EventType.FILTER_CHANGED, (event) => {
59-
if (event.detail.batchIndex !== this.batch.index) return;
60-
this.updateFilteredRows();
61-
dispatch(
62-
EventType.FILTERED_DATA_CHANGED,
63-
{batchIndex: event.detail.batchIndex});
64-
});
6558
}
6659

6760
/** Updates the filteredRowIndices based on the batch and the fieldFilters. */
68-
updateFilteredRows() {
61+
updateFilteredRows(commonFields: CommonField[]) {
6962
this.filteredRowIndices =
70-
getFilteredRowIndices(this.batch, this.fieldFilters);
63+
getFilteredRowIndices(this.batch, this.fieldFilters, commonFields);
7164
}
7265
}

src/batch_selection_actions_ui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class BatchSelectionActionsUi extends LitElement {
4141

4242
return html`
4343
<mwc-icon-button
44+
class="batchInfo"
4445
icon="info"
4546
title="Show details"
4647
@click=${() => {

src/batch_selection_test.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('BatchSelection', () => {
3737
expect(batch.fields[1].isNumber).toBeTrue();
3838

3939
selection = new BatchSelection(batch);
40-
selection.updateFilteredRows();
40+
selection.updateFilteredRows([]);
4141
});
4242

4343
it('filters rows', () => {
@@ -55,28 +55,13 @@ describe('BatchSelection', () => {
5555
// Filter out one image.
5656
selection.fieldFilters[0].enabled = true;
5757
selection.fieldFilters[0].uniqueValues.delete('path/to/image');
58-
dispatch(EventType.FILTER_CHANGED, {batchIndex: batch.index});
58+
selection.updateFilteredRows([]);
5959
expect(selection.filteredRowIndices).toEqual([1, 2]);
6060

6161
// Reduce the range of numeric values.
6262
selection.fieldFilters[1].enabled = true;
6363
selection.fieldFilters[1].rangeEnd = 4.6;
64-
dispatch(EventType.FILTER_CHANGED, {batchIndex: batch.index});
64+
selection.updateFilteredRows([]);
6565
expect(selection.filteredRowIndices).toEqual([2]);
6666
});
67-
68-
it('dispatches an event back', () => {
69-
batch.index = 42;
70-
71-
let eventBatchIndex: number|undefined = undefined;
72-
window.addEventListener(EventType.FILTERED_DATA_CHANGED, (event) => {
73-
eventBatchIndex = event.detail.batchIndex;
74-
}, {once: true});
75-
expect(eventBatchIndex).toBeUndefined();
76-
dispatch(EventType.FILTER_CHANGED, {batchIndex: batch.index});
77-
expect(eventBatchIndex).not.toBeUndefined();
78-
if (eventBatchIndex !== undefined) {
79-
expect(eventBatchIndex).toBe(batch.index);
80-
}
81-
});
8267
});

src/batch_ui.ts

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,28 @@ export class BatchUi extends LitElement {
5050
this.requestUpdate();
5151
};
5252

53+
const refIndex = this.state.referenceBatchSelectionIndex;
5354
const batchIndex = this.batch.index;
5455
const onFilteredDataInfoRequest = () => {
5556
dispatch(EventType.FILTERED_DATA_INFO_REQUEST, {batchIndex});
5657
onClose();
5758
};
59+
const onSetAsReference = () => {
60+
this.state.referenceBatchSelectionIndex = batchIndex;
61+
dispatch(EventType.REFERENCE_CHANGED);
62+
this.requestUpdate();
63+
};
5864
const onMatchesInfoRequest = () => {
5965
dispatch(EventType.MATCHES_INFO_REQUEST, {batchIndex});
6066
onClose();
6167
};
6268

69+
// Keep the batches in the same order.
70+
const minIndex = Math.min(refIndex, batchIndex);
71+
const maxIndex = Math.max(refIndex, batchIndex);
72+
const twoBatchLink = `?batch=${this.state.batches[minIndex].url}&batch=${
73+
this.state.batches[maxIndex].url}${window.location.hash}`;
74+
6375
return html`
6476
<div id="background" @click=${onClose}></div>
6577
<div id="dialog">
@@ -83,6 +95,7 @@ export class BatchUi extends LitElement {
8395
</mwc-button>
8496
8597
<mwc-button
98+
id="showRows"
8699
raised
87100
icon="clear_all"
88101
label="Show rows"
@@ -91,7 +104,32 @@ export class BatchUi extends LitElement {
91104
</mwc-button>
92105
93106
${
94-
batchIndex === this.state.referenceBatchSelectionIndex ?
107+
batchIndex === refIndex ?
108+
// disabled mwc-button title does not appear. Use a div.
109+
html`
110+
<div title="This batch is already the reference batch"
111+
class="left-margin">
112+
<mwc-button
113+
raised
114+
icon="center_focus_strong"
115+
label="Set as reference"
116+
disabled>
117+
</mwc-button>
118+
</div>
119+
` :
120+
html`
121+
<mwc-button
122+
raised
123+
icon="center_focus_weak"
124+
label="Set as reference"
125+
title="Use this batch as reference to compare other codecs with"
126+
@click=${onSetAsReference}
127+
class="left-margin">
128+
</mwc-button>
129+
`}
130+
131+
${
132+
batchIndex === refIndex ?
95133
// disabled mwc-button title does not appear. Use a div.
96134
html`
97135
<div title="The reference batch cannot be matched with itself">
@@ -105,13 +143,42 @@ export class BatchUi extends LitElement {
105143
` :
106144
html`
107145
<mwc-button
146+
id="showMatches"
108147
raised
109148
icon="join_inner"
110149
label="Show matches"
111150
title="Display the matches between this batch and the reference batch"
112151
@click=${onMatchesInfoRequest}>
113152
</mwc-button>
114153
`}
154+
155+
${
156+
this.state.batches.length < 3 ?
157+
html`` :
158+
batchIndex === refIndex ?
159+
// disabled mwc-button title does not appear. Use a div.
160+
html`
161+
<div title="Only available with another batch as reference">
162+
<mwc-button
163+
raised
164+
icon="filter_2"
165+
label="Two-batch view"
166+
disabled>
167+
<mwc-icon>open_in_new</mwc-icon>
168+
</mwc-button>
169+
</div>
170+
` :
171+
html`
172+
<a href="${twoBatchLink}" target="_blank">
173+
<mwc-button
174+
raised
175+
icon="filter_2"
176+
label="Two-batch view"
177+
title="Compare only this batch and the reference batch">
178+
<mwc-icon>open_in_new</mwc-icon>
179+
</mwc-button>
180+
</a>
181+
`}
115182
</div>
116183
117184
<mwc-fab id="closeButton" icon="close" title="Close" @click=${onClose}>
@@ -172,6 +239,16 @@ export class BatchUi extends LitElement {
172239
display: flex;
173240
flex-direction: row;
174241
justify-content: space-evenly;
242+
gap: 20px;
243+
}
244+
245+
.left-margin {
246+
margin-left: auto;
247+
}
248+
249+
mwc-icon {
250+
margin-left: 8px;
251+
font-size: 16px;
175252
}
176253
`;
177254
}

src/codec_compare.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import './help_ui';
3434
import {css, html, LitElement} from 'lit';
3535
import {customElement, query} from 'lit/decorators.js';
3636

37+
import {sourceTagsFromBatchesAndCommonFields} from './common_field';
3738
import {Batch} from './entry';
3839
import {loadBatchJson, loadJsonContainingBatchJsonPaths} from './entry_loader';
3940
import {dispatch, EventType, listen} from './events';
@@ -44,13 +45,17 @@ import {SettingsUi} from './settings_ui';
4445
import {State} from './state';
4546
import {Tab} from './tab';
4647
import {UrlState} from './url_state';
48+
import {reverseMap} from './utils';
4749

4850
/** Main component of the codec comparison static viewer. */
4951
@customElement('codec-compare')
5052
export class CodecCompare extends LitElement {
5153
/** The root data object containing the full state. */
5254
private readonly state = new State();
5355
private readonly urlState = new UrlState();
56+
/** Maps asset tags to the set of source asset names that have them. */
57+
private tagToAssetNames = new Map<string, Set<string>>();
58+
private assetNameToTags = new Map<string, Set<string>>();
5459
/** True if all batches are loaded into the state. */
5560
private isLoaded = false;
5661
/** True if at least one batch failed to load. */
@@ -74,18 +79,20 @@ export class CodecCompare extends LitElement {
7479
}
7580

7681
private renderSentence() {
77-
// #sentenceContainer is an overlay of the whole #comparisons block.
7882
return html`
7983
<div id="sentenceContainer">
8084
<sentence-ui .state=${this.state}></sentence-ui>
8185
</div>`;
8286
}
8387

8488
private renderGallery() {
85-
// #galleryContainer is an overlay of the whole #comparisons block.
8689
return html`
8790
<div id="galleryContainer">
88-
<gallery-ui .state=${this.state}></gallery-ui>
91+
<gallery-ui
92+
.state=${this.state}
93+
.tagToAssetNames=${this.tagToAssetNames}
94+
.assetNameToTags=${this.assetNameToTags}>
95+
</gallery-ui>
8996
</div>`;
9097
}
9198

@@ -201,7 +208,7 @@ export class CodecCompare extends LitElement {
201208
</p>
202209
203210
<p id="credits">
204-
Codec Compare beta version 0.2.4<br>
211+
Codec Compare beta version 0.2.5<br>
205212
<a href="https://github.com/webmproject/codec-compare">
206213
Sources on GitHub
207214
</a>
@@ -241,6 +248,9 @@ export class CodecCompare extends LitElement {
241248

242249
private async onAllBatchesLoaded() {
243250
this.state.initialize();
251+
this.tagToAssetNames = sourceTagsFromBatchesAndCommonFields(
252+
this.state.batches, this.state.commonFields);
253+
this.assetNameToTags = reverseMap(this.tagToAssetNames);
244254
this.urlState.setDefaultValues(this.state);
245255
this.state.initializePostUrlStateDefaultValues();
246256
this.urlState.load(this.state);

0 commit comments

Comments
 (0)