def admin(): loggedIn = False all_projects = None all_users = None all_projects_map = None all_users_map = None all_issues = None all_issues_img = None all_issues_map = None if request.method == 'POST': username = request.form['username'] password = request.form['password'] if(username=='admin' and password == 'admin'): session['admin'] = True return redirect(url_for('admin')) else: if 'admin' in session: #logged in as admin loggedIn = True all_projects = json.loads(requests.get(url=DOMAIN+"/projects").text)["data"] all_users = json.loads(requests.get(url=DOMAIN+"/users").text)["data"] all_issues = json.loads(requests.get(url=DOMAIN+"/issues").text)["data"] # all_issues_img = [requests.get(url=DOMAIN+"/issue_image/"+i["id"]) for i in all_issues] all_issues_img = [i for i in range(len(all_issues))] style="width:100%;height:400px;border: 1px solid black; border-radius: 15px;" all_projects_map = create_map(style, [(i["lat"], i["lng"]) for i in all_projects], ["<p><strong>"+i["name"].upper()+"</strong></p><p><strong>Availability: </strong>"+str(i["count"])+"/"+str(i["num_people"])+"</p>" for i in all_projects], "projects01") all_users_map = create_map(style, [(i["lat"], i["lng"]) for i in all_users], ["<p><strong>"+i["first_name"].upper()+" "+i["last_name"].upper()+"</strong></p>" for i in all_users], "users01") all_issues_map = create_map(style, [(i["lat"], i["lng"]) for i in all_issues], ["<p><strong>"+i["kind"].upper()+"</strong></p>" for i in all_issues], "issues01") tmp = [{"img":all_issues_img[i],"data":all_issues[i]} for i in range(len(all_issues))] all_issues = tmp return render_template('admin.html', loggedIn=loggedIn, all_projects=all_projects, all_projects_map=all_projects_map, all_users=all_users, all_users_map=all_users_map, all_issues=all_issues, all_issues_map=all_issues_map)
def jsonGenerate(model): name = globals() rules, prov_dict = ruleGenerate() your_castle = "" computer_castle = [] if model == 1: map1 = create_map(your_castle, computer_castle) prov = get_province() computer_choice = play(prov, your_castle, computer_castle, rules) computer_castle.append(computer_choice) list_computer_castle = name[computer_choice].birth list_computer_castle.sort() for i in list_computer_castle: computer_castle.append(prov_dict[str(i)]) if model == 1: map2 = create_map(your_castle, computer_castle) key = key_generate(rules, your_castle, computer_castle) jsonObject = [{"rules": rules}, {"your_castle": your_castle, "computer_castle": computer_castle}, {"your_choice": "", "computer_choice": computer_choice}, {"key": key}] encodedjson = json.dumps(jsonObject) if model == 1: return encodedjson, map1, map2 else: return encodedjson
def screen_name(): form = LoginForm() if request.method == 'POST': print(request.form.get('username')) print(create_map.create_map(request.form.get('username'))) return create_map.create_map(request.form.get('username')) else: return render_template('login.html', title='Map', form=form)
def update_prediction(date, model_names): print('Updating prediction...') for model_name in model_names: create_map.create_map('prediction/' + model_name + '/' + date + '.png', filename='prediction/' + model_name + '/' + 'map_' + date + '.png') list_earthquakes.list_earthquakes('prediction/' + model_name + '/' + date + '.csv', filename='prediction/' + model_name + '/' + 'list_' + date + '.csv') with open('prediction/' + model_name + '/' + 'date.txt', 'w') as f: f.write(date) with open('prediction/' + model_name + '/' + 'archive.txt', 'a') as f: f.write('\n' + date) print('Prediction updated successfully!')
def get_map(authToken): #get map file - return map as dictionary try: with open("../utils/map.txt") as json_file: print("the file exists!") data = json.load(json_file) data = {int(k): v for k, v in data.items()} return data except FileNotFoundError: print("that file doesn't exist!") #do all the stuff to make a map #return map from explore function or read from here after exploring create_map(authToken) get_map(authToken)
def application(): """ () -> (html) This function uses html queries type of "GET" and builds a web map returns: html map with markers of user`s friends """ try: if not request.form['name'] or not request.form['counter']: raise ValueError elif request.form['name'] and request.form['counter']: int(request.form['counter']) cm.create_map(request.form['name'], request.form['counter']) return render_template("Map.html") except (ValueError, HTTPError): return render_template("error.html")
def map(): # Accept an API key values = request.get_json() initializeURL = 'https://lambda-treasure-hunt.herokuapp.com/api/adv/init/' headers = {'Authorization': 'Token ' + values['api_key']} # Initialize room initialize = requests.get(initializeURL, headers=headers) initialize_data = initialize.json() # Returns a dict with rooms with ids # traversing_map rooms_with_ids = create_map(headers, initialize_data, 500) print(rooms_with_ids) return rooms_with_ids, 200
def index(): email = None all_projects = None all_projects_map = None my_projects = None if 'email' in session: #loggedIn email = session['email'] my_projects = json.loads(requests.get(url=DOMAIN+"/projects/"+email).text)["data"] all_projects = json.loads(requests.get(url=DOMAIN+"/projects").text)["data"] names_my_p = [i["name"] for i in my_projects] greens = [(i["lat"], i["lng"]) for i in all_projects if i["name"] in names_my_p] reds = [(i["lat"], i["lng"]) for i in all_projects if i["name"] not in names_my_p] infoboxReds = ["<p><strong>"+i["name"].upper()+"</strong></p><p><strong>Availability: </strong>"+str(i["count"])+"/"+str(i["num_people"])+"</p>" for i in all_projects if i["name"] not in names_my_p] infoboxGreens = ["<p><strong>"+i["name"].upper()+"</strong></p><p><strong>Availability: </strong>"+str(i["count"])+"/"+str(i["num_people"])+"</p>" for i in all_projects if i["name"] in names_my_p] all_projects_map = create_map("width:100%;height:400px;border: 1px solid black; border-radius: 15px;", {"http://maps.google.com/mapfiles/ms/icons/green-dot.png":greens, "http://maps.google.com/mapfiles/ms/icons/red-dot.png":reds}, infoboxGreens+infoboxReds, "projects01") all_projects = [i for i in all_projects if i["name"] not in names_my_p] print('Logged in as {}'.format(email)) return render_template('index.html', email=email, all_projects=all_projects, all_projects_map=all_projects_map, my_projects=my_projects)
# Upload the ID files for each of the 7 studies ID_mapping_ober = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/ID_Mapping/QAQC.ober.txt" ID_mapping_williams = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/ID_Mapping/QAQC.williams.txt" ID_mapping_london = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/ID_Mapping/QAQC.london.txt" ID_mapping_burchard = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/ID_Mapping/QAQC.burchard.txt" # Upload the phenotype files from each of the 7 studies (Weiss is separated into two files) pheno_data_ober = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/MT_pheno_files/ober_MT_phenotypes2.csv" pheno_data_williams = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/MT_pheno_files/williams_MT_phenotypes2.csv" pheno_data_london = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/MT_pheno_files/london_MT_phenotypes2.csv" pheno_data_burchard = "/Users/KevinMagnaye/Documents/Mito_Asthma_Project/exome_chip_mitochondria/MT_pheno_files/burchard_MT_phenotypes2.csv" # Weiss and Barnes were done in a separate script create_lgen.create_lgen(raw_data_ober, ID_mapping_ober, pheno_data_ober, "ober.lgen") create_lgen.create_lgen(raw_data_williams, ID_mapping_williams, pheno_data_williams, "williams.lgen") create_lgen.create_lgen(raw_data_london, ID_mapping_london, pheno_data_london, "london.lgen") create_lgen.create_lgen(raw_data_burchard, ID_mapping_burchard, pheno_data_burchard, "burchard.lgen") create_map.create_map("ober.map") create_map.create_map("williams.map") create_map.create_map("weiss.map") create_map.create_map("london.map") create_map.create_map("burchard.map") create_map.create_map("barnes.map")
print('Saving the name list...') with open('names.txt', 'w') as f: for item in names: f.write("%s\n" % item) print('Getting all birth data...') save_all_birthdata(names, databasename) print('Getting all movement information...') save_all_places(names, databasename) # Generate the birthdate histogram print('Generating birth histogram...') birth_histogram() print('Generating travel distance distribution...') travel_distance_histogram() # Generate the maps # TODO generate a table of the most popular birth cities print('Generating maps of birth places....') create_map() # UPload the figures to wikipast print('Uploading the figures to the wikipast page...') add_all_figures(upload_all_figures(login_obj), login_obj) # Get the success rate by looking at the quantity of NotFound in the database print('Creating success rate file...') create_success_file()
def attack(encodedjson, model): json_file = json.loads(encodedjson) rules = json_file[0]['rules'] your_castle = json_file[1]['your_castle'] computer_castle = json_file[1]['computer_castle'] your_choice = json_file[2]['your_choice'] computer_choice = json_file[2]['computer_choice'] key = json_file[3]['key'] if key_check(rules, your_castle, computer_castle, key) != True: rt = "抱歉,密钥匹配失败,请重新尝试!" encodedjson = json_failed_Generate(rules, your_castle, computer_castle, your_choice, computer_choice, rt) return encodedjson if your_choice in your_castle: rt = "抱歉,您选择的城堡已经被己方占领,请重新尝试!" encodedjson = json_failed_Generate(rules, your_castle, computer_castle, your_choice, computer_choice, rt) return encodedjson if your_choice in computer_castle: rt = "抱歉,您选择的城堡已经被敌方占领,请重新尝试!" encodedjson = json_failed_Generate(rules, your_castle, computer_castle, your_choice, computer_choice, rt) return encodedjson prov = get_province() if your_choice not in prov: rt = "抱歉,您选择的城堡不在中国的省份内,请重新尝试!" encodedjson = json_failed_Generate(rules, your_castle, computer_castle, your_choice, computer_choice, rt) return encodedjson your_castle, computer_castle = reset_castle(rules, your_castle, computer_castle, your_choice, "your") print(your_castle, computer_castle) if model == 1: map1 = create_map(your_castle, computer_castle) if check_gameover(your_castle, computer_castle): final_score = score(your_castle) rt = "恭喜你,您的游戏结束了,最后得分是:%s" % (final_score) encodedjson = json_failed_Generate(rules, your_castle, computer_castle, your_choice, computer_choice, rt) if model == 1: map2 = "" return encodedjson, map1, map2 elif model == 0: return encodedjson computer_choice = play(prov, your_castle, computer_castle, rules) your_castle, computer_castle = reset_castle(rules, your_castle, computer_castle, computer_choice, "computer") print(your_castle, computer_castle) if model == 1: map2 = create_map(your_castle, computer_castle) if check_gameover(your_castle, computer_castle): final_score = score(your_castle) rt = "恭喜你,您的游戏结束了,最后得分是:%s" % final_score encodedjson = json_failed_Generate(rules, your_castle, computer_castle, your_choice, computer_choice, rt) if model == 1: return encodedjson, map1, map2 elif model == 0: return encodedjson encodedjson = json_Generate(rules, your_castle, computer_castle, computer_choice) if model == 1: return encodedjson, map1, map2 else: return encodedjson