def print_couch_stats(self, domain):
     couchdb = XFormInstance.get_db()
     for entity in MissingIds.DOC_TYPES:
         count = get_couch_doc_count(domain, entity, couchdb)
         print(f"Total {entity}s: {count}")
     received_on = get_last_form_submission_received(domain)
     print(f"Last form submission: {received_on}")
    def log_module_info(self, module, path, domains, in_module_map):
        domains_exist = []
        plans = []
        last_form_submissions = []
        all_community = True
        for domain in domains:
            domain_obj = Domain.get_by_name(domain)
            plan = "Not Found"
            domains_exist.append(domain_obj is not None)
            if domain_obj:
                subscription = Subscription.get_active_subscription_by_domain(domain)
                if subscription:
                    plan = subscription.plan_version.plan.name
                    if subscription.plan_version.plan.edition != SoftwarePlanEdition.COMMUNITY:
                        all_community = False
                last_form_submissions.append("{}".format(get_last_form_submission_received(domain)))
            else:
                last_form_submissions.append("None")
            plans.append(plan)

        return [
            module,
            path[len(settings.FILEPATH) + 1:],
            " | ".join(domains),
            " | ".join(map(str, domains_exist)),
            " | ".join(plans),
            " | ".join(last_form_submissions),
            in_module_map,
            all(domains_exist) and all_community,
        ]
예제 #3
0
 def rows_for_domain(self, domain_obj):
     return [[
         self.format_date(domain_obj.date_created),
         len(domain_obj.applications()),
         get_mobile_user_count(domain_obj.name, include_inactive=False),
         get_web_user_count(domain_obj.name, include_inactive=False),
         self.format_date(get_last_form_submission_received(domain_obj.name)),
     ] + self.domain_properties(domain_obj)]
예제 #4
0
 def rows_for_domain(self, domain):
     return [[
         self.format_date(domain.date_created),
         len(domain.applications()),
         get_mobile_user_count(domain.name, include_inactive=False),
         get_web_user_count(domain.name, include_inactive=False),
         self.format_date(get_last_form_submission_received(domain.name)),
     ] + self.domain_properties(domain)]
예제 #5
0
 def rows_for_domain(self, domain):
     subscription = Subscription.get_active_subscription_by_domain(
         domain.name)
     plan_version = subscription.plan_version if subscription else DefaultProductPlan.get_default_plan_version(
     )
     return [[
         plan_version.plan.name,
         self.format_date(domain.date_created),
         get_mobile_user_count(domain.name, include_inactive=False),
         get_web_user_count(domain.name, include_inactive=False),
         self.format_date(get_last_form_submission_received(domain.name)),
     ] + self.domain_properties(domain)]
예제 #6
0
def _get_usage_info(toggle):
    """Returns usage information for each toggle
    """
    last_used = {}
    active_domains = 0
    for enabled in toggle.enabled_users:
        name = _enabled_item_name(enabled)
        if _namespace_domain(enabled):
            last_form_submission = get_last_form_submission_received(name)
            last_used[name] = _format_date(last_form_submission)
            if last_form_submission:
                active_domains += 1
        else:
            try:
                user = CouchUser.get_by_username(name)
                last_used[name] = _format_date(user.last_login) if user else NOT_FOUND
            except ResourceNotFound:
                last_used[name] = NOT_FOUND
    last_used["_latest"] = _get_most_recently_used(last_used)
    last_used["_active_domains"] = active_domains
    return last_used
예제 #7
0
파일: views.py 프로젝트: bazuzi/commcare-hq
def _get_usage_info(toggle):
    """Returns usage information for each toggle
    """
    last_used = {}
    active_domains = 0
    for enabled in toggle.enabled_users:
        name = _enabled_item_name(enabled)
        if _namespace_domain(enabled):
            last_form_submission = get_last_form_submission_received(name)
            last_used[name] = _format_date(last_form_submission)
            if last_form_submission:
                active_domains += 1
        else:
            try:
                user = CouchUser.get_by_username(name)
                last_used[name] = _format_date(user.last_login) if user else NOT_FOUND
            except ResourceNotFound:
                last_used[name] = NOT_FOUND
    last_used["_latest"] = _get_most_recently_used(last_used)
    last_used["_active_domains"] = active_domains
    return last_used
예제 #8
0
def generate_malt(monthspans, domains=None):
    """
    Populates MALTRow SQL table with app submission data for a given list of months
    :param monthspans: list of DateSpan objects
    :param domains: list of domain names
    """
    domain_names = domains or Domain.get_all_names()
    for domain_name in domain_names:
        last_submission_date = get_last_form_submission_received(domain_name)
        last_malt_run_dates_by_month = _get_last_run_date_for_malt_by_month(domain_name, monthspans)
        for monthspan in monthspans:
            # if the MALTRow last_run_date is none, use the start date of the month
            last_malt_run_date = last_malt_run_dates_by_month.get(monthspan.startdate.date(), monthspan.startdate)
            if last_submission_date and last_submission_date >= last_malt_run_date:
                # use this date to populate last_run_date for all MALTRows with this domain and month
                run_date = datetime.datetime.utcnow()
                logger.info(f"Building MALT for {domain_name} for {monthspan} up to {run_date}")
                all_users = get_all_user_rows(domain_name, include_inactive=False, include_docs=True)
                for users in chunked(all_users, 1000):
                    users_by_id = {user['id']: CouchUser.wrap_correctly(user['doc']) for user in users}
                    malt_row_dicts = _get_malt_row_dicts(domain_name, monthspan, users_by_id, run_date)
                    if malt_row_dicts:
                        _save_malt_row_dicts_to_db(malt_row_dicts)
예제 #9
0
 def test_get_last_form_submission_received(self):
     self.assertEqual(get_last_form_submission_received(self.domain),
                      self.now)
예제 #10
0
 def test_get_last_form_submission_received(self):
     self.assertEqual(get_last_form_submission_received(self.domain), self.now)
예제 #11
0
def last_form_submission(domain, display=True):
    try:
        submission_time = get_last_form_submission_received(domain)
    except ValueError:
        return None
    return display_time(submission_time, display) if submission_time else None
예제 #12
0
def last_form_submission(domain, display=True):
    try:
        submission_time = get_last_form_submission_received(domain)
    except ValueError:
        return None
    return display_time(submission_time, display) if submission_time else None