def getShopData (request): shopid = request.GET.get ('shopid', 256365) now = previews.nnow() res1 = toolsviews.QueryRestaurantOrders(shopid, now-datetime.timedelta(days=7), now) data1 = [] for x in res1: data1.append ([x.longitude, x.latitude]) cent, clus = toolsviews.KMeans (mat(data1), 5) geocoor1 = {} for i, x in enumerate(cent): print (x) geocoor1['商圈'+str(i)] = [x[0], x[1]] weid = [] for i in range (len(cent)): weid.append ({'name':'商圈' + str(i), 'value': 0}) for x in clus: t = int(x[0, 0]) weid[t]['value'] += 1 for i in range (len(cent)): weid[i]['value'] /= len (clus) al = {'a':geocoor1, 'b': weid} print (geocoor1) return HttpResponse(json.dumps(geocoor1), content_type="application/json")
def getChangeData (request): shopid = request.session.get ('shopid', 256365) menu = ['商圈1', '商圈2','商圈3','商圈4'] now = previews.nnow() before = (now - datetime.timedelta(days=7)) res = toolsviews.QueryRestaurantOrders(shopid,before,now) data = collections.OrderedDict() for i in range (7): t = (now - datetime.timedelta(days=7-i)).strftime("%m-%d") data[t] = 0 for x in res: timeStamp = x.order_time t = timeStamp.strftime("%m-%d") for v in x.foods: data[t] = data.get (t, 0) + 1 response_data = {} response_data['dates'] = [] response_data['values'] = [] for k, v in data.items(): response_data['dates'].append (k) response_data['values'].append (v) return HttpResponse(json.dumps(response_data), content_type="application/json")