-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
52 lines (43 loc) · 1.33 KB
/
main.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# coding=utf-8
"""
This script will dump all the files (or a test sample) from the files/nc4/
directory
"""
from random import randint
import sys
__author__ = 'Lorenzo'
from files.loadfiles import return_dataset, return_files_paths
from src.formatdata import create_generator_from_dataset
def main(full=False):
paths = return_files_paths()
print(paths, len(paths))
# check the full flag
if not full:
l = randint(0, len(paths) - 1)
# try the first thousand rows of one random file
dataset = [return_dataset(paths[l])]
luke = (create_generator_from_dataset(d, 1000) for d in dataset)
else:
# dump all the files
dataset = []
dataset += [return_dataset(p) for p in paths]
luke = (create_generator_from_dataset(d) for d in dataset)
#print(luke, )
# Luke is a >> generator of generators <<
# Feel the Force
print('DUMPING...')
from src.formatdata import bulk_dump
i = 0
while True:
try:
_, n = bulk_dump(next(luke))
i += n
except StopIteration:
print('>>> {} Xco2 data dumped <<<'.format(i))
break
except KeyboardInterrupt:
break
sys.exit(0)
if __name__ == '__main__':
# set full=True if you want to dump all the downloaded files
main(full=True)