from eve_sde.sde_tasks import process_from_sde
from networkx import to_dict_of_dicts

from django.core.management.base import BaseCommand

from routing.graph import build
from routing.tasks import regenerate_connections


class Command(BaseCommand):
    help = "Precompute routing data"

    def handle(self, *args, **options) -> None:

        process_from_sde()  # update django eve sde just in case.

        regenerate_connections()

        G = build()

        with open("routing_output.txt", "w") as f:
            f.write(str(to_dict_of_dicts(G)))
