Esempio n. 1
0
def register():
    """Register user."""
    # if user reached route via POST (as by submitting a form via POST)
    if request.method == "POST":

        # ensure username exists
        if User.userexist(request.form.get("username")):
            return render_template("register.html", InUse=True)

        # register user
        hash1 = pwd_context.hash(request.form.get("password"))
        User.registeruser(request.form.get("username"), hash1)

        # make list name
        list_name = "list of " + request.form.get("username")

        # give an user a list
        Lists.create_list(request.form.get("username"), list_name)

        # remember which user has logged in
        session["user_id"] = User.user(request.form.get("username"))[0]["id"]
        session["username"] = request.form.get("username")

        # redirect user to home page
        return redirect(url_for("index"))

    else:
        return render_template("register.html")
Esempio n. 2
0
 def setupKodisplay(self):
     self.settings = Settings(self.distro, self.display_w, self.display_h)
     self.settings.readSettings()
     self.lists = Lists(self.distro, self.display_w, self.display_h)
     if self.lists.createLists():
         self.startThreads()
         return True
     else:
         return False
Esempio n. 3
0
def mylist():

    # Remove item from list.
    if request.method == "POST":
        Lists.remove_item(Lists.get_listid(session["username"]),
                          request.form.get("listremove"))

    # Get all information.
    information = Lists.showlist(session["username"])

    # Show list.
    return render_template("lists.html", information=information)
Esempio n. 4
0
    def __init__(self, slug, api_key):
        super(NationBuilder, self).__init__()

        self.people = People(slug, api_key)
        self.tags = NBTags(slug, api_key)
        self.lists = Lists(slug, api_key)
        self.contacts = Contacts(slug, api_key)
Esempio n. 5
0
    def preview(communityname):
        comlist = Lists.showlist(communityname)
        preview = [film["image"] for film in comlist][:4]

        # Add stock photo's if list is too short.
        while len(preview) < 4:
            preview.append("https://cdn2.iconfinder.com/data/icons/cinema-and-television/500/Entertainment_film_film_reel_film_roll_movie_reel_roll_theate-512.png")
        return preview
Esempio n. 6
0
	def setupKodisplay(self):
		self.settings = Settings(self.distro, self.display_w, self.display_h)
		self.settings.readSettings()
		self.lists = Lists(self.distro, self.display_w, self.display_h)
		if self.lists.createLists():
			self.startThreads()
			return True
		else:
			return False
Esempio n. 7
0
def movie_info():

    # Check if user is logged in.
    try:
        session["user_id"]
        mycommunities = com.mycommunities()
    except KeyError:
        mycommunities = []

    # Get movie information.
    similar_films = Search.similar_films(request.args.get("imdb_id"))
    actors = Search.movie_actors(request.args.get("imdb_id"))
    full_movie_info = Search.title_info(request.args.get("imdb_id"))

    if request.method == "POST":
        # Add movie to a user list.
        if request.form.get("listadd") == "add":
            Lists.add_item(User.get_list_id(session["username"]),
                           request.args.get("imdb_id"))
            return render_template("movie_information.html",
                                   full_movie_info=full_movie_info,
                                   actors=actors,
                                   similars=similar_films,
                                   movie_select=True,
                                   mycom=mycommunities)

        # Add movie to a community list.
        else:
            Lists.add_item(com.get_list_id(request.form.get("comadd")),
                           request.args.get("imdb_id"))
            return render_template("movie_information.html",
                                   full_movie_info=full_movie_info,
                                   actors=actors,
                                   similars=similar_films,
                                   movie_select=True,
                                   mycom=mycommunities)
    # Show movie info page.
    else:
        return render_template("movie_information.html",
                               full_movie_info=full_movie_info,
                               actors=actors,
                               similars=similar_films,
                               movie_select=True,
                               mycom=mycommunities)
 def __init__(self):
     Lists.__init__(self)
     self.double_check()
Esempio n. 9
0
 def __init__(self):
     Lists.__init__(self)
     self.double_check()
Esempio n. 10
0
def myprofile():
    # Show personal profile.
    return render_template("profilepage.html",
                           movies=Lists.showlist(session["username"]),
                           communities=com.mycommunities())
Esempio n. 11
0
 def lists(self):
     return Lists(self)
Esempio n. 12
0
def community():

    # Gather required information.
    films = Lists.showlist(request.args.get('community'))
    comments = com.community_comments(request.args.get('community'))

    if request.method == "POST":

        # Get changed community description and save it.
        if request.form.get("save"):
            com.change_description(request.form.get("save"),
                                   request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Lets user join community.
        if request.form.get("comaction") == "join":
            com.join(session["username"], request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Lets user leave community.
        elif request.form.get("comaction") == "leave":
            com.remove_member(session["username"],
                              request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Removes item from community list.
        elif request.form.get("comlistremove"):
            Lists.remove_item(Lists.get_listid(request.args.get('community')),
                              request.form.get("comlistremove"))
            films = Lists.showlist(request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Save comment.
        if request.form.get("commented"):
            username = session["username"]
            com.save_comment(username, request.args.get('community'),
                             request.form.get("comment"))
            comments = com.community_comments(request.args.get('community'))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Add item to user list.
        if request.form.get("listadd"):
            Lists.add_item(User.get_list_id(session["username"]),
                           request.form.get("listadd"))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        # Add item to other community list.
        elif request.form.get("comadd"):
            print(request.form.get("comadd") + "fwkogfwkefgjew")
            Lists.add_item(com.get_list_id(request.args.get("community")),
                           request.form.get("comadd"))
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))

        #wrong post request
        else:
            return render_template(
                "community.html",
                mycom=com.mycommunities(),
                comments=comments,
                page=com.show(request.args.get('community'))[0],
                members=com.showmembers(request.args.get('community')),
                films=films,
                member=com.member(session["user_id"],
                                  request.args.get('community')))
    # Render page.
    else:
        return render_template(
            "community.html",
            mycom=com.mycommunities(),
            comments=comments,
            page=com.show(request.args.get('community'))[0],
            members=com.showmembers(request.args.get('community')),
            films=films,
            member=com.member(session["user_id"],
                              request.args.get('community')))
Esempio n. 13
0
class Display():

	def __init__(self):
		pygame.display.init()
		pygame.font.init()
		pygame.mouse.set_visible(False)
		self.distro = distro
		self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
		self.clock = pygame.time.Clock()
		self.background = pygame.Surface(self.screen.get_size()).convert()
		self.display_w = pygame.display.Info().current_w
		self.display_h = pygame.display.Info().current_h
		xbmc_log(xbmc.LOGNOTICE, 'Version %s is running on %s' %(__addonversion__, self.distro))
		xbmc_log(xbmc.LOGNOTICE, 'Resolution: ' + str(self.display_w) + 'x' + str(self.display_h))
		if self.setupKodisplay():
			self.run()

	def startThreads(self):
		self.srth = SurfaceRenderingThread(pygame, self.settings, self.lists)
		self.qdth = QueryDataThread(self.settings, self.lists)
		self.srth.start()
		self.qdth.start()

	def stopThreads(self):
		self.srth.stop()
		self.qdth.stop()
		self.srth.join()
		self.qdth.join()

	def updateSettings(self):
		xbmc_log(xbmc.LOGNOTICE, 'Settings changed, perform update')
		self.stopThreads()
		if self.setupKodisplay():
			xbmc_log(xbmc.LOGNOTICE, 'Settings updated')
		else:
			xbmc_log(xbmc.LOGWARNING, 'Updating settings has failed!')

	def setupKodisplay(self):
		self.settings = Settings(self.distro, self.display_w, self.display_h)
		self.settings.readSettings()
		self.lists = Lists(self.distro, self.display_w, self.display_h)
		if self.lists.createLists():
			self.startThreads()
			return True
		else:
			return False

	def drawFrame(self, mode):
		# blit the rendered surfaces on the background
		for index in range(0, len(self.lists.layout[mode])):
			if self.lists.render[mode][index][0] == 1 and self.lists.query[mode][index][1] == 'visible':
				self.background.blit(self.lists.render[mode][index][1], self.lists.render[mode][index][2])

	def drawDebugInfo(self, infostring, xpos):
		font = pygame.font.Font(None, 36)
		infosurface = font.render(infostring, 1, (255, 165, 0)).convert_alpha()
		infopos = infosurface.get_rect()
		if xpos < 0:
			infopos.x = self.display_w - infosurface.get_width() + xpos
		else:
			infopos.x = xpos
		infopos.y = self.display_h - infosurface.get_height() - 2
		backgroundsurface = pygame.Surface(infosurface.get_size()).convert()
		backgroundsurface.fill((0, 0, 0))
		self.background.blit(backgroundsurface, infopos)
		self.background.blit(infosurface, infopos)

	def run(self):
		monitor = MyMonitor(update_settings = self.updateSettings)

		# run the event loop
		while not monitor.abortRequested():

			self.clock.tick(self.settings.fps)

			if glob.addonDebug:
				starttime = time.time()

			currentmode = self.lists.currentmode
			self.drawFrame(currentmode)

			# show info on display, if activated
			if self.settings.debug_show_fps:
				fpsstring = "FPS: {:.2f}".format(self.clock.get_fps())
				self.drawDebugInfo(fpsstring, 2)
			if self.settings.debug_show_wid:
				self.windowid = int(xbmcgui.getCurrentWindowId())
				widstring = "WinID: " + str(self.windowid)
				self.drawDebugInfo(widstring, -2)

			# blit the background on a screen and flip the display
			self.screen.blit(self.background, (0, 0))
			pygame.display.flip()

			if glob.addonDebug and self.settings.debug_log_tpf:
				xbmc_log(xbmc.LOGDEBUG, 'NEW FRAME: %s\tTime:%s' % (currentmode, str(time.time() - starttime)))
				xbmc_log(xbmc.LOGDEBUG, 'Time: %s' % str(self.clock.get_time()))

			if monitor.waitForAbort(0.0001):
				break

		self.stopThreads()
Esempio n. 14
0
class Display():
    def __init__(self):
        pygame.display.init()
        pygame.font.init()
        pygame.mouse.set_visible(False)
        self.distro = distro
        self.screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
        self.clock = pygame.time.Clock()
        self.background = pygame.Surface(self.screen.get_size()).convert()
        self.display_w = pygame.display.Info().current_w
        self.display_h = pygame.display.Info().current_h
        xbmc_log(
            xbmc.LOGNOTICE,
            'Version %s is running on %s' % (__addonversion__, self.distro))
        xbmc_log(
            xbmc.LOGNOTICE,
            'Resolution: ' + str(self.display_w) + 'x' + str(self.display_h))
        if self.setupKodisplay():
            self.run()

    def startThreads(self):
        self.srth = SurfaceRenderingThread(pygame, self.settings, self.lists)
        self.qdth = QueryDataThread(self.settings, self.lists)
        self.srth.start()
        self.qdth.start()

    def stopThreads(self):
        self.srth.stop()
        self.qdth.stop()
        self.srth.join()
        self.qdth.join()

    def updateSettings(self):
        xbmc_log(xbmc.LOGNOTICE, 'Settings changed, perform update')
        self.stopThreads()
        if self.setupKodisplay():
            xbmc_log(xbmc.LOGNOTICE, 'Settings updated')
        else:
            xbmc_log(xbmc.LOGWARNING, 'Updating settings has failed!')

    def setupKodisplay(self):
        self.settings = Settings(self.distro, self.display_w, self.display_h)
        self.settings.readSettings()
        self.lists = Lists(self.distro, self.display_w, self.display_h)
        if self.lists.createLists():
            self.startThreads()
            return True
        else:
            return False

    def drawFrame(self, mode):
        # blit the rendered surfaces on the background
        for index in range(0, len(self.lists.layout[mode])):
            if self.lists.render[mode][index][0] == 1 and self.lists.query[
                    mode][index][1] == 'visible':
                self.background.blit(self.lists.render[mode][index][1],
                                     self.lists.render[mode][index][2])

    def drawDebugInfo(self, infostring, xpos):
        font = pygame.font.Font(None, 36)
        infosurface = font.render(infostring, 1, (255, 165, 0)).convert_alpha()
        infopos = infosurface.get_rect()
        if xpos < 0:
            infopos.x = self.display_w - infosurface.get_width() + xpos
        else:
            infopos.x = xpos
        infopos.y = self.display_h - infosurface.get_height() - 2
        backgroundsurface = pygame.Surface(infosurface.get_size()).convert()
        backgroundsurface.fill((0, 0, 0))
        self.background.blit(backgroundsurface, infopos)
        self.background.blit(infosurface, infopos)

    def run(self):
        monitor = MyMonitor(update_settings=self.updateSettings)

        # run the event loop
        while not monitor.abortRequested():

            self.clock.tick(self.settings.fps)

            if glob.addonDebug:
                starttime = time.time()

            currentmode = self.lists.currentmode
            self.drawFrame(currentmode)

            # show info on display, if activated
            if self.settings.debug_show_fps:
                fpsstring = "FPS: {:.2f}".format(self.clock.get_fps())
                self.drawDebugInfo(fpsstring, 2)
            if self.settings.debug_show_wid:
                self.windowid = int(xbmcgui.getCurrentWindowId())
                widstring = "WinID: " + str(self.windowid)
                self.drawDebugInfo(widstring, -2)

            # blit the background on a screen and flip the display
            self.screen.blit(self.background, (0, 0))
            pygame.display.flip()

            if glob.addonDebug and self.settings.debug_log_tpf:
                xbmc_log(
                    xbmc.LOGDEBUG, 'NEW FRAME: %s\tTime:%s' %
                    (currentmode, str(time.time() - starttime)))
                xbmc_log(xbmc.LOGDEBUG,
                         'Time: %s' % str(self.clock.get_time()))

            if monitor.waitForAbort(0.0001):
                break

        self.stopThreads()
Esempio n. 15
0
	def post(self):
		state_key_dict = None

		#===============================FULL DATABASE LOAD FROM SCRATCH==========================
		if self.request.get('fill_all') == 'True':

			self.nukeItAll()#clear the entire db, since we're filling it from scratch

			#===============GENERATE AND GET ALL OUR LISTS------------------------
			L = Lists()
			container_class_defs.generate_all_states(L)
			container_class_defs.generate_all_districts(L)
			container_class_defs.generate_all_electoral_college(L)
			db_State_list = []
			key_list = []
									#==============STATES===============================
			#===================GET THE STATES FROM THE CONTAINERS AND PUT THEM IN THE DB============
			for i, our_state in enumerate(L.all_state_classes):

				#key_list.append(ndb.Key(db_defs.State, 'States'))
				db_State_list.append(db_defs.State())

				db_State_list[i].abbr = our_state.abbr
				db_State_list[i].quant_districts = our_state.quant_districts
				db_State_list[i].quant_registered = our_state.quant_registered
				db_State_list[i].quant_electors = our_state.quant_electors
				#db_State_list[i].dist_key_list = []
				#db_State_list[i].elector_key_list = []

			state_keys = ndb.put_multi(db_State_list)#batch put all state keys in the db

			state_key_dict = {key.get().abbr: key for key in state_keys}#build a dict out of the state_keys list to use in District obj building
									#==============================DISTRICTS======================
			#============GET THE DISTRICTS FROM CONTAINERS, GET THEIR STATES, FILL STATE.DIST LISTS, PUT IN DB====
			db_Dist_list = []
			key_list = []

			for i, our_dist in enumerate(L.all_district_classes):

				#key_list.append(ndb.Key(db_defs.District, 'Districts'))
				db_Dist_list.append(db_defs.District())

				db_Dist_list[i].number = our_dist.number
				db_Dist_list[i].state_key = state_key_dict[str(our_dist.state.abbr)]
				#db_Dist_list[i].voters = []

			dist_keys = ndb.put_multi(db_Dist_list)#batch put all district keys in the db, store the keys in dist_keys

			#===================================================STATES.DISTRICT_KEY_LISTS======================================
			#===============PUT A COPY OF EVERY NEWLY CREATED DISTRICT KEY IN IT'S PROPER STATE LIST IN THE DB=================
			#extracts state object from dist_key, assigne the dist_key as an element in the state's dist_key_list...just trust me

			
			state_dist_keys_dict = {}
			state_to_put_list = []
			for state_key in state_keys:
				dist_key_list = []
				for dist_key in dist_keys:
					if dist_key.get().state_key == state_key:
						state_dist_keys_dict[state_key] = dist_key_list.append(dist_key)

				state_dist_keys_dict[state_key] = {dist.get().number : dist for dist in dist_key_list}

				state_to_put = state_key.get()
				state_to_put.dist_key_list = dist_key_list

				state_to_put_list.append(state_to_put)

				#state_to_put.put()
				#break

			ndb.put_multi(state_to_put_list)


	#============================================ELECTORAL_COLLEGE============================================
			#============GET THE DISTRICTS FROM CONTAINERS, GET THEIR STATES, FILL STATE.DIST LISTS, PUT IN DB====
			db_EC_list = []
			key_list = []

			for i, our_ec in enumerate(L.all_electoral_classes):

				#key_list.append(ndb.Key(db_defs.Electoral_College, 'Electors'))
				db_EC_list.append(db_defs.Electoral_College())

				db_EC_list[i].evoter_id = our_ec.evoter_id
				db_EC_list[i].state_key = state_key_dict[str(our_ec.state.abbr)]


				db_EC_list[i].candidate = our_ec.candidate
				#db_Dist_list[i].voters = []

			ec_keys = ndb.put_multi(db_EC_list)#batch put all district keys in the db, store the keys in dist_keys

			#===================================================STATES.ELECTORS_KEY_LISTS======================================
			#===============PUT A COPY OF EVERY NEWLY CREATED ELECTOR KEY IN IT'S PROPER STATE LIST IN THE DB=================
			#extracts state object from ec_key, assigne the ec_key as an element in the state's ec_key_list...just trust me

			
			state_ec_keys_dict = {}
			state_to_put_list = []
			for state_key in state_keys:
				ec_key_list = []
				for ec_key in ec_keys:
					if ec_key.get().state_key == state_key:
						state_ec_keys_dict[state_key] = ec_key_list.append(ec_key)

				state_ec_keys_dict[state_key] = ec_key_list
				state_to_put = state_key.get()
				state_to_put.elector_key_list = ec_key_list

				state_to_put_list.append(state_to_put)

				#state_to_put.put()
				#break

			ndb.put_multi(state_to_put_list)

			#============================================VOTERS============================================
			#=====================================GET THE VOTERS FROM CONTAINERS==========================

		#condition that the parameter to generate a number of random votes has been set to 
		if self.request.get('fill_votes') == 'True':

			#condition that states, districts, and electoral college entities have not yet been generated here and need to be
			if not self.request.get('fill_all'):
				L = Lists()
				L.voterID_list = [voter.voter_id for voter in db_defs.Voter.query().fetch()]
				container_class_defs.generate_all_states(L)
				container_class_defs.generate_all_districts(L)
				container_class_defs.generate_all_electoral_college(L)

			n = int(self.request.get('num'))

			#set range of voter ids to be randomly selected from to be either 10 x the size of the voterID list 
			#or 10 * the size of the number of votes to be generated if none are generated yet
			if (len(L.voterID_list) > 0):
				n_range = (len(L.voterID_list) + n) * 10
			else:
				n_range = n * 10
			container_class_defs.generateRandVoters(n, n_range, L)
			container_class_defs.generateRandVotes(L)

			db_voter_list = []
			key_list = []

			for i, voter in enumerate(L.all_voter_classes):

				#key_list.append(ndb.Key(db_defs.Voter, 'Voters'))
				db_voter_list.append(db_defs.Voter())

				db_voter_list[i].voter_id = voter.id
				db_voter_list[i].party = voter.party
				db_voter_list[i].age = voter.age
				db_voter_list[i].sex = voter.sex == 'M'
				db_voter_list[i].income_lvl = voter.income_lvl
				db_voter_list[i].ethnicity = voter.ethnicity
				db_voter_list[i].education_lvl = voter.education_lvl

			del L.all_voter_classes

			future_voter_keys = ndb.put_multi_async(db_voter_list)#batch put all voter keys in the db

			voter_key_dict = {key.get_result().get().voter_id: key.get_result() for key in future_voter_keys}


			i = 0
			db_vote_list = []
			
			#create the necessary dicts and lists if only generating new votes, not generating votes from scratch
			if state_key_dict is None:

				states = db_defs.State.query().fetch(keys_only=True)
				dists = db_defs.District.query().fetch(keys_only=True)
				dist_keys = [dist for dist in dists]
				state_key_dict = {state.get().abbr : state for state in states}
				state_dist_keys_dict = {state : {dist.get().number : dist for dist in state.get().dist_key_list} for state in states}


			for i, vote in enumerate(L.all_vote_classes):

				#key_list.append(ndb.Key(db_defs.Vote, 'Votes'))
				db_vote_list.append(db_defs.Vote())
				
				db_vote_list[i].voter_key = voter_key_dict[vote.voter_id]
				db_vote_list[i].candidate = vote.candidate
				db_vote_list[i].issues = vote.issues
				db_vote_list[i].state_key = state_key_dict[vote.state]
				dist_dict = state_dist_keys_dict[db_vote_list[i].state_key]
				db_vote_list[i].dist_key = dist_dict[vote.district]

			del L.all_vote_classes

			future_vote_key_list = ndb.put_multi_async(db_vote_list)

			#===================================PUT ALL VOTE_KEYS IN VOTERS==================================================
			db_voter_list = []
			for vote_key in future_vote_key_list:
				vote_key.get_result().get().voter_key.get().vote_key = vote_key.get_result()
				db_voter_list.append(vote_key.get_result().get().voter_key.get())

				self.response.write("Voter id: %d\n" % (db_voter_list[-1].voter_id))

			#time.sleep(30)
			future_voter_key_list = ndb.put_multi(db_voter_list)

			#===================================PUT ALL VOTER_KEYS IN DISTRICTS==================================================

			dist_to_put_list = []
			for future_vote_key in future_vote_key_list:
				vote_key = future_vote_key.get_result()
				the_dist = vote_key.get().dist_key.get()
				the_dist.vote_key_list.append(vote_key)
				if the_dist not in dist_to_put_list:
					dist_to_put_list.append(the_dist)

			ndb.put_multi(dist_to_put_list)
"""Cronometra o tempo de execução entre algoritmos de ordenação de listas."""

import time as t
from ordenator import Ordenator
from lists import Lists


# Quantidade de elementos na lista
SIZE_LIST = 5000

# Gerando variações de listas
lts = Lists()
lists = {
    'Random': lts.random(SIZE_LIST),
    'Sorted': lts.sorted(SIZE_LIST),
    'Nearly Sorted': lts.nearly_sorted(SIZE_LIST)
}

# Instanciando o Ordenador
ordenator = Ordenator()

# Cronometrando as execuções
for i, l in lists.items():
    print("\n### LIST: {} ###".format(i))

    # Bubble
    start = t.time()
    result_list = ordenator.bubble(l)
    end = t.time()
    print("[Bubble]:\t{}".format(end - start))
 def __init__(self):
     Lists.__init__(self)
Esempio n. 18
0
import sys
import random
from lists import Lists

L = Lists()
#L.json_read_test()
 

seed = random.seed()

class Electoral_College():
    def __init__(self, elector_id, state, theLists):
        self.evoter_id = elector_id
        self.state = state
        self.candidate = random.randint(0, len(theLists.candidate_list) - 1)
        theLists.all_electoral_classes.append(self)
        
    def db_decode_candidate(self, theLists):
        if type(self.candidate) is int:
            self.candidate = theLists.candidate_list[self.candidate]
        
    def db_encode_candidate(self, theLists):
        if type(self.candidate) is str:
            self.candidate = theLists.candidate_list.index(self.candidate)        

class District():
    def __init__(self, district, state, theLists):
        self.number = district['Number']
        self.state = state
        self.voters = []
        theLists.all_district_classes.append(self)