Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Mar 13, 2024
1 parent 1cc6405 commit bc3ffd5
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 37 deletions.
11 changes: 0 additions & 11 deletions .idea/fesk-ts.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/jsLibraryMappings.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

166 changes: 166 additions & 0 deletions __tests__/image-service-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,170 @@ describe('image service loader', () => {
expect(prediection).toEqual(null);
});
});

describe('Getty - normal', () => {
const services = [
{
'@context': 'http://iiif.io/api/image/2/context.json',
protocol: 'http://iiif.io/api/image',
width: 5537,
height: 7630,
sizes: [
{ width: 173, height: 238 },
{ width: 346, height: 476 },
{ width: 692, height: 953 },
{ width: 1384, height: 1907 },
{ width: 2768, height: 3815 },
],
tiles: [{ width: 256, height: 256, scaleFactors: [1, 2, 4, 8, 16, 32] }],
'@id': 'https://media.getty.edu/iiif/image/d915e1a9-8dab-49de-8be1-c29b2228e0bf',
profile: [
'http://iiif.io/api/image/2/level2.json',
{
formats: ['jpg', 'png', 'webp'],
qualities: ['native', 'color', 'gray', 'bitonal'],
supports: [
'regionByPct',
'regionSquare',
'sizeByForcedWh',
'sizeByWh',
'sizeAboveFull',
'sizeUpscaling',
'rotationBy90s',
'mirroring',
],
maxWidth: 30000,
maxHeight: 30000,
},
],
},
{
'@context': 'http://iiif.io/api/image/2/context.json',
protocol: 'http://iiif.io/api/image',
width: 5262,
height: 7488,
sizes: [
{ width: 164, height: 234 },
{ width: 328, height: 468 },
{ width: 657, height: 936 },
{ width: 1315, height: 1872 },
{ width: 2631, height: 3744 },
],
tiles: [{ width: 256, height: 256, scaleFactors: [1, 2, 4, 8, 16, 32] }],
'@id': 'https://media.getty.edu/iiif/image/2efd825f-41fe-4f93-b928-f25644c67b23',
profile: [
'http://iiif.io/api/image/2/level2.json',
{
formats: ['jpg', 'png', 'webp'],
qualities: ['native', 'color', 'gray', 'bitonal'],
supports: [
'regionByPct',
'regionSquare',
'sizeByForcedWh',
'sizeByWh',
'sizeAboveFull',
'sizeUpscaling',
'rotationBy90s',
'mirroring',
],
maxWidth: 30000,
maxHeight: 30000,
},
],
},
{
'@context': 'http://iiif.io/api/image/2/context.json',
protocol: 'http://iiif.io/api/image',
width: 5209,
height: 7397,
sizes: [
{ width: 162, height: 231 },
{ width: 325, height: 462 },
{ width: 651, height: 924 },
{ width: 1302, height: 1849 },
{ width: 2604, height: 3698 },
],
tiles: [{ width: 256, height: 256, scaleFactors: [1, 2, 4, 8, 16, 32] }],
'@id': 'https://media.getty.edu/iiif/image/90049c0d-bfd0-4ee9-8b32-70e45597bf5c',
profile: [
'http://iiif.io/api/image/2/level2.json',
{
formats: ['jpg', 'png', 'webp'],
qualities: ['native', 'color', 'gray', 'bitonal'],
supports: [
'regionByPct',
'regionSquare',
'sizeByForcedWh',
'sizeByWh',
'sizeAboveFull',
'sizeUpscaling',
'rotationBy90s',
'mirroring',
],
maxWidth: 30000,
maxHeight: 30000,
},
],
},
];

const infoA = services[0];
const infoB = services[1];
const infoC = services[2];

test('A -> B -> C', async () => {
const loader = new ImageServiceLoader();
loader.setConfig({ enableFetching: false });

await loader.sample(infoA as any);
await loader.sample(infoB as any);
// await loader.sample();

const prediection = loader.predict({
id: infoC['@id'],
width: infoC.width as number,
height: infoC.height as number,
}) as Service;

expect(prediection).not.toEqual(null);

// ROUNDING ERROR.
// expect(prediection).toMatchObject(infoC);
});
test('C -> B -> A', async () => {
const loader = new ImageServiceLoader();
loader.setConfig({ enableFetching: false });

await loader.sample(infoC as any);
await loader.sample(infoB as any);
// await loader.sample();

const prediection = loader.predict({
id: infoA['@id'],
width: infoA.width as number,
height: infoA.height as number,
}) as Service;

expect(prediection).not.toEqual(null);
// expect(prediection).toMatchObject(infoA);
});
test('A -> C -> B', async () => {
const loader = new ImageServiceLoader();
loader.setConfig({ enableFetching: false });

await loader.sample(infoA as any);
await loader.sample(infoC as any);
// await loader.sample();

const prediection = loader.predict({
id: infoB['@id'],
width: infoB.width as number,
height: infoB.height as number,
}) as Service;

expect(prediection.height).not.toEqual(null);

// expect(prediection).toMatchObject(infoB);
});
});
});
16 changes: 16 additions & 0 deletions src/image-service-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export class ImageServiceLoader {
const serverId = getImageServerFromId(getId(resource));
const imageServer = this.knownImageServers[serverId];

// console.log({
// '!imageServer': !imageServer,
// '!imageServer.result': !imageServer?.result,
// '!(source?.height || resource.height)': !(source?.height || resource.height),
// '!(source?.width || resource.width)': !(source?.width || resource.width),
// '(!force && (imageServer.malformed || imageServer.verifications < this.config.verificationsRequired))':
// !force && (imageServer.malformed || imageServer.verifications < this.config.verificationsRequired),
// 'isLevel0(resource.source)': isLevel0(resource.source),
// });

// No known image server.
if (
!imageServer ||
Expand All @@ -181,12 +191,18 @@ export class ImageServiceLoader {
(!force && (imageServer.malformed || imageServer.verifications < this.config.verificationsRequired)) ||
isLevel0(resource.source)
) {
console.log('WAS NULL HIT');
return null;
}

const serviceUrl = canonicalServiceUrl(getId(resource));

// console.log('serviceUrl', serviceUrl);
// console.log('this.imageServices[serviceUrl]', this.imageServices[serviceUrl]);

if (!this.imageServices[serviceUrl]) {
console.log('TRYING TO GENERATE IMAGE SERVICE');

this.imageServices[serviceUrl] = {
'@context': imageServer.result.context,
'@id': getId(resource),
Expand Down

0 comments on commit bc3ffd5

Please sign in to comment.