Merge pull request #774 from web3privacy/pk/ranks

feat(data): add ranks with conditions
This commit is contained in:
Klein Petr 2024-09-17 10:53:25 +02:00 committed by GitHub
commit b7883e664e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 279 additions and 24 deletions

View file

@ -9,3 +9,5 @@ properties:
pattern: '^[a-z0-9-]+$' pattern: '^[a-z0-9-]+$'
name: name:
type: string type: string
icon:
type: string

View file

@ -25,10 +25,10 @@ properties:
type: string type: string
pattern: '^[A-Z0-9-]+$' pattern: '^[A-Z0-9-]+$'
ecosystem: ecosystem:
anyOf: [{type: array}, {type: string}] type: array
items: items:
type: string type: string
pattern: '^[A-Z0-9-]+$' pattern: '^[a-z0-9-]+$'
project_type: project_type:
type: string type: string
description: description:
@ -100,6 +100,8 @@ properties:
time: time:
type: string type: string
history: history:
type: array
items:
type: object type: object
properties: properties:
title: title:
@ -314,3 +316,8 @@ properties:
type: boolean type: boolean
mainnet: mainnet:
type: boolean type: boolean
usecases:
type: array
items:
type: string
pattern: '^[a-z0-9-]+$'

48
schema/rank.yaml Normal file
View file

@ -0,0 +1,48 @@
type: object
properties:
id:
type: string
name:
type: string
references:
type: array
items:
type: object
properties:
field:
type: string
label:
type: object
properties:
name:
type: string
positive:
type: string
negative:
type: string
condition:
type: object
properties:
exists:
type: boolean
minLength:
type: integer
regex:
type: string
equals:
oneOf:
- type: boolean
- type: string
- type: integer
points:
type: integer
required:
- field
- label
- condition
- points
required:
- id
- name
- references
additionalProperties: false

View file

@ -1,12 +1,17 @@
- id: ethereum - id: ethereum
name: Ethereum name: Ethereum
icon: https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628
- id: bitcoin - id: bitcoin
name: Bitcoin name: Bitcoin
icon: https://assets.coingecko.com/coins/images/1/standard/bitcoin.png?1696501400
- id: solana - id: solana
name: Solana name: Solana
icon: https://assets.coingecko.com/coins/images/4128/standard/solana.png?1718769756
- id: cosmos - id: cosmos
name: Cosmos name: Cosmos
icon: https://assets.coingecko.com/coins/images/1481/standard/cosmos_hub.png?1696502525
- id: monero - id: monero
name: Monero name: Monero
icon: https://assets.coingecko.com/coins/images/69/standard/monero_logo.png?1696501460
- id: other - id: other
name: Other name: Other

165
src/ranks.yaml Normal file
View file

@ -0,0 +1,165 @@
- id: openess
name: Openess
references:
- field: team.teammembers
label:
name: Team
positive: Member
negative: Anonymous
condition:
minLength: 1
points: 10
- field: links.docs
label:
name: Documentation
positive: Link
negative: Not available
condition:
exists: true
points: 10
- field: links.github
label:
name: Github
positive: Link
negative: Not available
condition:
exists: true
points: 10
- field: links.twitter
label:
name: Twitter
positive: Link
negative: Not available
condition:
exists: true
points: 1
- field: links.telegram
label:
name: Twitter
positive: Link
negative: Not available
condition:
exists: true
points: 1
- field: links.discord
label:
name: Discord
positive: Link
negative: Not available
condition:
exists: true
points: 1
- field: links.lens
label:
name: Lens
positive: Link
negative: Not available
condition:
exists: true
points: 1
- field: links.farcaster
label:
name: Farcaster
positive: Link
negative: Not available
condition:
exists: true
points: 1
- field: links.whitepaper
label:
name: Whitepaper
positive: Link
negative: Not available
condition:
exists: true
points: 10
- field: funding.value
label:
name: Funding
positive: Investment
negative: Not available
condition:
exists: true
points: 10
- id: technology
name: Technology
references:
- field: project_status.mainnet
label:
name: Mainnet
positive: Yes
negative: No
condition:
exists: true
points: 10
- field: blockchain_features.opensource
label:
name: Open Source
positive: Yes
negative: No
condition:
equals: true
points: 20
- field: blockchain_features.asset_custody_type
label:
name: Non Custody
positive: None
negative: Custodial
condition:
equals: non-custody
points: 10
- field: blockchain_features.upgradability.enabled
label:
name: Upgradability
positive: Disabled
negative: Enabled
condition:
equals: false
points: 10
- field: audits
label:
name: Audits
positive: Audit
negative: None
condition:
minLength: 1
points: 10
- id: privacy
name: Privacy
references:
- field: privacy_policy.link
label:
name: Privacy Policy
positive: Link
negative: Not available
condition:
exists: true
points: 10
- field: traceability.kyc
label:
name: KYC
positive: No
negative: Yes
condition:
equals: false
points: 10
- field: compliance
label:
name: Compliance
positive: No
negative: OFAC
condition:
equals: true
points: 5
- field: default_privacy
label:
name: Default Privacy
positive: YES
negative: No
condition:
equals: true
points: 10

View file

@ -1,5 +1,6 @@
import Ajv from "https://esm.sh/ajv@8.8.1?pin=v58"; import Ajv from "https://esm.sh/ajv@8.17.1?pin=v58";
import addFormats from "https://esm.sh/ajv-formats@2.1.1"; import addFormats from "https://esm.sh/ajv-formats@2.1.1";
import { betterAjvErrors } from 'https://esm.sh/@apideck/better-ajv-errors@0.3.6?pin=v58';
import yaml from "npm:js-yaml"; import yaml from "npm:js-yaml";
import { W3PData } from "./w3pdata.js"; import { W3PData } from "./w3pdata.js";
@ -7,7 +8,7 @@ import { W3PData } from "./w3pdata.js";
const w3pd = new W3PData(); const w3pd = new W3PData();
await w3pd.init(); await w3pd.init();
const ajv = new Ajv({ strict: false }); const ajv = new Ajv({ strict: false, allErrors: true });
addFormats(ajv); addFormats(ajv);
async function loadSchemas() { async function loadSchemas() {
@ -19,17 +20,44 @@ async function loadSchemas() {
return out; return out;
} }
function getDeepPropertiesKeys(obj, parentKey = '') {
let keys = [];
if (obj.hasOwnProperty('properties')) {
const properties = obj['properties'];
for (const key in properties) {
if (properties.hasOwnProperty(key)) {
const newKey = parentKey ? `${parentKey}.${key}` : key;
if (properties[key].hasOwnProperty('properties')) {
keys = keys.concat(getDeepPropertiesKeys(properties[key], newKey));
} else {
keys.push(newKey);
}
}
}
}
return keys;
}
const matrix = { const matrix = {
categories: "category", categories: "category",
projects: "project", projects: "project",
assets: "asset",
ecosystems: "ecosystem",
features: "feature",
usecases: "usecase",
ranks: "rank",
}; };
const schemaDir = "./schema"; const schemaDir = "./schema";
const schemas = await loadSchemas(); const schemas = await loadSchemas();
schemas.project.properties.categories.items.enum = w3pd.data.categories.map( schemas.rank.properties.references.items.properties.field.enum = getDeepPropertiesKeys(schemas.project);
(c) => c.id schemas.project.properties.categories.items.enum = w3pd.data.categories.map((c) => c.id);
); schemas.project.properties.usecases.items.enum = w3pd.data.usecases.map((c) => c.id);
for (const col of Object.keys(w3pd.data)) { for (const col of Object.keys(w3pd.data)) {
const validator = ajv.compile(schemas[matrix[col]]); const validator = ajv.compile(schemas[matrix[col]]);
@ -56,9 +84,9 @@ for (const col of Object.keys(w3pd.data)) {
if (Object.keys(item).length > 1) { if (Object.keys(item).length > 1) {
Deno.test(testName + " (schema)", () => { Deno.test(testName + " (schema)", () => {
if (!validator(item)) { if (!validator(item)) {
// throw validator.errors; const betterErrors = betterAjvErrors({ errors: validator.errors });
// log instead of throwing to proceed building all projects // throw betterErrors;
console.log(validator.errors); console.log(betterErrors);
} }
}); });
} }