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

OSM-Integration #30

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would really be great if we can avoid publishing personalized setting even if they are turned into comments

// "vscode_custom_css.imports": [
// "file:///Users/ILeyberman/.vscode/extensions/webrender.synthwave-x-fluoromachine-0.0.11/synthwave-x-fluoromachine.css"
// ]
}
1 change: 1 addition & 0 deletions src/common/models/traderProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TraderProfile {
status: TraderProfileStatus;
soMeShare: boolean;
confirmedLocation?: number[];
completenessIndex: number;
storeType: {
gastronomie: boolean;
lebensmittel: boolean;
Expand Down
48 changes: 48 additions & 0 deletions src/common/services/import/import.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
// import * as traders from '../../repositories/traders.repository';
import admin = require('firebase-admin');
import { TraderProfile } from '../../models/traderProfile';



const WEIGHTS_OF_COMP_INDEX: any = {
businessname: 10,
ownerFirstname: 10,
ownerLastname: 10,
postcode: 10,
city: 10,
street: 10,
number: 10,
description: 10,
pickup: 5,
delivery: 5,
email: 25,
telephone: 20,
homepage: 20,
confirmedLocation: 50,
defaultImagePath: 0
}

const MAX_COMP_INDEX = Object.values(WEIGHTS_OF_COMP_INDEX)
.map(v => v as number)
.reduce((a,b) => a + b);


function getServiceProvider(source: string){
return require('./' + source +'/provider');
Expand All @@ -15,12 +41,34 @@ export async function importData(app: admin.app.App, source: string, options: an
for(const trader of traders) {
try {
// console.log(trader);
buildCompletenessIndex(trader);
// console.log(trader.completenessIndex);
// await traders.upsert(app, trader);
} catch(e) {
console.log('errow while importing', trader);
}
}

const sortedTraders = (traders as []).sort((a: any, b: any) => a.completenessIndex - b.completenessIndex);
sortedTraders.forEach((t:any) => {
console.log(t.completenessIndex);
});

console.log('items: ' + traders.length)
}
}

function buildCompletenessIndex(trader:TraderProfile) {
let currentIndex = 0;

if (trader) {

for(const key of Object.keys(trader)){
const prop = (trader as any)[key];
if (prop && WEIGHTS_OF_COMP_INDEX[key])
currentIndex += WEIGHTS_OF_COMP_INDEX[key];
}

trader.completenessIndex = 100 / MAX_COMP_INDEX * currentIndex;
}
}