Tweak feed display
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "module",
|
||||||
"main": "dist/dvm/src/index.js",
|
"main": "dist/dvm/src/index.js",
|
||||||
"types": "dist/dvm/src/index.d.ts",
|
"types": "dist/dvm/src/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
"type": "module",
|
||||||
"main": "dist/feeds/src/index.js",
|
"main": "dist/feeds/src/index.js",
|
||||||
"types": "dist/feeds/src/index.d.ts",
|
"types": "dist/feeds/src/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export const displayAddressFeed = (feed: AddressFeed) => {
|
|||||||
export const displayAuthorFeed = (feed: AuthorFeed) => {
|
export const displayAuthorFeed = (feed: AuthorFeed) => {
|
||||||
const n = getFeedArgs(feed).length
|
const n = getFeedArgs(feed).length
|
||||||
|
|
||||||
return `events from ${n} replaceable {n === 1 ? 'person' : 'people'}`
|
return `from ${n} replaceable {n === 1 ? 'person' : 'people'}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayCreatedAtFeed = (feed: CreatedAtFeed) => {
|
export const displayCreatedAtFeed = (feed: CreatedAtFeed) => {
|
||||||
@@ -57,10 +57,10 @@ export const displayCreatedAtFeed = (feed: CreatedAtFeed) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (descriptions.length === 0) {
|
if (descriptions.length === 0) {
|
||||||
return "events from any time"
|
return "from any time"
|
||||||
}
|
}
|
||||||
|
|
||||||
return `events ${displayList(descriptions, "or")}`
|
return displayList(descriptions, "or")
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayDVMFeed = (feed: DVMFeed) => {
|
export const displayDVMFeed = (feed: DVMFeed) => {
|
||||||
@@ -83,29 +83,29 @@ export const displayDVMFeed = (feed: DVMFeed) => {
|
|||||||
descriptions.push(parts.join(" "))
|
descriptions.push(parts.join(" "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return `events from DVM requests of ${displayList(descriptions)}`
|
return `from DVM requests of ${displayList(descriptions)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayDifferenceFeed = (feed: DifferenceFeed) => {
|
export const displayDifferenceFeed = (feed: DifferenceFeed) => {
|
||||||
const [base, ...excluded] = getFeedArgs(feed)
|
const [base, ...excluded] = getFeedArgs(feed)
|
||||||
|
|
||||||
return `all ${displayFeed(base)}, excluding ${displayList(excluded.map(displayFeed))}`
|
return `${displayFeed(base)}, excluding ${displayList(excluded.map(displayFeed))}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayIDFeed = (feed: IDFeed) => `${getFeedArgs(feed).length} events`
|
export const displayIDFeed = (feed: IDFeed) => `matching ${getFeedArgs(feed).length} IDs`
|
||||||
|
|
||||||
export const displayIntersectionFeed = (feed: IntersectionFeed) =>
|
export const displayIntersectionFeed = (feed: IntersectionFeed) =>
|
||||||
`events matching ${displayList(getFeedArgs(feed).map(displayFeed))}`
|
displayList(getFeedArgs(feed).map(displayFeed))
|
||||||
|
|
||||||
export const displayGlobalFeed = (feed: GlobalFeed) => "anything"
|
export const displayGlobalFeed = (feed: GlobalFeed) => "anything"
|
||||||
|
|
||||||
export const displayKindFeed = (feed: KindFeed) =>
|
export const displayKindFeed = (feed: KindFeed) =>
|
||||||
`events of kind ${displayList(getFeedArgs(feed))}`
|
`of kind ${displayList(getFeedArgs(feed))}`
|
||||||
|
|
||||||
export const displayListFeed = (feed: ListFeed) => {
|
export const displayListFeed = (feed: ListFeed) => {
|
||||||
const addresses = uniq(getFeedArgs(feed).flatMap(({addresses}) => addresses))
|
const addresses = uniq(getFeedArgs(feed).flatMap(({addresses}) => addresses))
|
||||||
|
|
||||||
return `events from ${addresses.length} list${addresses.length === 1 ? "" : "s"}`
|
return `from ${addresses.length} list${addresses.length === 1 ? "" : "s"}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayLabelFeed = (feed: LabelFeed) => {
|
export const displayLabelFeed = (feed: LabelFeed) => {
|
||||||
@@ -134,7 +134,7 @@ export const displayLabelFeed = (feed: LabelFeed) => {
|
|||||||
descriptions.push(parts.join(" "))
|
descriptions.push(parts.join(" "))
|
||||||
}
|
}
|
||||||
|
|
||||||
return `events ${displayList(descriptions)}`
|
return displayList(descriptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayWOTFeed = (feed: WOTFeed) => {
|
export const displayWOTFeed = (feed: WOTFeed) => {
|
||||||
@@ -142,25 +142,25 @@ export const displayWOTFeed = (feed: WOTFeed) => {
|
|||||||
min === max ? `WOT score of ${min}` : `WOT score between ${min} and ${max}`,
|
min === max ? `WOT score of ${min}` : `WOT score between ${min} and ${max}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
return `Events from authors with ${displayList(descriptions)}`
|
return `from authors with ${displayList(descriptions)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayRelayFeed = (feed: RelayFeed) => `events from ${displayList(getFeedArgs(feed))}`
|
export const displayRelayFeed = (feed: RelayFeed) => `from ${displayList(getFeedArgs(feed))}`
|
||||||
|
|
||||||
export const displayScopeFeed = (feed: ScopeFeed) =>
|
export const displayScopeFeed = (feed: ScopeFeed) =>
|
||||||
`events from ${displayList(getFeedArgs(feed).map(s => s.toLowerCase()))}`
|
`from ${displayList(getFeedArgs(feed).map(s => s.toLowerCase()))}`
|
||||||
|
|
||||||
export const displaySearchFeed = (feed: SearchFeed) =>
|
export const displaySearchFeed = (feed: SearchFeed) =>
|
||||||
`events matching ${displayList(getFeedArgs(feed).map(term => `"${term}"`))}`
|
`matching ${displayList(getFeedArgs(feed).map(term => `"${term}"`))}`
|
||||||
|
|
||||||
export const displayTagFeed = (feed: TagFeed) => {
|
export const displayTagFeed = (feed: TagFeed) => {
|
||||||
const [key, ...values] = getFeedArgs(feed)
|
const [key, ...values] = getFeedArgs(feed)
|
||||||
|
|
||||||
return `events with ${key} tag matching ${displayList(values, "or")}`
|
return `with ${key} tag matching ${displayList(values, "or")}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const displayUnionFeed = (feed: UnionFeed) =>
|
export const displayUnionFeed = (feed: UnionFeed) =>
|
||||||
`all ${displayList(getFeedArgs(feed).map(displayFeed))}`
|
displayList(getFeedArgs(feed).map(displayFeed))
|
||||||
|
|
||||||
export const displayFeed = (feed: Feed): string => {
|
export const displayFeed = (feed: Feed): string => {
|
||||||
switch (feed[0]) {
|
switch (feed[0]) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {ensureNumber} from "@welshman/lib"
|
import {ensureNumber} from "@welshman/lib"
|
||||||
import type {Filter} from "@welshman/util"
|
import {Filter, unionFilters} from "@welshman/util"
|
||||||
import {getTagValues} from "@welshman/util"
|
import {getTagValues} from "@welshman/util"
|
||||||
import {
|
import {
|
||||||
FeedType,
|
FeedType,
|
||||||
@@ -195,7 +195,7 @@ export const feedsFromFilter = ({since, until, ...filter}: Filter) => {
|
|||||||
export const feedFromFilter = (filter: Filter) => makeIntersectionFeed(...feedsFromFilter(filter))
|
export const feedFromFilter = (filter: Filter) => makeIntersectionFeed(...feedsFromFilter(filter))
|
||||||
|
|
||||||
export const feedFromFilters = (filters: Filter[]) =>
|
export const feedFromFilters = (filters: Filter[]) =>
|
||||||
makeUnionFeed(...filters.map(filter => feedFromFilter(filter)))
|
makeUnionFeed(...unionFilters(filters).map(filter => feedFromFilter(filter)))
|
||||||
|
|
||||||
export const walkFeed = (feed: Feed, visit: (feed: Feed) => void) => {
|
export const walkFeed = (feed: Feed, visit: (feed: Feed) => void) => {
|
||||||
visit(feed)
|
visit(feed)
|
||||||
|
|||||||
@@ -628,6 +628,21 @@ export const groupBy = <T, K>(f: (x: T) => K, xs: T[]) => {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts array elements by key function
|
||||||
|
* @param f - Function to generate group key
|
||||||
|
* @param xs - Array to count entries
|
||||||
|
* @returns Map of counts
|
||||||
|
*/
|
||||||
|
export const countBy = <T, K>(f: (x: T) => K, xs: T[]) => {
|
||||||
|
const r = new Map<K, number>()
|
||||||
|
for (const [k, items] of groupBy(f, xs)) {
|
||||||
|
r.set(k, items.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates map from array using key function
|
* Creates map from array using key function
|
||||||
* @param f - Function to generate key
|
* @param f - Function to generate key
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export type Selection = {
|
|||||||
relays: string[]
|
relays: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeSelection = (relays: string[], weight = 1): Selection => ({
|
export const makeSelection = (relays: string[], weight = 1): Selection => ({
|
||||||
relays: relays.filter(isRelayUrl).map(normalizeRelayUrl),
|
relays: relays.filter(isRelayUrl).map(normalizeRelayUrl),
|
||||||
weight,
|
weight,
|
||||||
})
|
})
|
||||||
@@ -322,7 +322,7 @@ export class RouterScenario {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scoreRelay = (relay: string) => {
|
const scoreRelay = (relay: string) => {
|
||||||
const quality = this.router.options.getRelayQuality?.(relay)
|
const quality = this.router.options.getRelayQuality?.(relay) || 1
|
||||||
const weight = relayWeights.get(relay)!
|
const weight = relayWeights.get(relay)!
|
||||||
|
|
||||||
// Log the weight, since it's a straight count which ends up over-weighting hubs.
|
// Log the weight, since it's a straight count which ends up over-weighting hubs.
|
||||||
|
|||||||
Reference in New Issue
Block a user