diff --git a/api/ceramic_cache/test/test_weights.py b/api/ceramic_cache/test/test_weights.py index def94cae3..393fd3196 100644 --- a/api/ceramic_cache/test/test_weights.py +++ b/api/ceramic_cache/test/test_weights.py @@ -1,8 +1,10 @@ -from account.models import Community -from scorer_weighted.models import Scorer, BinaryWeightedScorer -from django.test import Client -from django.conf import settings import pytest +from django.conf import settings +from django.test import Client + +from account.models import Community +from registry.weight_models import WeightConfiguration, WeightConfigurationItem +from scorer_weighted.models import BinaryWeightedScorer, Scorer pytestmark = pytest.mark.django_db # noqa: F821 @@ -16,7 +18,20 @@ def test_get_weights( self, scorer_account, ): + config = WeightConfiguration.objects.create( + version="v1", + threshold=20.0, + active=True, + description="Test", + ) scorer_weights = {"provider-1": "0.5", "provider-2": "0.5"} + for provider, weight in scorer_weights.items(): + WeightConfigurationItem.objects.create( + weight_configuration=config, + provider=provider, + weight=float(weight), + ) + scorer = BinaryWeightedScorer.objects.create( type=Scorer.Type.WEIGHTED_BINARY, weights=scorer_weights ) diff --git a/api/passport_admin/tests/conftest.py b/api/passport_admin/tests/conftest.py index 4d0e0a771..2132e785b 100644 --- a/api/passport_admin/tests/conftest.py +++ b/api/passport_admin/tests/conftest.py @@ -1,9 +1,10 @@ from scorer.test.conftest import ( - api_key, - sample_address, - sample_provider, - sample_token, - scorer_account, - scorer_user, - verifiable_credential, + api_key, # noqa + sample_address, # noqa + sample_provider, # noqa + sample_token, # noqa + scorer_account, # noqa + scorer_user, # noqa + verifiable_credential, # noqa + weight_config, # noqa ) diff --git a/api/passport_admin/tests/test_notifications.py b/api/passport_admin/tests/test_notifications.py index 11fbe5c86..0605ac705 100644 --- a/api/passport_admin/tests/test_notifications.py +++ b/api/passport_admin/tests/test_notifications.py @@ -116,7 +116,7 @@ def custom_notifications(current_date, sample_address, community): @pytest.fixture -def community(scorer_account): +def community(scorer_account, weight_config): scorer = BinaryWeightedScorer.objects.create( type=Scorer.Type.WEIGHTED_BINARY, weights=scorer_weights ) diff --git a/api/registry/test/conftest.py b/api/registry/test/conftest.py index 55b362356..84701d872 100644 --- a/api/registry/test/conftest.py +++ b/api/registry/test/conftest.py @@ -1,7 +1,7 @@ import pytest from registry.weight_models import WeightConfiguration, WeightConfigurationItem -from scorer.settings.gitcoin_passport_weights import GITCOIN_PASSPORT_WEIGHTS +from scorer.config.gitcoin_passport_weights import GITCOIN_PASSPORT_WEIGHTS # pylint: disable=unused-import from scorer.test.conftest import ( @@ -26,7 +26,7 @@ def weight_config(request): config = WeightConfiguration.objects.create( version="v1", - threshold=5.0, + threshold=20.0, active=True, description="Test", ) diff --git a/api/registry/weight_models.py b/api/registry/weight_models.py index df1c81f3b..01e78c456 100644 --- a/api/registry/weight_models.py +++ b/api/registry/weight_models.py @@ -28,10 +28,8 @@ class Meta: def get_active_threshold(cls): try: active_config = cls.objects.filter(active=True).get() - except ObjectDoesNotExist: - return settings.GITCOIN_PASSPORT_THRESHOLD except Exception as e: - raise Exception(f"Failed to load settings: {str(e)}") + raise Exception(f"Failed to load active threshold: {str(e)}") return active_config.threshold @@ -59,11 +57,8 @@ def __str__(self): def get_active_weights(cls): try: active_config = WeightConfiguration.objects.filter(active=True).get() - except ObjectDoesNotExist: - print("NO ACTIVE CONFIGURATION FOUND") - # return settings.GITCOIN_PASSPORT_WEIGHTS except Exception as e: - raise Exception(f"Failed to load settings: {str(e)}") + raise Exception(f"Failed to load active weights: {str(e)}") weight_items = cls.objects.filter(weight_configuration=active_config) diff --git a/api/scorer/config/gitcoin_passport_weights.py b/api/scorer/config/gitcoin_passport_weights.py new file mode 100644 index 000000000..27a1fb5a7 --- /dev/null +++ b/api/scorer/config/gitcoin_passport_weights.py @@ -0,0 +1,56 @@ +"""Configuration for the gitcoin scorer""" + +# Weight values for each stamp based on its perceived significance in assessing the unique humanity of the Passport holder +GITCOIN_PASSPORT_WEIGHTS = { + "BeginnerCommunityStaker": "1.513", + "Brightid": "0.802", + "CivicCaptchaPass": "1.014", + "CivicLivenessPass": "3.004", + "CivicUniquenessPass": "6.005", + "CoinbaseDualVerification": "16.042", + "Discord": "0.516", + "Ens": "0.408", + "ETHDaysActive#50": "0.507", + "ETHGasSpent#0.25": "1.003", + "ETHnumTransactions#100": "0.51", + "ETHScore#50": "10.012", + "ETHScore#75": "2.001", + "ETHScore#90": "2.009", + "ExperiencedCommunityStaker": "2.515", + "GitcoinContributorStatistics#totalContributionAmountGte#1000": "5.018", + "GitcoinContributorStatistics#totalContributionAmountGte#100": "2.017", + "GitcoinContributorStatistics#totalContributionAmountGte#10": "0.523", + "githubContributionActivityGte#120": "3.019", + "githubContributionActivityGte#30": "2.020", + "githubContributionActivityGte#60": "2.021", + "GnosisSafe": "0.822", + "Google": "0.525", + "GuildAdmin": "0.724", + "GuildPassportMember": "0.54", + "HolonymGovIdProvider": "16.026", + "IdenaState#Human": "2.027", + "IdenaState#Newbie": "6.028", + "IdenaState#Verified": "2.029", + "Lens": "0.93", + "Linkedin": "1.531", + "NFT": "1.032", + "NFTScore#50": "10.033", + "NFTScore#75": "2.034", + "NFTScore#90": "2.035", + "SelfStakingBronze": "1.036", + "SelfStakingGold": "3.037", + "SelfStakingSilver": "2.038", + "SnapshotProposalsProvider": "0.839", + "TrustaLabs": "0.511", + "TrustedCitizen": "4.041", + "ZkSyncEra": "0.606", + "zkSyncScore#20": "1.67", + "zkSyncScore#50": "1.67", + "zkSyncScore#5": "1.67", + "Outdid": "10", + "BinanceBABT": "16.021", +} + + +# The Boolean scorer deems Passport holders unique humans if they meet or exceed the below thresholdold +GITCOIN_PASSPORT_THRESHOLD = "20" diff --git a/api/scorer/settings/__init__.py b/api/scorer/settings/__init__.py index 228e619f8..624b67659 100644 --- a/api/scorer/settings/__init__.py +++ b/api/scorer/settings/__init__.py @@ -2,7 +2,6 @@ from .base import * from .celery import * from .feature_flags import * -from .gitcoin_passport_weights import * from .model_config import * from .ninja_jwt import * from .ratelimit import * diff --git a/api/scorer/test/conftest.py b/api/scorer/test/conftest.py index 6704b3b73..b813d9507 100644 --- a/api/scorer/test/conftest.py +++ b/api/scorer/test/conftest.py @@ -9,7 +9,7 @@ from ceramic_cache.api.v1 import DbCacheToken from registry.models import GTCStakeEvent, Passport, Score from registry.weight_models import WeightConfiguration, WeightConfigurationItem -from scorer.settings.gitcoin_passport_weights import GITCOIN_PASSPORT_WEIGHTS +from scorer.config.gitcoin_passport_weights import GITCOIN_PASSPORT_WEIGHTS from scorer_weighted.models import BinaryWeightedScorer, Scorer, WeightedScorer User = get_user_model() @@ -88,7 +88,7 @@ def scorer_api_key_no_permissions(scorer_account): def weight_config(): config = WeightConfiguration.objects.create( version="v1", - threshold=5.0, + threshold=20.0, active=True, description="Test", ) diff --git a/api/scorer_weighted/models.py b/api/scorer_weighted/models.py index 0914fe69b..7d852849d 100644 --- a/api/scorer_weighted/models.py +++ b/api/scorer_weighted/models.py @@ -8,7 +8,7 @@ from django.db import models import api_logging as logging -from registry.weight_models import WeightConfigurationItem +from registry.weight_models import WeightConfiguration, WeightConfigurationItem log = logging.getLogger(__name__) @@ -66,7 +66,7 @@ def get_default_threshold(): """ This function shall provide the default threshold for the default binary scorer from the settings. """ - return round(Decimal(settings.GITCOIN_PASSPORT_THRESHOLD), THRESHOLD_DECIMAL_PLACES) + return WeightConfiguration.get_active_threshold() class Scorer(models.Model):