Skip to content

Instantly share code, notes, and snippets.

@bpgergo
Last active November 6, 2024 11:59
Show Gist options
  • Save bpgergo/d672b0ee7b0e868040568dfe16fa29c0 to your computer and use it in GitHub Desktop.
Save bpgergo/d672b0ee7b0e868040568dfe16fa29c0 to your computer and use it in GitHub Desktop.
megmerettetes.hu 2024 python1
import geopy.distance
import pandas as pd
import osmnx as ox
import networkx as nx
G = ox.graph_from_place('Budapest, Hungary', network_type='walk')
regular_guests_income = 12000
new_guests_income = 6000
num_of_regs = 120
coords1 = (47.54148318014639, 19.040601611694765) # Florian ter, Budapest
def get_dist(coords2):
return geopy.distance.geodesic(coords1, coords2).m
def get_walking_dist(coords2):
node1, dist1 = ox.distance.nearest_nodes(G, coords1[0], coords1[1], return_dist=True)
node2, dist2 = ox.distance.nearest_nodes(G, coords2[0], coords2[1], return_dist=True)
#exclude distance between coords2 and node2
return dist1 + nx.shortest_path_length(G, node1, node2, weight='length')
def profit_from_row(row):
return profit(row['latitude'], row['longitude'], row['area'], row['rent'], row['competitors'],
row['exposure'], row['population'])
def profit(latitude,longitude,area,rent,competitors,exposure,population):
regs = num_of_regs
dist = get_dist((latitude, longitude))
regs = round(max(regs - (dist / 30), 0))
news = round(population * exposure / (competitors + 1))
max_gests = round(((area - 400) / 15) * 10)
news = min(max_gests - regs, news)
income = regs * regular_guests_income + news * new_guests_income
profit = income - rent
return profit
df = pd.read_csv('2_feladat/helyszinek.csv')
df['profit'] = df.apply(profit_from_row, axis=1)
df.sort_values(by=["profit"], inplace=True)
print(df.tail(1)['contact'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment