Skip to content

Commit

Permalink
chore: adjust deafult thershold logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-schultz committed Aug 22, 2024
1 parent 3976e8f commit c09f527
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 26 deletions.
23 changes: 19 additions & 4 deletions api/ceramic_cache/test/test_weights.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
)
Expand Down
15 changes: 8 additions & 7 deletions api/passport_admin/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion api/passport_admin/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions api/registry/test/conftest.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -26,7 +26,7 @@ def weight_config(request):

config = WeightConfiguration.objects.create(
version="v1",
threshold=5.0,
threshold=20.0,
active=True,
description="Test",
)
Expand Down
9 changes: 2 additions & 7 deletions api/registry/weight_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
56 changes: 56 additions & 0 deletions api/scorer/config/gitcoin_passport_weights.py
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion api/scorer/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
4 changes: 2 additions & 2 deletions api/scorer/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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",
)
Expand Down
4 changes: 2 additions & 2 deletions api/scorer_weighted/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c09f527

Please sign in to comment.