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

Re-format sources #162

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
248 changes: 124 additions & 124 deletions server/api/services/generateLocationData.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,139 +323,139 @@ function enrichFountain(fountain: Fountain, dbg: string): Promise<Fountain> {

gl = galleryArr.length;
//if (galleryArr.isEmpty()) {
let i = 0;
let lzAtt = '';
const showDetails = true;
const singleRefresh = true;
const imgUrlSet = new Set<string>();
const catPromises: Promise<ImageLike[]>[] = [];
let numberOfCategories = -1;
let numberOfCategoriesLazyAdded = 0;
const imgUrlsLazyByCategory: ImageLike[] = [];
// TODO @ralfhauser, this condition does not make sense, if value.length < 0 means basically if it is empty and if it is empty, then numberOfCategories will always be 0 and the for-loop will do nothing
if (hasWikiCommonsCategories(props) && 0 < props.wiki_commons_name.value.length) {
numberOfCategories = props.wiki_commons_name.value.length;
let j = 0;
for (const cat of props.wiki_commons_name.value) {
j++;
if (null == cat) {
l.info(i + '-' + j + ' controller.js: null == commons category "' + cat + '" "' + dbg);
continue;
}
if (null == cat.c) {
l.info(i + '-' + j + ' controller.js: null == commons cat.c "' + cat + '" "' + dbg);
continue;
}
if (isBlacklisted(cat.c)) {
l.info(i + '-' + j + ' controller.js: commons category blacklisted "' + cat + '" "' + dbg);
continue;
}
const add = 0 > cat.l;
if (add) {
numberOfCategoriesLazyAdded++;
if (0 == imgUrlSet.size) {
for (const img of gallery.value) {
imgUrlSet.add(img.pgTit);
}
let i = 0;
let lzAtt = '';
const showDetails = true;
const singleRefresh = true;
const imgUrlSet = new Set<string>();
const catPromises: Promise<ImageLike[]>[] = [];
let numberOfCategories = -1;
let numberOfCategoriesLazyAdded = 0;
const imgUrlsLazyByCategory: ImageLike[] = [];
// TODO @ralfhauser, this condition does not make sense, if value.length < 0 means basically if it is empty and if it is empty, then numberOfCategories will always be 0 and the for-loop will do nothing
if (hasWikiCommonsCategories(props) && 0 < props.wiki_commons_name.value.length) {
numberOfCategories = props.wiki_commons_name.value.length;
let j = 0;
for (const cat of props.wiki_commons_name.value) {
j++;
if (null == cat) {
l.info(i + '-' + j + ' controller.js: null == commons category "' + cat + '" "' + dbg);
continue;
}
if (null == cat.c) {
l.info(i + '-' + j + ' controller.js: null == commons cat.c "' + cat + '" "' + dbg);
continue;
}
if (isBlacklisted(cat.c)) {
l.info(i + '-' + j + ' controller.js: commons category blacklisted "' + cat + '" "' + dbg);
continue;
}
const add = 0 > cat.l;
if (add) {
numberOfCategoriesLazyAdded++;
if (0 == imgUrlSet.size) {
for (const img of gallery.value) {
imgUrlSet.add(img.pgTit);
}
const catPromise = getImgsOfCat(cat, dbg, imgUrlSet, imgUrlsLazyByCategory, 'dbgIdWd', props, true);
//TODO we might prioritize categories with small number of images to have greater variety of images?
catPromises.push(catPromise);
}
getCatExtract(singleRefresh, cat, catPromises, dbg);
const catPromise = getImgsOfCat(cat, dbg, imgUrlSet, imgUrlsLazyByCategory, 'dbgIdWd', props, true);
//TODO we might prioritize categories with small number of images to have greater variety of images?
catPromises.push(catPromise);
}
getCatExtract(singleRefresh, cat, catPromises, dbg);
}
return Promise.all(catPromises).then(
r => {
for (let k = 0; k < imgUrlsLazyByCategory.length && k < MAX_IMG_SHOWN_IN_GALLERY; k++) {
//between 6 && 50 imgs are on the gallery-preview
const img = imgUrlsLazyByCategory[k];
//TODO @ralfhauser, val does not exist on GalleryValue but value, changed it
const nImg: GalleryValue = {
s: img.src,
pgTit: img.value,
c: img.cat,
t: img.typ,
};
gallery.value.push(nImg);
}
if (0 < imgUrlsLazyByCategory.length) {
}
return Promise.all(catPromises).then(
r => {
for (let k = 0; k < imgUrlsLazyByCategory.length && k < MAX_IMG_SHOWN_IN_GALLERY; k++) {
//between 6 && 50 imgs are on the gallery-preview
const img = imgUrlsLazyByCategory[k];
//TODO @ralfhauser, val does not exist on GalleryValue but value, changed it
const nImg: GalleryValue = {
s: img.src,
pgTit: img.value,
c: img.cat,
t: img.typ,
};
gallery.value.push(nImg);
}
if (0 < imgUrlsLazyByCategory.length) {
l.info(
'controller.js byId lazy img by lazy cat added: attempted ' +
imgUrlsLazyByCategory.length +
' in ' +
numberOfCategoriesLazyAdded +
'/' +
numberOfCategories +
' cats, tot ' +
gl +
' ' +
dbg +
' "' +
name +
'" ' +
r.length
);
}
for (const img of gallery.value) {
const imMetaDat = img.metadata;
if (null == imMetaDat && 'wm' == img.t) {
lzAtt += i + ',';
l.info(
'controller.js byId lazy img by lazy cat added: attempted ' +
imgUrlsLazyByCategory.length +
' in ' +
numberOfCategoriesLazyAdded +
'/' +
numberOfCategories +
' cats, tot ' +
gl +
' ' +
dbg +
' "' +
name +
'" ' +
r.length
'controller.js byId lazy getImageInfo: ' + i + '/' + gl + ' "' + img.pgTit + '" "' + name + '" ' + dbg
);
}
for (const img of gallery.value) {
const imMetaDat = img.metadata;
if (null == imMetaDat && 'wm' == img.t) {
lzAtt += i + ',';
l.info(
'controller.js byId lazy getImageInfo: ' + i + '/' + gl + ' "' + img.pgTit + '" "' + name + '" ' + dbg
);
imgMetaPromises.push(
getImageInfo(img, i + '/' + gl + ' ' + dbg + ' ' + name, showDetails, props).catch(giiErr => {
//TODO @ralfhauser, dbgIdWd does not exist
const dbgIdWd = undefined;
l.info(
'wikimedia.service.js: fillGallery getImageInfo failed for "' +
img.pgTit +
'" ' +
dbg +
' ' +
dbgIdWd +
' "' +
name +
'"' +
'\n' +
giiErr.stack
);
})
);
lazyAdded++;
} else {
// l.info('controller.js byId: of '+cityS+' found imMetaDat '+i+' in gal of size '+gl+' "'+name+'" '+dbg);
}
getImgClaims(singleRefresh, img, imgMetaPromises, i + ': ' + dbg);
i++;
}
if (0 < lazyAdded) {
l.info(
'controller.js byId lazy img metadata loading: attempted ' +
lazyAdded +
'/' +
gl +
' (' +
lzAtt +
') ' +
dbg +
' "' +
name +
'"'
imgMetaPromises.push(
getImageInfo(img, i + '/' + gl + ' ' + dbg + ' ' + name, showDetails, props).catch(giiErr => {
//TODO @ralfhauser, dbgIdWd does not exist
const dbgIdWd = undefined;
l.info(
'wikimedia.service.js: fillGallery getImageInfo failed for "' +
img.pgTit +
'" ' +
dbg +
' ' +
dbgIdWd +
' "' +
name +
'"' +
'\n' +
giiErr.stack
);
})
);
lazyAdded++;
} else {
// l.info('controller.js byId: of '+cityS+' found imMetaDat '+i+' in gal of size '+gl+' "'+name+'" '+dbg);
}
return waitForImgMetaPromises(fountain, lazyAdded, imgMetaPromises, gl + ' ' + dbg + ' "' + name + '"');
},
err => {
l.error(`controller.js: Failed on imgMetaPromises: ${err.stack} .` + dbg + ' "' + name + '"');
throw err;
getImgClaims(singleRefresh, img, imgMetaPromises, i + ': ' + dbg);
i++;
}
);
// } else {
// l.info('controller.js byId: gl > 0 - '+ gl+' ' + dbg);
// return waitForImgMetaPromises(fountain, lazyAdded, imgMetaPromises, gl + ' ' + dbg + ' "' + name + '"');
// }
if (0 < lazyAdded) {
l.info(
'controller.js byId lazy img metadata loading: attempted ' +
lazyAdded +
'/' +
gl +
' (' +
lzAtt +
') ' +
dbg +
' "' +
name +
'"'
);
}
return waitForImgMetaPromises(fountain, lazyAdded, imgMetaPromises, gl + ' ' + dbg + ' "' + name + '"');
},
err => {
l.error(`controller.js: Failed on imgMetaPromises: ${err.stack} .` + dbg + ' "' + name + '"');
throw err;
}
);
// } else {
// l.info('controller.js byId: gl > 0 - '+ gl+' ' + dbg);
// return waitForImgMetaPromises(fountain, lazyAdded, imgMetaPromises, gl + ' ' + dbg + ' "' + name + '"');
// }
}

function waitForImgMetaPromises(
Expand Down
9 changes: 2 additions & 7 deletions server/api/services/wikimedia.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ class WikimediaService {
//TODO @ralfhauser, img.val does not exist, changed it to img.value, please check if this is correct
//TODO @ralfhauser, are description and metadata optional values? They are not defined here. Moreover, not every ImageLike has a Category which means this needs to be optional for SCTPT as well
const nImg: GalleryValue = { s: img.src, pgTit: img.value, c: img.cat, t: img.typ };
l.info('wikimedia.service.js: fillGallery imgFromMap === undefined "' +
dbg +
' ' +
dbgIdWd
);
l.info('wikimedia.service.js: fillGallery imgFromMap === undefined "' + dbg + ' ' + dbgIdWd);
galValPromises.push(
//TODO @ralfhauser getImageInfo returns Promise<void> this statement most likely does not make sense
// My guess, galValPromises should have nImg instead, hence I added the `then` after the catch, please check if this fix is correct
Expand Down Expand Up @@ -396,8 +392,7 @@ function makeMetadata(data: ImageInfoExtMetadataCollection, dbg: string): ImageI
},
];
const metadata = {};
l.info('wikimedia.service.js: makeMetadata "' +
dbg + '" ');
l.info('wikimedia.service.js: makeMetadata "' + dbg + '" ');
_.forEach(template, pair => {
if (Object.prototype.hasOwnProperty.call(data.extmetadata, pair.sourceName)) {
metadata[pair.outputName] = data.extmetadata[pair.sourceName].value;
Expand Down