Esempio n. 1
0
 def get(self):
     sections = [db.get(Key(i)) for i in self.request.get("keys").split(",")]
     classes = [i.class_id for i in sections]
     page = "view/imported_books.html"
     self.template_values['classes']= classes
     self.template_values['sections']= sections
     self.response.out.write(render_template(self.template_values, page))
Esempio n. 2
0
 def get(self):
     user_to = self.request.get("id")
     if user_to == "thewizard":
         self.template_values['to']= "Webmaster"
         self.template_values['email'] = "*****@*****.**"
     else:
         user_to = User.get(Key(user_to))
         self.template_values['to']=user_to.name
         self.template_values['email']=str(user_to.key())
     page="view/sendmessage.html"
     self.response.out.write(render_template(self.template_values, page))
Esempio n. 3
0
 def post(self):
     classn = []
     sections = []
     for i in re.finditer(r'([A-Z]+) (\w?\d+).(\d+).(\d+).(\d+)',self.request.get("book_import")):
         tmp = Class.gql("WHERE dept=:1 AND number=:2",i.group(1), i.group(2)).get()
         tmps = Section.gql("WHERE section=:1 AND semester=:2 AND class_id=:3", i.group(3), i.group(4)+i.group(5), tmp).get()
         if tmp:
             classn.append(tmp)
         if tmps:
             sections.append(tmps)
     page = "view/imported_books.html"
     self.template_values['classes']= classn
     self.template_values['sections']= sections
     self.response.out.write(render_template(self.template_values, page))
Esempio n. 4
0
 def getClass(self, section):
     if not section.name:
         section.name = section.class_id.name
         section.put()
     if not section.picture:
         self.template_values['picture']='/img/noimage_generic.jpg'
     else:
         self.template_values['picture']=section.picture.link
     self.template_values['is_class'] = True
     self.template_values['classbooks'] = ClassBooks.gql("WHERE section_id=:1",section)
     self.template_values['userclasses'] = UserClasses.gql("WHERE section_id=:1",section)
     self.template_values['title']="%s (%s %s)"%(section.name,
                                                 ("Spring" if section.semester[-2:-1]=="1" else "Summer" if section.semester[-2:-1]=="2" else "Fall"),
                                                  section.semester[:-1])
     self.response.out.write(render_template(self.template_values, self.page))
Esempio n. 5
0
 def getUser(self, user):
     if user.level < 2 and not self.template_values['signed_in']:
         self.redirect('/signup_page?redirect=%s'%self.request.url)
         return
     if not user.picture:
         self.template_values['picture']='/img/noimage.jpg'
     else:
         self.template_values['picture']=user.picture.link;
     self.template_values['title']=user.name
     if user.level != 2:
         self.template_values['newb'] = True
     self.template_values['pro'] = (user.cubmail == "*****@*****.**"
                                    or user.cubmail == "*****@*****.**"
                                    or user.cubmail == "*****@*****.**"
                                    or user.cubmail == "*****@*****.**")
     self.template_values['is_user'] = True
     self.template_values['user_class_list'] = UserClasses.gql("WHERE user_id=:1",user);
     self.template_values['book_want_list'] = UserBooks.gql("WHERE user_id=:1 AND status=:2",user,0)
     self.template_values['book_have_list'] = UserBooks.gql("WHERE user_id=:1 AND status=:2",user,1)
     self.response.out.write(render_template(self.template_values, self.page))
Esempio n. 6
0
def kaldi_adapt_lm(kaldi_root, src_model_dir, lm_fn, work_dir, dst_model_name):

    steps_path = '%s/egs/wsj/s5/steps' % kaldi_root
    if not os.path.exists(steps_path):
        raise Exception(
            '%s does not exist - is kaldi really installed in %s ?' %
            (steps_path, kaldi_root))

    tmpl_dir = os.path.dirname(os.path.abspath(__file__)) + '/templates'

    #
    # copy dictionary and phoneme sets from original model
    #
    logging.info("copying dictionary and phoneme sets from original model...")

    misc.mkdirs('%s/data/local/dict' % work_dir)
    misc.copy_file('%s/data/local/dict/lexicon.txt' % src_model_dir,
                   '%s/data/local/dict/lexicon.txt' % work_dir)
    misc.copy_file('%s/data/local/dict/nonsilence_phones.txt' % src_model_dir,
                   '%s/data/local/dict/nonsilence_phones.txt' % work_dir)
    misc.copy_file('%s/data/local/dict/silence_phones.txt' % src_model_dir,
                   '%s/data/local/dict/silence_phones.txt' % work_dir)
    misc.copy_file('%s/data/local/dict/optional_silence.txt' % src_model_dir,
                   '%s/data/local/dict/optional_silence.txt' % work_dir)
    misc.copy_file('%s/data/local/dict/extra_questions.txt' % src_model_dir,
                   '%s/data/local/dict/extra_questions.txt' % work_dir)

    #
    # language model
    #
    misc.copy_file(lm_fn, '%s/lm.arpa' % work_dir)

    #
    # create skeleton dst model
    #
    logging.info("creating skeleton destination model...")

    misc.mkdirs('%s/exp/adapt' % work_dir)

    misc.copy_file('%s/model/final.mdl' % src_model_dir,
                   '%s/exp/adapt/final.mdl' % work_dir)
    misc.copy_file('%s/model/cmvn_opts' % src_model_dir,
                   '%s/exp/adapt/cmvn_opts' % work_dir)
    misc.copy_file('%s/model/tree' % src_model_dir,
                   '%s/exp/adapt/tree' % work_dir)

    for optional_file in [
            'final.mat', 'splice_opts', 'final.occs', 'full.mat'
    ]:
        if os.path.exists('%s/model/%s' % (src_model_dir, optional_file)):
            misc.copy_file('%s/model/%s' % (src_model_dir, optional_file),
                           '%s/exp/adapt/%s' % (work_dir, optional_file))

    if os.path.exists('%s/extractor' % src_model_dir):

        misc.mkdirs('%s/exp/extractor' % work_dir)

        misc.copy_file('%s/extractor/final.mat' % src_model_dir,
                       '%s/exp/extractor/final.mat' % work_dir)
        misc.copy_file('%s/extractor/global_cmvn.stats' % src_model_dir,
                       '%s/exp/extractor/global_cmvn.stats' % work_dir)
        misc.copy_file('%s/extractor/final.dubm' % src_model_dir,
                       '%s/exp/extractor/final.dubm' % work_dir)
        misc.copy_file('%s/extractor/final.ie' % src_model_dir,
                       '%s/exp/extractor/final.ie' % work_dir)
        misc.copy_file('%s/extractor/splice_opts' % src_model_dir,
                       '%s/exp/extractor/splice_opts' % work_dir)

        misc.mkdirs('%s/exp/ivectors_test_hires/conf' % work_dir)

        misc.copy_file(
            '%s/ivectors_test_hires/conf/splice.conf' % src_model_dir,
            '%s/exp/ivectors_test_hires/conf' % work_dir)

    misc.mkdirs('%s/conf' % work_dir)
    misc.copy_file('%s/conf/mfcc.conf' % src_model_dir,
                   '%s/conf/mfcc.conf' % work_dir)
    misc.copy_file('%s/conf/mfcc_hires.conf' % src_model_dir,
                   '%s/conf/mfcc_hires.conf' % work_dir)
    misc.copy_file('%s/conf/online_cmvn.conf' % src_model_dir,
                   '%s/conf/online_cmvn.conf' % work_dir)

    #
    # copy scripts and config files
    #
    misc.copy_file('%s/kaldi-run-adaptation.sh' % tmpl_dir,
                   '%s/run-adaptation.sh' % work_dir)
    misc.copy_file('%s/kaldi-cmd.sh' % tmpl_dir, '%s/cmd.sh' % work_dir)
    misc.render_template('%s/kaldi-path.sh.template' % tmpl_dir,
                         '%s/path.sh' % work_dir,
                         kaldi_root=kaldi_root)
    misc.copy_file('%s/kaldi-model-dist.sh' % tmpl_dir,
                   '%s/model-dist.sh' % work_dir)

    misc.symlink('%s/egs/wsj/s5/steps' % kaldi_root, '%s/steps' % work_dir)
    misc.symlink('%s/egs/wsj/s5/utils' % kaldi_root, '%s/utils' % work_dir)

    cmd = '/bin/bash -c "pushd %s && bash run-adaptation.sh && popd"' % work_dir
    logging.info(cmd)
    os.system(cmd)

    cmd = '/bin/bash -c "pushd %s && bash model-dist.sh "%s" && popd"' % (
        work_dir, dst_model_name)
    logging.info(cmd)
    os.system(cmd)
Esempio n. 7
0
    def get(self):
        render_template(None, 'view/footer.html')
        render_template(None, 'view/header.html')
        render_template(None, 'view/scripts.html')
        path = self.request.path;
        um = UserManagement(self)
        signed_in = um.isLoggedIn()

        template_values = {'signed_in': signed_in, 'um':um}
        template_values['recent_comments'] = Comment.getRecent()
        page = "view/"
        if(path == "/"):
            page+="index.html"
            data = UserBooks().getRecent(20)
            template_values['recent_activity']=data
            template_values['is_homepage']=True
            template_values['title']="Home"
        elif(re.match(r'/find', path)):
            page+="find_books.html"
            template_values['title']="Find Books"
        elif(re.match(r'/about', path)):
            page+="about.html"
            template_values['about']=True
        elif(re.match(r'/settings', path)):
            page+="settings.html"
        elif(re.match(r'/search', path)):
            KeyHandler(self).get()
            return
        elif(re.match(r'/recent_listings', path)):
            page+="recent_listings.html"
            template_values['books'] = UserBooks().getRecent(100)
            template_values['title']="Recent Listings"
        elif(re.match(r'/complete',path)):
            page+="complete.html"
            if self.request.get("justsignedup"):
                template_values['justsignedup']=True
            template_values['task']="Mission"
        elif(re.match(r'/error',path)):
            page+="complete.html"
            template_values['reason']=self.request.get("type")
        elif(re.match(r'/profile',path)):
            if(signed_in):
                sh = SubjectHandler(self, template_values)
                sh.path = '/user/'+str(um.getUser().key())
                sh.template_values['profile'] = True
                sh.get()
                return
            else:
                self.redirect('/signup_page?redirect=%s'%self.request.url)
                return
        elif(re.match(r'/messages',path)):
            MessageHandler(self,template_values).get()
            return
        elif(re.match(r'/enroll', path)):
            class_id = self.request.get("class")
            try:
                section_id = Section.get(Key(class_id))
                user_id = um.getUser()
                userclass = UserClasses.gql("WHERE user_id = :1 AND section_id = :2", user_id, section_id).get()
                if not userclass:
                    userclass = UserClasses(user_id=user_id, section_id = section_id, relationship=0)
                    userclass.put()
                self.redirect("/complete")
            except Exception, e:
                self.redirect('/error?type='+str(e))
            return
Esempio n. 8
0
        elif(re.match(r'/sendmessage', path)):
            SendHandler(self,template_values).get()
            return
        else:
            m = re.match(r'/(book|user|class)/(.+)$', self.request.path)
            if(m):
                SubjectHandler(self, template_values).get()
                return
            elif(self.request.path == "/import"):
                ImportHandler(self, template_values).get()
                return
            else:
                self.redirect("/")

        try:
            self.response.out.write(render_template(template_values, page))
        except Exception, e:
            self.redirect("/signup_page?redirect=/&reason="+str(e))



apps_binding = []
apps_binding.append(('/image', GetImage))
#apps_binding.append(('/db_print', PrintDB))
#apps_binding.append(('/reset', ClearDB))
apps_binding.append(('/getbooksforclass', ClassHandler))
#apps_binding.append(('/get_classes', InitialSetup))
apps_binding.append(('/data', GetData))
apps_binding.append(('/act.*', UserAction))
apps_binding.append(('/login', UserManagement))
apps_binding.append(('/logout', UserManagement))
Esempio n. 9
0
 def get(self):
     page = "view/import_books.html"
     self.template_values['title']="Import"
     self.response.out.write(render_template(self.template_values, page))