Skip to content

Commit

Permalink
sharing the constants LANGS and CACHE_FOR_HRS_i45db with proximap also
Browse files Browse the repository at this point in the history
via the location.js
  • Loading branch information
Ralf Hauser committed Mar 22, 2020
1 parent 3311e5d commit a443486
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
20 changes: 11 additions & 9 deletions config/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ Therefore responsible citizens have mapped out all fountains of the festival hos
},
bounding_box: {
// osm wm-image ch-zh Brunnentrog mit Relief "Möve" https://github.com/water-fountains/proximap/issues/306
"latMin": 47.3655,
"lngMin": 8.54524,
"latMax": 47.3656,
"lngMax": 8.54525
// "latMin": 47.3655,
// "lngMin": 8.54524,
// "latMax": 47.3656,
// "lngMax": 8.54525
//Klusdörfli without P18 nor coordinates 47.36518, 8.568826
// "latMin": 47.3644,
// "lngMin": 8.56875,
// "latMax": 47.3652,
// "lngMax": 8.56885
"latMin": 47.3644,
"lngMin": 8.56875,
"latMax": 47.3652,
"lngMax": 8.56885
// Schule Friesenberg with multiple Categories
// "latMin": 47.3602,
// "lngMin": 8.5054,
Expand Down Expand Up @@ -440,5 +440,7 @@ Therefore responsible citizens have mapped out all fountains of the festival hos
url_template: null
}
},
gak:`${process.env.GOOGLE_API_KEY}`
gak:`${process.env.GOOGLE_API_KEY}`,
CACHE_FOR_HRS_i45db: 48,
LANGS: ['en', 'de', 'fr', 'it', 'tr', 'sr']
};
12 changes: 6 additions & 6 deletions server/api/controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import {extractProcessingErrors} from "./processing-errors.controller";
import {getImageInfo,getImgsOfCat} from "../services/wikimedia.service";
const haversine = require("haversine");
const _ = require('lodash');
import {MAX_IMG_SHOWN_IN_GALLERY, LAZY_ARTIST_NAME_LOADING_i41db,
CACHE_FOR_HRS_i45db} from "../../common/constants";
import {MAX_IMG_SHOWN_IN_GALLERY, LAZY_ARTIST_NAME_LOADING_i41db //,CACHE_FOR_HRS_i45db
} from "../../common/constants";


// Configuration of Cache after https://www.npmjs.com/package/node-cache
const cityCache = new NodeCache( {
stdTTL: 60*60*CACHE_FOR_HRS_i45db, // time till cache expires, in seconds
stdTTL: 60*60*locations.CACHE_FOR_HRS_i45db, // time till cache expires, in seconds
checkperiod: 30, // how often to check for expiration, in seconds
deleteOnExpire: false, // on expire, we want the cache to be recreated not deleted
useClones: false // do not create a clone of the data when fetching from cache
Expand All @@ -55,7 +55,7 @@ cityCache.on('expired', (key, value)=>{
generateLocationData(key)
.then(fountainCollection=>{
// save newly generated fountainCollection to the cache
cityCache.set(key, fountainCollection, 60*60*CACHE_FOR_HRS_i45db); // expire after two hours
cityCache.set(key, fountainCollection, 60*60*locations.CACHE_FOR_HRS_i45db); // expire after two hours

// create a reduced version of the data as well
cityCache.set(key + '_essential', essenceOf(fountainCollection));
Expand All @@ -79,7 +79,7 @@ export class Controller {
generateLocationData(location_code)
.then(fountainCollection => {
// save new data to storage
cityCache.set(location_code, fountainCollection, 60 * 60 * CACHE_FOR_HRS_i45db); // expire after two hours
cityCache.set(location_code, fountainCollection, 60 * 60 * locations.CACHE_FOR_HRS_i45db); // expire after two hours
// create a reduced version of the data as well
cityCache.set(location_code + '_essential', essenceOf(fountainCollection));
// also create list of processing errors (for proximap#206)
Expand Down Expand Up @@ -119,7 +119,7 @@ export class Controller {
generateLocationData(req.query.city)
.then(fountainCollection => {
// save new data to storage
cityCache.set(req.query.city, fountainCollection, 60*60*CACHE_FOR_HRS_i45db);
cityCache.set(req.query.city, fountainCollection, 60*60*locations.CACHE_FOR_HRS_i45db);

// create a reduced version of the data as well
let r_essential = essenceOf(fountainCollection);
Expand Down
10 changes: 6 additions & 4 deletions server/api/services/processing.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const _ = require ('lodash');
import WikimediaService from './wikimedia.service';
import WikipediaService from './wikipedia.service';
import WikidataService from './wikidata.service';
import {locations} from '../../../config/locations';
import l from '../../common/logger';
import {fountain_property_metadata} from "../../../config/fountain.properties"
import {PROP_STATUS_INFO, PROP_STATUS_OK,LAZY_ARTIST_NAME_LOADING_i41db, LANGS} from "../../common/constants";
import {PROP_STATUS_INFO, PROP_STATUS_OK,LAZY_ARTIST_NAME_LOADING_i41db//, LANGS
} from "../../common/constants";

export function defaultCollectionEnhancement(fountainCollection,dbg, debugAll) {
l.info('processing.service.js defaultCollectionEnhancement: '+dbg+' '+new Date().toISOString());
Expand Down Expand Up @@ -115,7 +117,7 @@ export function fillOperatorInfo(fountainCollection, dbg){
export function fillWikipediaSummary(fountain, dbg, tot, promises) {
// check all languages to see if a wikipedia page is referenced
let i = 0;
_.forEach(LANGS, lang =>{
_.forEach(locations.LANGS, lang =>{
let urlParam = `wikipedia_${lang}_url`;
i=i+1;
const dbgHere = i+'/'+tot+' '+dbg;
Expand Down Expand Up @@ -254,7 +256,7 @@ export function fillOutNames(fountainCollection,dbg) {
}
i++;
if(fProps.name.value === null){
for(let lang of LANGS){
for(let lang of locations.LANGS){
let fPopLng = fProps[`name_${lang}`];
if(fPopLng != null && fPopLng.value !== null){
// take the first language-specific name that is not null and apply it to the default name
Expand All @@ -269,7 +271,7 @@ export function fillOutNames(fountainCollection,dbg) {
}
// fill lang-specific names if null and if a default name exists
if(fProps.name.value !== null) {
for (let lang of LANGS) {
for (let lang of locations.LANGS) {
let fPopLng = fProps[`name_${lang}`];
if (fPopLng != null && fPopLng.value === null) {
fPopLng.value = fProps.name.value;
Expand Down
5 changes: 3 additions & 2 deletions server/api/services/wikidata.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const axios = require('axios');
import { cacheAdapterEnhancer } from 'axios-extensions';
const _ = require ('lodash');
const wdk = require('wikidata-sdk');
import {LANGS} from "../../common/constants";
//import {LANGS} from "../../common/constants";
import {locations} from '../../../config/locations';

// Set up caching of http requests
const http = axios.create({
Expand Down Expand Up @@ -190,7 +191,7 @@ class WikidataService {
}
// Try to find a useful link
// Look for Wikipedia entry in different languages
for(let lang of LANGS){
for(let lang of locations.LANGS){
if(entity.sitelinks.hasOwnProperty(lang+'wiki')){
fountain.properties.artist_name.derived.website.url = `https://${lang}.wikipedia.org/wiki/${entity.sitelinks[lang+'wiki']}`;
return fountain;
Expand Down
6 changes: 4 additions & 2 deletions server/api/services/wikimedia.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const axios = require ('axios');
const { ConcurrencyManager } = require("axios-concurrency");
import l from '../../common/logger';
import {PROP_STATUS_ERROR, PROP_STATUS_INFO, PROP_STATUS_OK, PROP_STATUS_WARNING,
MAX_IMG_SHOWN_IN_GALLERY, LANGS} from "../../common/constants";
MAX_IMG_SHOWN_IN_GALLERY//, LANGS
} from "../../common/constants";
import {locations} from '../../../config/locations';

let api = axios.create({});

Expand All @@ -30,7 +32,7 @@ class WikimediaService {
getName(f) {
const props = f.properties;
if(props.name.value === null){
for(let lang of LANGS){
for(let lang of locations.LANGS){
const pL= props[`name_${lang}`];
if(null != pL && pL.value !== null){
return pL.value;
Expand Down
4 changes: 2 additions & 2 deletions server/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ export const PROP_STATUS_NOT_DEFINED = 'PROP_STATUS_NOT_DEFINED';
export const PROP_STATUS_NOT_AVAILABLE = 'PROP_STATUS_NOT_AVAILABLE';
export const MAX_IMG_SHOWN_IN_GALLERY = 50;
export const LAZY_ARTIST_NAME_LOADING_i41db = true;
export const LANGS = ['en', 'de', 'fr', 'it', 'tr', 'sr'];
export const CACHE_FOR_HRS_i45db = 48;
//export const LANGS = ['en', 'de', 'fr', 'it', 'tr', 'sr'];
//export const CACHE_FOR_HRS_i45db = 48;

0 comments on commit a443486

Please sign in to comment.