예제 #1
0
 def test_it_creates_an_array_from_a_file(self):
     # given a file
     filename = os.getcwd() + '/10.txt'
     # and a file importer
     file_importer = FileImporter(filename)
     # get an array from the file
     arr = file_importer.get_array()
     # check the size of the array
     self.assertEqual(len(arr), 10)
     # check if the values are in the array
     self.assertEqual(arr, [17, 63, 31, 95, 51, 38, 30, 22, 33, 83])
예제 #2
0
 def __init__(self, import_name):
     super(AudioRec, self).__init__(import_name)
     
     self.route("/audiorec/")(self.audiorec)
     self.route("/select")(self.selectArticlePage)
     self.route("/loading-results/")(self.loadScreen)
     self.route("/selectfunc", methods=['GET','POST'])(self.text_choice_func)
     self.fi = STTFileImporter()
     self.am = AnalysisManager()
     self.dbh = DatabaseHelper().getInstance()
     self.tipSelector = FileImporter()
     lh = LoggerHelper().getInstance()
     self.recordinglogger = lh.createLoggerWorker("recording","DEBUG",2)
     self.recordinglogger.info("Audio Rec Instantiated")
예제 #3
0
class AudioRec(flask.Flask):
    def __init__(self, import_name):
        super(AudioRec, self).__init__(import_name)
        
        self.route("/audiorec/")(self.audiorec)
        self.route("/select")(self.selectArticlePage)
        self.route("/loading-results/")(self.loadScreen)
        self.route("/selectfunc", methods=['GET','POST'])(self.text_choice_func)
        self.fi = STTFileImporter()
        self.am = AnalysisManager()
        self.dbh = DatabaseHelper().getInstance()
        self.tipSelector = FileImporter()
        lh = LoggerHelper().getInstance()
        self.recordinglogger = lh.createLoggerWorker("recording","DEBUG",2)
        self.recordinglogger.info("Audio Rec Instantiated")
        
    def text_choice_func(self):
        if flask.request.method == "POST":
            file = flask.request.form['file']
            file += '.txt'
            orderNames = self.fi.getOrdering(flask.session['sessionID'])
            for val in orderNames:
                text_files = fnmatch.filter(os.listdir('files/daily-articles/' + val + '/' ), '*.txt')
                
                if file in text_files:
                    try:
                        f = open('files/daily-articles/' + val + '/' + file)
                    except:
                        f = codecs.open('files/daily-articles/' + val + '/' + file, "r", encoding="windows-1252")
                    self.text = f.read()
                    self.text = self.fi.trimText(self.text)
                    return flask.jsonify('complete')

        return flask.render_template('wrong.html')
    
    @login_required
    def selectArticlePage(self):
        orderNames = self.fi.getOrdering(flask.session['sessionID'])
        orderImages = []
        orderhead1 = []
        orderhead2 = []
        orderhead3 = []
        
        countEmpty = 0
        self.flasklogger.debug("{}".format(orderNames))
        for val in orderNames:
            with open('files/Daily-Articles/ArticleSites.txt') as f:
                for line in f:
                    line = line.split()
                    if line[0] == val:
                        orderImages.append(line[3])
            
            text_files = fnmatch.filter(os.listdir('files/daily-articles/' + val + '/' ), '*.txt')
            self.flasklogger.debug("text files: {}".format(text_files))
           
            while len(text_files)< 3:
                text_files.append("EMPTY")
                countEmpty += 1
                self.flasklogger.debug("Number of empty values: {}".format( countEmpty))
            orderhead1.append(text_files[0].replace(".txt", ''))
            orderhead2.append(text_files[1].replace(".txt", ''))
            orderhead3.append(text_files[2].replace(".txt", ''))
        
        if countEmpty < 9:
            ser_imgs = pd.Series(orderImages, index = [orderNames], name = "images")
            ser_head1 = pd.Series(orderhead1, index = [orderNames], name = "head1")
            ser_head2 = pd.Series(orderhead2, index = [orderNames], name = "head2")
            ser_head3 = pd.Series(orderhead3, index = [orderNames], name = "head3")
        
            frame = pd.concat([ser_imgs,ser_head1,ser_head2,ser_head3],axis=1)
            frame.to_json("static/json/prefs.json")
            f = open("static/json/prefs.json", 'r')
            jsonstring = f.read()
            return flask.render_template('selectArticle.html', jsonstring=jsonstring)
        else:
            self.flasklogger.debug("Number of empty values: {}".format( countEmpty))
            self.text = self.fi.loadFile()
            return flask.redirect('/audiorec/')
        
    # This function deals with the recording page
    @login_required    
    def audiorec(self):
        try:
            self.tip = self.tipSelector.loadFile()
            self.userID = flask.session['sessionID']
            self.username = flask.session['user']
            return flask.render_template('recordnew.html', value = self.text, username=self.username,
                                         filename=self.am.generateFilename(self.username))
        except Exception as e:
            self.recordinglogger.error("Recording Page Failed: Exception:{0}".format(e))
            return flask.render_template('wrong.html', error = "{}".format(e))
    # This function starts the analysis threads
    @login_required
    def loadScreen(self):
        try:
            self.am.startAnalysis(self.userID,self.text)
            return flask.render_template('loading.html', value = self.tip)
        except Exception as e:
            self.recordinglogger.error("Load Screen Failed: Exception:{0}".format(e))
            return flask.render_template('wrong.html', error = "{}".format(e))
예제 #4
0
            psr.genHypothesis()
        except Exception as e:
            logger.error("Failed to generate hypothesis".format(e))
            self.fail("Failed generating hypothesis")


class FacialAnalyzerTestCases(unittest2.TestCase):
    def test_analysis_thread(self):
        try:
            facialAnalyzer.beginAnalysisThread("test_img_no_delete", 1010, dbh,
                                               "testfilename", "TEST")
        except Exception as e:
            logger.error("Facial Analyzer Thread Failed".format(e))
            self.fail("Facial Analyzer Thread Failed")


if __name__ == '__main__':
    lh = LoggerHelper().getInstance()
    logger = lh.createLoggerWorker("unittest", "DEBUG", 2)
    dbh = DatabaseHelper().getInstance()
    facialAnalyzer = FacialAnalyzer()
    ac = AccuracyChecker()
    afa = AudioFeatureAnalyzer("UnittestAudio\\TestCase.wav")
    sfi = STTFileImporter()
    fi = FileImporter()
    formatter = STTFormatter()
    psr = pocketSphinxRecognizer(
        "pocketsphinx-data\\en-US\\acoustic-model",
        'pocketsphinx-data\\en-US\\language-model.lm.bin',
        'pocketsphinx-data\\en-US\\pronounciation-dictionary.dict')
    unittest2.main()
예제 #5
0
from FileImporter import FileImporter
from FileWriter import FileWriter
from os.path import basename

if __name__ == '__main__':
    # begin execution

    if len(sys.argv) < 3:
        print("Not enough paramaters")
        exit(1)

    bucket_size = int(sys.argv[1])
    input_file_name = str(sys.argv[2])
    output_file_name = "owens-" + \
        os.path.splitext(basename(input_file_name))[
            0] + "-" + str(bucket_size) + ".txt"
    fw = FileWriter(output_file_name)
    fi = FileImporter(input_file_name)
    arr = fi.get_array()
    start_times = []
    end_times = []
    for _ in range(3):
        start_times.append(time.clock())
        ret = bucket_sort(QuickSort, arr, bucket_size)
        end_times.append(time.clock())

    quick_sort_time = sum(end_times) - sum(start_times)
    fw = fw.set_number_buckets(bucket_size).set_sort_size(
        len(ret)).set_quick_sort_time(quick_sort_time)
    fw.set_out_array(ret).write()