From d2b4bcc2fcbe81857273338f5bf14bc4d2a0bd27 Mon Sep 17 00:00:00 2001 From: Tyson Brost Date: Sun, 1 Oct 2023 11:54:51 -0600 Subject: [PATCH] Update --- __pycache__/basis_prices.cpython-311.pyc | Bin 3514 -> 3514 bytes __pycache__/cash_prices.cpython-311.pyc | Bin 3541 -> 5910 bytes __pycache__/futures_prices.cpython-311.pyc | Bin 3499 -> 3499 bytes basis_prices.py | 46 ++++++++++++++++---- cash_prices.py | 48 +++++++++++++++++---- futures_prices.py | 45 +++++++++++++++---- testing.ipynb | 16 +++---- 7 files changed, 121 insertions(+), 34 deletions(-) diff --git a/__pycache__/basis_prices.cpython-311.pyc b/__pycache__/basis_prices.cpython-311.pyc index 064f25201149be8cd89164c7cd3a8964504e124c..bc12397cb066bcd7d48112bd33bb5a85c5d97128 100644 GIT binary patch delta 62 zcmdlby-S*RIWI340}zwry-NPLZLWF`IX?`?ClHU(f<0e&vh& OAy@cAHcRjKodwq(goTyG+poD8DNO*ac0H|Ozq0m zM%uJOTDGDJ>O-}nDrFT`n~(j-$A0YBYCmVtNU=tWHqxpe`6Fs0?dEIG9eWJpLe=5s z-gECg_q@-!*ZJP>_hRt$xo18n2)tV42@4`B0z31^6mW8L=v=sqmd&N?NZ zxsPGS3K_T^8*P-=T9%72~hq@7@KonjtGNJr>Ne)J#Cy zG7rWCnHr|{0eIpe@`mwM(D6zw<_?Bsyz|xO4B)cX00+!q-AJfE*Mq3t6RvPy4K`BgH6c9+2_ zMaFx>fw)$z`feEcAVa^US=N{v0DNdpv23j+{|=fP8GojBDdV)FjwcV<1 zw$5UetthFel@KL$`Q4)L_zuxmw~H6+Ag?jz1myR?&pcTVJleOZTLzg{=FRn!)+&l5 znm=TsWE*zTqrs|gMMQ2zOMN9CgTdS4)MeQ>M2mCOI|3JDMcpY)3%n@FRrG8(8{?DR z@XDa&8q`M+UUV3so|t$`cS!sVHYx9)lcbb55Qzx%?VedqnoCcoMOJ{L5}TBIVtgX< z3XjOnNP^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k?9s4%5jxkBFI+`adLX3QZnD_)F9G^yV%tro7T z%!=hVYa)d30Qn?69*IIW6Mnm6WVPF!a=Id)t;%QTPpxsjg`veng-cbr)GC+ytfa`E zNV?w##OS^5#qo;JRu$Uj2PjwNVl_dn`K4MgR`ZAJe$E^F2B`dGQfKl@B6lN)hA*!Q z6BS{iDonVJ3nPmI6)sWb606OLyJ+qi!ST};A?=2dv+y2Pp>I~p>zaxC=mz&P*-s9| wws#+6OIGs>;JUi~_{|@_QPAfMbOeu66T3&|B)K0uk*<4=LYSl$FF#-TW=o6X% delta 62 zcmZ22y;_=gIWI340}zx=6HV>d$a{y4k$3Vdwry= start_date) & (df['Date'] <= end_date)] + + df = df[['Location','year','week_of_year', 'Attribute','Value']] wheat_table=df.query('Attribute == @ATTRIBUTE & Location == @CITY') @@ -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 = 'Link to GitHub' # return href diff --git a/cash_prices.py b/cash_prices.py index eb1309a..dcbb480 100644 --- a/cash_prices.py +++ b/cash_prices.py @@ -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") @@ -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)] @@ -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 = 'Link to GitHub' diff --git a/futures_prices.py b/futures_prices.py index d8b0558..f20e387 100644 --- a/futures_prices.py +++ b/futures_prices.py @@ -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") @@ -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') @@ -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 = 'Link to GitHub' diff --git a/testing.ipynb b/testing.ipynb index dce4daf..6f1bbea 100644 --- a/testing.ipynb +++ b/testing.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -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'])" ] } ],