-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from SolidStateGroup/feature/get-org-usage
Feature/get org usage
- Loading branch information
Showing
19 changed files
with
446 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import json | ||
|
||
from apiclient.discovery import build | ||
from django.conf import settings | ||
from google.oauth2 import service_account | ||
|
||
GA_SCOPES = ['https://www.googleapis.com/auth/analytics.readonly'] | ||
GA_API_NAME = 'analytics' | ||
GA_API_VERSION = 'v3' | ||
|
||
|
||
def get_service(): | ||
""" | ||
Get the google service object to use to query the API | ||
""" | ||
credentials = service_account.Credentials.from_service_account_info( | ||
json.loads(settings.GOOGLE_SERVICE_ACCOUNT), scopes=GA_SCOPES) | ||
|
||
# Build the service object. | ||
return build(GA_API_NAME, GA_API_VERSION, credentials=credentials) | ||
|
||
|
||
def get_events_for_organisation(organisation): | ||
""" | ||
Get number of tracked events for last 30 days for an organisation | ||
:return: number of events as integer | ||
""" | ||
ga_response = get_service().data().ga().get( | ||
ids=settings.GA_TABLE_ID, | ||
start_date='30daysAgo', | ||
end_date='today', | ||
metrics='ga:totalEvents', | ||
dimensions='ga:date', | ||
filters=f'ga:eventCategory=={organisation.get_unique_slug()}').execute() | ||
|
||
return int(ga_response['totalsForAllResults']['ga:totalEvents']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.18 on 2019-04-24 15:55 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('features', '0011_historicalfeature_squashed_0012_historicalfeaturestate_historicalfeaturestatevalue'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='historicalfeature', | ||
name='project', | ||
field=models.ForeignKey(blank=True, db_constraint=False, help_text='Changing the project selected will remove previous Feature States for the previously associated projects Environments that are related to this Feature. New default Feature States will be created for the new selected projects Environments for this Feature.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='projects.Project'), | ||
), | ||
migrations.AlterField( | ||
model_name='historicalfeaturestate', | ||
name='identity', | ||
field=models.ForeignKey(blank=True, db_constraint=False, default=None, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='environments.Identity'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class SegmentsConfig(AppConfig): | ||
name = 'segments' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.18 on 2019-04-24 15:55 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Segment', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=2000)), | ||
('description', models.TextField(blank=True, null=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='SegmentCondition', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('trait_key', models.CharField(max_length=200)), | ||
('condition_type', models.CharField(choices=[('ExactMatch', 'ExactMatch'), ('GreaterThan', 'GreaterThan'), ('LessThan', 'LessThan')], default='ExactMatch', max_length=20)), | ||
('match_value', models.TextField(blank=True, null=True)), | ||
('segment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='segment_conditions', to='segments.Segment')), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import models | ||
|
||
from django.utils.encoding import python_2_unicode_compatible | ||
|
||
# Condition Operation Value Types | ||
EXACT_MATCH = "ExactMatch" | ||
GREATER_THAN = "GreaterThan" | ||
LESS_THAN = "LessThan" | ||
|
||
@python_2_unicode_compatible | ||
class Segment(models.Model): | ||
name = models.CharField(max_length=2000) | ||
description = models.TextField(null=True, blank=True) | ||
|
||
@python_2_unicode_compatible | ||
class SegmentCondition(models.Model): | ||
CONDITION_OPERATION_TYPES = ( | ||
(EXACT_MATCH, 'ExactMatch'), | ||
(GREATER_THAN, 'GreaterThan'), | ||
(LESS_THAN, 'LessThan') | ||
) | ||
|
||
segment = models.ForeignKey(Segment, related_name='segment_conditions') | ||
trait_key = models.CharField(max_length=200) | ||
condition_type = models.CharField(max_length=20, choices=CONDITION_OPERATION_TYPES, default=EXACT_MATCH, | ||
null=False, blank=False) | ||
match_value = models.TextField(null=True, blank=True) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |