You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB

from SS01.utils import getPublicData
import random
import time
travelMapData = getPublicData.getAllTravelInfoMapData()
def getIndexTagData(): #获得数据库中的数据
A5Len = 0
commentsLenMax = 0
commentsLenTitle = ''
provienceDic = {}
for travel in travelMapData:
if travel.level == '5A景区':
A5Len += 1
if int(travel.commentsLen) > commentsLenMax:
commentsLenMax = int(travel.commentsLen)
commentsLenTitle = travel.title
if provienceDic.get(travel.province,-1) == -1:
provienceDic[travel.province] = 1
else:
provienceDic[travel.province] += 1
provienceDicSort = list(sorted(provienceDic.items(),key=lambda x:x[1],reverse=True))[0][0]
return A5Len,commentsLenTitle,provienceDicSort
def getAnthorData(): #获得数据库中评分数据
scoreTop10 = []
for travel in travelMapData:
if travel.score == '5':
scoreTop10.append(travel)
maxLen = len(scoreTop10)
scoreTop10Data = []
for i in range(10):
randomIndex = random.randint(0, maxLen - 1)
scoreTop10Data.append(scoreTop10[randomIndex])
saleCountTop10 = list(sorted(travelMapData,key=lambda x:int(x.saleCount),reverse=True))[:10]#对销量前十进行排序
return scoreTop10Data,saleCountTop10
def getNowTime(): #时间
timeFormat = time.localtime()
year = timeFormat.tm_year
mon = timeFormat.tm_mon
day = timeFormat.tm_mday
return year,mon,day
def getGeoData():
dataDic = {}
for i in travelMapData:
for j in getPublicData.cityList:
for city in j['city']:
if city.find(i.province) != -1:
if dataDic.get(j['province'],-1) == -1:
dataDic[j['province']] = 1
else:
dataDic[j['province']] += 1
resultData = []
for key,value in dataDic.items():
resultData.append({
'name':key,
'value':value,
})
return resultData