# Path: roadmaptools/init.py

# 
# Path: roadmaptools/printer.py
# def print_info(info, file=sys.stdout, end="\n"):
#     print("[{0}]: {1}".format(datetime.now().strftime('%H:%M:%S'), info), file=file, end=end)


import networkx as nx
import roadmaptools.inout
from networkx import DiGraph
from geojson.feature import FeatureCollection
from tqdm import tqdm
from roadmaptools.init import config
from roadmaptools.printer import print_info
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#



def get_biggest_component(graph: DiGraph) -> set:
	biggest_subgraph = graph

	if not nx.is_strongly_connected(graph):
		maximum_number_of_nodes = -1
		for subgraph in nx.strongly_connected_components(graph):
			if len(subgraph) > maximum_number_of_nodes:
				maximum_number_of_nodes = len(subgraph)
				biggest_subgraph = subgraph

	id_dict = nx.get_edge_attributes(graph, "id")

	print_info("Creating edge id set")
	edge_ids = set()
	for coordinates, id in id_dict.items():
		if coordinates[0] in biggest_subgraph and coordinates[1] in biggest_subgraph:
			edge_ids.add(id)

	return edge_ids


def filter_geojson_features_by_graph(geojson_data: FeatureCollection, edge_ids: set):


# Path: roadmaptools/init.py

# 
# Path: roadmaptools/printer.py
# def print_info(info, file=sys.stdout, end="\n"):
#     print("[{0}]: {1}".format(datetime.now().strftime('%H:%M:%S'), info), file=file, end=end)


# Path: roadmaptools/sanitize.py
import networkx as nx
import roadmaptools.inout
from networkx import DiGraph
from geojson.feature import FeatureCollection
from tqdm import tqdm
from roadmaptools.init import config
from roadmaptools.printer import print_info

#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#



def get_biggest_component(graph: DiGraph) -> set:
	biggest_subgraph = graph

	if not nx.is_strongly_connected(graph):
		maximum_number_of_nodes = -1
		for subgraph in nx.strongly_connected_components(graph):
			if len(subgraph) > maximum_number_of_nodes:
				maximum_number_of_nodes = len(subgraph)
				biggest_subgraph = subgraph

	id_dict = nx.get_edge_attributes(graph, "id")

	print_info("Creating edge id set")
	edge_ids = set()
	for coordinates, id in id_dict.items():
		if coordinates[0] in biggest_subgraph and coordinates[1] in biggest_subgraph:
			edge_ids.add(id)

	return edge_ids


def filter_geojson_features_by_graph(geojson_data: FeatureCollection, edge_ids: set):


	print_info("Filtering geojson by edge id set")