chore: code formatting
This commit is contained in:
@@ -27,15 +27,15 @@ export default async function({login, q, imports, data, account}, {enabled = fal
|
||||
|
||||
//Load page
|
||||
if (!url)
|
||||
throw {error:{message:"Skyline URL is not set"}}
|
||||
throw {error: {message: "Skyline URL is not set"}}
|
||||
console.debug(`metrics/compute/${login}/plugins > skyline > loading ${url.replaceAll("${login}", login).replaceAll("${year}", year)}`)
|
||||
await page.goto(url.replaceAll("${login}", login).replaceAll("${year}", year), {timeout: 90 * 1000})
|
||||
console.debug(`metrics/compute/${login}/plugins > skyline > waiting for initial render`)
|
||||
const frame = page.mainFrame()
|
||||
if (ready)
|
||||
await page.waitForFunction(ready.replaceAll("${login}", login).replaceAll("${year}", year), {timeout: 90 * 1000})
|
||||
if ((wait)&&(wait > 0))
|
||||
await new Promise(solve => setTimeout(solve, wait*1000))
|
||||
if ((wait) && (wait > 0))
|
||||
await new Promise(solve => setTimeout(solve, wait * 1000))
|
||||
if (hide)
|
||||
await frame.evaluate(hide => [...document.querySelectorAll(hide)].map(element => element.style.display = "none"), hide)
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//Setup
|
||||
export default async function({login, graphql, data, imports, q, queries, account}, {enabled = false, extras = false, "worldmap.token":_worldmap_token} = {}) {
|
||||
export default async function({login, graphql, data, imports, q, queries, account}, {enabled = false, extras = false, "worldmap.token": _worldmap_token} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
@@ -7,7 +7,7 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {"charts.type": _charts, worldmap:_worldmap, "worldmap.sample":_worldmap_sample} = imports.metadata.plugins.stargazers.inputs({data, account, q})
|
||||
let {"charts.type": _charts, worldmap: _worldmap, "worldmap.sample": _worldmap_sample} = imports.metadata.plugins.stargazers.inputs({data, account, q})
|
||||
|
||||
//Retrieve stargazers from graphql api
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > querying api`)
|
||||
@@ -98,9 +98,9 @@ export default async function({login, graphql, data, imports, q, queries, accoun
|
||||
|
||||
//Generating worldmap
|
||||
let worldmap = null
|
||||
if ((_worldmap)&&(imports.metadata.plugins.stargazers.extras("worldmap", {extras}))) {
|
||||
const {default:generate} = await import("./worldmap/index.mjs")
|
||||
worldmap = await generate(login, {locations, imports, token:_worldmap_token, sample:_worldmap_sample})
|
||||
if ((_worldmap) && (imports.metadata.plugins.stargazers.extras("worldmap", {extras}))) {
|
||||
const {default: generate} = await import("./worldmap/index.mjs")
|
||||
worldmap = await generate(login, {locations, imports, token: _worldmap_token, sample: _worldmap_sample})
|
||||
}
|
||||
|
||||
//Results
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//Imports
|
||||
import { Client as Gmap } from "@googlemaps/google-maps-services-js"
|
||||
import color from "color"
|
||||
import * as d3 from "d3"
|
||||
import D3Node from "d3-node"
|
||||
import color from "color"
|
||||
import {Client as Gmap} from "@googlemaps/google-maps-services-js"
|
||||
|
||||
/**
|
||||
* Worldmap
|
||||
* Mostly ported from https://github.com/dyatko/worldstar
|
||||
* License: https://raw.githubusercontent.com/dyatko/worldstar/master/LICENSE
|
||||
*/
|
||||
export default async function (login, {locations, sample, imports, token}) {
|
||||
export default async function(login, {locations, sample, imports, token}) {
|
||||
//Parse geocodes
|
||||
let stars = new Map()
|
||||
if (token) {
|
||||
@@ -20,7 +20,7 @@ export default async function (login, {locations, sample, imports, token}) {
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > worldmap > looking for ${location}`)
|
||||
if (!cache.has(location)) {
|
||||
try {
|
||||
const {data:{results}} = await get.geocode({params:{address:location, key:token}})
|
||||
const {data: {results}} = await get.geocode({params: {address: location, key: token}})
|
||||
const country = results.at(0).address_components.find(({types}) => types.includes("country"))
|
||||
cache.set(location, country.short_name ?? country.long_name)
|
||||
console.debug(`metrics/compute/${login}/plugins > stargazers > worldmap > ${location} resolved to ${cache.get(location)}`)
|
||||
@@ -33,7 +33,9 @@ export default async function (login, {locations, sample, imports, token}) {
|
||||
stars.set(code, (stars.get(code) ?? 0) + 1)
|
||||
}
|
||||
}
|
||||
else throw {error:{message:"Google Maps API token is not set"}}
|
||||
else {
|
||||
throw {error: {message: "Google Maps API token is not set"}}
|
||||
}
|
||||
|
||||
//Generate SVG
|
||||
const d3n = new D3Node()
|
||||
@@ -47,10 +49,10 @@ export default async function (login, {locations, sample, imports, token}) {
|
||||
.data(countries.features)
|
||||
.join("path")
|
||||
.attr("id", ({id}) => id)
|
||||
.style("fill", ({properties:{iso_a2, wb_a2, sov_a3}}) => {
|
||||
.style("fill", ({properties: {iso_a2, wb_a2, sov_a3}}) => {
|
||||
const code = iso_a2?.match(/[A-Z]{2}/) ? iso_a2 : wb_a2?.match(/[A-Z]{2}/) ? wb_a2 : sov_a3?.substr(0, 2) ?? ""
|
||||
const value = stars.get(code)
|
||||
return color("#216e39").mix(color("#ffffff"), 1 - Math.max(0, splits.indexOf(value))/splits.length).hex()
|
||||
return color("#216e39").mix(color("#ffffff"), 1 - Math.max(0, splits.indexOf(value)) / splits.length).hex()
|
||||
})
|
||||
.style("stroke", "#afafaf")
|
||||
.style("stroke-width", "0.6px")
|
||||
|
||||
@@ -15,9 +15,9 @@ export default function({faker, query, login = faker.internet.userName()}) {
|
||||
edges: new Array(faker.datatype.number({min: 50, max: 100})).fill(null).map(() => ({
|
||||
starredAt: `${faker.date.recent(30)}`,
|
||||
cursor: "MOCKED_CURSOR",
|
||||
node:{
|
||||
node: {
|
||||
location: faker.address.city(),
|
||||
}
|
||||
},
|
||||
})),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//Imports
|
||||
import { faker } from "@faker-js/faker"
|
||||
import { Client as Gmap } from "@googlemaps/google-maps-services-js"
|
||||
import axios from "axios"
|
||||
import fs from "fs/promises"
|
||||
import paths from "path"
|
||||
import rss from "rss-parser"
|
||||
import urls from "url"
|
||||
import {Client as Gmap} from "@googlemaps/google-maps-services-js"
|
||||
|
||||
//Mocked state
|
||||
let mocked = false
|
||||
@@ -160,39 +160,39 @@ export default async function({graphql, rest}) {
|
||||
const city = faker.address.city()
|
||||
const country = faker.address.country()
|
||||
return {
|
||||
data:{
|
||||
results:[
|
||||
data: {
|
||||
results: [
|
||||
{
|
||||
address_components: [
|
||||
{
|
||||
long_name: city,
|
||||
short_name: city,
|
||||
types: [ "political" ]
|
||||
types: ["political"],
|
||||
},
|
||||
{
|
||||
long_name: country,
|
||||
short_name: faker.address.countryCode(),
|
||||
types: [ "country", "political" ]
|
||||
}
|
||||
types: ["country", "political"],
|
||||
},
|
||||
],
|
||||
formatted_address: `${city}, ${country}`,
|
||||
geometry: {
|
||||
bounds: {
|
||||
northeast: { lat, lng },
|
||||
southwest: { lat, lng }
|
||||
northeast: {lat, lng},
|
||||
southwest: {lat, lng},
|
||||
},
|
||||
location: { lat, lng },
|
||||
location: {lat, lng},
|
||||
location_type: "APPROXIMATE",
|
||||
viewport: {
|
||||
northeast: { lat, lng },
|
||||
southwest: { lat, lng }
|
||||
}
|
||||
northeast: {lat, lng},
|
||||
southwest: {lat, lng},
|
||||
},
|
||||
},
|
||||
place_id: "ChIJu9FC7RXupzsR26dsAapFLgg",
|
||||
types: ["locality", "political"],
|
||||
},
|
||||
],
|
||||
},
|
||||
place_id: 'ChIJu9FC7RXupzsR26dsAapFLgg',
|
||||
types: [ "locality", "political" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user