Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create DomainMetrics SQL table #35415

Merged
merged 8 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions corehq/apps/data_analytics/migrations/0011_domainmetrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Generated by Django 4.2.16 on 2024-12-06 01:12

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('data_analytics', '0010_maltrow_last_run_date'),
]

operations = [
migrations.CreateModel(
name='DomainMetrics',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('domain', models.TextField(db_index=True, unique=True)),
('date_created', models.DateTimeField(auto_now_add=True)),
('last_modified', models.DateTimeField(auto_now=True)),
('has_project_icon', models.BooleanField()),
('has_security_settings', models.BooleanField()),
('is_active', models.BooleanField()),
('is_first_domain_for_creating_user', models.BooleanField()),
('lookup_tables', models.IntegerField()),
('repeaters', models.IntegerField()),
('ucrs', models.IntegerField()),
('apps', models.IntegerField()),
('apps_with_icon', models.IntegerField()),
('apps_with_multiple_languages', models.IntegerField()),
('mobile_workers', models.IntegerField()),
('web_users', models.IntegerField()),
('active_mobile_workers', models.IntegerField()),
('active_mobile_workers_in_last_365_days', models.IntegerField()),
('case_sharing_groups', models.IntegerField()),
('case_sharing_locations', models.IntegerField()),
('has_custom_roles', models.BooleanField()),
('has_locations', models.BooleanField()),
('location_restricted_users', models.IntegerField()),
('users_with_submission', models.IntegerField()),
('cases', models.IntegerField()),
('active_cases', models.IntegerField()),
('cases_modified_in_last_30_days', models.IntegerField()),
('cases_modified_in_last_60_days', models.IntegerField()),
('cases_modified_in_last_90_days', models.IntegerField()),
('inactive_cases', models.IntegerField()),
('usercases_modified_in_last_30_days', models.IntegerField()),
('forms', models.IntegerField()),
('forms_submitted_in_last_30_days', models.IntegerField()),
('forms_submitted_in_last_60_days', models.IntegerField()),
('forms_submitted_in_last_90_days', models.IntegerField()),
('first_form_submission', models.DateTimeField(null=True)),
('most_recent_form_submission', models.DateTimeField(null=True)),
('three_hundredth_form_submission', models.DateTimeField(null=True)),
('total_sms', models.IntegerField()),
('sms_in_last_30_days', models.IntegerField()),
('sms_in_last_60_days', models.IntegerField()),
('sms_in_last_90_days', models.IntegerField()),
('incoming_sms', models.IntegerField()),
('incoming_sms_in_last_30_days', models.IntegerField()),
('incoming_sms_in_last_60_days', models.IntegerField()),
('incoming_sms_in_last_90_days', models.IntegerField()),
('outgoing_sms', models.IntegerField()),
('outgoing_sms_in_last_30_days', models.IntegerField()),
('outgoing_sms_in_last_60_days', models.IntegerField()),
('outgoing_sms_in_last_90_days', models.IntegerField()),
('telerivet_backends', models.IntegerField()),
('case_exports', models.IntegerField()),
('custom_exports', models.IntegerField()),
('deid_exports', models.IntegerField()),
('saved_exports', models.IntegerField()),
],
),
]
91 changes: 91 additions & 0 deletions corehq/apps/data_analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,94 @@ def export_row(self, past_months):
experienced_threshold=self.experienced_threshold or DEFAULT_EXPERIENCED_THRESHOLD,
performance_threshold=self.performance_threshold or DEFAULT_PERFORMANCE_THRESHOLD,
)


class DomainMetrics(models.Model):

domain = models.TextField(unique=True, db_index=True)
date_created = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_now=True)

has_project_icon = models.BooleanField()
has_security_settings = models.BooleanField()
is_active = models.BooleanField()
is_first_domain_for_creating_user = models.BooleanField()

lookup_tables = models.IntegerField()
repeaters = models.IntegerField()
ucrs = models.IntegerField()

# App Metrics
apps = models.IntegerField()
apps_with_icon = models.IntegerField()
apps_with_multiple_languages = models.IntegerField()

# User Metrics
mobile_workers = models.IntegerField()
web_users = models.IntegerField()

active_mobile_workers = models.IntegerField()
active_mobile_workers_in_last_365_days = models.IntegerField()
case_sharing_groups = models.IntegerField()
case_sharing_locations = models.IntegerField()
has_custom_roles = models.BooleanField()
has_locations = models.BooleanField()
location_restricted_users = models.IntegerField()
users_with_submission = models.IntegerField()

# Case Metrics
cases = models.IntegerField()

active_cases = models.IntegerField()
cases_modified_in_last_30_days = models.IntegerField()
cases_modified_in_last_60_days = models.IntegerField()
cases_modified_in_last_90_days = models.IntegerField()
inactive_cases = models.IntegerField()
usercases_modified_in_last_30_days = models.IntegerField()

# Form Metrics
forms = models.IntegerField()
forms_submitted_in_last_30_days = models.IntegerField()
forms_submitted_in_last_60_days = models.IntegerField()
forms_submitted_in_last_90_days = models.IntegerField()

first_form_submission = models.DateTimeField(null=True)
most_recent_form_submission = models.DateTimeField(null=True)
three_hundredth_form_submission = models.DateTimeField(null=True)

# SMS Metrics
total_sms = models.IntegerField()
sms_in_last_30_days = models.IntegerField()
sms_in_last_60_days = models.IntegerField()
sms_in_last_90_days = models.IntegerField()

incoming_sms = models.IntegerField()
incoming_sms_in_last_30_days = models.IntegerField()
incoming_sms_in_last_60_days = models.IntegerField()
incoming_sms_in_last_90_days = models.IntegerField()

outgoing_sms = models.IntegerField()
outgoing_sms_in_last_30_days = models.IntegerField()
outgoing_sms_in_last_60_days = models.IntegerField()
outgoing_sms_in_last_90_days = models.IntegerField()

telerivet_backends = models.IntegerField()

# Export Metrics
case_exports = models.IntegerField()
custom_exports = models.IntegerField()
deid_exports = models.IntegerField()
saved_exports = models.IntegerField()

# Calculated properties
@property
def has_app(self):
return bool(self.apps)

@property
def has_used_sms(self):
return bool(self.total_sms)

@property
def has_used_sms_in_last_30_days(self):
return bool(self.sms_in_last_30_days)
1 change: 1 addition & 0 deletions corehq/apps/domain/deletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ def _delete_demo_user_restores(domain_name):
ModelDeletion('custom_data_fields', 'CustomDataFieldsDefinition', 'domain', [
'CustomDataFieldsProfile', 'Field',
]),
ModelDeletion('data_analytics', 'DomainMetrics', 'domain'),
ModelDeletion('data_analytics', 'GIRRow', 'domain_name'),
ModelDeletion('data_analytics', 'MALTRow', 'domain_name'),
ModelDeletion('data_dictionary', 'CaseType', 'domain', [
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/dump_reload/tests/test_dump_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"cleanup.DeletedCouchDoc",
"cleanup.DeletedSQLDoc",
"contenttypes.ContentType",
"data_analytics.DomainMetrics",
"data_analytics.GIRRow",
"data_analytics.MALTRow",
"django_celery_results.ChordCounter",
Expand Down
1 change: 1 addition & 0 deletions migrations.lock
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ data_analytics
0008_auto_20161114_1903
0009_remove_girrow_wam
0010_maltrow_last_run_date
0011_domainmetrics
data_dictionary
0001_squashed_0002_auto_20161116_2209
0002_auto_20161118_1537
Expand Down
Loading