def testOutputExecTimeGraphs(self): m = mox.Mox() m.StubOutWithMock(main, 'write_to_file') m.StubOutWithMock(main, 'system') main.problems = ['problem'] main.variations = ['seq'] main.languages = ['language'] main.threads = [999] main.results = { 999: {'problem': { 'seq': {'language': {0: 100}}}}} main.write_to_file('output/images/graph-exec-time-seq-0.perf', '=cluster;language\ncolors=black,yellow,red,med_blue,light_green,cyan\n=table\nyformat=%g\n=norotate\nxscale=1\nmax=150.000000\nylabel=Sequential execution time in seconds for input 0\nproblem 100.0000000000\n') main.system('output/bargraph.pl -fig output/images/graph-exec-time-seq-0.perf | fig2dev -L ppm -m 4 > output/images/graph-exec-time-seq-0.ppm') main.system('mogrify -reverse -flatten output/images/graph-exec-time-seq-0.ppm') main.system('mogrify -resize 700x700 -format png output/images/graph-exec-time-seq-0.ppm') main.write_to_file('output/chapters/graph-exec-time-0.tex', '\\begin{figure}[htbp]\n %\\centering\n \\includegraphics[width=125mm]{images/graph-exec-time-seq-0.png}\n \\caption{Sequential Execution Time}\n \\label{fig:exec:time:seq:0}\n\\end{figure}\n') m.ReplayAll() main.create_graph("exec-time", main.results[999], '', use_subfigure=False) m.UnsetStubs() m.VerifyAll()
def testOutputExecTimeGraphs(self): m = mox.Mox() m.StubOutWithMock(main, "write_to_file") m.StubOutWithMock(main, "system") main.problems = ["problem"] main.variations = ["seq"] main.languages = ["language"] main.threads = [999] main.results = {999: {"problem": {"seq": {"language": {0: 100}}}}} main.write_to_file( "../../../ufrgs/tc/images/graph-exec-time-seq-0.perf", "=cluster;language\ncolors=black,yellow,red,med_blue,light_green,cyan\n=table\nyformat=%g\n=norotate\nxscale=1\nmax=150.000000\nylabel=Sequential execution time in seconds for input 0\nproblem 100.0000000000\n", ) main.system( "../../../ufrgs/tc/bargraph.pl -fig ../../../ufrgs/tc/images/graph-exec-time-seq-0.perf | fig2dev -L ppm -m 4 > ../../../ufrgs/tc/images/graph-exec-time-seq-0.ppm" ) main.system("mogrify -reverse -flatten ../../../ufrgs/tc/images/graph-exec-time-seq-0.ppm") main.system("mogrify -resize 700x700 -format png ../../../ufrgs/tc/images/graph-exec-time-seq-0.ppm") main.write_to_file( "../../../ufrgs/tc/chapters/graph-exec-time-0.tex", "\\begin{figure}[htbp]\n %\\centering\n \\includegraphics[width=125mm]{images/graph-exec-time-seq-0.png}\n \\caption{Sequential Execution Time}\n \\label{fig:exec:time:seq:0}\n\\end{figure}\n", ) m.ReplayAll() main.create_graph("exec-time", main.results[999], "", use_subfigure=False) m.VerifyAll() m.UnsetStubs()
def begin_gradient(): #reset time tick() #where source images are stored input_dir = './in/' #where resultant images will be stored output_dir = './out2/' #Used if images are processed in chunks last_file = '' file_counter = 0 #Grab a list of the files in the input directory and sort them #Exclude files that have already been processed (as defined by last_file) # edge_ascii.set_occurence(charfreq.get_most_frequent(input_dir)) files = sorted([ f for f in listdir(input_dir) if isfile(join(input_dir,f)) and f > last_file]) for f in files: if(f[f.index('.'):len(f)] is not ".txt"): continue image = input_dir + f # print f name,_ = f.split('.') #the real work happens here write_to_file(image, output_dir + name+".txt") file_counter = file_counter + 1 #output time t = tock(True) print(name+".txt was made") print("Time Elapsed: " + str(t)[:7] + " Average time: " + str(float(t)/file_counter)[:7])
def run(args): text = args['text'] or main.read_whole_file(args['file']) p_params, l_params = main.separate_params(args) prep_text = preprocessor.prepare(text, args['mode'], **p_params) min_d = (args['min_dictionary_absolute'] or 0) / len(prep_text) or args['min_dictionary_relative'] max_d = (args['max_dictionary_absolute'] or 0) / len(prep_text) or args['max_dictionary_relative'] freq = stats.relative_frequency(prep_text, args['ngram']) vocab = [k for k, v in freq.items() if v >= min_d and v <= max_d] res = [] output_file = args['output_file'] for v in vocab: args['template_string'] = v args['output_file'] = None args['aprox_output_file'] = None _, gamma = main.run(args, False) res.append((v, gamma)) if output_file is not None and len(output_file) > 0: main.write_to_file(output_file, res, False)
def run(button): props = app.getAllEntries() l = [] data = main.read_tsv(props['file']) popv = main.approx(data) print(popv) if len(props['Output file']) > 0: main.write_to_file(props['Output file'], [popv], False)
def co(): flag_date = True region = 'все' if request.method == "POST" and 'submit_button' in request.form: region = request.form['region'] if request.form['options'] == '0': flag_date = True else: flag_date = False print(region) db_sess = db_session.create_session() list_problems = [] for i in db_sess.query(Complaint).all(): if i.n_confirmation >= 5: flag = True else: flag = False if f'{i.id}.jpg' not in os.listdir('static/img/img_problems'): write_to_file(i.photo, f'static/img/img_problems/{i.id}.jpg') diction = {} diction['id'] = i.id diction['name'] = i.name diction['text'] = i.description diction['lat'] = i.coordinates.split(',')[0] diction['lon'] = i.coordinates.split(',')[1] diction['datetime'] = i.modifed_date diction['date'] = transformation_date(str(i.modifed_date)) diction['category'] = i.category diction['n_ver'] = i.n_confirmation diction['ver'] = flag diction['color'] = DICT_COLORS_PROBLEMS[i.category] diction['label'] = DICT_COLORS_LABELS[i.category] print( geocode(f'{diction["lon"]},{diction["lat"]}')['metaDataProperty'] ['GeocoderMetaData']['text']) if region != 'все' and region in geocode( f'{diction["lon"]},{diction["lat"]}' )['metaDataProperty']['GeocoderMetaData']['text']: list_problems.append(diction) elif region == 'все': list_problems.append(diction) if flag_date: list_problems.sort(key=operator.itemgetter('datetime'), reverse=True) else: list_problems.sort(key=operator.itemgetter('n_ver'), reverse=True) with open('static/txt/regions.txt', 'r', encoding='utf-8') as file: lst = file.readlines() return render_template('problems.html', list_problems=list_problems, title='Проблемы', lst_regions=lst)
def testGenerateErlangMain(self): m = mox.Mox() m.StubOutWithMock(main, "write_to_file") main.write_to_file("directory/main.sh", "dir=directory") m.StubOutWithMock(main, "get_directory") main.get_directory("erlang", "problem", "variation").AndReturn("directory") m.StubOutWithMock(main, "get_problems_with_variations") main.get_problems_with_variations().AndReturn([("problem", "variation")]) main.ERLANG_MAIN = "dir=%s" m.ReplayAll() main.generate_erlang_main() m.VerifyAll() m.UnsetStubs()
def start_download(room, url): print("downloading", url) try: create_folder(SID, Sname[1], DOWNLOAD_DIR) with workers: ready_to_download[hashed_url]["state"] = "loading" final_state = None for is_finished, state in fetch_episode(session, SID, season, episode, headers, base_url): if is_finished: final_state = state break gevent.sleep(1) emit("event", { "hash": hashed_url, "state": "loading", "details": round(state) }, namespace="/", room=room) print("finished waiting! lets goooo") ready_to_download[hashed_url]["state"] = "downloading" for chunk in write_to_file(final_state, Sname[1], "{}_S{:02d}E{:02d}.mp4".format( Sname[1], season, episode ), DOWNLOAD_DIR): emit("event", { "hash": hashed_url, "state": "downloading", "details": { "current": chunk, "total": int(final_state.headers['Content-length']) } }, namespace="/", room=room) emit("event", { "hash": hashed_url, "state": "download_complete", }, namespace="/", room=room) ready_to_download[hashed_url]["state"] = "download_complete" except Exception as e: emit("event", { "error": str(e), "hash": hashed_url, "state": "error" }, namespace="/", room=room) raise RuntimeError from e
def testGenerateErlangMain(self): m = mox.Mox() m.StubOutWithMock(main, 'write_to_file') main.write_to_file('directory/main.sh', 'dir=directory') m.StubOutWithMock(main, 'get_directory') main.get_directory('erlang', 'problem', 'variation').AndReturn( 'directory') m.StubOutWithMock(main, 'get_problems_with_variations') main.get_problems_with_variations().AndReturn( [('problem', 'variation')]) main.ERLANG_MAIN = 'dir=%s' m.ReplayAll() main.generate_erlang_main() m.UnsetStubs() m.VerifyAll()
def testOutputLanguageSpeedupGraphs(self): m = mox.Mox() m.StubOutWithMock(main, 'write_to_file') m.StubOutWithMock(main, 'system') main.problems = ['problem'] main.variations = ['seq', 'par'] main.languages = ['language'] main.threads = [2, 4] main.results = { 2: {'problem': { 'par': {'language': {0: 50}}}}, 4: {'problem': { 'seq': {'language': {0: 100}}, 'par': {'language': {0: 25}}}}} main.write_to_file('other.script', '\nset xrange [0:8]\nset xtics 1\nset yrange [0:8]\nset ytics 1\nset xlabel "threads"\nset ylabel "speedup"\nset terminal png\nset output "plot.png"\nset key left\nplot \'output/images/graph-speedup-language-problem-0.dat\' using 1:4 title \'ideal speedup\' w lp, \'output/images/graph-speedup-language-problem-0.dat\' using 1:3 title \'problem speedup\' w lp') main.system('gnuplot other.script') main.system('mv plot.png output/images/graph-language-speedup-language-0.png') main.system('rm other.script') main.write_to_file('output/chapters/graph-language-speedup-language-0.tex', '\\begin{figure}[htbp]\n %\\centering\n \\includegraphics[width=100mm]{images/graph-language-speedup-language-0.png}\n \\caption{Speedup for language language in all problems}\n \\label{fig:exec:spd:language:0}\n\\end{figure}\n') main.write_to_file('output/chapters/graph-language-speedup.tex', '\\input{chapters/graph-language-speedup-language-0.tex}\n') m.ReplayAll() main.create_language_speedup_graph("language-speedup", "speedup", use_subfigure=False) m.UnsetStubs() m.VerifyAll()
def testOutputSpeedupGraphs(self): m = mox.Mox() m.StubOutWithMock(main, 'write_to_file') m.StubOutWithMock(main, 'system') main.problems = ['problem'] main.variations = ['seq', 'par'] main.languages = ['language'] main.threads = [2, 4] main.results = { 2: {'problem': { 'par': {'language': {0: 50}}}}, 4: {'problem': { 'seq': {'language': {0: 100}}, 'par': {'language': {0: 25}}}}} main.write_to_file( 'output/images/graph-speedup-language-problem-0.dat', '2\t50.0000000000\t2.0000000000\t2\t1.0000000000\t1\n4\t25.0000000000\t4.0000000000\t4\t1.0000000000\t1\n') main.system('cp output/images/graph-speedup-language-problem-0.dat plot.dat') main.system('gnuplot output/plot.script') main.system('mv plot.png output/images/graph-speedup-language-problem-0.png') main.system('rm plot.dat') main.write_to_file('output/chapters/graph-speedup-language-problem-0.tex', '\\begin{figure}[htbp]\n %\\centering\n \\includegraphics[width=100mm]{images/graph-speedup-language-problem-0.png}\n \\caption{Speedup and efficiency for language language in problem problem}\n \\label{fig:exec:spd:language:problem:0}\n\\end{figure}\n') main.write_to_file('output/chapters/graph-speedup.tex', '\\input{chapters/graph-speedup-language-problem-0.tex}\n') m.ReplayAll() main.create_speedup_graph("speedup", main.results, use_subfigure=False) m.UnsetStubs() m.VerifyAll()
def testOutputSpeedupGraphs(self): m = mox.Mox() m.StubOutWithMock(main, "write_to_file") m.StubOutWithMock(main, "system") main.problems = ["problem"] main.variations = ["seq", "par"] main.languages = ["language"] main.threads = [2, 4] main.results = { 2: {"problem": {"par": {"language": {0: 50}}}}, 4: {"problem": {"seq": {"language": {0: 100}}, "par": {"language": {0: 25}}}}, } main.write_to_file( "../../../ufrgs/tc/images/graph-speedup-language-problem-0.dat", "2\t50.0000000000\t2.0000000000\t2\t1.0000000000\t1\n4\t25.0000000000\t4.0000000000\t4\t1.0000000000\t1\n", ) main.system("cp ../../../ufrgs/tc/images/graph-speedup-language-problem-0.dat plot.dat") main.system("gnuplot ../../../ufrgs/tc/plot.script") main.system("mv plot.png ../../../ufrgs/tc/images/graph-speedup-language-problem-0.png") main.system("rm plot.dat") main.write_to_file( "../../../ufrgs/tc/chapters/graph-speedup-language-problem-0.tex", "\\begin{figure}[htbp]\n %\\centering\n \\includegraphics[width=100mm]{images/graph-speedup-language-problem-0.png}\n \\caption{Speedup and Efficiency for language language in problem problem}\n \\label{fig:exec:spd:language:problem:0}\n\\end{figure}\n", ) main.write_to_file( "../../../ufrgs/tc/chapters/graph-speedup.tex", "\\input{chapters/graph-speedup-language-problem-0.tex}\n" ) m.ReplayAll() main.create_speedup_graph("speedup", main.results, use_subfigure=False) m.VerifyAll() m.UnsetStubs()
def testOutputLanguageSpeedupGraphs(self): m = mox.Mox() m.StubOutWithMock(main, "write_to_file") m.StubOutWithMock(main, "system") main.problems = ["problem"] main.variations = ["seq", "par"] main.languages = ["language"] main.threads = [2, 4] main.results = { 2: {"problem": {"par": {"language": {0: 50}}}}, 4: {"problem": {"seq": {"language": {0: 100}}, "par": {"language": {0: 25}}}}, } main.write_to_file( "other.script", "\nset xrange [0:8]\nset xtics 1\nset yrange [0:8]\nset ytics 1\nset xlabel \"threads\"\nset terminal png\nset output \"plot.png\"\nset key left\nplot '../../../ufrgs/tc/images/graph-speedup-language-problem-0.dat' using 1:4 title 'ideal speedup' w lp, '../../../ufrgs/tc/images/graph-speedup-language-problem-0.dat' using 1:3 title 'problem speedup' w lp", ) main.system("gnuplot other.script") main.system("mv plot.png ../../../ufrgs/tc/images/graph-language-speedup-language-0.png") main.system("rm other.script") main.write_to_file( "../../../ufrgs/tc/chapters/graph-language-speedup-language-0.tex", "\\begin{figure}[htbp]\n %\\centering\n \\includegraphics[width=100mm]{images/graph-language-speedup-language-0.png}\n \\caption{Speedup for language language in all problems}\n \\label{fig:exec:spd:language:0}\n\\end{figure}\n", ) main.write_to_file( "../../../ufrgs/tc/chapters/graph-language-speedup.tex", "\\input{chapters/graph-language-speedup-language-0.tex}\n", ) m.ReplayAll() main.create_language_speedup_graph("language-speedup", "speedup", use_subfigure=False) m.VerifyAll() m.UnsetStubs()
def test_write_file(self): self.assertEqual( main.write_to_file("check writing data to file", "Brute Force"), None)
def testCreateInputs(self): m = mox.Mox() m.StubOutWithMock(main, 'write_to_file') main.problem_classes = [ main.RandmatProblem(), main.ThreshProblem(), main.WinnowProblem(), main.OuterProblem(), main.ProductProblem(), main.ChainProblem()] main.inputs = [main.ProblemInput(10, 15, 20, 30, 40)] main.write_to_file('randmat_10_15_20.in', '10 15 20\n') main.write_to_file('thresh_10_15_30.in', '10 15 30\n') main.write_to_file('winnow_10_15_30_40.in', '10 15 40\n') main.write_to_file('outer_40.in', '40\n') main.write_to_file('product_40.in', '40\n') main.write_to_file('chain_10_20_30_40.in', '10\n20\n30\n40\n') m.ReplayAll() main.create_inputs() m.UnsetStubs() m.VerifyAll()
def testCreateInputs(self): m = mox.Mox() m.StubOutWithMock(main, "write_to_file") main.problem_classes = [ main.RandmatProblem(), main.ThreshProblem(), main.WinnowProblem(), main.OuterProblem(), main.ProductProblem(), main.ChainProblem(), ] main.inputs = [main.ProblemInput(10, 15, 20, 30, 40)] main.write_to_file("randmat_10_15_20.in", "10 15 20\n") main.write_to_file("thresh_10_15_30.in", "10 15 30\n") main.write_to_file("winnow_10_15_30_40.in", "10 15 40\n") main.write_to_file("outer_40.in", "40\n") main.write_to_file("product_40.in", "40\n") main.write_to_file("chain_10_20_30_40.in", "10\n20\n30\n40\n") m.ReplayAll() main.create_inputs() m.VerifyAll() m.UnsetStubs()
if __name__ == '__main__': current_dir = os.path.dirname(os.path.abspath(__file__)) data = main.read_from_file(os.path.join(current_dir, 'data.txt')) stop_words = main.read_from_file( os.path.join(current_dir, 'stop_words.txt')) tokens = main.tokenize(data) print(f'Raw text: {data[:5]}') print(f'Tokenized text: {tokens[:5]}') tokens = main.remove_stop_words(tokens, stop_words) print(f'Text without stop-words: {tokens[:5]}') frequencies = main.calculate_frequencies(tokens[:5000]) print(f'Frequencies: {frequencies[tokens[0]]}') word = 'dog' concordance = main.get_concordance(tokens, word, 2, 0) print(f'The concordance for {word}: {concordance[:5]}') adjacent = main.get_adjacent_words(tokens, 'dog', 2, 0) print(f'Adjacent words: {adjacent[:5]}') sorted_concordance = main.sort_concordance(tokens, 'dog', 2, 0, True) print(f'Sorted concordance: {sorted_concordance[:5]}') main.write_to_file('', sorted_concordance) RESULT = sorted_concordance assert RESULT, 'Concordance not working'