Skip to content

Commit

Permalink
refactor: major change
Browse files Browse the repository at this point in the history
  • Loading branch information
leehanchung authored and hurshd0 committed Apr 17, 2020
1 parent 798763a commit f36a31a
Show file tree
Hide file tree
Showing 24 changed files with 592 additions and 644 deletions.
2 changes: 2 additions & 0 deletions ncov19_dash/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .dash_app import app
from .flask_server import server
from .cache import server_cache

# from ncov19_dash.app import create_app

# app = create_app()
10 changes: 10 additions & 0 deletions ncov19_dash/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask_caching import Cache


server_cache = Cache(
config={
"CACHE_TYPE": "filesystem",
"CACHE_DEFAULT_TIMEOUT": 3600,
"CACHE_DIR": "cache",
},
)
3 changes: 1 addition & 2 deletions ncov19_dash/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from .confirmed_cases_chart import confirmed_cases_chart
# from .confirmed_cases_chart import confirmed_cases_chart
from .daily_stats import daily_stats
from .new_infection_trajectory_chart import new_infection_trajectory_chart
from .news_feed import news_feed
from .scatter_mapbox import confirmed_scatter_mapbox, drive_thru_scatter_mapbox
from .twitter_feed import twitter_feed
from .daily_stats import daily_stats
from .daily_stats_mobile import daily_stats_mobile
from .column_stats import last_updated
from .column_stats_mobile import mobile_last_updated
Expand Down
4 changes: 2 additions & 2 deletions ncov19_dash/components/cases_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests
import pandas as pd
import plotly.graph_objects as go
from ncov19_dash.flask_server import cache
from ncov19_dash.cache import server_cache
from ncov19_dash.utils import REVERSE_STATES_MAP
from ncov19_dash.utils import config

Expand All @@ -23,7 +23,7 @@ def human_format(num):
)


@cache.memoize(timeout=3600)
@server_cache.memoize(timeout=3600)
def cases_chart(state="US") -> go.Figure:
"""Bar chart data for the selected state.
:params state: get the time series data for a particular state for confirmed, deaths, and recovered. If None, the whole US.
Expand Down
6 changes: 2 additions & 4 deletions ncov19_dash/components/column_stats.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import requests
import dash_bootstrap_components as dbc
import dash_html_components as html
from ncov19_dash.utils import REVERSE_STATES_MAP
from ncov19_dash.utils import config
import pandas as pd

from ncov19_dash.utils import config


try:
URL = config.NCOV19_API + config.COUNTY
Expand Down
6 changes: 2 additions & 4 deletions ncov19_dash/components/column_stats_mobile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import requests
import dash_bootstrap_components as dbc
import dash_html_components as html
from ncov19_dash.utils import config
from ncov19_dash.flask_server import cache
import pandas as pd

from ncov19_dash.utils import config


try:
URL = config.NCOV19_API + config.COUNTY
Expand Down
73 changes: 0 additions & 73 deletions ncov19_dash/components/confirmed_cases_chart.py

This file was deleted.

6 changes: 3 additions & 3 deletions ncov19_dash/components/daily_stats.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import gc
import json
import requests
from typing import List, Dict

import requests
import dash_bootstrap_components as dbc
import dash_html_components as html
from ncov19_dash.flask_server import cache
from ncov19_dash.utils import STATES_COORD

from ncov19_dash.utils import config


Expand Down
8 changes: 5 additions & 3 deletions ncov19_dash/components/daily_stats_mobile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import gc
import json
import requests
from typing import List, Dict

import requests
import dash_bootstrap_components as dbc
import dash_html_components as html
from ncov19_dash.flask_server import cache

from ncov19_dash.cache import server_cache
from ncov19_dash.utils import config
from ncov19_dash.utils import STATES_COORD

Expand Down Expand Up @@ -78,7 +80,7 @@ def get_daily_stats_mobile(state="United States") -> Dict:
return stats


@cache.memoize(timeout=600)
@server_cache.memoize(timeout=600)
def daily_stats_mobile(state="US") -> List[dbc.Row]:
"""Returns a top bar as a list of Plotly dash components displaying tested, confirmed , and death cases for the top row.
TODO: move to internal API.
Expand Down
4 changes: 2 additions & 2 deletions ncov19_dash/components/deaths_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests
import pandas as pd
import plotly.graph_objects as go
from ncov19_dash.flask_server import cache
from ncov19_dash.cache import server_cache
from ncov19_dash.utils import REVERSE_STATES_MAP
from ncov19_dash.utils import config

Expand All @@ -23,7 +23,7 @@ def human_format(num):
)


@cache.memoize(timeout=3600)
@server_cache.memoize(timeout=3600)
def deaths_chart(state="US") -> go.Figure:
"""Bar chart data for the selected state.
:params state: get the time series data for a particular state for confirmed, deaths, and recovered. If None, the whole US.
Expand Down
6 changes: 2 additions & 4 deletions ncov19_dash/components/new_infection_trajectory_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
import json
import requests
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from ncov19_dash.flask_server import cache
from ncov19_dash.cache import server_cache
from ncov19_dash.utils import REVERSE_STATES_MAP
from ncov19_dash.utils import config



@cache.memoize(timeout=3600)
@server_cache.memoize(timeout=3600)
def new_infection_trajectory_chart(state="US") -> go.Figure:
"""Line chart data for the selected state.
Expand Down
9 changes: 5 additions & 4 deletions ncov19_dash/components/news_feed.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import gc
import json

import requests
import pandas as pd
import dash_bootstrap_components as dbc
import dash_html_components as html
from ncov19_dash.flask_server import cache
from ncov19_dash.utils import STATES_COORD

from ncov19_dash.cache import server_cache
from ncov19_dash.utils import config
import json


@cache.memoize(timeout=900)
@server_cache.memoize(timeout=900)
def news_feed(state="US") -> dbc.ListGroup:
"""Displays news feed on the right hand side of the display. Adjust the NewsAPI time
time to Eastern Time (w/ DST).
Expand Down
4 changes: 2 additions & 2 deletions ncov19_dash/components/scatter_mapbox.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import gc
from datetime import datetime, timedelta

import requests
import numpy as np
import pandas as pd
import flask
from dash.dependencies import Input, Output, State
import plotly.express as px
import plotly.graph_objects as go

from ncov19_dash.flask_server import cache
from ncov19_dash.utils import STATES_COORD
from ncov19_dash.utils import config
import requests


px.set_mapbox_access_token(config.MAPBOX_ACCESS_TOKEN)
Expand Down
2 changes: 0 additions & 2 deletions ncov19_dash/components/stats_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from ncov19_dash.utils import REVERSE_STATES_MAP
from ncov19_dash.utils import config

from ncov19_dash.flask_server import cache


def stats_table(state="US"):
"""Callback to change between news and twitter feed
Expand Down
4 changes: 2 additions & 2 deletions ncov19_dash/components/twitter_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import requests
import dash_bootstrap_components as dbc
import dash_html_components as html
from ncov19_dash.flask_server import cache
from ncov19_dash.cache import server_cache
from ncov19_dash.utils import config
from ncov19_dash.utils import STATES_COORD


@cache.memoize(timeout=900)
@server_cache.memoize(timeout=900)
def twitter_feed(state="US") -> List[dbc.Card]:
"""Displays twitter feed on the left hand side of the display.
Expand Down
Loading

0 comments on commit f36a31a

Please sign in to comment.