def update_locally(exp): users = methods.read_data("users.json") user = users[str(session_id)] user["exp"] += exp user["weekly_exp"] += exp user["level"] = calculate_level(user["exp"] / 25) methods.write_data(users, "users.json")
def setUp(self): '''Set up an instance pior to every test execution''' self.df = f.read_data(testing_df) self.X_train, self.X_test, self.y_train, self.y_test = f.split_train_test( self.df) self.X_train, self.X_test, self.vocab_size, self.real_maxlen = f.tokenize( self.X_train, self.X_test, test_mode=True)
def setUp(self): '''Set up an instance pior to every test execution''' self.df = f.read_data(testing_df) self.X_train, self.X_test, self.y_train, self.y_test = f.split_train_test( self.df) self.X_train, self.X_test, self.vocab_size, self.real_maxlen = f.tokenize( self.X_train, self.X_test, test_mode=True) self.model = f.my_model(maxlen=self.real_maxlen, embedding_dim=5, vocab_size=self.vocab_size, lr=0.001, epochs=1)
def save_user_locally(userId, username, password, description, exp, weekly_exp, level): # Save users profile locally as well users = methods.read_data("users.json") users[str(userId)] = { "name": username, "password": password_hash(password), "description": description, "exp": exp, "weekly_exp": weekly_exp, "level": level } methods.write_data(users, "users.json")
def save_des(): """Get the description from box and write it into the file""" users = methods.read_data("users.json") # Get the input temp = DesLabel.get(1.0, END) # Remove the \n and edit the data des = temp.replace("\n", "") users[str(session_id)]["description"] = des # Write it into the json file methods.write_data(users, "users.json") methods.post_remote("updateDescription", { "id": session_id, "description": des })
def retrieve(category, quantity): url = "https://opentdb.com/api.php?amount=" + str( quantity) + "&category=" + str(category) # Read JSON data from url error = 0 try: response = urllib.urlopen(url) try: jsonData = json.loads(response.read()) except ValueError: error = 1 except IOError: error = 1 if (error == 1): jsonData = methods.read_data("backup.json") results = jsonData[str(category)][str(quantity)] else: results = jsonData["results"] questions = [] for i in range(0, len(results)): data = results[i] # Place them all in their respective variables difficulty, category, question, correct_answer, incorrect_answers = data[ "difficulty"], data["category"], data["question"], data[ "correct_answer"], data["incorrect_answers"] # Append the incorrect_answers list to our options list options = [] options.extend(incorrect_answers) # Calculate a random index to place our correct_answer in the options list random_index = random.randrange(len(options) + 1) options.insert(random_index, correct_answer) # Append it in the form of an object/dictionary to our questions list questions.append({ "question": question, "options": options, "correct_answer": random_index }) # Shuffle our questions random.shuffle(questions, random.random) return questions
def login(username, password): print "sending request" request = methods.post_remote("loginUser", {"name": username}) print request # If request did not fail: if (request != None): data = json.loads(request) # If there are errors ( caused by non-existing username ) and password does not match the password stored in the database: if (("error" in data and data["error"] == True) or data["password"] != password_hash(password)): tkMessageBox.showerror("Error", "Please Try Again!") else: tkMessageBox.showinfo("Done", "Login Successfully!") save_user_locally(data["id"], username, password, data["description"], data["exp"], data["weekly_exp"], data["level"]) LogWindow.destroy() RegWindow.destroy() profile.session_id = data["id"] profile.show_window() else: # If request to remote server failed, log in locally print "logging in locally" users = methods.read_data("users.json") counter = 0 for i in users: counter = counter + 1 if users[str(i)]["name"] == username and users[str( i)]["password"] == password_hash(password): tkMessageBox.showinfo("Done", "Login Successfully!") LogWindow.destroy() RegWindow.destroy() profile.session_id = str(i) profile.show_window() break else: if (counter == len(users)): tkMessageBox.showerror("Error", "Please Try Again!") break else: continue
def show_ranking(): users = methods.read_remote_json("public") if (users == False): users = methods.read_data("users.json") ###UI positioning### root = methods.define_window("AskTrivia Leaderboard", "320x400") root.rowconfigure(0, weight=1) root.rowconfigure(1, weight=1) root.rowconfigure(2, weight=1) tabs = ttk.Notebook(root) exp_frame = ttk.Frame(tabs) weeklyexp_frame = ttk.Frame(tabs) tabs.add(exp_frame, text="Overall Ranking") tabs.add(weeklyexp_frame, text="Ranking by week") tabs.grid(row=1) leaderboard_text = Label(root, text="Leaderboard", font="Times", fg="Black") leaderboard_text.grid(row=0, padx=100) ##Overall ranking## rank_text = Label(exp_frame, text="Rank") name_text = Label(exp_frame, text="Name") exp_text = Label(exp_frame, text="EXP") rank_text.grid(row=2, column=0, columnspan=2, pady=10) name_text.grid(row=2, column=2, columnspan=2) exp_text.grid(row=2, column=4, columnspan=2) rank_by_exp = sort_exp("exp", users) if len(rank_by_exp) >= 1: for i in range(1, len(rank_by_exp) + 1): if i == 11: break rank = Label(exp_frame, text=str(i)).grid(row=i + 2, column=0, columnspan=2) name = Label(exp_frame, text=rank_by_exp[i]["name"]).grid(row=i + 2, column=2, columnspan=2, sticky=W) exp = Label(exp_frame, text=rank_by_exp[i]["exp"]).grid(row=i + 2, column=4, columnspan=2, sticky=E) #ranking by week rank_text = Label(weeklyexp_frame, text="Rank") name_text = Label(weeklyexp_frame, text="Name") exp_text = Label(weeklyexp_frame, text="EXP") rank_text.grid(row=2, column=0, columnspan=2, pady=10) name_text.grid(row=2, column=2, columnspan=2) exp_text.grid(row=2, column=4, columnspan=2) rank_by_exp = sort_exp("weekly_exp", users) if len(rank_by_exp) >= 1: for i in range(1, len(rank_by_exp) + 1): if i == 11: break rank = Label(weeklyexp_frame, text=str(i)).grid(row=i + 2, column=0, columnspan=2) name = Label(weeklyexp_frame, text=rank_by_exp[i]["name"]).grid(row=i + 2, column=2, columnspan=2, sticky=W) exp = Label(weeklyexp_frame, text=rank_by_exp[i]["weekly_exp"]).grid(row=i + 2, column=4, columnspan=2, sticky=E) root.mainloop()
def reset_weeklyexp(): users = methods.read_data("users.json") for i in users: users[i]["weekly_exp"] = 0 methods.write_data(users, "users.json")
from __future__ import print_function from methods import read_data, compute_methods demo_data = """ a v 0.138 0.148 0.220 0.171 0.291 0.234 0.560 0.324 0.766 0.390 1.460 0.493 """ s, v0 = read_data(demo_data) print ('s =', s) print ('v0 =', v0) results = compute_methods(s, v0) print (results) f = results.plot_hypers() f.savefig('hypers.png') f.savefig('hypers.pdf') f = results.plot_others() f.savefig('others.png') f.savefig('others.pdf')
def setUp(self): '''Set up an instance pior to every test execution''' self.df = f.read_data(testing_df) self.X_train, self.X_test, self.y_train, self.y_test = f.split_train_test( self.df)
def setUp(self): '''Set up an instance pior to every test execution''' self.df = f.read_data(original_df)
# Variable Start here ######################################### session_id = "0" quiz.session_id = session_id frame_count = 0 # As a counter for gif frame later framenumber = 0 animaterun = True ######################################### # Constant Variable Start here ######################################### PROFILE_HEIGHT = 90 PROFILE_WIDTH = 90 PROFILE_PIC_LINK = methods.read_data("pic/profile.gif") # Initialization in SetPathTitleLabel = ""; Profile_Pic = "" NameLabel = "" DesTitleLabel = "" DesLabel = "" SaveDesButton = "" PlayButton = "" RandomQuesButton = "" RankingButton = "" ######################################### # Function Start here #########################################