Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
TBrost committed Oct 1, 2023
1 parent 128f77e commit d2b4bcc
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 34 deletions.
Binary file modified __pycache__/basis_prices.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/cash_prices.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/futures_prices.cpython-311.pyc
Binary file not shown.
46 changes: 37 additions & 9 deletions basis_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import requests
import io
import plotly.express as px
from datetime import datetime
from datetime import date
def basis_page():
st.title("Basis Prices")
#st.write("Below is the cash price for wheat in different strands in different parts of the state. Select the region and strand you are interested in and the table and the chart will adjust to your input. This data is separated into rows by week of the year. In many areas and strands there is no information recorded, but for every week there should be an aggregate value for referance")
Expand Down Expand Up @@ -34,7 +36,18 @@ def basis_page():
'Select a Strain',
('Basis - Wheat (SWW)','Basis - Wheat (HRW)','Basis - Wheat (DNS)'))

start_date = st.date_input("Start Date", date(2015, 12, 31))
start_date = datetime(start_date.year, start_date.month, start_date.day)
end_date = st.date_input("End Date")
end_date = datetime(end_date.year, end_date.month, end_date.day)

df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')
df['Date'] = df['Date'].dt.strftime("%Y/%d/%m")
df['Date'] = pd.to_datetime(df['Date'], format='%Y/%d/%m')
# Filter the DataFrame based on the selected date range
df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]

df = df[['Location','year','week_of_year', 'Attribute','Value']]

wheat_table=df.query('Attribute == @ATTRIBUTE & Location == @CITY')

Expand Down Expand Up @@ -66,18 +79,33 @@ def convert_df(df):
['Median', 'Max', 'Min']
)

#st.line_chart(df_pivot[['Average','Max','Min']])
# Create a Plotly line chart
fig = px.line(df_pivot, x='week of year', y=selected_columns, title='Three Lines Chart')
fig = px.line(df_pivot, x='week of year', y=selected_columns, title='Value Summaries by week of the year:')
st.plotly_chart(fig)




#st.subheader('Charted over the Year')
#st.write("Seelct which metrics you want to see, you can select multiple")


st.subheader('Annual Summary')

# List of columns to exclude from summarization
exclude_columns = ['Location', 'Attribute','week of year','Average','Median','Max','Min','Standard Deviation']

# Identify columns to summarize (exclude the excluded columns)
columns_to_summarize = [col for col in df_pivot.columns if col not in exclude_columns]


# Summarize selected columns and save to another DataFrame
summary_df = pd.DataFrame({
'Mean': df_pivot[columns_to_summarize].mean(),
'Min': df_pivot[columns_to_summarize].min(),
'Max': df_pivot[columns_to_summarize].max()
})
# Reshape the DataFrame
summary_df = summary_df.reset_index(names=['year', 'Mean', 'Min', 'Max'])
fig2 = px.line(summary_df, x='year', y=['Mean', 'Max', 'Min'], title='Summary values over years (not adjusted for inflation):')
summary_df.set_index('year', inplace=True)
# Transpose (T) the DataFrame and reset the index
reshaped_df = summary_df.T
st.dataframe(reshaped_df)
st.plotly_chart(fig2)
#def link_to_github():
# href = '<a href="https://github.com/Lusk27/app_display/tree/main/Data" target="_blank">Link to GitHub</a>'
# return href
Expand Down
48 changes: 39 additions & 9 deletions cash_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import requests
import io
import plotly.express as px
from datetime import datetime
from datetime import date
def cash_page():
st.title("Cash Prices")
#st.write("Below is the cash price for wheat in different strands in different parts of the state. Select the region and strand you are interested in and the table and the chart will adjust to your input. This data is separated into rows by week of the year. In many areas and strands there is no information recorded, but for every week there should be an aggregate value for referance")
Expand Down Expand Up @@ -32,9 +34,14 @@ def cash_page():
ATTRIBUTE = st.selectbox(
'Select a Strain',
('Barley (Feed)', 'Barley (Malting)', 'SWW (Milling)', 'HRW (11.5% Protein)', 'DNS (14% Protein)', 'HWW'))
start_date = st.date_input("Start Date")
start_date = st.date_input("Start Date", date(2015, 12, 31))
start_date = datetime(start_date.year, start_date.month, start_date.day)
end_date = st.date_input("End Date")
end_date = datetime(end_date.year, end_date.month, end_date.day)

df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')
df['Date'] = df['Date'].dt.strftime("%Y/%d/%m")
df['Date'] = pd.to_datetime(df['Date'], format='%Y/%d/%m')
# Filter the DataFrame based on the selected date range
df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]

Expand Down Expand Up @@ -74,17 +81,40 @@ def convert_df(df):
['Median', 'Max', 'Min']
)

#st.line_chart(df_pivot[['Average','Max','Min']])
# Create a Plotly line chart
fig = px.line(df_pivot, x='week of year', y=selected_columns, title='Three Lines Chart')
fig = px.line(df_pivot, x='week of year', y=selected_columns, title='Value Summaries by week of the year:')
st.plotly_chart(fig)




#st.subheader('Charted over the Year')
#st.write("Seelct which metrics you want to see, you can select multiple")

st.subheader('Annual Summary')

# List of columns to exclude from summarization
exclude_columns = ['Location', 'Attribute','week of year','Average','Median','Max','Min','Standard Deviation']

# Identify columns to summarize (exclude the excluded columns)
columns_to_summarize = [col for col in df_pivot.columns if col not in exclude_columns]


# Summarize selected columns and save to another DataFrame
summary_df = pd.DataFrame({
'Mean': df_pivot[columns_to_summarize].mean(),
'Min': df_pivot[columns_to_summarize].min(),
'Max': df_pivot[columns_to_summarize].max()
})
# Reshape the DataFrame
summary_df = summary_df.reset_index(names=['year', 'Mean', 'Min', 'Max'])
fig2 = px.line(summary_df, x='year', y=['Mean', 'Max', 'Min'], title='Summary values over years (not adjusted for inflation):')
summary_df.set_index('year', inplace=True)
# Transpose (T) the DataFrame and reset the index
reshaped_df = summary_df.T
st.dataframe(reshaped_df)
st.plotly_chart(fig2)

#selected_columns2 = st.selectbox(
# 'Select summary columns for the line chart',
# [2016, 2017, 2018, 2019, 2020,2021,2022, 2023, 2024],7
#)
#fig2 = px.line(df_pivot, x='week of year', y=selected_columns2, title='Value over selected year year:')
#st.plotly_chart(fig2)

#def link_to_github():
# href = '<a href="https://github.com/Lusk27/app_display/tree/main/Data" target="_blank">Link to GitHub</a>'
Expand Down
45 changes: 37 additions & 8 deletions futures_prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import requests
import io
import plotly.express as px
from datetime import datetime
from datetime import date
def futures_page():
st.title("Future Prices")
#st.write("Below is the cash price for wheat in different strands in different parts of the state. Select the region and strand you are interested in and the table and the chart will adjust to your input. This data is separated into rows by week of the year. In many areas and strands there is no information recorded, but for every week there should be an aggregate value for referance")
Expand Down Expand Up @@ -33,7 +35,19 @@ def futures_page():
ATTRIBUTE = st.selectbox(
'Select a Strain',
('Future - SWW', 'Future - HRW', 'Future - DNS'))

start_date = st.date_input("Start Date", date(2015, 12, 31))
start_date = datetime(start_date.year, start_date.month, start_date.day)
end_date = st.date_input("End Date")
end_date = datetime(end_date.year, end_date.month, end_date.day)

df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')
df['Date'] = df['Date'].dt.strftime("%Y/%d/%m")
df['Date'] = pd.to_datetime(df['Date'], format='%Y/%d/%m')
# Filter the DataFrame based on the selected date range
df = df[(df['Date'] >= start_date) & (df['Date'] <= end_date)]

df = df[['Location','year','week_of_year', 'Attribute','Value']]

wheat_table=df.query('Attribute == @ATTRIBUTE & Location == @CITY')

Expand Down Expand Up @@ -65,17 +79,32 @@ def convert_df(df):
['Median', 'Max', 'Min']
)

#st.line_chart(df_pivot[['Average','Max','Min']])
# Create a Plotly line chart
fig = px.line(df_pivot, x='week of year', y=selected_columns, title='Three Lines Chart')
fig = px.line(df_pivot, x='week of year', y=selected_columns, title='Value Summaries by week of the year:')
st.plotly_chart(fig)




#st.subheader('Charted over the Year')
#st.write("Seelct which metrics you want to see, you can select multiple")

st.subheader('Annual Summary')

# List of columns to exclude from summarization
exclude_columns = ['Location', 'Attribute','week of year','Average','Median','Max','Min','Standard Deviation']

# Identify columns to summarize (exclude the excluded columns)
columns_to_summarize = [col for col in df_pivot.columns if col not in exclude_columns]

# Summarize selected columns and save to another DataFrame
summary_df = pd.DataFrame({
'Mean': df_pivot[columns_to_summarize].mean(),
'Min': df_pivot[columns_to_summarize].min(),
'Max': df_pivot[columns_to_summarize].max()
})
# Reshape the DataFrame
summary_df = summary_df.reset_index(names=['year', 'Mean', 'Min', 'Max'])
fig2 = px.line(summary_df, x='year', y=['Mean', 'Max', 'Min'], title='Summary values over years (not adjusted for inflation):')
summary_df.set_index('year', inplace=True)
# Transpose (T) the DataFrame and reset the index
reshaped_df = summary_df.T
st.dataframe(reshaped_df)
st.plotly_chart(fig2)

#def link_to_github():
# href = '<a href="https://github.com/Lusk27/app_display/tree/main/Data" target="_blank">Link to GitHub</a>'
Expand Down
16 changes: 8 additions & 8 deletions testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -24,16 +24,16 @@
"# Make a GET request to the raw file URL\n",
"response = requests.get(raw_url, headers=headers)\n",
"df = pd.read_csv(io.StringIO(response.text))\n",
"\n",
"df2 = df[['Location','year','week_of_year', 'Attribute','Value']]\n",
"\n",
"df_pivot = df.pivot(index=['Attribute','week_of_year', 'Location', 'Contract', 'Date'], columns=['year'], values='Value')\n",
"#df_pivot['Average'] = df_pivot.mean(axis=1)\n",
"#df_pivot['Median'] = df_pivot.median(axis=1)\n",
"#df_pivot['Max'] = df_pivot.max(axis=1)\n",
"#df_pivot['Min'] = df_pivot.min(axis=1)\n",
"#df_pivot['Standard Deviation'] = df_pivot.std(axis=1)\n",
"df_pivot['Average'] = df_pivot.mean(axis=1)\n",
"df_pivot['Median'] = df_pivot.median(axis=1)\n",
"df_pivot['Max'] = df_pivot.max(axis=1)\n",
"df_pivot['Min'] = df_pivot.min(axis=1)\n",
"df_pivot['Standard Deviation'] = df_pivot.std(axis=1)\n",
"\n",
"#df_pivot = df_pivot.reset_index(names=['Attribute', 'week of year', 'Location'])"
"df_pivot = df_pivot.reset_index(names=['Attribute', 'week of year', 'Location', 'Contract', 'Date'])"
]
}
],
Expand Down

0 comments on commit d2b4bcc

Please sign in to comment.