Coverage for functions \ flipdare \ generated \ model \ internal \ dare_stats_model.py: 100%

0 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-05-08 12:22 +1000

1#!/usr/bin/env python 

2# 

3# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved. 

4# 

5# This file is part of Flipdare's proprietary software and contains 

6# confidential and copyrighted material. Unauthorised copying, 

7# modification, distribution, or use of this file is strictly 

8# prohibited without prior written permission from Flipdare Pty Ltd. 

9# 

10# This software includes third-party components licensed under MIT, 

11# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details. 

12# 

13# NOTE: THIS FILE IS AUTO GENERATED. DO NOT EDIT. 

14# 

15# Generated by codegen_models.py 

16# 

17# Modify 'codegen_models.py' 

18# and re-run the script above to update. 

19# 

20# pragma: no cover 

21from __future__ import annotations 

22from typing import Any, TypedDict, cast, Unpack 

23from enum import StrEnum 

24from pydantic import Field, ConfigDict, TypeAdapter 

25from flipdare.firestore.core.app_base_model import AppBaseModel 

26 

27 

28class DareStatsKeys(StrEnum): 

29 BACKERS = "backers" 

30 FLAGS = "flags" 

31 REQUESTED = "requested" 

32 ACCEPTED = "accepted" 

33 COMPLETED = "completed" 

34 EARNINGS = "earnings" 

35 

36 

37class DareStatsModel(AppBaseModel): 

38 """Stores statistics for a dare, including counts of backers, flags, requests, accepts, completions, and total pledge amount.""" 

39 

40 model_config = ConfigDict(populate_by_name=True) 

41 

42 backers: int = Field(default=0) 

43 flags: int = Field(default=0) 

44 requested: int = Field(default=0) 

45 accepted: int = Field(default=0) 

46 completed: int = Field(default=0) 

47 earnings: int = Field(default=0) 

48 

49 @classmethod 

50 def validate_partial(cls, **data: Unpack[DareStatsDict]) -> dict[str, Any]: 

51 """ 

52 Uses Unpack to give you autocomplete and static warnings 

53 if you pass an invalid key or type in your code. 

54 

55 Returns a dict with Firestore field names (aliases) for use with batch.update(). 

56 """ 

57 result: dict[str, Any] = {} 

58 for k, v in data.items(): 

59 if k in cls.__pydantic_fields__: 

60 field_info = cls.__pydantic_fields__[k] 

61 validated_value = cast( 

62 "Any", 

63 TypeAdapter(field_info.annotation).validate_python(v), 

64 ) 

65 # Use alias if defined, otherwise use field name 

66 output_key = field_info.alias or k 

67 result[output_key] = validated_value 

68 return result 

69 

70 # ---- Convenience predicates ----------------------------------------- 

71 def count(self) -> int: 

72 """Returns the total count of all stats except earnings.""" 

73 return self.backers + self.flags + self.requested + self.accepted + self.completed 

74 

75 def increment(self, key: DareStatsKeys, amount: int = 1) -> None: 

76 """Increment a specific stat by a given amount.""" 

77 if hasattr(self, key): 

78 current_value = getattr(self, key) 

79 setattr(self, key, current_value + amount) 

80 

81 

82DARESTATS_FIELD_NAMES: list[str] = list(DareStatsModel.model_fields.keys()) 

83 

84 

85class DareStatsDict(TypedDict, total=False): 

86 backers: int | None 

87 flags: int | None 

88 requested: int | None 

89 accepted: int | None 

90 completed: int | None 

91 earnings: int | None