-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
40325c8
commit 1362f0e
Showing
11 changed files
with
408 additions
and
263 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
discovery-provider/src/challenges/audio_matching_challenge.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Dict, Optional, Tuple | ||
|
||
from sqlalchemy.orm.session import Session | ||
|
||
from src.challenges.challenge import ChallengeManager, ChallengeUpdater | ||
from src.models.users.user import User | ||
|
||
|
||
def generate_audio_matching_specifier(user_id: int, extra: Dict) -> str: | ||
return f"{user_id}=>{extra['track_id']}" | ||
|
||
|
||
def does_user_exist_with_verification_status( | ||
session, user_id: int, is_verified: bool | ||
) -> bool: | ||
user: Optional[Tuple[int]] = ( | ||
session.query(User.user_id) | ||
.filter( | ||
User.user_id == user_id, | ||
bool(User.is_current), | ||
User.is_verified == is_verified, | ||
) | ||
.one_or_none() | ||
) | ||
return bool(user) | ||
|
||
|
||
class AudioMatchingBuyerChallengeUpdater(ChallengeUpdater): | ||
def generate_specifier(self, user_id: int, extra: Dict) -> str: | ||
return generate_audio_matching_specifier(user_id, extra) | ||
|
||
def should_create_new_challenge( | ||
self, session, event: str, user_id: int, extra: Dict | ||
) -> bool: | ||
return does_user_exist_with_verification_status(session, user_id, False) | ||
|
||
def should_show_challenge_for_user(self, session: Session, user_id: int) -> bool: | ||
return does_user_exist_with_verification_status(session, user_id, False) | ||
|
||
|
||
class AudioMatchingSellerChallengeUpdater(ChallengeUpdater): | ||
def generate_specifier(self, user_id: int, extra: Dict) -> str: | ||
return generate_audio_matching_specifier(extra["sender_user_id"], extra) | ||
|
||
def should_create_new_challenge( | ||
self, session, event: str, user_id: int, extra: Dict | ||
) -> bool: | ||
return does_user_exist_with_verification_status(session, user_id, True) | ||
|
||
def should_show_challenge_for_user(self, session: Session, user_id: int) -> bool: | ||
return does_user_exist_with_verification_status(session, user_id, True) | ||
|
||
|
||
audio_matching_buyer_challenge_manager = ChallengeManager( | ||
"b", AudioMatchingBuyerChallengeUpdater() | ||
) | ||
audio_matching_seller_challenge_manager = ChallengeManager( | ||
"s", AudioMatchingSellerChallengeUpdater() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,82 @@ | ||
[ | ||
{ | ||
"id": "listen-streak", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "track-upload", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "referrals", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "ref-v", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "referred", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "connect-verified", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "mobile-install", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "tt", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "tut", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "tp", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "send-first-tip", | ||
"type": "boolean", | ||
"amount": 2, | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "first-playlist", | ||
"type": "boolean", | ||
"amount": 2, | ||
"active": true, | ||
"starting_block": 0 | ||
} | ||
] | ||
{ | ||
"id": "listen-streak", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "track-upload", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "referrals", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "ref-v", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "referred", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "connect-verified", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "mobile-install", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "tt", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "tut", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "tp", | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "send-first-tip", | ||
"type": "boolean", | ||
"amount": 2, | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "first-playlist", | ||
"type": "boolean", | ||
"amount": 2, | ||
"active": true, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "b", | ||
"type": "aggregate", | ||
"amount": "1", | ||
"active": true, | ||
"step_count": 2147483647, | ||
"starting_block": 0 | ||
}, | ||
{ | ||
"id": "s", | ||
"type": "aggregate", | ||
"amount": "1", | ||
"active": true, | ||
"step_count": 2147483647, | ||
"starting_block": 0 | ||
} | ||
] |
Oops, something went wrong.