Skip to content

Instantly share code, notes, and snippets.

@lucidguppy
Created March 27, 2021 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucidguppy/7216ca2137ada4a9e224298897995c27 to your computer and use it in GitHub Desktop.
Save lucidguppy/7216ca2137ada4a9e224298897995c27 to your computer and use it in GitHub Desktop.
local point crawl scrap
import csv
import os
import random
from itertools import chain
from graphviz import Graph
def local_point_crawl(points, point_count, connections, connection_count):
dot = Graph(comment='Area Map')
pairs = set()
subset = random.sample(points, point_count)
for thing in subset:
for _ in range(connection_count):
first = thing
others = set(subset)
others.remove(thing)
second = random.choice(list(others))
pair = sorted([first, second])
pairs.add(tuple(pair))
for pair in pairs:
dot.edge(pair[0], pair[1], label=f"{random.choice(connections)}")
dot.render('test-output/area_map.gv', view=True)
print(dot.source)
if __name__ == "__main__":
options = {}
for root, dirs, files in os.walk(os.path.expanduser('points')):
for file in sorted(files):
if file.endswith("csv"):
rows = [row[0] for row in csv.reader(open(os.path.join(root, file)))]
name = file.split(".")[0]
options[name] = rows
local_point_crawl(list(chain(options["landmarks"], options['forest'])), 7,
options["forest_connections"], 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment