import sps

"""
Preplot importing functions.
"""

def from_file (file, realpath = None):
	filepath = realpath or file["path"]
	if not "type" in file or file["type"] == "sps":
		records = sps.from_file(filepath, file["format"] if "format" in file else None )
	else:
		return "Not an SPS file"

	lines = []
	line_names = set([r["line_name"] for r in records])
	for line_name in line_names:
		line = dict(line_name=line_name)
		line_points = [r for r in records if r["line_name"] == line_name]
		if line_points:
			line["points"] = line_points
			lines.append(line)

	return lines
