Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Adds weight property
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Mar 23, 2017
1 parent 65c98c3 commit 4239016
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
28 changes: 19 additions & 9 deletions app/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,13 @@ var synopsisNormalizer = () => {
}

const normalizePinned = (dataPinned, total, target) => dataPinned.map((publisher) => {
let newPer = Math.floor((publisher.pinPercentage / total) * target)
const floatNumber = (publisher.pinPercentage / total) * target
let newPer = Math.floor(floatNumber)
if (newPer < 1) {
newPer = 1
}

publisher.weight = floatNumber
publisher.pinPercentage = newPer
return publisher
})
Expand All @@ -1057,7 +1059,8 @@ var synopsisNormalizer = () => {
secondsSpent: 0,
faviconURL: result.faviconURL,
score: result.scores[scorekeeper],
pinPercentage: result.pinPercentage
pinPercentage: result.pinPercentage,
weight: result.pinPercentage
}
// HACK: Protocol is sometimes blank here, so default to http:// so we can
// still generate publisherURL.
Expand Down Expand Up @@ -1108,6 +1111,7 @@ var synopsisNormalizer = () => {
// excluded
let publisher = getPublisherData(result)
publisher.percentage = 0
publisher.weight = 0
dataExcluded.push(publisher)
}
})
Expand All @@ -1118,29 +1122,35 @@ var synopsisNormalizer = () => {
dataUnPinned = dataUnPinned.map((result) => {
let publisher = getPublisherData(result)
publisher.percentage = 0
publisher.weight = 0
return publisher
})

// sync synopsis
dataPinned.forEach((item) => {
synopsis.publishers[item.site].pinPercentage = item.pinPercentage
})

// sync app store
appActions.changeLedgerPinnedPercentages(dataPinned)
} else {
// unpinned publishers
dataUnPinned = dataUnPinned.map((result) => {
let publisher = getPublisherData(result)
publisher.percentage = Math.round((publisher.score / unPinnedTotal) * (100 - pinnedTotal))
const floatNumber = (publisher.score / unPinnedTotal) * (100 - pinnedTotal)
publisher.percentage = Math.round(floatNumber)
publisher.weight = floatNumber
return publisher
})

// normalize unpinned values
dataUnPinned = roundToTarget(dataUnPinned, (100 - pinnedTotal), 'percentage')
}

return dataPinned.concat(dataUnPinned, dataExcluded)
const newData = dataPinned.concat(dataUnPinned, dataExcluded)

// sync synopsis
newData.forEach((item) => {
synopsis.publishers[item.site].weight = item.weight
synopsis.publishers[item.site].pinPercentage = item.pinPercentage
})

return newData
}

/*
Expand Down
3 changes: 2 additions & 1 deletion docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,8 @@ WindowStore
secondsSpent: number, // e.g., 4
site: string, // publisher name, e.g., "wikipedia.org"
verified: boolean, // there is a verified wallet for this publisher
views: number // total page-views
views: number, // total page-views,
weight: number // float indication of the ration
}], // one entry for each publisher having a non-zero `score`
synopsisOptions: {
minDuration: number, // e.g., 8000 for 8 seconds
Expand Down

0 comments on commit 4239016

Please sign in to comment.