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-]+$'
name:
type: string
icon:
type: string

View file

@ -25,10 +25,10 @@ properties:
type: string
pattern: '^[A-Z0-9-]+$'
ecosystem:
anyOf: [{type: array}, {type: string}]
type: array
items:
type: string
pattern: '^[A-Z0-9-]+$'
pattern: '^[a-z0-9-]+$'
project_type:
type: string
description:
@ -100,6 +100,8 @@ properties:
time:
type: string
history:
type: array
items:
type: object
properties:
title:
@ -314,3 +316,8 @@ properties:
type: boolean
mainnet:
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
name: Ethereum
icon: https://assets.coingecko.com/coins/images/279/standard/ethereum.png?1696501628
- id: bitcoin
name: Bitcoin
icon: https://assets.coingecko.com/coins/images/1/standard/bitcoin.png?1696501400
- id: solana
name: Solana
icon: https://assets.coingecko.com/coins/images/4128/standard/solana.png?1718769756
- id: cosmos
name: Cosmos
icon: https://assets.coingecko.com/coins/images/1481/standard/cosmos_hub.png?1696502525
- id: monero
name: Monero
icon: https://assets.coingecko.com/coins/images/69/standard/monero_logo.png?1696501460
- id: 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 { betterAjvErrors } from 'https://esm.sh/@apideck/better-ajv-errors@0.3.6?pin=v58';
import yaml from "npm:js-yaml";
import { W3PData } from "./w3pdata.js";
@ -7,7 +8,7 @@ import { W3PData } from "./w3pdata.js";
const w3pd = new W3PData();
await w3pd.init();
const ajv = new Ajv({ strict: false });
const ajv = new Ajv({ strict: false, allErrors: true });
addFormats(ajv);
async function loadSchemas() {
@ -19,17 +20,44 @@ async function loadSchemas() {
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 = {
categories: "category",
projects: "project",
assets: "asset",
ecosystems: "ecosystem",
features: "feature",
usecases: "usecase",
ranks: "rank",
};
const schemaDir = "./schema";
const schemas = await loadSchemas();
schemas.project.properties.categories.items.enum = w3pd.data.categories.map(
(c) => c.id
);
schemas.rank.properties.references.items.properties.field.enum = getDeepPropertiesKeys(schemas.project);
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)) {
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) {
Deno.test(testName + " (schema)", () => {
if (!validator(item)) {
// throw validator.errors;
// log instead of throwing to proceed building all projects
console.log(validator.errors);
const betterErrors = betterAjvErrors({ errors: validator.errors });
// throw betterErrors;
console.log(betterErrors);
}
});
}