Skip to content

Commit

Permalink
clean up awesome data explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Skov Madsen authored and Marc Skov Madsen committed Feb 5, 2020
1 parent b0728ae commit ab191b2
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 23 deletions.
Expand Up @@ -6,7 +6,9 @@
Author: [Ali Avni Cirik](https://www.linkedin.com/in/aliavnicirik)\n
Source: [Github](https://github.com/aliavni/awesome-data-explorer)
"""
import logging
from pathlib import Path
from typing import Dict, Tuple, Union

import altair as alt
import git
Expand All @@ -18,6 +20,7 @@

@st.cache
def get_awesome_data_repo():
"""Clones the data catalogue"""
try:
git.Git(".").clone("https://github.com/awesomedata/apd-core")
except git.GitCommandError:
Expand All @@ -26,38 +29,68 @@ def get_awesome_data_repo():


@st.cache
def get_categories_and_file_names() -> dict:
p = Path("apd-core/core")
category_files = {}
for i in p.glob("**/*"):
def get_categories_and_file_names() -> Dict:
"""Returns a dictionary of categories and files
Returns
-------
Dict
Key is the name of the category, value is a dictionary with information on files in that \
category
"""
path = Path("apd-core/core")
category_files: Dict = {}
for i in path.glob("**/*"):
if i.is_dir():
continue

category, file_name = i.parts[-2:]

file = Path("apd-core/core") / category / file_name
try:
with file.open() as open_file:
data_info = yaml.load(open_file.read(), Loader=yaml.FullLoader)

with file.open() as f:
data_info = yaml.load(f.read(), Loader=yaml.FullLoader)

if category in category_files:
category_files[category][file_name] = data_info
else:
category_files[category] = {file_name: data_info}
if category in category_files:
category_files[category][file_name] = data_info
else:
category_files[category] = {file_name: data_info}
except UnicodeDecodeError as err:
logging.exception("Error. Could not read %s", file.name, exc_info=err)

return category_files


def get_data_info(category: str, file_name: str) -> dict:
p = Path("apd-core/core") / category / file_name
def get_data_info(category: str, file_name: str) -> Dict:
"""Returns a dictionary of information on the specified file
with p.open() as f:
data = yaml.load(f.read(), Loader=yaml.FullLoader)
Parameters
----------
category : str
The name of the category, like 'Sports'
file_name : str
A name of a file
Returns
-------
Dict
Information on the file
"""
path = Path("apd-core/core") / category / file_name

with path.open() as open_file:
data = yaml.load(open_file.read(), Loader=yaml.FullLoader)
return data


def create_info_table(selected_data_info):
def create_info_table(selected_data_info: Dict):
"""Writes the information to the table
Parameters
----------
selected_data_info : Dict
The information to show
"""
info_table = pd.DataFrame()

data_description = selected_data_info["description"]
Expand All @@ -79,21 +112,34 @@ def create_info_table(selected_data_info):


@st.cache()
def check_url(url: str):
def check_url(url: str) -> Tuple[bool, Union[str, requests.Response]]:
"""Returns information on the availability of the url
Parameters
----------
url : str
The url to test
Returns
-------
Tuple[bool, Union[str, Response]]
Whether the url is available and a string reponse
"""
try:
response = requests.head(url, allow_redirects=False)
return True, response
except requests.exceptions.SSLError as e:
except requests.exceptions.SSLError:
return False, "SSL error"
except requests.exceptions.ConnectionError as e:
except requests.exceptions.ConnectionError:
return False, "Connection error"
except requests.exceptions.InvalidSchema as e:
except requests.exceptions.InvalidSchema:
return False, "Invalid schema"
except requests.exceptions.MissingSchema as e:
except requests.exceptions.MissingSchema:
return check_url("https://" + url)


def show_homepage(data_info):
"""Shows information on the availability of the url to the user"""
homepage = data_info["homepage"]

if homepage.startswith("http:"):
Expand All @@ -118,6 +164,7 @@ def show_homepage(data_info):


def main():
"""Run this to run the programme"""
st.title("Awesome Data Explorer")
st.markdown("This app explores data in the Awesome Public Datasets repository.")

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,4 +1,4 @@
"""This app demonstrates the use of the awesome [deck.gl](https://deck.gl/#/) framework for visual
"""This app demonstrates the use of the awesome [deck.gl]() framework for visual
exploratory data analysis of large datasets.
Deck.gl is now (as of Streamlit v. 0.53) supported via the
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions mypy.ini
Expand Up @@ -40,3 +40,5 @@ ignore_missing_imports=True
ignore_missing_imports=True
[mypy-pydeck.*]
ignore_missing_imports=True
[mypy-git.*]
ignore_missing_imports=True
2 changes: 1 addition & 1 deletion package/awesome_streamlit/database/apps_in_gallery.py
Expand Up @@ -22,7 +22,7 @@
APPS_IN_GALLERY = [
Resource(
name="Awesome Data Explorer",
url=GITHUB_RAW_GALLERY_URL + "awesome_data_explorer/app.py",
url=GITHUB_RAW_GALLERY_URL + "awesome_data_explorer/awesome_data_explorer.py",
tags=[tags.CODE, tags.APP_IN_GALLERY],
is_awesome=True,
author=authors.ALI_AVNI_CIRIK,
Expand Down
15 changes: 15 additions & 0 deletions scripts/issues/issue_duplicate_widget.py
@@ -0,0 +1,15 @@
import streamlit as st
import time

slider_ph = st.empty()
info_ph = st.empty()

value = slider_ph.slider("slider", 0, 100, 25, 1)
info_ph.info(value)

if st.button('animate'):
for x in range(20):
time.sleep(.5)

value = slider_ph.slider("slider", 0, 100, value + 1, 1)
info_ph.info(value)

0 comments on commit ab191b2

Please sign in to comment.