forked from MapComplete/MapComplete
Add a contributor counting actor
This commit is contained in:
parent
2a9faad288
commit
f6cbb44454
1 changed files with 21 additions and 0 deletions
21
Logic/ContributorCount.ts
Normal file
21
Logic/ContributorCount.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
/// Given a feature source, calculates a list of OSM-contributors who mapped the latest versions
|
||||
import FeatureSource from "./FeatureSource/FeatureSource";
|
||||
import {UIEventSource} from "./UIEventSource";
|
||||
|
||||
export default class ContributorCount {
|
||||
|
||||
public readonly Contributors: UIEventSource<Map<string, number>>;
|
||||
|
||||
constructor(featureSource: FeatureSource) {
|
||||
this.Contributors = featureSource.features.map(features => {
|
||||
const hist = new Map<string, number>();
|
||||
for (const feature of features) {
|
||||
const contributor = feature.feature.properties["_last_edit:contributor"]
|
||||
const count = hist.get(contributor) ?? 0;
|
||||
hist.set(contributor, count + 1)
|
||||
}
|
||||
return hist;
|
||||
})
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue