From 081ff0cdcdd31186108070b5dd9a9859fa7b6e92 Mon Sep 17 00:00:00 2001
From: xinjiel2 <xinjielan1@gmail.com>
Date: Sun, 12 May 2019 22:40:35 +1000
Subject: [PATCH] real time

---
 web_app_django/tweet/views.py | 77 +++++++++++++++++++++++++++++++++--
 1 file changed, 74 insertions(+), 3 deletions(-)

diff --git a/web_app_django/tweet/views.py b/web_app_django/tweet/views.py
index b7bdf01..30b18fe 100644
--- a/web_app_django/tweet/views.py
+++ b/web_app_django/tweet/views.py
@@ -23,14 +23,85 @@ def index(request):
         #GET /tweet_resutls/_design/city/_view/city-view HTTP/1.1
 
         cityInfo = []
-        for doc in docs.view('city/city-view',group = True):
+        cityTotal = []
+        cityPercentage = {}
+        for doc in docs.view('results/result-view',group = True):
 
             print(doc.key, doc.value)
             cityInfo.append(doc)
-        print(cityInfo)
-            
+        for doc in docs.view('results/cityTweet-view',group = True):
+
+            #print(doc.key,doc.value)
+            #cityTotal.append(doc)
+            for data in cityInfo:
+                if data.key == doc.key:
+                    number = (data.value/doc.value)*100
+                    percentage = str(round(number,2))+"%"
+                    #print(percentage)
+                    cityPercentage[data.key] = percentage
+        
+
+        #print(cityTotal)
+
+        #print(cityInfo)
+
+        context = cityPercentage
         context = {'cityInfo':cityInfo}
 
+        docsNsw = SERVER['aurin_nsw']
+        #print(docs)
+        #print(docs.view('city/city-view',key = "melbourne"))
+        countId = []
+        #print(docs['f6376ce946ac201c045408615e00d502'])
+        for doc in docsNsw:
+            features = docsNsw[doc]['features']
+            for feature in features:
+                countId.append(feature["id"])
+            print(len(countId))
+        docsNswDomestic = SERVER['aurin_nsw_domestic']
+        for doc in docsNswDomestic.view('domesitc/new-view'):
+            for element in doc.value:
+                #print(doc.value[element])
+                countDomesitc += doc.value[element]
+        countDomesitc += len(countId)
+        print(countDomesitc)
+        context = {'NswCount':countDomesitc}
+            
+            #print(docs[doc]['features'])
+        #GET /tweet_resutls/_design/city/_view/city-view HTTP/1.1
+        docsVic = SERVER['aurin_vic']
+        att = ['a10','a20','a50','a80']
+        count = 0
+        for doc in docsVic.view('vic/new-view'):
+
+            #print(doc.key, doc.value)
+            for properties in doc.value:
+                #print(properties)
+                for element in properties:
+                    if element in att:
+                    
+                        if properties[element] == 'lga_code_2011':
+                            continue
+                        elif properties[element] == None:
+                            continue
+                        else:
+                            count += properties[element]
+            print(count)
+            context = {'VicCount':count}
+        docsSa = SERVER['aurin_sa']
+        countForSa = 0
+        for doc in docsSa.view('sa/new-view'):
+            for properties in doc.value:
+                for element in properties:
+                    if element == 'month' or element == "id":
+                        continue
+                    else:
+                        if not properties[element] == None:
+                            #print(countForSa)
+                            countForSa += properties[element]
+        print(countForSa)
+        context = {'SaCount':countForSa}
+
         #context = {'file':2}
     else:
         context = {'file':error}
-- 
GitLab