From e424df11397e28910bd92a3ffd754b086e4e1a67 Mon Sep 17 00:00:00 2001 From: 0xdevant <0xdevant@gmail.com> Date: Mon, 22 Jul 2024 14:37:20 +0800 Subject: [PATCH 1/3] feat: enable scoring model on Project by certain data points --- components/Project/ProjectHeading.vue | 79 +++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/components/Project/ProjectHeading.vue b/components/Project/ProjectHeading.vue index 1098ea8..1e438d0 100644 --- a/components/Project/ProjectHeading.vue +++ b/components/Project/ProjectHeading.vue @@ -13,16 +13,76 @@ const availableSupport = computed(() => { return 0 }) + +/** + * From data points + - product readiness + - docs (yes/no) + - github (yes/no) + - team: anon / public + - audit: yes / no + */ +const calculateScore = computed(() => { + const criterias: { value: string, key?: string }[] = [ + { value: 'product_readiness' }, + { value: "github", key: 'links' }, + { value: "docs", key: 'links' }, + { value: 'team' }, + { value: 'audits' } + ]; + + let matched = 0; + for (let i = 0; i < criterias.length; i++) { + let value; + if (criterias[i].key) { + if(props.project[criterias[i].key] === null || props.project[criterias[i].key] === undefined) continue; + value = props.project[criterias[i].key][criterias[i].value]; + // console.log(props.project[criterias[i].key] == null); + } else { + value = props.project[criterias[i].value]; + } + // console.log(value); + + if (fulfilled(value)) { + matched++; + // console.log('matched', matched); + } + } + + return 100 / criterias.length * matched; +}) + +function fulfilled(value: any): boolean { + const type = typeof value; + switch (type) { + case 'string': + if (value !== '') return true; + break; + case 'array': + if (value.length > 0) return true; + break; + case 'object': + if (Object.keys(value).length > 0) return true; + break; + + default: + return false; + break; + } +} + const logo = props.project?.logos?.at(0)?.url {{ project.links?.github ? 'YES' : 'NO' }} - + @@ -79,7 +137,8 @@ const logo = props.project?.logos?.at(0)?.url
- + {{ project.blockchain_features?.network }} From 950b4164a06599d47f12df92299cfb3bed87fb5a Mon Sep 17 00:00:00 2001 From: 0xdevant <0xdevant@gmail.com> Date: Mon, 22 Jul 2024 15:36:53 +0800 Subject: [PATCH 2/3] fix: account for null values --- components/Project/ProjectHeading.vue | 86 +++++++++++++++------------ 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/components/Project/ProjectHeading.vue b/components/Project/ProjectHeading.vue index 1e438d0..537fd74 100644 --- a/components/Project/ProjectHeading.vue +++ b/components/Project/ProjectHeading.vue @@ -13,7 +13,6 @@ const availableSupport = computed(() => { return 0 }) - /** * From data points - product readiness @@ -22,52 +21,53 @@ const availableSupport = computed(() => { - team: anon / public - audit: yes / no */ -const calculateScore = computed(() => { - const criterias: { value: string, key?: string }[] = [ +const calculateScore: number = computed(() => { + const criterias: { value: string; key?: string }[] = [ { value: 'product_readiness' }, - { value: "github", key: 'links' }, - { value: "docs", key: 'links' }, + { value: 'github', key: 'links' }, + { value: 'docs', key: 'links' }, { value: 'team' }, - { value: 'audits' } - ]; + { value: 'audits' }, + ] - let matched = 0; + let matched = 0 for (let i = 0; i < criterias.length; i++) { - let value; + let value if (criterias[i].key) { - if(props.project[criterias[i].key] === null || props.project[criterias[i].key] === undefined) continue; - value = props.project[criterias[i].key][criterias[i].value]; - // console.log(props.project[criterias[i].key] == null); - } else { - value = props.project[criterias[i].value]; + if (props.project[criterias[i].key] === null || props.project[criterias[i].key] === undefined) + continue + value = props.project[criterias[i].key][criterias[i].value] + } + else { + if (props.project[criterias[i].value] === null || props.project[criterias[i].value] === undefined) + continue + value = props.project[criterias[i].value] } // console.log(value); + // console.log(Object.keys(props.project["team"]).length); - if (fulfilled(value)) { - matched++; + if (fulfilled(value)) + matched++ // console.log('matched', matched); - } } - return 100 / criterias.length * matched; + return 100 / criterias.length * matched }) function fulfilled(value: any): boolean { - const type = typeof value; + const type = typeof value switch (type) { case 'string': - if (value !== '') return true; - break; - case 'array': - if (value.length > 0) return true; - break; + if (value !== '') + return true + break case 'object': - if (Object.keys(value).length > 0) return true; - break; + if (Object.keys(value).length > 0) + return true + break default: - return false; - break; + return false } } @@ -76,13 +76,17 @@ const logo = props.project?.logos?.at(0)?.url {{ project.links?.github ? 'YES' : 'NO' }} - + @@ -137,8 +145,10 @@ const logo = props.project?.logos?.at(0)?.url
- + {{ project.blockchain_features?.network }} From abc5e3cd4d85b8054f283dae3f0391b655c43aaa Mon Sep 17 00:00:00 2001 From: 0xdevant <0xdevant@gmail.com> Date: Mon, 22 Jul 2024 18:17:18 +0800 Subject: [PATCH 3/3] fix: optional return for null cases --- components/Project/ProjectHeading.vue | 39 +++++++++++++-------------- types/project.ts | 4 +++ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/components/Project/ProjectHeading.vue b/components/Project/ProjectHeading.vue index 537fd74..fd8cd3b 100644 --- a/components/Project/ProjectHeading.vue +++ b/components/Project/ProjectHeading.vue @@ -1,5 +1,5 @@