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

Metrics api #126

Merged
merged 13 commits into from
Mar 18, 2024
24 changes: 15 additions & 9 deletions .github/workflows/get-metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import numpy as np
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest

print('testing 1 2 3')
# from google.analytics.data_v1beta import BetaAnalyticsDataClient
# from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest

PORTAL_ID = os.environ['PORTAL_ID']
FOUNDATIONS_ID = os.environ['FOUNDATIONS_ID']
COOKBOOKS_ID = os.environ['COOKBOOKS_ID']

PRIVATE_KEY_ID = os.environ.get('PRIVATE_KEY_ID')
PRIVATE_KEY = os.environ.get('PRIVATE_KEY').replace('$', '\n')
PRIVATE_KEY = os.environ.get('PRIVATE_KEY')
print(len(PRIVATE_KEY))

credentials_dict = {
'type': 'service_account',
'project_id': 'cisl-vast-pythia',
'private_key_id': PRIVATE_KEY_ID,
'private_key': PRIVATE_KEY,
'private_key_id': str(PRIVATE_KEY_ID),
'private_key': str(PRIVATE_KEY),
'client_email': '[email protected]',
'client_id': '113402578114110723940',
'auth_uri': 'https://accounts.google.com/o/oauth2/auth',
Expand All @@ -30,11 +33,13 @@
'client_x509_cert_url': 'https://www.googleapis.com/robot/v1/metadata/x509/pythia-metrics-api%40cisl-vast-pythia.iam.gserviceaccount.com',
'universe_domain': 'googleapis.com',
}
client = BetaAnalyticsDataClient.from_service_account_info(credentials_dict)

print(credentials_dict)
# client = BetaAnalyticsDataClient.from_service_account_info(credentials_dict)


def _format_rounding(value):
return f"{round(value / 1000, 1):.1f}K"
return f'{round(value / 1000, 1):.1f}K'


def run_total_users_report(property_id):
Expand Down Expand Up @@ -156,7 +161,7 @@ def plot_usersXcountry(foundations_id):

top_10_countries = sorted(users_by_country.items(), key=lambda item: item[1], reverse=True)[:10]
top_10_text = '\n'.join(
f"{country}: {_format_rounding(value)}" for i, (country, value) in enumerate(top_10_countries)
f'{country}: {_format_rounding(value)}' for i, (country, value) in enumerate(top_10_countries)
)

fig = plt.figure(figsize=(10, 4))
Expand Down Expand Up @@ -210,4 +215,5 @@ def get_metrics():


if __name__ == '__main__':
get_metrics()
print(credentials_dict)
# get_metrics()
17 changes: 8 additions & 9 deletions .github/workflows/nightly-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ on:
schedule:
- cron: '0 0 * * *' # Daily “At 00:00”

env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}

jobs:
automate-metrics:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Automate Metrics
env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
run: |
python -m venv analytics-api
source analytics-api/bin/activate
pip install google-analytics-data
conda install cartopy matplotlib
pip install google-analytics-data cartopy matplotlib

curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/get-metrics.py
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/write-metrics-md.py
Expand All @@ -31,6 +29,7 @@ jobs:
python write-metrics-md.py

build:
needs: automate-metrics
if: ${{ github.repository_owner == 'ProjectPythia' }}
uses: ProjectPythia/cookbook-actions/.github/workflows/build-book.yaml@main
with:
Expand Down
17 changes: 8 additions & 9 deletions .github/workflows/publish-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ on:
- main
workflow_dispatch:

env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}

jobs:
automate-metrics:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Automate Metrics
env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
run: |
python -m venv analytics-api
source analytics-api/bin/activate
pip install google-analytics-data
conda install cartopy matplotlib
pip install google-analytics-data cartopy matplotlib

curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/get-metrics.py
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/write-metrics-md.py
Expand All @@ -33,6 +31,7 @@ jobs:
python write-metrics-md.py

build:
needs: automate-metrics
uses: ProjectPythia/cookbook-actions/.github/workflows/build-book.yaml@main
with:
environment_file: 'environment.yml'
Expand Down
17 changes: 8 additions & 9 deletions .github/workflows/trigger-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ on:
- requested
- completed

env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}

jobs:
automate-metrics:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Automate Metrics
env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
run: |
python -m venv analytics-api
source analytics-api/bin/activate
pip install google-analytics-data
conda install cartopy matplotlib
pip install google-analytics-data cartopy matplotlib

curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/get-metrics.py
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/write-metrics-md.py
Expand All @@ -36,6 +34,7 @@ jobs:
uses: ProjectPythia/cookbook-actions/.github/workflows/find-pull-request.yaml@main
deploy-preview:
needs: find-pull-request
needs: automate-metrics
if: github.event.workflow_run.conclusion == 'success'
uses: ProjectPythia/cookbook-actions/.github/workflows/deploy-book.yaml@main
with:
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/trigger-site-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@ name: trigger-site-build
on:
pull_request:

env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}

jobs:
automate-metrics:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Automate Metrics
env:
PORTAL_ID: ${{ secrets.PORTAL_ID }}
FOUNDATIONS_ID: ${{ secrets.FOUNDATIONS_ID }}
COOKBOOKS_ID: ${{ secrets.COOKBOOKS_ID }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_ID: ${{ secrets.PRIVATE_KEY_ID }}
run: |
python -m venv analytics-api
source analytics-api/bin/activate
pip install google-analytics-data
conda install cartopy matplotlib
pip install google-analytics-data cartopy matplotlib

curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/get-metrics.py
curl -O https://raw.githubusercontent.com/jukent/projectpythia.github.io/main/.github/workflows/write-metrics-md.py
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/user_metrics.json

This file was deleted.

Loading