Created
March 27, 2021 02:49
-
-
Save lucidguppy/7216ca2137ada4a9e224298897995c27 to your computer and use it in GitHub Desktop.
local point crawl scrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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