def test_access_initialize_without_supply_value_col_in_list_raises_value_error(self): with self.assertRaises(ValueError): bad_value_name = ['Not a col in supply df'] access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = bad_value_name)
def test_access_initialize_without_demand_index_col_raises_value_error(self): with self.assertRaises(ValueError): bad_index_name = 'Not a col in demand df' access(demand_df = self.demand_grid, demand_index = bad_index_name, demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = 'value')
def test_access_initialize_without_valid_neighbor_cost_name_in_list_raises_value_error(self): with self.assertRaises(ValueError): bad_cost_name = ["Not a valid cost name column"] access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = 'value', neighbor_cost_df = self.cost_matrix, neighbor_cost_origin = 'origin', neighbor_cost_dest = 'dest', neighbor_cost_name = bad_cost_name)
def test_access_initialize_without_valid_cost_origin_raises_value_error(self): with self.assertRaises(ValueError): bad_cost_origin = "Not a valid cost origin column" access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = 'value', cost_df = self.cost_matrix, cost_origin = bad_cost_origin, cost_dest = 'dest', cost_name = 'cost')
def test_weighted_catchment_with_gravity_weights(self): n = 5 supply_grid = tu.create_nxn_grid(n) demand_grid = supply_grid cost_matrix = tu.create_cost_matrix(supply_grid, 'euclidean') self.model = access(demand_df=demand_grid, demand_index='id', demand_value='value', supply_df=supply_grid, supply_index='id', supply_value='value', cost_df=cost_matrix, cost_origin='origin', cost_dest='dest', cost_name='cost') gravity = weights.gravity(scale=60, alpha=1) self.model.weighted_catchment(name='gravity', weight_fn=gravity) ids = [1, 5, 13, 19, 24] expected_vals = [ 1.322340210, 1.322340210, 0.780985109, 0.925540119, 1.133733026, ] for id, expected in zip(ids, expected_vals): actual = self.model.access_df.gravity_value.loc[id] self.assertAlmostEqual(actual, expected)
def main(): """ Print list of gmail message body """ service = access() # User input user_id = 'me' label_name = input('Enter label name: ') response = service.users().labels().list(userId=user_id).execute() labels = response['labels'] # Call the Gmail API label_id = get_label_id(labels, label_name) f = open("out.txt", 'w') # Get all message body for msg in list_messages_with_labels(service, user_id, label_id): get_message_body(service, user_id, msg['id'], f) f.write('================================') f.write('================================') f.close()
def test_access_initialize_with_supply_value_col_in_dict_raises_value_error(self): with self.assertRaises(ValueError): value_in_dict = {'value':''} self.model = access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = value_in_dict)
def test_access_initialize_with_supply_value_col_in_list(self): value_in_list = ['value'] self.model = access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = value_in_list) actual = self.model.supply_types self.assertEqual(actual, ['value'])
def test_access_initialize_with_valid_neighbor_cost_name_in_dict_raises_value_error(self): with self.assertRaises(ValueError): cost_name_dict = {'cost':''} self.model = access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = 'value', neighbor_cost_df = self.cost_matrix, neighbor_cost_origin = 'origin', neighbor_cost_dest = 'dest', neighbor_cost_name = cost_name_dict)
def setUp(self): n = 5 supply_grid = tu.create_nxn_grid(n) demand_grid = supply_grid.sample(1) cost_matrix = tu.create_cost_matrix(supply_grid, 'euclidean') self.model = access(demand_df = demand_grid, demand_index = 'id', demand_value = 'value', supply_df = supply_grid, supply_index = 'id', supply_value = 'value', cost_df = cost_matrix, cost_origin = 'origin', cost_dest = 'dest', cost_name = 'cost', neighbor_cost_df = cost_matrix, neighbor_cost_origin = 'origin', neighbor_cost_dest = 'dest', neighbor_cost_name = 'cost')
def test_access_initialize_with_valid_neighbor_cost_name_in_list(self): cost_name_list = ['cost'] self.model = access(demand_df = self.demand_grid, demand_index = 'id', demand_value = 'value', supply_df = self.supply_grid, supply_index = 'id', supply_value = 'value', neighbor_cost_df = self.cost_matrix, neighbor_cost_origin = 'origin', neighbor_cost_dest = 'dest', neighbor_cost_name = cost_name_list) actual = self.model.neighbor_cost_names self.assertEqual(actual, ['cost'])
def transaction(): jsonData = request.get_json(cache=False) user=jsonData["userName"] type = "Transaction" if request.method =='GET': getData = access(graph, type, user, user) elif request.method=='POST': postData = [jsonData["userName"], jsonData["transName"], jsonData["transDate"], jsonData["transLocation"],jsonData["transAmount"]] insert(graph,type,postData) elif request.method=='PUT': current=["currentItem"] mod = jsonData["modItem"] modify(graph,type,user,current,mod) elif request.method=='DELETE': delItem=jsonData["delItem"] delete(graph,type,user,delItem)
def saving(): jsonData = request.get_json(cache=False) user=jsonData["userName"] type = "Goal" if request.method =='GET': getData = access(graph, type, user, user) elif request.method=='POST': postData = [jsonData["userName"], jsonData["savingsName"], jsonData["amount"], jsonData["downpay"],jsonData["term"],jsonData["description"]] insert(graph,type,postData) elif request.method=='PUT': current=["currentItem"] mod = jsonData["modItem"] modify(graph,type,user,current,mod) elif request.method=='DELETE': delItem=jsonData["delItem"] delete(graph,type,user,delItem)
def setUp(self): demand_data = pd.DataFrame({ 'id': [0, 1], 'x': [0, 0], 'y': [0, 1], 'value': [1, 1] }) demand_grid = gpd.GeoDataFrame(demand_data, geometry=gpd.points_from_xy( demand_data.x, demand_data.y)) demand_grid['geometry'] = demand_grid.buffer(.5) supply_data = pd.DataFrame({ 'id': [1], 'x': [0], 'y': [1], 'value': [1] }) supply_grid = gpd.GeoDataFrame(supply_data, geometry=gpd.points_from_xy( supply_data.x, supply_data.y)) cost_matrix = pd.DataFrame({ 'origin': [0, 0, 1, 1], 'dest': [1, 0, 0, 1], 'cost': [1, 0, 1, 0] }) self.model = access(demand_df=demand_grid, demand_index='id', demand_value='value', supply_df=supply_grid, supply_index='id', supply_value='value', cost_df=cost_matrix, cost_origin='origin', cost_dest='dest', cost_name='cost', neighbor_cost_df=cost_matrix, neighbor_cost_origin='origin', neighbor_cost_dest='dest', neighbor_cost_name='cost')
def getdb(dburl="mysql://*****:*****@localhost:3306/dbname"): ''' db generator ''' s=dburl pos=dburl.find("://") if pos==-1: raise Exception("bad dburl: "+dburl) type=s[:pos] r=s[pos+3:] if type=='access' or type=='sqllite': file=r else: r=r.split("@") if len(r)!=2: raise Exception("bad dburl: "+dburl) l=r[0].split(":") if len(l)!=2: raise Exception("bad dburl: "+dburl) user=l[0] pwd=l[1] t=r[1].split("/") if len(t)!=2: raise Exception("bad dburl: "+dburl) db=t[1] r=t[0].split(":") host=r[0] port=int(r[1]) if len(r)==2 else None if type=="mysql": return mysql(host, user, pwd, db, port) elif type=="sqlserver": import sqlserver return sqlserver.sqlserver(host, user, pwd, db) elif type=="sqllite": import sqllite return sqllite.sqllite(file) elif type=="access": import access return access.access(file) elif type=="postprogress": return None else: raise Exception("bad db type")
import algorithms import access import simulate import Gnuplot import random shiftrange = range(1, 20) ws = access.wsmake(mem=range(10000), rand=random, size=5) alist = [] for i in range(500000): alist.append(access.access(range(10000), ws, random, 0.95)) if not i % 10: access.wsmove(range(10000), ws, random) if not i % 1000: print "alist: " + str(i) ratios = [] for i in shiftrange: mms = algorithms.Aging(6, bits=4, shift=i) # Instantiate. ratios.append((i, simulate.simulate(mms, alist))) print "Shifting frequency: " + str(i) g = Gnuplot.Gnuplot() g('set data style points') g('set yrange[0:]') g('set terminal epslatex monochrome')
if __name__ == "__main__": import data from access import access from access_jit import access as access_jit from access_tab import access as access_tab from datetime import datetime print("-" * 30 + "confirm agreement" + "-" * 30) filter_flows = False a1 = access(data.toy(), filter_flow=filter_flows) j1 = access_jit(data.toy(), filter_flow=filter_flows) t1 = access_tab(data.toy(), filter_flow=filter_flows) numpy.testing.assert_array_equal(t1.accessibility, a1.accessibility) numpy.testing.assert_array_equal(t1.accessibility, j1.accessibility) print("passed toy tabular unfiltered") filter_flows = True a1f = access(data.toy(), filter_flow=filter_flows) j1f = access_jit(data.toy(), filter_flow=filter_flows) t1f = access_tab(data.toy(), filter_flow=filter_flows) numpy.testing.assert_array_equal(t1f.accessibility, a1f.accessibility) numpy.testing.assert_array_equal(t1f.accessibility, j1f.accessibility) print("passed toy tabular unfiltered") filter_flows = False a2 = access(data.flows(n_hubs=20), filter_flow=filter_flows) j2 = access_jit(data.flows(n_hubs=20), filter_flow=filter_flows) t2 = access_tab(data.flows(n_hubs=20), filter_flow=filter_flows)
import access import downloader # ここでダウンロードする数を設定します。 # 入力した数字×40個のbookmarkが調べられます # 例えば3を入力した場合120件ダウンロードされます times = 3 token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" authorization = "Bearer " + str(token) first = access.access(0, authorization) next_id = first['next_id'] data = first['data'] downloader.downloader(data, authorization) errors = 0 time = 1 while int(time) < int(times): loops = access.access(next_id, authorization) data = loops['data'] downloaded = downloader.downloader(data, authorization) errors = int(errors) + int(downloaded['error']) if len(str(loops['next_id'])) == 'stop': print("登録されているbookmarkがなくなりました作業を終了しています") break else: next_id = loops['next_id'] time += 1