File .deepsource.toml
not found in the default branch of the repository root. Please refer to the docs.
411 end_date,
412 granularity,
413 customer=None,
414 group_by=[], 415 proration=None,
416 ) -> dict[Customer.customer_name, dict[datetime.datetime, float]]:
417 from metering_billing.billable_metrics import METRIC_HANDLER_MAP
444 return usage
445
446 def get_earned_usage_per_day(
447 self, start, end, customer, group_by=[], proration=None 448 ):
449 from metering_billing.billable_metrics import METRIC_HANDLER_MAP
450
75 def get_current_usage(
76 self,
77 subscription: Subscription,
78 group_by: list[str] = [], 79 ) -> float:
80 """This method will be used to calculate how much usage a customer currently has on a subscription. THough there are cases where get_usage and get_current_usage will be the same, there are cases where they will not. For example, if your billable metric is Stateful with a Max aggregation, then your usage over some period will be the max over past readings, but your current usage will be the latest reading."""
81 pass
86 start: datetime.date,
87 end: datetime.date,
88 customer: Customer,
89 group_by: list[str] = [], 90 proration: Optional[METRIC_GRANULARITY] = None,
91 ) -> dict[datetime.datetime, float]:
92 """This method will be used when calculating a concept known as "earned revenue" which is very important in accounting. It essentially states that revenue is "earned" not when someone pays, but when you deliver the goods/services at a previously agreed upon price. To accurately calculate accounting metrics, we will need to be able to tell for a given susbcription, where each cent of revenue came from, and the first step for that is to calculate how much billable usage was delivered each day. This method will be used to calculate that.
95 pass
96
97 @abc.abstractmethod
98 def _build_filter_kwargs(self, start, end, customer, group_by=[]): 99 """This method will be used to build the filter args for the get_usage and get_earned_usage_per_day methods. You should build the filter args for the Event model, and return them as a dictionary. You should also handle the case where customer is None, which means that you should return the usage for all customers."""
100 now = now_utc()
101 filter_kwargs = {
Do not use a mutable like list
or dictionary
as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.
def my_function(elem, l=[]):
l.append(elem)
return l
print(my_function(2)) # [2]
print(my_function(5)) # [2, 5]
def my_function(elem, l=None):
if l is None:
l = []
l.append(elem)
return l
print(my_function(2)) # [2]
print(my_function(5)) # [5]