def run(self): while not self.should_kill: if is_sorted(app.array): print self.vars['iterations'], self.vars['swaps'], self.count self.kill() else: self.count += 1 s.sort(self, app.array, app)
def handle_main(): infile = request.files["fileToUpload"] print(infile) filename = secure_filename(infile.filename) infile.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) my_value = request.form['value'] sort(my_value, filename) return main(my_value), 204
def search(request): query = request.GET.get('query') post_ids = searchClient.search(query) post_list = Post.objects.filter(id__in=post_ids).order_by('-pub_date')[0:10] follow_list = Following.objects.filter(follower=request.user) post_list = sorter.sort(post_list, follow_list, query) context = { 'post_list': post_list } return render(request, 'micro/search.html', context)
def sort(sort_algo:str): ''' expects two parameters list:arr[], and include_states:bool ''' # handle and parse list lst = json.loads(request.args.get('list')) # Should return error if is not a valid list or does not exist lst = list(map( lambda v : float(v), list(lst))) # using eval instead of float to avoid having to change if I decide to use int or other datatype # handle states - converts to boolean include_states = request.args.get('states')!=None return json.dumps(sorter.sort(sort_algo, lst, include_states))
def custom_accept(self): """Does some input checking and does the dirty work.""" if not self.is_valid_path(Path(self.imageDirectoryLineEdit.text())): # invalid folder self.no_selected_directory() # tell the user # do not pass to Ui_Dialog.accept() return False else: self.configure_script() # note that this sets the variables we'll use to call sort() if self.must_resort(): sorter.sort(use_gui=True) # use GUI when sorting if not self.added_to_crontab(): if self.crontab_configure() != 0: # Houston, we have a problem self.accept() # quit return False # don't show msgbox msgbox = QMessageBox() msgbox.setText("Operation successful!") msgbox.exec() # quit the dialog self.accept() # if this isn't working, it's because main.ui got rewritten return True
def __init__(self, source, destination, fileWithEntries, keepSumControl=True): self.__oldFile = self.__load_old_file(source) not_sorted_entries = EntryLoader.load_entries(fileWithEntries) self.__bytes_stack = bytearray() if keepSumControl: not_sorted_entries = self.__parse_entries(not_sorted_entries) self.__translationEntries = sorter.sort(not_sorted_entries)
def draw_images(self): sorted = sorter.sort(self.images) for item in sorted: self.qim = item.image pix = QtGui.QPixmap.fromImage(self.qim) pos = item.pos size = item.size lbl = QLabel() lbl.setPixmap(pix) lbl.move(pos[0], pos[1]) self.image_cont.addWidget(lbl)
def display(self): self.scene.clear() if len(self.images): sorted = sorter.sort(self.images) images = sorted[0] for item in images: self.qim = item.image pix = QtGui.QPixmap.fromImage(self.qim) pos = item.pos size = item.size snapimage = SnapImage(self, pix, pos[0], pos[1]) self.scene.addItem(snapimage)
def main_loop(): Rectangle.rectangle.set_dimentions(display_width, display_height, sorter_box_height) rectangles = Rectangle.rectangle.generate_rectangles(amount) Rectangle.rectangle.shuffle(rectangles) rectangles = Rectangle.rectangle.set_color(rectangles, color) # Buttons start = button(25, 25, 100, 50, "START", (100, 100, 100), (110, 110, 110)) stop = button(150, 25, 100, 50, "STOP", (100, 100, 100), (110, 110, 110)) reset = button(275, 25, 100, 50, "RESET", (75, 75, 75), (85, 85, 85)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() gameDisplay.fill((255, 255, 255)) # Button drawing start.draw(gameDisplay) stop.draw(gameDisplay) reset.draw(gameDisplay) # Colors tmp_color = color draw_colorboxes(gameDisplay) if tmp_color != color: rectangles = Rectangle.rectangle.set_color(rectangles, color) if button.on: rectangles = sorter.sort(rectangles, repeat) # Sorting if button.reset or sorter.done and repeat == "on": # Reseting rectangles = Rectangle.rectangle.generate_rectangles(amount) Rectangle.rectangle.shuffle(rectangles) rectangles = Rectangle.rectangle.set_color(rectangles, color) button.reset = False sorter.reset() draw_rectangles(rectangles) pygame.display.update() if speed.isdigit(): clock.tick(int(speed))
import committer import Counter import sorter import allrep from committer import test from Counter import big_list from sorter import list_sorted from allrep import repolist from extr import ReportGenerator from req import GithubRequester token = input('enter aut. token>>>') Fname = input('enter name for generated Excel file>>> ') allrep.getallrepo(token) y = 1 req = GithubRequester() for x in range(len(repolist)): while req.rest_request( "GET", "https://api.github.com/repos/performgroup/{}/commits?page={}&per_page=100" .format(repolist[x], y), token) != []: response = req.rest_request( "GET", "https://api.github.com/repos/performgroup/{}/commits?page={}&per_page=100" .format(repolist[x], y), token) committer.commit_er(response) y = y + 1 Counter.counter(test) sorter.sort(big_list) generate = ReportGenerator("{}.xlsx".format(Fname)) generate.generate_excel(30, list_sorted)
# Create filenames for all of the output files. output_prefix = ws_name + "/output/" + ws_name + "_" current_runoff_filename = output_prefix + "current_runoff.csv" future_runoff_filename = output_prefix + "future_runoff.csv" sorted_filename = output_prefix + "sorted_ws.csv" culvert_geometry_filename = output_prefix + "culv_geom.csv" capacity_filename = output_prefix + "capacity_output.csv" return_period_filename = output_prefix + 'return_periods.csv' final_output_filename = output_prefix + 'model_output.csv' print "\nRunning calculations for culverts in county " + ws_name + ":" # 1. WATERSHED PEAK DISCHARGE # Sort watersheds so they match original numbering (GIS changes numbering) sorter.sort(ws_data, ws_name, field_data, sorted_filename) # Culvert Peak Discharge function calculates the peak discharge for each culvert for current and future precip print " * Calculating current runoff and saving it to " + current_runoff_filename + "." runoff.calculate(sorted_filename, ws_precip, 1.0, current_runoff_filename) print " * Calculating future runoff and saving it to " + current_runoff_filename + "." runoff.calculate( sorted_filename, ws_precip, 1.15, future_runoff_filename ) # 15% increase in rainfall predicted for future conditions # 2. CULVERT GEOMETRY print " * Calculating culvert geometry and saving it to " + culvert_geometry_filename + "." # Culvert Capacity Prep function calculates the cross sectional area and assigns c and Y coeffs to each culvert capacity_prep.geometry(field_data, culvert_geometry_filename) # 3. CULVERT CAPACITY
#!/usr/bin/python import sys import sorter from optparse import OptionParser if __name__ == "__main__": parser = OptionParser() parser.add_option("-s", "--source", action="store", type="str", dest="src", help="Source directory") parser.add_option("-d", "--destination", action="store", type="str", dest="dest", help="Destination directory") parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, help="Don't print status messages to stdout") parser.add_option("-x", "--debug", action="store_true", dest="debug", default=False, help="Do a debug run (simulate without copying files)") (options, args) = parser.parse_args() if not options.src: parser.print_help() sys.exit() if not options.dest: parser.print_help() sys.exit() sorter.sort(options.src, options.dest, options.debug, options.quiet)
def sort(sort_algo: str): return jsonify(sorter.sort(sort_algo, _handle_list(), _handle_states()))
def __test_sorted(self, expected_sort, entries): actual_sort = sorter.sort(entries) self.assertEqual(len(actual_sort), len(expected_sort)) for i in range(len(actual_sort)): self.__entries_equal(expected_sort[i], actual_sort[i])
async def text(ctx, char, move): response = sorter.sort(char, move) await ctx.send(response)
parser.add_option("-d", "--destination", action="store", type="str", dest="dest", help="Destination directory") parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, help="Don't print status messages to stdout") parser.add_option("-x", "--debug", action="store_true", dest="debug", default=False, help="Do a debug run (simulate without copying files)") (options, args) = parser.parse_args() if not options.src: parser.print_help() sys.exit() if not options.dest: parser.print_help() sys.exit() sorter.sort(options.src, options.dest, options.debug, options.quiet)
current_runoff_filename = output_prefix + "current_runoff.csv" future_runoff_filename = output_prefix + "future_runoff.csv" sorted_filename = output_prefix + "sorted_ws.csv" culvert_geometry_filename = output_prefix + "culv_geom.csv" capacity_filename = output_prefix + "capacity_output.csv" return_period_filename = output_prefix + 'return_periods.csv' final_output_filename = output_prefix + 'model_output.csv' #Notifies user about runnign calculations print "\nRunning calculations for culverts in county " + county_abbreviation + ":" # 1. WATERSHED PEAK DISCHARGE # Sort watersheds so they match original numbering (GIS changes numbering) print " * Sorting watersheds by BarrierID and saving it to " + sorted_filename + "." sorter.sort(watershed_data_input_filename, county_abbreviation, sorted_filename) # Culvert Peak Discharge function calculates the peak discharge for each culvert for current and future precip print " * Calculating current runoff and saving it to " + current_runoff_filename + "." runoff.calculate(sorted_filename, watershed_precip_input_filename, 1.0, current_runoff_filename) print " * Calculating future runoff and saving it to " + future_runoff_filename + "." runoff.calculate( sorted_filename, watershed_precip_input_filename, 1.15, future_runoff_filename) # 1.15 times the rain in the future. # 2. CULVERT GEOMETRY print " * Calculating culvert geometry and saving it to " + culvert_geometry_filename + "." # Culvert Capacity Prep function calculates the cross sectional area and assigns c and Y coeffs to each culvert capacity_prep.geometry(field_data_input_filename, culvert_geometry_filename)