-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
74 lines (68 loc) · 2.77 KB
/
test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
from csv import DictWriter
from django.conf import settings
from transformToLD.Automatic.autmatic_convert import auto_convert_csv, auto_convert_text, auto_convert_html
def test_csv(settings, DictWriter):
path = settings.MEDIA_URL+"tests/"
report_file = open(settings.MEDIA_URL+'report_test.csv', 'w')
writer = DictWriter(report_file, fieldnames=[
"filename", 'size', "exec_time", 'nb_rows', 'nb_cols', 'extract', 'preprocess', 'map', 'convert', 'sum', 'nb_triplets'])
writer.writeheader()
for i, csv_file in enumerate(os.listdir(path)):
record = {}
file_path = os.path.join(path, csv_file)
if (os.path.isfile(file_path)):
size = os.path.getsize(file_path)
record["filename"] = csv_file
record['size'] = size
print("file {} size= {}".format(file_path, size))
record = auto_convert_csv(file_path, str(i))
record.update({
'filename': csv_file,
'size': size,
})
writer.writerow(record)
report_file.close()
path = settings.MEDIA_URL+"tests/text/"
report_file = open(settings.MEDIA_URL+'report_test_text.csv', 'w')
writer = DictWriter(report_file, fieldnames=[
"filename", 'nb_sentences', 'size', "exec_time", 'extract', 'preprocess', 'map', 'convert', 'nb_triplets'])
writer.writeheader()
for i, csv_file in enumerate(os.listdir(path)):
record = {}
file_path = os.path.join(path, csv_file)
if (os.path.isfile(file_path)):
size = os.path.getsize(file_path)
record["filename"] = csv_file
record['size'] = size
print("file {} size= {}".format(file_path, size))
record = auto_convert_text(file_path, "text"+str(i))
record.update({
'filename': csv_file,
'size': size,
})
print(record)
writer.writerow(record)
report_file.close()
def test_html():
path = settings.MEDIA_URL+"tests/html/"
report_file = open(settings.MEDIA_URL+'report_test_html.csv', 'w')
writer = DictWriter(report_file, fieldnames=[
"filename", 'size', 'extract', 'nb_tables', 'nb_paragraphs'])
writer.writeheader()
for i, csv_file in enumerate(os.listdir(path)):
record = {}
file_path = os.path.join(path, csv_file)
if (os.path.isfile(file_path)):
size = os.path.getsize(file_path)
record["filename"] = csv_file
record['size'] = size
print("file {} size= {}".format(file_path, size))
record = auto_convert_html(file_path, "html"+str(i))
record.update({
'filename': csv_file,
'size': size,
})
print(record)
writer.writerow(record)
report_file.close()