summaryrefslogtreecommitdiff
path: root/szilagyi/_dataset/__init__.py
blob: cfa1aeeb9c7b354bd31ad88e23148b42daa023fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import csv
import os
import re

from ..nomogram import Vector


ROOT = os.path.dirname(os.path.abspath(__file__))


def load():
	def _read(iterable):
		for x, y in iterable:
			yield Vector(float(x), float(y))

	def _load(filename):
		with open(filename) as fd:
			reader = csv.reader(fd)
			return list(_read(reader))

	def _files(directory):
		for filename in os.listdir(directory):
			match = re.match(r"SWI_(-?\d+)\.csv", filename)
			if match:
				yield int(match.group(1)), os.path.join(directory, filename)

	return [(x, _load(y)) for x, y in sorted(_files(ROOT), key=lambda x: x[0])]