Commits

Anonymous committed 6401a01

get specific stats for user, see list of all translators

  • Participants
  • Parent commits 5c297aa

Comments (0)

Files changed (3)

search/.server.py.swp

Binary file removed.

search/static/js/.search.js.swp

Binary file removed.

translate/server.py

           (r'/importTranslation', ImportTranslation),
           (r'/importTranslator', ImportTranslator),
           (r'/log', Log),
-          (r'/stats', Stats)
+          (r'/stats', Stats),
+          (r'/translators', Translators)
         ]
         settings = dict(
         login_url=options.root_url + "login",
     db = conn.konbit_translate
     peopleCollection = db.people
     people = peopleCollection.find().sort("asterisk_id").limit(3000)
+    translatorEmail = self.get_argument("translator",None)
+    user = self.get_current_user()
+    if user['email'] != translatorEmail and translatorEmail:
+      self.write("you can't view other translators stats!")
+      return
     
     totalMessages = 0
     totalMessagesLeft = 0
     totalPeople = 0
     totalPeopleLeft = 0
     totalTimeSpent = 0
+    messagesTranslated = 0
     for person in people:
       for key, item in person.iteritems():
         if type(item) is dict:
-          if person[key]['translated'] == False and person[key]['not_translatable'] == False:
-            #logging.error(person[key])
-            totalMessagesLeft += 1
-          elif person[key]['translated'] == True and 'audio_length' in person[key]:
-           totalTimeSpent += person[key]['audio_length'] * 2
-          if person[key]['not_translatable'] == False: totalMessages += 1
+          if person[key]['translator'] == translatorEmail or translatorEmail is None:
+            if person[key]['translated'] == False and person[key]['not_translatable'] == False:
+              #logging.error(person[key])
+              totalMessagesLeft += 1
+            elif person[key]['translated'] == True and 'audio_length' in person[key]:
+             totalTimeSpent += person[key]['audio_length'] * 2
+             messagesTranslated += 1
+            if person[key]['not_translatable'] == False: totalMessages += 1
       if person['completely_translated'] == False:
         totalPeopleLeft += 1
       totalPeople += 1
 
-    stats = {"messages: total":totalMessages,"messages: translated":totalMessages-totalMessagesLeft,"people: total":totalPeople,"people: finished":totalPeople-totalPeopleLeft,"total time worked (mins)":totalTimeSpent,"percent complete":(totalMessages-totalMessagesLeft)/float(totalMessages)*100}
+    if translatorEmail:
+      stats = {" translator":translatorEmail,"messages: translated":messagesTranslated,"total time worked (mins)":totalTimeSpent}
+    else:
+      stats = {"messages: total":totalMessages,"messages: translated":totalMessages-totalMessagesLeft,"people: total":totalPeople,"people: finished":totalPeople-totalPeopleLeft,"total time worked (mins)":totalTimeSpent,"percent complete":(totalMessages-totalMessagesLeft)/float(totalMessages)*100}
 
     self.write(json_encode(stats))
             
     
+class Translators(BaseHandler):
+  @tornado.web.authenticated
+  def get(self):
+    conn = pymongo.Connection(options.mongo_host, options.mongo_port)
+    db = conn.konbit_translate
+    translatorsCollection = db.translators
+    translators = translatorsCollection.find().sort("email")
     
+    translatorEmails = ""
+    for translator in translators:
+      translatorEmails += "<BR> <a href='stats?translator=%s'>%s</a>" % (translator['email'], translator['email'])
+
+    self.write(translatorEmails)
+