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

Add Chart builder #168

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
52085fa
add more series support
Andywang201605 Aug 23, 2022
c613521
update plot callback
Andywang201605 Aug 23, 2022
c24a21e
fix method not loading issue
Andywang201605 Aug 24, 2022
60faa8e
add link from chart to series
Andywang201605 Aug 26, 2022
6784979
add url search support
Andywang201605 Aug 26, 2022
88f932f
link series to chart builder
Andywang201605 Aug 26, 2022
418aed9
reformat
Andywang201605 Aug 26, 2022
d22cd75
initial upload
ardimirzaei Sep 16, 2022
00951f6
Update datasource_checker.py
ardimirzaei Sep 16, 2022
ab1d510
handle timeout cases
ardimirzaei Sep 19, 2022
344bf91
calculate timeouts
ardimirzaei Sep 23, 2022
16acb44
add fred api key and better handling timeout
ardimirzaei Sep 23, 2022
2e9c12e
fix exception as e
ardimirzaei Sep 23, 2022
35a9c5d
Update datasource_checker.py
ardimirzaei Sep 23, 2022
2abf6b7
fix timeout error
ardimirzaei Sep 23, 2022
3b8734a
add badges
ardimirzaei Sep 23, 2022
cafc80a
try venv for docker action
ardimirzaei Sep 23, 2022
6c82864
fix badge
ardimirzaei Sep 23, 2022
be229dc
run on master and staging
ardimirzaei Sep 23, 2022
aa20ca2
remove venv
ardimirzaei Sep 23, 2022
bcdeceb
remove libopenblas-base
ardimirzaei Sep 23, 2022
cde6c32
Update requirements-bin.txt
ardimirzaei Sep 23, 2022
85d4979
remove build essential and libopenblas-base
ardimirzaei Sep 23, 2022
48dc9f9
Update requirements-bin.txt
ardimirzaei Sep 23, 2022
a132b8a
clean home page linking
ardimirzaei Oct 8, 2022
e3d15fe
Merge branch 'master' into staging
ardimirzaei Oct 8, 2022
4e5bc26
Merge branch 'staging' into pr/168
ardimirzaei Oct 29, 2022
ffabada
add page registration
ardimirzaei Oct 29, 2022
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
55 changes: 55 additions & 0 deletions .github/datasource_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 9 11:17:36 2022

@author: ArdiMirzaei
"""

import json
import requests
import pandas as pd
import os

with open("./shared_config/data_sources.json") as data_sources_json_file:
data_sources_list = json.load(data_sources_json_file)

#%%

results = []
for data_source in data_sources_list:
payload = None
title = data_source["title"]
url = data_source["url"]
if data_source["source"] == "Fred":
FRED_API = os.environ["FRED_API_KEY"]
payload = {"api_key": FRED_API, "file_type": "json"}
try:
status = requests.get(
url, timeout=(6.05, 12), params=payload
).status_code
except requests.Timeout:
status = 99
except Exception as e:
print(e)

print(f"{title} - {status}")
results.append([title, url, status])

results = pd.DataFrame(results)

#%%
results.columns = ["Title", "URL", "Status"]

#%%
results_grouped = results["Status"].value_counts().reset_index()

print(
f"There are {results_grouped['Status'][results_grouped['index'] == 99].sum()} that were not reached because they timed out"
)
print(
f"There are { results_grouped['Status'][(results_grouped['index'] >= 200) & (results_grouped['index'] <= 400)].sum()} data sources that are reachable."
)
print(
f"The following {results_grouped['Status'][results_grouped['index'] > 400].sum()} are not reachable:\n"
)
print(results[["Title", "Status"]][results["Status"] > 400])
67 changes: 67 additions & 0 deletions .github/workflows/Docker_build_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: Build and deploy Python app - staging-forecast-lab

on:
push:
branches:
- master
- staging
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.9'

# - name: Create and start virtual environment
# run: |
# python -m venv venv
# source venv/bin/activate

- name: Run Docker
run: |
docker network create web
docker-compose up --force-recreate --build -d


# Optional: Add step to run tests here (PyTest, Django test suites, etc.)

- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/

# deploy:
# runs-on: ubuntu-latest
# needs: build
# environment:
# name: 'Production'
# url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
#
# steps:
# - name: Download artifact from build job
# uses: actions/download-artifact@v2
# with:
# name: python-app
# path: .
#
# - name: 'Deploy to Azure Web App'
# uses: azure/webapps-deploy@v2
# id: deploy-to-webapp
# with:
# app-name: 'staging-forecast-lab'
# slot-name: 'Production'
# publish-profile: ${{ secrets. }}
31 changes: 31 additions & 0 deletions .github/workflows/datasources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Check Data Sources

on:
push:
branches:
- master
- staging

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pandas
- name: Check Data Sources
env:
FRED_API_KEY: ${{ secrets.FRED_API_KEY}}
run: |
python .github/datasource_checker.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Build Status](https://github.com/forecastlab/forecast_dash/actions/workflows/ci.yml/badge.svg)
![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/forecastlab/forecast_dash/Build%20and%20deploy%20Python%20app%20-%20staging-forecast-lab/staging?label=Build) ![BlackResults)](https://img.shields.io/github/workflow/status/forecastlab/forecast_dash/CI/master?label=Clean%20Code) ![Check Data Sources](https://img.shields.io/github/workflow/status/forecastlab/forecast_dash/Check%20Data%20Sources/staging?label=Data%20Sources) ![GitHub commit activity](https://img.shields.io/github/commit-activity/y/forecastlab/forecast_dash) ![GitHub contributors](https://img.shields.io/github/contributors/forecastlab/forecast_dash)

# USYD Forecasting Lab

Expand Down
8 changes: 1 addition & 7 deletions dash/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
],
)

app.layout = html.Div(
[
header(),
dash.page_container,
footer(),
]
)
app.layout = html.Div([header(), dash.page_container, footer(),])

### callback for toggling the collapse on small screens
@callback(
Expand Down
31 changes: 5 additions & 26 deletions dash/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ def component_git_version():
def footer():
return dbc.Container(
[
dbc.Row(
dbc.Col(html.Hr(style={"margin-top": "64px"}), lg=12),
),
dbc.Row(dbc.Col(html.Hr(style={"margin-top": "64px"}), lg=12),),
dbc.Row(
[
dbc.Col(
Expand Down Expand Up @@ -557,15 +555,7 @@ def component_figs_2col(row_title, series_titles):
raise ValueError("series_titles must have 3 elements")

return dbc.Row(
[
dbc.Col(
[
html.H2(row_title),
],
lg=12,
className="text-center",
),
]
[dbc.Col([html.H2(row_title),], lg=12, className="text-center",),]
+ [
dbc.Col(
[
Expand Down Expand Up @@ -596,10 +586,7 @@ def component_figs_3col(row_title, series_titles):
return dbc.Row(
[
dbc.Col(
[
html.H3(row_title, style={"text-align": "center"}),
],
lg=12,
[html.H3(row_title, style={"text-align": "center"}),], lg=12,
),
]
+ [
Expand Down Expand Up @@ -726,12 +713,7 @@ def component_leaderboard_4col(series_list):
body = []

for index, row in leaderboard_counts.iterrows():
body.append(
html.Li(
index,
className="lead",
)
)
body.append(html.Li(index, className="lead",))

return dbc.Col(
[
Expand All @@ -741,10 +723,7 @@ def component_leaderboard_4col(series_list):
className="subtitle text-muted",
),
html.Ol(body),
html.A(
html.P("View full leaderboard"),
href="/leaderboard",
),
html.A(html.P("View full leaderboard"), href="/leaderboard",),
],
lg=4,
)
Expand Down
24 changes: 4 additions & 20 deletions dash/pages/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ def _mission():
dbc.Row(
dbc.Col(
[
html.H1(
"Our Mission",
className="display-4",
),
html.H1("Our Mission", className="display-4",),
html.Hr(),
html.P(
html.Ul(
Expand Down Expand Up @@ -123,13 +120,7 @@ def _builtby():


def _section_title(title):
return dbc.Col(
html.H2(
title,
style={"margin-bottom": "32px"},
),
lg=12,
)
return dbc.Col(html.H2(title, style={"margin-bottom": "32px"},), lg=12,)


def parse_people(person_list):
Expand Down Expand Up @@ -181,9 +172,7 @@ def parse_people(person_list):
if "links" in person_dict
else []
)
+ [
html.P(person_dict["bio"], className="text-justify"),
],
+ [html.P(person_dict["bio"], className="text-justify"),],
lg=4,
sm=6,
className="text-center mb-5",
Expand Down Expand Up @@ -261,12 +250,7 @@ def body_layout():
return dbc.Container(
[
breadcrumb_layout([("Home", "/"), ("About", "")]),
dbc.Row(
[
_about(),
_mission(),
]
),
dbc.Row([_about(), _mission(),]),
dbc.Row([_builtby()]),
dbc.Row(_section_title("Active Contributors")),
dbc.Row(parse_people(active_contributors)),
Expand Down
39 changes: 8 additions & 31 deletions dash/pages/blog/blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def _blog_layout():
return dbc.Container(
[
breadcrumb_layout([("Home", "/"), ("Blog", "")]),
dbc.Row(
[
dbc.Col([html.H1("Recent posts"), html.Hr()]),
]
),
dbc.Row([dbc.Col([html.H1("Recent posts"), html.Hr()]),]),
html.Div(id="body"),
],
style={"margin-bottom": "64px"},
Expand Down Expand Up @@ -73,8 +69,7 @@ def _collect_blog_posts():
def _post_review_title(blog_post):
return html.A(
html.H2(
blog_post["attributes"]["title"],
style={"padding-top": "8px"},
blog_post["attributes"]["title"], style={"padding-top": "8px"},
),
href=f"/blog/post?title={blog_post['filename']}",
id=blog_post["filename"],
Expand All @@ -90,8 +85,7 @@ def _post_review_author(blog_post):
humanize.naturaltime(
datetime.now()
- datetime.strptime(
blog_post["attributes"]["date"],
"%Y-%m-%d",
blog_post["attributes"]["date"], "%Y-%m-%d",
)
),
],
Expand Down Expand Up @@ -121,10 +115,7 @@ def _post_review_abstract(blog_post):
def _post_review_readmore(blog_post):
return html.A(
html.P(
html.Strong(
"Read more",
className="text-left",
),
html.Strong("Read more", className="text-left",),
style={"padding-bottom": "24px"},
),
href=f"/blog/post?title={blog_post['filename']}",
Expand All @@ -145,18 +136,12 @@ def _navigation_previous(page_int, n_pages):
else []
)

return dbc.Col(
previous_link,
lg=2,
)
return dbc.Col(previous_link, lg=2,)


def _navigation_pagecount(page_int, n_pages):
return dbc.Col(
html.P(
f"Page {page_int} of {n_pages}",
className="text-center",
),
html.P(f"Page {page_int} of {n_pages}", className="text-center",),
lg=4,
)

Expand All @@ -173,10 +158,7 @@ def _navigation_earlier(page_int):
else []
)

return dbc.Col(
earlier_link,
lg=2,
)
return dbc.Col(earlier_link, lg=2,)


def _render_post_reviews(value, n_posts_per_page=5): # value from url
Expand Down Expand Up @@ -231,9 +213,4 @@ def body(value):

### final layout function
def layout(page=None, post=None):
return html.Div(
[
dcc.Location(id="url", refresh=False),
_blog_layout(),
]
)
return html.Div([dcc.Location(id="url", refresh=False), _blog_layout(),])
Loading