Return started_during Subscriptions with plan counts annotated.
762986
def started_plan_summary_for(self, year, month):
		""""""
		return (
			self.started_during(year, month)
			.values("plan")
			.order_by()
			.annotate(count=models.Count("plan"))
		)
431293
def calculate_subscription_lifecycle(subscription_id):
    
    subscription = Subscription.objects.select_related("messageset", "schedule").get(
        id=subscription_id
    )
    behind = subscription.messages_behind()
    if behind == 0:
        return

    current_messageset = subscription.messageset
    current_sequence_number = subscription.next_sequence_number
    end_subscription = Subscription.fast_forward_lifecycle(subscription, save=False)[-1]
    BehindSubscription.objects.create(
        subscription=subscription,
        messages_behind=behind,
        current_messageset=current_messageset,
        current_sequence_number=current_sequence_number,
        expected_messageset=end_subscription.messageset,
        expected_sequence_number=end_subscription.next_sequence_number,
    )
601009
def started(topic, event)
      subscribers_for(topic).each{ |subscriber| subscriber.started(event) }
    end
88891
public function subscribed($subscription = 'default', $planId = null)
    {
        $subscription = $this->subscription($subscription);

        if (is_null($subscription)) {
            return false;
        }

        if (is_null($planId)) {
            return $subscription->isActive();
        }

        if ($planId == $subscription->plan_id and $subscription->isActive()) {
            return true;
        }

        return false;
    }
618838
def get_next(self):
        """"""
        return BillingCycle.objects.filter(date_range__gt=self.date_range).order_by('date_range').first()
1169327
def paid_totals_for(self, year, month):
		""""""
		return self.during(year, month).aggregate(total_amount=models.Sum("amount"))
1046182
def preview
      notifications = Correspondent::Notification.for_subscriber(params[:subscriber_type], params[:subscriber_id])

      if stale?(notifications)
        render(
          json: {
            count: notifications.count,
            notification: notifications.limit(1).first
          }
        )
      end
    end
673526
def GetCountStopTimes(self):
    """"""
    cursor = self._schedule._connection.cursor()
    cursor.execute(
        'SELECT count(*) FROM stop_times WHERE trip_id=?', (self.trip_id,))
    return cursor.fetchone()[0]
1027291
def start_subscribe(self):
        """"""
        if not self.conn:
            raise ValueError('Not connected')
        elif not self.pubsub_conn:
            raise ValueError('PubSub not enabled')

        # creates a new context manager
        return Subscription(self)
801261
def planSummary(self):
        """"""
        if not self._counters_calculated:
            self._counters_calculated = True
            self._extract_counters()

        return self._planSummary
692897
def paid_totals_for(self, year, month):
		""""""
		return (
			self.during(year, month)
			.filter(paid=True)
			.aggregate(
				total_amount=models.Sum("amount"), total_refunded=models.Sum("amount_refunded")
			)
		)
876285
def get_all_subscriptions_by_topic(name, region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    cache_key = _subscriptions_cache_key(name)
    try:
        return __context__[cache_key]
    except KeyError:
        pass

    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    ret = conn.get_all_subscriptions_by_topic(get_arn(name, region, key, keyid, profile))
    __context__[cache_key] = ret['ListSubscriptionsByTopicResponse']['ListSubscriptionsByTopicResult']['Subscriptions']
    return __context__[cache_key]
403445
private Map<UUID, DateTime> getNextTransitionsForSubscriptions(final BillingEventSet billingEvents) {

        final DateTime now = clock.getUTCNow();
        final Map<UUID, DateTime> result = new HashMap<UUID, DateTime>();
        for (final BillingEvent evt : billingEvents) {
            final UUID subscriptionId = evt.getSubscriptionId();
            final DateTime evtEffectiveDate = evt.getEffectiveDate();
            if (evtEffectiveDate.compareTo(now) <= 0) {
                continue;
            }
            final DateTime nextUpcomingPerSubscriptionDate = result.get(subscriptionId);
            if (nextUpcomingPerSubscriptionDate == null || nextUpcomingPerSubscriptionDate.compareTo(evtEffectiveDate) > 0) {
                result.put(subscriptionId, evtEffectiveDate);
            }
        }
        return result;
    }
234576
def get_subscriptions(self, limit=100, offset=0, params={}):
        
        url = self.SUBSCRIPTIONS_URL + "?limit=%s&offset=%s" % (limit, offset)

        for key, value in params.items():
            if key is 'ids':
                value = ",".join(value)

            url += '&%s=%s' % (key, value)

        connection = Connection(self.token)
        connection.set_url(self.production, url)

        return connection.get_request()
151981
def actualPlanSummary(self):
        """"""
        if not self._counters_calculated:
            self._counters_calculated = True
            self._extract_counters()

        return self._actualPlanSummary
660716
def list_subscriptions(self, service):
        """"""
        data = {
            'service': service,
        }
        return self._perform_post_request(self.list_subscriptions_endpoint, data, self.token_header)
230478
def post_send_process(context):
    
    if "error" in context:
        return context

    [deserialized_subscription] = serializers.deserialize(
        "json", context["subscription"]
    )
    subscription = deserialized_subscription.object
    [messageset] = serializers.deserialize("json", context["messageset"])
    messageset = messageset.object

    # Get set max
    set_max = messageset.messages.filter(lang=subscription.lang).count()
    logger.debug("set_max calculated - %s" % set_max)

    # Compare user position to max
    if subscription.next_sequence_number == set_max:
        with transaction.atomic():
            # Mark current as completed
            logger.debug("marking current subscription as complete")
            subscription.completed = True
            subscription.active = False
            subscription.process_status = 2  # Completed
            deserialized_subscription.save(
                update_fields=("completed", "active", "process_status")
            )
            # If next set defined create new subscription
            if messageset.next_set:
                logger.info("Creating new subscription for next set")
                newsub = Subscription.objects.create(
                    identity=subscription.identity,
                    lang=subscription.lang,
                    messageset=messageset.next_set,
                    schedule=messageset.next_set.default_schedule,
                )
                logger.debug("Created Subscription <%s>" % newsub.id)
    else:
        # More in this set so increment by one
        logger.debug("incrementing next_sequence_number")
        subscription.next_sequence_number = F("next_sequence_number") + 1
        logger.debug("setting process status back to 0")
        subscription.process_status = 0
        logger.debug("saving subscription")
        deserialized_subscription.save(
            update_fields=("next_sequence_number", "process_status")
        )
    # return response
    return "Subscription for %s updated" % str(subscription.id)