-
Notifications
You must be signed in to change notification settings - Fork 1
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
Update workflow #24
Merged
Merged
Update workflow #24
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,74 @@ | ||
import dask.dataframe as dd | ||
import plotly.express as px | ||
import datetime | ||
import time | ||
|
||
import pandas as pd | ||
import streamlit as st | ||
|
||
from pipeline.settings import RESULTS_DIR | ||
|
||
|
||
@st.cache_data | ||
def get_data(region, part_type): | ||
return dd.read_parquet( | ||
RESULTS_DIR / region / part_type.upper() / "*.parquet" | ||
).compute() | ||
|
||
def get_data(segment): | ||
return pd.read_parquet(RESULTS_DIR / f"{segment.lower()}.snappy.parquet") | ||
|
||
description = """ | ||
### Recommended Suppliers | ||
_Some text that explains the business problem being addressed..._ | ||
|
||
This query finds which supplier should be selected to place an order for a given part in a given region. | ||
st.markdown( | ||
""" | ||
### Top Unshipped Orders | ||
_Top 50 unshipped orders with the highest revenue._ | ||
""" | ||
st.markdown(description) | ||
regions = list(map(str.title, ["EUROPE", "AFRICA", "AMERICA", "ASIA", "MIDDLE EAST"])) | ||
region = st.selectbox( | ||
"Region", | ||
regions, | ||
index=None, | ||
placeholder="Please select a region...", | ||
) | ||
part_types = list(map(str.title, ["COPPER", "BRASS", "TIN", "NICKEL", "STEEL"])) | ||
part_type = st.selectbox( | ||
"Part Type", | ||
part_types, | ||
|
||
SEGMENTS = ["automobile", "building", "furniture", "machinery", "household"] | ||
|
||
|
||
def files_exist(): | ||
# Do we have all the files needed for the dashboard? | ||
files = list(RESULTS_DIR.rglob("*.snappy.parquet")) | ||
return len(files) == len(SEGMENTS) | ||
|
||
|
||
with st.spinner("Waiting for data..."): | ||
while not files_exist(): | ||
time.sleep(5) | ||
|
||
segments = list( | ||
map(str.title, ["automobile", "building", "furniture", "machinery", "household"]) | ||
) | ||
segment = st.selectbox( | ||
"Segment", | ||
segments, | ||
index=None, | ||
placeholder="Please select a part type...", | ||
placeholder="Please select a product segment...", | ||
) | ||
if region and part_type: | ||
df = get_data(region, part_type) | ||
if segment: | ||
df = get_data(segment) | ||
df = df.drop(columns="o_shippriority") | ||
df["l_orderkey"] = df["l_orderkey"].map(lambda x: f"{x:09}") | ||
df["revenue"] = df["revenue"].round(2) | ||
now = datetime.datetime.now() | ||
dt = now.date() - datetime.date(1995, 3, 15) | ||
df["o_orderdate"] = (df["o_orderdate"] + dt).dt.date | ||
df = df.rename( | ||
columns={ | ||
"n_name": "Country", | ||
"s_name": "Supplier", | ||
"s_acctbal": "Balance", | ||
"p_partkey": "Part ID", | ||
"l_orderkey": "Order ID", | ||
"o_orderdate": "Date Ordered", | ||
"revenue": "Revenue", | ||
} | ||
) | ||
maxes = df.groupby("Country").Balance.idxmax() | ||
data = df.loc[maxes] | ||
figure = px.choropleth( | ||
data, | ||
locationmode="country names", | ||
locations="Country", | ||
featureidkey="Supplier", | ||
color="Balance", | ||
color_continuous_scale="viridis", | ||
hover_data=["Country", "Supplier", "Balance"], | ||
|
||
df = df.set_index("Order ID") | ||
st.dataframe( | ||
df.style.format({"Revenue": "${:,}"}), | ||
column_config={ | ||
"Date Ordered": st.column_config.DateColumn( | ||
"Date Ordered", | ||
format="MM/DD/YYYY", | ||
help="Date order was placed", | ||
), | ||
"Revenue": st.column_config.NumberColumn( | ||
"Revenue (in USD)", | ||
help="Total revenue of order", | ||
), | ||
}, | ||
) | ||
st.plotly_chart(figure, theme="streamlit", use_container_width=True) | ||
on = st.toggle("Show data") | ||
if on: | ||
st.write( | ||
df[["Country", "Supplier", "Balance", "Part ID"]], use_container_width=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
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 was deleted.
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to do more than just add
now - 1995
or whatever. We might want to do an affine transform so that the entire previous range (like1985-1995
) gets squeezed into the last hour.