chore: code formatting

This commit is contained in:
github-actions[bot]
2022-07-21 04:37:55 +00:00
parent 48f4ef79ed
commit aa83b84522
5 changed files with 36 additions and 34 deletions

View File

@@ -27,15 +27,15 @@ export default async function({login, q, imports, data, account}, {enabled = fal
//Load page //Load page
if (!url) 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)}`) 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}) await page.goto(url.replaceAll("${login}", login).replaceAll("${year}", year), {timeout: 90 * 1000})
console.debug(`metrics/compute/${login}/plugins > skyline > waiting for initial render`) console.debug(`metrics/compute/${login}/plugins > skyline > waiting for initial render`)
const frame = page.mainFrame() const frame = page.mainFrame()
if (ready) if (ready)
await page.waitForFunction(ready.replaceAll("${login}", login).replaceAll("${year}", year), {timeout: 90 * 1000}) await page.waitForFunction(ready.replaceAll("${login}", login).replaceAll("${year}", year), {timeout: 90 * 1000})
if ((wait)&&(wait > 0)) if ((wait) && (wait > 0))
await new Promise(solve => setTimeout(solve, wait*1000)) await new Promise(solve => setTimeout(solve, wait * 1000))
if (hide) if (hide)
await frame.evaluate(hide => [...document.querySelectorAll(hide)].map(element => element.style.display = "none"), hide) await frame.evaluate(hide => [...document.querySelectorAll(hide)].map(element => element.style.display = "none"), hide)

View File

@@ -1,5 +1,5 @@
//Setup //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 //Plugin execution
try { try {
//Check if plugin is enabled and requirements are met //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 return null
//Load inputs //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 //Retrieve stargazers from graphql api
console.debug(`metrics/compute/${login}/plugins > stargazers > querying 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 //Generating worldmap
let worldmap = null let worldmap = null
if ((_worldmap)&&(imports.metadata.plugins.stargazers.extras("worldmap", {extras}))) { if ((_worldmap) && (imports.metadata.plugins.stargazers.extras("worldmap", {extras}))) {
const {default:generate} = await import("./worldmap/index.mjs") const {default: generate} = await import("./worldmap/index.mjs")
worldmap = await generate(login, {locations, imports, token:_worldmap_token, sample:_worldmap_sample}) worldmap = await generate(login, {locations, imports, token: _worldmap_token, sample: _worldmap_sample})
} }
//Results //Results

View File

@@ -1,15 +1,15 @@
//Imports //Imports
import { Client as Gmap } from "@googlemaps/google-maps-services-js"
import color from "color"
import * as d3 from "d3" import * as d3 from "d3"
import D3Node from "d3-node" import D3Node from "d3-node"
import color from "color"
import {Client as Gmap} from "@googlemaps/google-maps-services-js"
/** /**
* Worldmap * Worldmap
* Mostly ported from https://github.com/dyatko/worldstar * Mostly ported from https://github.com/dyatko/worldstar
* License: https://raw.githubusercontent.com/dyatko/worldstar/master/LICENSE * 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 //Parse geocodes
let stars = new Map() let stars = new Map()
if (token) { 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}`) console.debug(`metrics/compute/${login}/plugins > stargazers > worldmap > looking for ${location}`)
if (!cache.has(location)) { if (!cache.has(location)) {
try { 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")) const country = results.at(0).address_components.find(({types}) => types.includes("country"))
cache.set(location, country.short_name ?? country.long_name) cache.set(location, country.short_name ?? country.long_name)
console.debug(`metrics/compute/${login}/plugins > stargazers > worldmap > ${location} resolved to ${cache.get(location)}`) 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) 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 //Generate SVG
const d3n = new D3Node() const d3n = new D3Node()
@@ -47,10 +49,10 @@ export default async function (login, {locations, sample, imports, token}) {
.data(countries.features) .data(countries.features)
.join("path") .join("path")
.attr("id", ({id}) => id) .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 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) 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", "#afafaf")
.style("stroke-width", "0.6px") .style("stroke-width", "0.6px")

View File

@@ -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(() => ({ edges: new Array(faker.datatype.number({min: 50, max: 100})).fill(null).map(() => ({
starredAt: `${faker.date.recent(30)}`, starredAt: `${faker.date.recent(30)}`,
cursor: "MOCKED_CURSOR", cursor: "MOCKED_CURSOR",
node:{ node: {
location: faker.address.city(), location: faker.address.city(),
} },
})), })),
}, },
}, },

View File

@@ -1,11 +1,11 @@
//Imports //Imports
import { faker } from "@faker-js/faker" import { faker } from "@faker-js/faker"
import { Client as Gmap } from "@googlemaps/google-maps-services-js"
import axios from "axios" import axios from "axios"
import fs from "fs/promises" import fs from "fs/promises"
import paths from "path" import paths from "path"
import rss from "rss-parser" import rss from "rss-parser"
import urls from "url" import urls from "url"
import {Client as Gmap} from "@googlemaps/google-maps-services-js"
//Mocked state //Mocked state
let mocked = false let mocked = false
@@ -160,39 +160,39 @@ export default async function({graphql, rest}) {
const city = faker.address.city() const city = faker.address.city()
const country = faker.address.country() const country = faker.address.country()
return { return {
data:{ data: {
results:[ results: [
{ {
address_components: [ address_components: [
{ {
long_name: city, long_name: city,
short_name: city, short_name: city,
types: [ "political" ] types: ["political"],
}, },
{ {
long_name: country, long_name: country,
short_name: faker.address.countryCode(), short_name: faker.address.countryCode(),
types: [ "country", "political" ] types: ["country", "political"],
} },
], ],
formatted_address: `${city}, ${country}`, formatted_address: `${city}, ${country}`,
geometry: { geometry: {
bounds: { bounds: {
northeast: { lat, lng }, northeast: {lat, lng},
southwest: { lat, lng } southwest: {lat, lng},
}, },
location: { lat, lng }, location: {lat, lng},
location_type: "APPROXIMATE", location_type: "APPROXIMATE",
viewport: { viewport: {
northeast: { lat, lng }, northeast: {lat, lng},
southwest: { lat, lng } southwest: {lat, lng},
} },
},
place_id: "ChIJu9FC7RXupzsR26dsAapFLgg",
types: ["locality", "political"],
},
],
}, },
place_id: 'ChIJu9FC7RXupzsR26dsAapFLgg',
types: [ "locality", "political" ]
}
]
}
} }
} }
} }