From edd41a727f1dbab2eba4bb80cdfc786718ac8793 Mon Sep 17 00:00:00 2001 From: osoken Date: Tue, 31 Oct 2023 22:46:42 +0900 Subject: [PATCH 1/5] feat(models): add special type for timestamp_of_last_earn_out --- birdxplorer/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/birdxplorer/models.py b/birdxplorer/models.py index eb8c094..c46b8a1 100644 --- a/birdxplorer/models.py +++ b/birdxplorer/models.py @@ -287,6 +287,7 @@ class EnrollmentState(str, Enum): UserEnrollmentLastStateChangeTimeStamp = Union[TwitterTimestamp, Literal["0"], Literal["103308100"]] +UserEnrollmentLastEarnOutTimestamp = Union[TwitterTimestamp, Literal["1"]] class UserEnrollment(BaseModel): @@ -294,7 +295,7 @@ class UserEnrollment(BaseModel): enrollment_state: EnrollmentState successful_rating_needed_to_earn_in: str timestamp_of_last_state_change: UserEnrollmentLastStateChangeTimeStamp - timestamp_of_last_earn_out: str + timestamp_of_last_earn_out: UserEnrollmentLastEarnOutTimestamp modeling_population: str modeling_group: str From b6b7d2d4c4b5e00605c42bedf3d5585ac67e01b6 Mon Sep 17 00:00:00 2001 From: osoken Date: Tue, 31 Oct 2023 23:02:43 +0900 Subject: [PATCH 2/5] feat(models): add NonNegativeInt class and apply to successful_rating_needed_to_earn_in column of UserEnrollment --- birdxplorer/models.py | 56 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/birdxplorer/models.py b/birdxplorer/models.py index eb8c094..714570d 100644 --- a/birdxplorer/models.py +++ b/birdxplorer/models.py @@ -152,7 +152,52 @@ def from_int(cls: Type[IntT], v: int) -> IntT: return TypeAdapter(cls).validate_python(v) -class BaseBoundedInt(BaseInt, ABC): +class BaseLowerBoundedInt(BaseInt, ABC): + """ + >>> class NaturalNumber(BaseLowerBoundedInt): + ... @classmethod + ... def min_value(cls) -> int: + ... return 1 + >>> NaturalNumber.from_int(1) + NaturalNumber(1) + >>> NaturalNumber.from_int(0) + Traceback (most recent call last): + ... + pydantic_core._pydantic_core.ValidationError: 1 validation error for function-after[validate(), constrained-int] + Input should be greater than or equal to 1 [type=greater_than_equal, input_value=0, input_type=int] + ... + """ + + @classmethod + @abstractmethod + def min_value(cls) -> int: + raise NotImplementedError + + @classmethod + def __get_extra_constraint_dict__(cls) -> dict[str, Any]: + return dict(super().__get_extra_constraint_dict__(), ge=cls.min_value()) + + +class NonNegativeInt(BaseLowerBoundedInt): + """ + >>> NonNegativeInt.from_int(1) + NonNegativeInt(1) + >>> NonNegativeInt.from_int(0) + NonNegativeInt(0) + >>> NonNegativeInt.from_int(-1) + Traceback (most recent call last): + ... + pydantic_core._pydantic_core.ValidationError: 1 validation error for function-after[validate(), constrained-int] + Input should be greater than or equal to 0 [type=greater_than_equal, input_value=-1, input_type=int] + ... + """ + + @classmethod + def min_value(cls) -> int: + return 0 + + +class BaseBoundedInt(BaseLowerBoundedInt): """ >>> class Under10NaturalNumber(BaseBoundedInt): ... @classmethod @@ -182,14 +227,9 @@ class BaseBoundedInt(BaseInt, ABC): def max_value(cls) -> int: raise NotImplementedError - @classmethod - @abstractmethod - def min_value(cls) -> int: - raise NotImplementedError - @classmethod def __get_extra_constraint_dict__(cls) -> dict[str, Any]: - return dict(super().__get_extra_constraint_dict__(), ge=cls.min_value(), le=cls.max_value()) + return dict(super().__get_extra_constraint_dict__(), le=cls.max_value()) class TwitterTimestamp(BaseBoundedInt): @@ -292,7 +332,7 @@ class EnrollmentState(str, Enum): class UserEnrollment(BaseModel): participant_id: ParticipantId enrollment_state: EnrollmentState - successful_rating_needed_to_earn_in: str + successful_rating_needed_to_earn_in: NonNegativeInt timestamp_of_last_state_change: UserEnrollmentLastStateChangeTimeStamp timestamp_of_last_earn_out: str modeling_population: str From 6fc79a6b09d6ae09439c8b9ae45e9c04af1bbe5e Mon Sep 17 00:00:00 2001 From: osoken Date: Tue, 31 Oct 2023 23:06:31 +0900 Subject: [PATCH 3/5] feat(models): update modelingPopulation type for UserEnrollment --- birdxplorer/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/birdxplorer/models.py b/birdxplorer/models.py index eb8c094..832df44 100644 --- a/birdxplorer/models.py +++ b/birdxplorer/models.py @@ -286,6 +286,11 @@ class EnrollmentState(str, Enum): earned_out_no_acknowledge = "earnedOutNoAcknowledge" +class ModelingPopulation(str, Enum): + control = "CORE" + treatment = "EXPANSION" + + UserEnrollmentLastStateChangeTimeStamp = Union[TwitterTimestamp, Literal["0"], Literal["103308100"]] @@ -295,7 +300,7 @@ class UserEnrollment(BaseModel): successful_rating_needed_to_earn_in: str timestamp_of_last_state_change: UserEnrollmentLastStateChangeTimeStamp timestamp_of_last_earn_out: str - modeling_population: str + modeling_population: ModelingPopulation modeling_group: str From 14f1fc2551cac10e189e3aacc38b9e4071cda927 Mon Sep 17 00:00:00 2001 From: NEKOYASAN Date: Wed, 1 Nov 2023 16:11:41 +0900 Subject: [PATCH 4/5] =?UTF-8?q?chore(ci):=20tox=E3=82=92=E4=BD=BF=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..325a08e --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,24 @@ +name: Project test +on: push + +permissions: + contents: read + packages: read + +jobs: + test-check: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup python 3.12 + uses: actions/setup-python@v4 + with: + python-version: 3.12 + cache: pip + cache-dependency-path: pyproject.toml + - name: dependency install + run: pip install -e ".[dev]" + - name: test + run: tox From 76784329403879c6ffd204190343a7e69dbd67f7 Mon Sep 17 00:00:00 2001 From: NEKOYASAN Date: Wed, 1 Nov 2023 16:18:47 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix(ci):=20env=E3=82=92=E3=82=B3=E3=83=94?= =?UTF-8?q?=E3=83=BC=E3=81=97=E3=81=A6=E6=8C=81=E3=81=A3=E3=81=A6=E3=81=8F?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 325a08e..8f672c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,5 +20,7 @@ jobs: cache-dependency-path: pyproject.toml - name: dependency install run: pip install -e ".[dev]" + - name: copy env + run: cp .env.example .env - name: test run: tox