Commits

kon...@konbit-vm.media.mit.edu  committed bd7e119

lenght of audio added to stats and db

  • Participants
  • Parent commits db89e2c

Comments (0)

Files changed (2)

File search/server.py

 
 from csv_unicode import csv_unicode
 
+import commands
+
 #mongo
 import pymongo, pymongo.json_util, json
 
   def get(self):
     conn = pymongo.Connection(options.mongo_host, options.mongo_port)
     db = conn.konbit_translate
-    peopleCollection = db.people.sort("asterisk_id")
+    peopleCollection = db.people
+    people = peopleCollection.find().sort("asterisk_id")
 
     i = 0
-    for person in peopleCollection:
+    for person in people:
       for key,item in person.iteritems():
         if type(item) is dict:
           if 'audio_length' not in person[key]:
             fpath = "/recordings/%d/%s.processed.mp3" % (int(person["asterisk_id"]), key)
             cmd = "nice sox %s -n stat 2>&1 | grep Length" % fpath
-            statOutput = runSystemCommand(cmd)
+            statOutput = self.runSystemCommand(cmd)
             lengthInSeconds = float(statOutput.replace("Length (seconds):", "").strip())
             lengthInMinutes = lengthInSeconds / 60.0
             person[key]['audio_length'] = lengthInMinutes
-      i += 1
-      if i > 2: break
+            peopleCollection.save(person)
+            logging.info("id %s, %s:%r" % (person['asterisk_id'], key, lengthInMinutes))
+      	    i += 1
+    self.write("%d messages computed" % i)
 
-  def runSystemCommand(cmd):
+  def runSystemCommand(self,cmd):
     """Runs a system command.
     If it does not exit successfully (error code 0), it raises an exception.
 
     #logging.debug("Exit %r: %r" % (status, output))
     if int(status) != 0:
       errorMsg = "Could not process %s; returned %r with message: %r" % (file, status, output)
-      raise Exception(errorMsg)
+      #raise Exception(errorMsg)
+      return "-1"
     return output
 
 

File translate/server.py

           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['completely_translated'] == False:
         totalPeopleLeft += 1
       totalPeople += 1
 
-    stats = {"messages: total":totalMessages,"messages: translated":totalMessages-totalMessagesLeft,"people: total":totalPeople,"people: finished":totalPeople-totalPeopleLeft,"average time worked (mins)":((totalMessages-totalMessagesLeft)*12)/60,"percent complete":(totalMessages-totalMessagesLeft)/float(totalMessages)*100}
+    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))