-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_statistics.mjs
More file actions
78 lines (65 loc) · 3.34 KB
/
Copy pathfetch_statistics.mjs
File metadata and controls
78 lines (65 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { SolidJobsClient } from './client.mjs';
const client = new SolidJobsClient();
const campaign = 'js-stats';
// ─────────────────────────────────────────────────────────────────────────────
// Printing helpers — walk every field the endpoint can return.
// ─────────────────────────────────────────────────────────────────────────────
function printBand(band) {
if (!band) return console.log(' (no offers with a declared salary)');
console.log(` min=${band.min} p25=${band.p25} median=${band.median} p75=${band.p75} max=${band.max}`);
}
function printContractSalary(label, stat) {
if (!stat) return console.log(` ${label}: (no precomputed data)`);
console.log(` ${label}: median=${stat.median} average=${stat.average} offers=${stat.offerCount}`);
}
function printBuckets(buckets) {
for (const b of buckets ?? []) {
console.log(` ${b.label.padEnd(24)} ${String(b.offerCount).padStart(5)} offers (${b.percentage}%)`);
}
}
function printStatistics(stats) {
console.log(`Scope: ${stats.scopeKind} / ${stats.scopeKey}`);
console.log(`Generated at: ${stats.generatedAt}`);
console.log(`Included sections: ${stats.includedSections.join(', ')}`);
if (stats.demand) {
const d = stats.demand;
console.log('\n[demand]');
console.log(` activeOffers=${d.activeOffers} distinctEmployers=${d.distinctEmployers}` +
` remoteOffers=${d.remoteOffers} remotePercentage=${d.remotePercentage}%`);
console.log(' offerTrend (quarterly):');
for (const point of d.offerTrend) {
console.log(` ${point.period}: ${point.offerCount} offers`);
}
}
if (stats.salary) {
const s = stats.salary;
console.log(`\n[salary] currency=${s.currency}`);
console.log(' overall (live percentiles):');
printBand(s.overall);
printContractSalary('b2b ', s.b2b);
printContractSalary('permanent ', s.permanent);
}
if (stats.experience) {
console.log('\n[experience]');
printBuckets(stats.experience);
}
if (stats.topLocations) {
console.log('\n[topLocations]');
printBuckets(stats.topLocations);
}
if (stats.topSkills) {
console.log('\n[topSkills]');
printBuckets(stats.topSkills);
}
}
// 1) Full snapshot — every section available for the React specialization
const full = await client.getMarketStatistics('subcategory', 'React', campaign);
printStatistics(full);
// 2) Partial fetch — ask only for `demand` and `salary` using the `fields` filter.
// `includedSections` in the response confirms exactly what came back.
console.log('\n───────────────────────────────────────────────');
console.log('Partial fetch with fields=demand,salary:');
const partial = await client.getMarketStatistics('subcategory', 'React', campaign, {
fields: ['demand', 'salary'],
});
console.log(`Included sections: ${partial.includedSections.join(', ')}`);