From 9bb991e8a15477ec60c47219fd762638ecff8c66 Mon Sep 17 00:00:00 2001
From: xinjiel2 <xinjielan1@gmail.com>
Date: Mon, 13 May 2019 00:04:06 +1000
Subject: [PATCH] server complete

---
 web_app_django/tweet/templates/index.html | 31 ++++++++++++------
 web_app_django/tweet/views.py             | 39 +++++++++++++++++++----
 2 files changed, 54 insertions(+), 16 deletions(-)

diff --git a/web_app_django/tweet/templates/index.html b/web_app_django/tweet/templates/index.html
index 0c88329..4fb600e 100644
--- a/web_app_django/tweet/templates/index.html
+++ b/web_app_django/tweet/templates/index.html
@@ -11,20 +11,31 @@
       <td>{{city.key}}</td>
       <td> {{city.value}}</td>
      
+       {% endfor %}
+       {% for city1 in cityTotal %}
+      <td>{{city1.melbourne}}</td>
+      <td> {{city1.sydney}}</td>
+      <td> {{city1.adelaide}}</td>
+      <td> {{city1.perth}}</td>
+      <td> {{city1.brisbane}}</td>
+     
+       {% endfor %}
+      
+     <td>{{NswCount}}</td>
+     <td>{{VicCount}}</td>
+     <td>{{SaCount}}</td>
+     {% for cityOld in cityTotalOld %}
+      <td>{{cityOld.melbourne}}</td>
+      <td> {{cityOld.sydney}}</td>
+      <td> {{cityOld.adelaide}}</td>
+     
        {% endfor %}
     {%else%}
     <hr>NO DATA</hr>
-    {% endif %}
     
-     <td>{{melbourne}}</td>
-     <td>{{sydney}}</td>
-     <td>{{adelaide}}</td>
-     <td>{{perth}}</td>
-     <td>{{brisbane}}</td>
-     <td>{{NswCount}}</td>
-     <td>{{VicCount}}</td>
-     <td>{{SacCount}}</td>
-       
+    
+     
+     {% endif %}
     </body>
      
       
diff --git a/web_app_django/tweet/views.py b/web_app_django/tweet/views.py
index 5f13fa0..6423e19 100644
--- a/web_app_django/tweet/views.py
+++ b/web_app_django/tweet/views.py
@@ -12,6 +12,7 @@ except:
 # Create your views here.
 
 def index(request):
+    context = {}
     
     
     if error == "no":
@@ -29,6 +30,7 @@ def index(request):
 
             print(doc.key, doc.value)
             cityInfo.append(doc)
+        print("space")
         for doc in docs.view('results/cityTweet-view',group = True):
 
             #print(doc.key,doc.value)
@@ -46,8 +48,9 @@ def index(request):
 
         #print(cityInfo)
 
-        context = {'cityTotal':cityTotal}
-        context = {'cityInfo':cityInfo}
+        context['cityTotal'] = cityTotal
+        context['cityInfo'] = cityInfo
+        
 
         docsNsw = SERVER['aurin_nsw']
         #print(docs)
@@ -59,7 +62,7 @@ def index(request):
             features = docsNsw[doc]['features']
             for feature in features:
                 countId.append(feature["id"])
-            print(len(countId))
+            #print(len(countId))
         docsNswDomestic = SERVER['aurin_nsw_domestic']
         for doc in docsNswDomestic.view('domesitc/new-view'):
             for element in doc.value:
@@ -67,7 +70,7 @@ def index(request):
                 countDomesitc += doc.value[element]
         countDomesitc += len(countId)
         print(countDomesitc)
-        context = {'NswCount':countDomesitc}
+        context['NswCount'] = countDomesitc
             
             #print(docs[doc]['features'])
         #GET /tweet_resutls/_design/city/_view/city-view HTTP/1.1
@@ -89,7 +92,7 @@ def index(request):
                         else:
                             count += properties[element]
             print(count)
-            context = {'VicCount':count}
+            context['VicCount'] = count
         docsSa = SERVER['aurin_sa']
         countForSa = 0
         for doc in docsSa.view('sa/new-view'):
@@ -102,7 +105,31 @@ def index(request):
                             #print(countForSa)
                             countForSa += properties[element]
         print(countForSa)
-        context = {'SaCount':countForSa}
+        context['SaCount'] = countForSa
+
+
+
+
+
+        docs = SERVER['tweet_2014_raw']
+        cityInfoOld = []
+        cityTotalOld = []
+        cityPercentageOld = {}
+        for doc in docs.view('results/result-view',group = True):
+            cityInfoOld.append(doc)
+            print(doc.key, doc.value)
+        print("total")
+        for doc in docs.view('results/cityTweet-view',group = True):
+            for data in cityInfoOld:
+                if data.key == doc.key:
+                    number = (data.value/doc.value)*100
+                    percentage = str(round(number,2))+"%"
+                    #print(percentage)
+                    cityPercentageOld[data.key] = percentage
+        cityTotalOld.append(cityPercentageOld)
+        context['cityTotalOld'] = cityTotalOld
+        print(cityTotalOld)
+
 
         #context = {'file':2}
     else:
-- 
GitLab