def access(self, exam_id, **kw):
        
        exam_collection = Exam()
        metric_preprocessor = MetricPreProcessor()
        client_preprocessor = ClientPreProcessor()
        db_pre_processor = DBPreProcessor()
        
        exam_doc = exam_collection.query_doc(exam_id)
        #print exam_data
        
        exam_dict = db_pre_processor.unicode_dict_from_DB_to_string(exam_doc)
        
        packet_to_metric = metric_preprocessor.produce_packet(exam_dict)
        
        #print "TEST\n", packet_to_metric

        """ Calculate the statistics information """
        statistics_info = after(packet_to_metric)

        print statistics_info
        
        """ Prepare information that will send to client """
        exam_doc['practices'] = client_preprocessor.dict_to_list(exam_doc['practices'])
        exam_doc['practices'] = client_preprocessor.sort_by_id(exam_doc['practices'])
        exam_doc['practices'] = client_preprocessor.add_key_from_list(exam_doc['practices'],'correct_rate',statistics_info['correct_rate'])
        exam_doc['practices'] = client_preprocessor.add_key_from_list(exam_doc['practices'],'real_difficulty',statistics_info['real_difficulty'])

        exam = {
            'exam_doc':exam_doc,
            'exam_statics':statistics_info
        }
        
        return exam
    def access(self, exam_id, **kw):

        exam_collection = Exam()
        metric_preprocessor = MetricPreProcessor()
        client_preprocessor = ClientPreProcessor()
        db_pre_processor = DBPreProcessor()

        exam_doc = exam_collection.query_doc(exam_id)
        # print exam_data

        exam_dict = db_pre_processor.unicode_dict_from_DB_to_string(exam_doc)

        packet_to_metric = metric_preprocessor.produce_packet(exam_dict)

        """ Calculate the statistics information """
        statistics_info = all(packet_to_metric)

        """ Prepare information that will send to client """
        exam_doc["practices"] = client_preprocessor.dict_to_list(exam_doc["practices"])
        exam_doc["practices"] = client_preprocessor.sort_by_id(exam_doc["practices"])

        exam = {"exam_doc": exam_doc, "exam_statics": statistics_info}

        return exam
 def upload_excel(self,**kw):
     global exam_info
     
     """Decode the json string"""
     excel_info = json.loads(kw['excel_info'])
     
     """Preprocess the data from client"""
     client_pre_processor = ClientPreProcessor()
     
     
     """"Transform the format"""
     raw_ans_info = client_pre_processor.transform_fromat(excel_info,u'學生答題狀況',u'學號')
     raw_prac_info = client_pre_processor.transform_fromat(excel_info,u'試題資訊',u'試題編號')
     
     #print raw_ans_info
     #print raw_prac_info['1']
     
     """Delete unwanted column data"""
     raw_ans_info = client_pre_processor.drop_unwanted_column(raw_ans_info)
     #print raw_ans_info['1010102']
     
     
     """ Transform key from Chinese to Eng"""
     ans_info = client_pre_processor.chinese_to_eng(raw_ans_info)
     prac_info = client_pre_processor.chinese_to_eng(raw_prac_info)
     #print raw_ans_info['1010102']
     #print raw_prac_info['1']
     
     """ Transform meaning data to the format for DB """
     db_pre_processor = DBPreProcessor()
     exam_doc = db_pre_processor.init_exam_doc()
     #print "Init Doc:\n", exam_doc
     exam_doc = db_pre_processor.update_exam_mata_data(exam_doc,exam_info)
     #print "With Metadata:\n",exam_doc
     exam_doc = db_pre_processor.update_exam_ans_data(exam_doc,ans_info)
     #print "With Ans:\n",exam_doc['stu_ans']['1010102']
     exam_doc = db_pre_processor.update_exam_prac_data(exam_doc,prac_info)
     #print "With Prac:\n",exam_doc['practices']['3']
     
     """Store in DB"""
     exam_collection = Exam()
     exam_collection.insert_doc(exam_doc)
     
     redirect('/upload',params=dict(page='upload',message="Upload Success!"))