양선아

5/29 update

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://127.0.0.1:8000/market_analysis/returnfarm?maptype=9&contenttype=edu",
"webRoot": "${workspaceFolder}"
}
]
}
\ No newline at end of file
......@@ -11,23 +11,33 @@
</head>
<body>
<h1><a href="http://127.0.0.1:8000/market_analysis/maplist">Statistics on Return Farm Project</a></h1>
<!--body-->
<div id="bodyWrap">
<div id="header">
<h1><a href="/market_analysis/maplist">Statistics on Return Farm Project</a></h1>
<br>
<h3>농산물 시장 유통에 대한 통계분석 입니다.</h3>
<br>
</div>
<div id="menubar">
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" href="http://127.0.0.1:8000/market_analysis/market">Market</a>
<a class="nav-link active" href="/market_analysis/market">Market</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1:8000/market_analysis/population">Population</a>
<a class="nav-link" href="/market_analysis/population">Population</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1:8000/market_analysis/returnfarm">Return Farm</a>
<a class="nav-link" href="/market_analysis/returnfarm">Return Farm</a>
</li>
</ul>
</div>
</div>
<!--content-->
<div id="contentWrap">
<h6>
explain 들어가는 부분
</h6>
</div>
</body>
</html>
\ No newline at end of file
......
......@@ -44,48 +44,48 @@
</head>
<body>
<h1><a href="http://127.0.0.1:8000/market_analysis/maplist">Statistics on Return Farm Project</a></h1>
<div id="bodyWrap">
<div id="header">
<h1><a href="/market_analysis/maplist">Statistics on Return Farm Project</a></h1>
<br>
<h3>농산물 시장 유통에 대한 통계분석 입니다.</h3>
<br>
</div>
<div id="menubar">
<ul class="nav justify-content-center">
<li class="nav-item">
<a class="nav-link active" href="http://127.0.0.1:8000/market_analysis/market">Market</a>
<a class="nav-link active" href="/market_analysis/market">Market</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1:8000/market_analysis/population">Population</a>
<a class="nav-link" href="/market_analysis/population">Population</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1:8000/market_analysis/returnfarm">Return Farm</a>
<a class="nav-link" href="/market_analysis/returnfarm">Return Farm</a>
</li>
</ul>
<!--return farm 단독 부분-->
<ul class="nav nav-pills mb-3" id="pills-tab" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-home-tab" data-toggle="pill" href="#pills-home" role="tab" aria-selected="true">지역</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">내용</a>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">교육</a>
<a class="dropdown-item" href="#">지원정책</a>
</div>
</li>
<li class="nav-item" role="presentation">
<a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#pills-contact" role="tab" aria-selected="false">Return Farm</a>
</li>
</ul>
<div class="tab-content" id="pills-tabContent">
<div class="tab-pane fade" id="pills-home" role="tabpanel" aria-labelledby="pills-home-tab">Hello</div>
<div class="tab-pane fade" id="pills-profile" role="tabpanel" aria-labelledby="pills-profile-tab">Bonjour</div>
<div class="tab-pane fade" id="pills-contact" role="tabpanel" aria-labelledby="pills-contact-tab">안녕하세요</div>
</div>
<div id="mapbase"></div>
<!--return farm 단독 부분-->
<div id="contentWrap">
<!--검색 바 만든 부분-->
<div id="searchmenu">
<form action="{% url 'returnfarm' %}" method="GET">
<div class="form-group">
<select name="maptype">
<option value="9">시도</option>
<option value="10">시군구</option>
</select>
<select name="contenttype">
<option value="edu">귀농귀촌 교육 수</option>
<option value="policy">귀농귀촌 정책 수 </option>
</select>
<input type="submit">
</div>
</form>
</div>
<!--지도 생성 부분-->
<div id="mapbase">
<script type="text/javascript">
///////////// 지도 생성해주는 부분임 //////////////
// map 객체 생성 map안에 넣어주는건 div id
// 위도, 경도, zoom 수준
var map = L.map('mapbase', {zoomDelta: 0.25, zoomSnap: 0}).setView([36.5205243,128.0540569], 7);
......@@ -101,48 +101,64 @@
// mapdata 가져오는 부분
// replace 쓰는 방법 : (바꾸기 전 문자, 바꾸고 난 후 문자)
var statesdata = "{{maps}}".replace(/&quot;/g,"\"");
var statesdata = "{{maps.mapdata}}".replace(/&quot;/g,"\"");
statesdata = JSON.parse(statesdata);
function getColor(d) {
return d > 30 ? '#800026' :
d > 25 ? '#BD0026' :
d > 20 ? '#E31A1C' :
d > 15 ? '#FC4E2A' :
d > 10 ? '#FD8D3C' :
d > 5 ? '#FEB24C' :
d > 0 ? '#FED976' :
'#FFEDA0';
}
function style(feature) {
return {
fillColor: getColor(feature.properties.density),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
let key = Object.keys(statesdata.features[1].properties);
</script>
</div>
<!--지도에 밀도 데이터 받는 부분-->
<div id="density_mapping">
{% for data in exportdata %}
<script>
// density data 추가하는 부분
for(var j=0; j<statesdata.features.length; j++)
{
if ("{{maps.id}}"==9){
if (statesdata.features[j]['properties'][key[2]]=="{{data.city}}")
{
statesdata.features[j]['properties']['density']="{{data.count}}";
break;
}
}
else
{
if (statesdata.features[j]['properties'][key[2]]=="{{data.cntr}}")
{
statesdata.features[j]['properties']['density']="{{data.count}}";
break;
}
}
}
</script>
{% endfor %}
</div>
<!--지도의 큰 모양 바꾸는 부분-->
<div id="map_design">
<script>
var geojson;
var density_max = 100;
function getColor(d) {
return d > density_max*0.9 ? '#FF0015' :
d > density_max*0.8 ? '#F20D20' :
d > density_max*0.7 ? '#E6192A' :
d > density_max*0.6 ? '#D92635' :
d > density_max*0.5 ? '#CC3340' :
d > density_max*0.4 ? '#BF404A' :
d > density_max*0.3 ? '#B34D55' :
d > density_max*0.2 ? '#A65960' :
d > density_max*0.1 ? '#99666A' :
'#8C7375';
}
function style(feature) {
return {
fillColor: getColor(feature.properties.density),
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
L.geoJson(statesdata, {style: style}).addTo(map);
// mouseover event listener
function highlightFeature(e) {
......@@ -179,11 +195,10 @@
style: style,
onEachFeature: onEachFeature
}).addTo(map);
</script>
</div>
<!--information, legend, zoom 넣는 부분-->
<div class="info"></div>
<div class="map_info">
<script>
var info = L.control();
......@@ -207,7 +222,7 @@
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 5, 10, 15, 20, 25, 30],
grades = [0, density_max*0.1, density_max*0.2, density_max*0.3, density_max*0.4,density_max*0.5, density_max*0.6, density_max*0.7, density_max*0.8,density_max*0.9],
labels = [],
from, to;
......@@ -222,8 +237,8 @@
return div;
};
legend.addTo(map);
</script>
</div>
</div>
</body>
</html>
\ No newline at end of file
......
from django.conf.urls import url
from django.urls import path
from . import views
urlpatterns = [
url('returnfarm/<int:maptype>', views.returnfarm),
url('population', views.population),
url('returnfarm', views.returnfarm, name="returnfarm"),
url('population', views.population, name="population"),
url('market', views.market),
url('', views.main),
]
\ No newline at end of file
......
#-*- coding:utf-8
from django.shortcuts import render
from django.db.models import Count
from django.db.models import Count, Max
from urllib.request import urlopen
from .models import RT_edu, Maps, RT_agri_policy
from bs4 import BeautifulSoup
import pandas as pd
# Create your views here.
def dbselect(contenttype, maptype):
def returnfarm_dbselect(contenttype, maptype):
if maptype == 9:
mapt = 'city'
elif maptype == 10:
mapt = 'cntr'
if contenttype=='policy':
myrtrn = RT_agri_policy.objects.values(mapt).annotate(count=Count(mapt))
return myrtrn
......@@ -17,18 +21,41 @@ def dbselect(contenttype, maptype):
myrtrn = RT_edu.objects.values(mapt).annotate(count=Count(mapt))
return myrtrn
# 공공데이터 불러오는 부분
def publicdata():
# 통계청 귀농가구원의 시도별, 시군별, 연령별
url = 'http://kosis.kr/openapi/statisticsData.do?method=getList&apiKey=M2I3MWFhNzE2MjlkYjhhNzgwNWFjNWQ3MGU0MzY5Y2Y=&format=json&jsonVD=Y&userStatsId=tjsdk3105/101/DT_1A02003/2/1/20200529160216&prdSe=Y&newEstPrdCnt=1'
data = urlopen(url).read().decode('utf8')
return data
def main(request):
return render(request, 'main.html')
def returnfarm(request, maptype):
mapp = Maps.objects.get(id=maptype)
mapp = mapp.mapdata
exportdatas = dbselect('policy', maptype)
def returnfarm(request):
try:
maptype = request.GET['maptype']
contenttype = request.GET['contenttype']
mapp = Maps.objects.get(id=int(maptype))
exportdatas = returnfarm_dbselect(contenttype, int(maptype))
except:
mapp = Maps.objects.get(id=9)
exportdatas = {}
context = {'exportdata': exportdatas, 'maps':mapp}
return render(request, 'returnfarm.html', context)
def population(request):
return render(request, 'population.html')
try:
maptype = request.GET['maptype']
densitytype = request.GET['densitytype']
mapp = Maps.objects.get(id=int(maptype))
exportdatas = publicdata()
except:
mapp = Maps.objects.get(id=9)
exportdatas = {}
exportdatas = publicdata()
context = {'exportdata': exportdatas, 'maps':mapp}
return render(request, 'population.html', context)
def market(request):
return render(request, 'market.html')
\ No newline at end of file
......
No preview for this file type
No preview for this file type
No preview for this file type