├── image.png ├── main.py ├── README.md ├── page.py ├── .gitignore ├── graph.py └── LICENSE /image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MansikKun/FishSalesView/HEAD/image.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from page import * 3 | 4 | 5 | 6 | if 'page' not in st.session_state: 7 | st.session_state['page'] = 'HOME' 8 | 9 | menus={'날짜별':home,"장소별":mapping} 10 | 11 | with st.sidebar: 12 | for menu in menus.keys(): 13 | if st.button(menu, use_container_width=True, type='primary' if st.session_state['page']==menu else 'secondary'): 14 | st.session_state['page']=menu 15 | st.rerun() 16 | 17 | for menu in menus.keys(): 18 | if st.session_state['page']==menu: 19 | menus[menu]() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FishSalesView 2 | 3 | ![alt text](image.png) 4 | ## 추가 할 내용들 5 | 6 | ### 1번 페이지 7 | * 어종을 고르면 아래있는 그래프들이 변경됨 8 | * 위판일자 위판수량 꺾은선 그래프,위판중량 막대 그래프 9 | * 10 | ### 2번 페이지 11 | * 맨위에 지도를 표시하고 위판장 위치(산지위판장 데이터활용)마다 마커를생성 12 | * 아래쪽에 위판장별 어종 상태에따라 히트맵 그래프 13 | * 업종별로 어느 어종이 가장 큰비율을 차지하는지 원형 그래프로 표시 14 | ### (시간여유가 되면 추가) 15 | * 어종 검색시 가장 많이 파는 위판장,가격이 가장싼곳을 비교후 표시 16 | * 위판중량 별 위판금액을 산점도로 표시 17 | * 위판금액 대비 어종을 막대 그래프로 표시 18 | * 19 | 20 | --- 21 | 2024/03/14 22 | * 1page 초안 완성 23 | * 위판일자 데이터를 문자열이아닌 데이트타임타입으로 변경/위판일자가 다안채워진 자료를 부른후 더양이많은 자료를 불렀을때 꺾은선 그래프가 꼬이는 문제 해결 24 | * 25 | --- 26 | 2024/03/15 27 | * 2page 지도,마커추가 28 | * 히트맵 추가(어종상태 선택시 히트맵 표시로 변경예정/변경완료,산지조합의 개수가 많으면 인덱스에 전부다 표시되지않는 경우가있음/해결) 29 | * 원그래프추가(레이블들이 서로 곂치는 문제있음/너무 작은 값들은 기타로 묶기+어종 레이블 박스에 따로표시) 30 | 31 | --- 32 | -------------------------------------------------------------------------------- /page.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from graph import * 3 | 4 | 5 | def home(): 6 | with st.sidebar: 7 | selected_fishes = st.multiselect('수산물 종류 선택', df['수산물표준코드명'].unique()) 8 | 9 | st.write('어종별 위판량 추이') 10 | date_amount(selected_fishes) 11 | st.write('어종별 평균중량 추이') 12 | date_height(selected_fishes) 13 | def mapping(): 14 | with st.sidebar: 15 | selected_species = st.selectbox('어종상태', options=(df_fish['어종상태명'].unique().tolist())) 16 | filtered_df = df_fish[df_fish['어종상태명'] == selected_species] 17 | selected_association = st.selectbox('산지조합', options=(filtered_df['산지조합명'].unique().tolist())) 18 | map_maker() 19 | hitmap(filtered_df) 20 | 21 | toggle_merge = st.checkbox('작은 값들을 "기타"로 묶기',value=True) 22 | association_data = filtered_df[filtered_df['산지조합명'] == selected_association] 23 | round(association_data,toggle_merge) 24 | 25 | pass -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | data/ 2 | # Byte-compiled / optimized / DLL files 3 | __pycache__/ 4 | *.py[cod] 5 | *$py.class 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | .Python 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | cover/ 54 | 55 | # Translations 56 | *.mo 57 | *.pot 58 | 59 | # Django stuff: 60 | *.log 61 | local_settings.py 62 | db.sqlite3 63 | db.sqlite3-journal 64 | 65 | # Flask stuff: 66 | instance/ 67 | .webassets-cache 68 | 69 | # Scrapy stuff: 70 | .scrapy 71 | 72 | # Sphinx documentation 73 | docs/_build/ 74 | 75 | # PyBuilder 76 | .pybuilder/ 77 | target/ 78 | 79 | # Jupyter Notebook 80 | .ipynb_checkpoints 81 | 82 | # IPython 83 | profile_default/ 84 | ipython_config.py 85 | 86 | # pyenv 87 | # For a library or package, you might want to ignore these files since the code is 88 | # intended to run in multiple environments; otherwise, check them in: 89 | # .python-version 90 | 91 | # pipenv 92 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 93 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 94 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 95 | # install all needed dependencies. 96 | #Pipfile.lock 97 | 98 | # poetry 99 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 100 | # This is especially recommended for binary packages to ensure reproducibility, and is more 101 | # commonly ignored for libraries. 102 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 103 | #poetry.lock 104 | 105 | # pdm 106 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 107 | #pdm.lock 108 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 109 | # in version control. 110 | # https://pdm.fming.dev/#use-with-ide 111 | .pdm.toml 112 | 113 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 114 | __pypackages__/ 115 | 116 | # Celery stuff 117 | celerybeat-schedule 118 | celerybeat.pid 119 | 120 | # SageMath parsed files 121 | *.sage.py 122 | 123 | # Environments 124 | .env 125 | .venv 126 | env/ 127 | venv/ 128 | ENV/ 129 | env.bak/ 130 | venv.bak/ 131 | 132 | # Spyder project settings 133 | .spyderproject 134 | .spyproject 135 | 136 | # Rope project settings 137 | .ropeproject 138 | 139 | # mkdocs documentation 140 | /site 141 | 142 | # mypy 143 | .mypy_cache/ 144 | .dmypy.json 145 | dmypy.json 146 | 147 | # Pyre type checker 148 | .pyre/ 149 | 150 | # pytype static type analyzer 151 | .pytype/ 152 | 153 | # Cython debug symbols 154 | cython_debug/ 155 | 156 | # PyCharm 157 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 158 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 159 | # and can be added to the global gitignore or merged into this file. For a more nuclear 160 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 161 | #.idea/ 162 | -------------------------------------------------------------------------------- /graph.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import matplotlib.pyplot as plt 3 | import numpy as np 4 | import streamlit as st 5 | import matplotlib.font_manager as fm 6 | 7 | import seaborn as sns 8 | 9 | from folium.plugins import MarkerCluster 10 | import folium 11 | from streamlit_folium import st_folium 12 | 13 | #한글폰트 지정 14 | plt.rcParams['font.family'] ='Malgun Gothic' 15 | 16 | df_fish = pd.read_csv('C:\workspace\FisherySalesView\data\해양수산부_위판장별위탁판매현황.CSV', encoding='cp949') 17 | df_shop = pd.read_csv('C:\workspace\FisherySalesView\data\산지위판장.csv', encoding='cp949') 18 | df = pd.DataFrame(df_fish) 19 | def date_amount(selected_fishes): 20 | #위판일자 데이터를 문자열이아닌 데이트타임타입으로 변경 21 | df['위판일자'] = pd.to_datetime(df['위판일자']) 22 | # 사용자가 여러 수산물 종류를 선택할 수 있도록 multiselect 사용 23 | 24 | 25 | # 위판일자별, 수산물 종류별로 위판수량 합계 계산 26 | summed_df = df.groupby(['위판일자', '수산물표준코드명'])['위판수량'].sum().reset_index() 27 | 28 | # 맷플롯립을 이용한 꺾은선 그래프 그리기 29 | #사이즈 설정 30 | plt.figure(figsize=(20, 10)) 31 | 32 | # 선택된 수산물 종류별로 그래프 그리기 33 | for fish in selected_fishes: 34 | fish_df = summed_df[summed_df['수산물표준코드명'] == fish] 35 | fish_df['위판일자'] 36 | plt.plot(np.array(fish_df['위판일자']),np.array(fish_df['위판수량']), label=fish, marker='o') 37 | 38 | plt.title('선택된 수산물 종류별 위판량 추이') 39 | plt.xlabel('위판일자') 40 | plt.ylabel('위판수량') 41 | plt.xticks(rotation=60) 42 | plt.legend() 43 | plt.tight_layout() 44 | 45 | # 스트림릿을 통해 그래프 보여주기 46 | return st.pyplot(plt) 47 | def date_height(selected_fishes): 48 | 49 | 50 | # 위판일자별, 수산물 종류별로 위판수량 합계 계산 51 | summed_df = df.groupby(['위판일자', '수산물표준코드명'])['위판중량'].mean().reset_index() 52 | 53 | # 맷플롯립을 이용한 막대그래프 그리기 54 | # 크기조정 55 | plt.figure(figsize=(20, 10)) 56 | # 바의 너비 설정 57 | bar_width = 0.35 58 | 59 | # 선택된 수산물 종류별로 그래프 그리기 60 | for fish in selected_fishes: 61 | fish_df = summed_df[summed_df['수산물표준코드명'] == fish] 62 | 63 | plt.bar(np.array(fish_df['위판일자']),np.array(fish_df['위판중량']), label=fish, alpha=0.7) 64 | 65 | plt.title('선택된 수산물 종류별 평균중량 추이') 66 | plt.xlabel('위판일자') 67 | plt.ylabel('위판중량') 68 | plt.xticks(rotation=60) 69 | plt.legend() 70 | plt.tight_layout() 71 | 72 | # 스트림릿을 통해 그래프 보여주기 73 | return st.pyplot(plt) 74 | #------------------------- 75 | def map_maker(): 76 | # Streamlit 애플리케이션 제목 77 | st.title('전국 위판장 위치') 78 | # 위도와 경도에서 NaN 값이 있는 행 제거 79 | df_shop.dropna(subset=['위도', '경도'], inplace=True) 80 | 81 | # 지도 생성 및 마커 추가 82 | m = folium.Map(location=[37.5665, 126.9780], zoom_start=7) 83 | marker_cluster = MarkerCluster().add_to(m) 84 | 85 | for idx, row in df_shop.iterrows(): 86 | folium.Marker(location=[row['위도'], row['경도']], tooltip=row['조합명']).add_to(marker_cluster) 87 | 88 | # 스트림릿에서 지도 표시 89 | return st_folium(m, width=725) 90 | pass 91 | def hitmap(filtered_df): 92 | # 히트맵에 사용할 데이터 준비 93 | pivot_table = filtered_df.pivot_table(index='산지조합명', columns='어종상태명', values='위판수량', aggfunc='mean') 94 | 95 | # 히트맵 생성을 위한 Figure와 Axes 객체 생성 96 | fig, ax = plt.subplots(figsize=(10, 11)) 97 | sns.heatmap(pivot_table, annot=True, fmt=".1f", cmap="YlGnBu", ax=ax ,yticklabels=True) 98 | plt.yticks(rotation=0) 99 | # 스트림릿에서 Figure 객체 전달 100 | return st.pyplot(fig) 101 | 102 | pass 103 | def round(association_data,toggle_merge): 104 | 105 | if toggle_merge: 106 | # 어종별 위판수량 집계 107 | species_counts = association_data.groupby('수산물표준코드명')['위판수량'].mean() 108 | # 수량 크기대로 내림차순 정리 109 | df_sorted = species_counts.sort_values(ascending=False) 110 | # 퍼센트 게이지 범위 설정, 너무 작은 것들 합치기 111 | threshold = 0.028 112 | other = df_sorted[df_sorted / df_sorted.sum() < threshold].sum() 113 | df_filtered = df_sorted[df_sorted / df_sorted.sum() >= threshold] 114 | df_filtered['기타'] = other # 너무 작은 값들을 '기타'로 합침 115 | else: 116 | # 어종별 위판수량 집계만 진행 117 | species_counts = association_data.groupby('수산물표준코드명')['위판수량'].mean() 118 | df_filtered = species_counts.sort_values(ascending=False) 119 | 120 | # 원그래프 그리기 121 | fig, ax = plt.subplots(figsize=(10, 8.5)) 122 | wedges, texts, autotexts = ax.pie(df_filtered, 123 | labels=df_filtered.index, 124 | autopct='%1.1f%%', 125 | textprops={'fontsize': 10}) 126 | 127 | ax.axis('equal') # 동그란 원 형태 유지 128 | #어종따로 표시 129 | ax.legend(wedges, df_filtered.index, 130 | title="어종", 131 | loc="center left", 132 | bbox_to_anchor=(1, 0, 0.5, 1)) 133 | 134 | # 스트림릿에서 그래프 출력 135 | st.pyplot(fig) 136 | #------------------------- -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------