forked from anilshanbhag/make-ssb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
95 lines (87 loc) · 1.63 KB
/
convert.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
nations = """ALGERIA
ARGENTINA
BRAZIL
CANADA
EGYPT
ETHIOPIA
FRANCE
GERMANY
INDIA
INDONESIA
IRAN
IRAQ
JAPAN
JORDAN
KENYA
MOROCCO
MOZAMBIQUE
PERU
CHINA
ROMANIA
SAUDI ARABIA
VIETNAM
RUSSIA
UNITED KINGDOM
UNITED STATES
"""
nations = nations.split('\n')
regions = """AFRICA
AMERICA
ASIA
EUROPE
MIDDLE EAST
"""
regions = regions.split('\n')
source_dir = '../data-raw20-m/'
dest_dir = source_dir
print "process suppliers"
lines = open(source_dir + 'supplier.tbl').readlines()
o = []
for line in lines:
try:
parts = line.split('|')
parts[4] = str(nations.index(parts[4]))
parts[5] = str(regions.index(parts[5]))
parts[3] = str(int(parts[4]) * 10 + int(parts[3][-1]))
o.append('|'.join(parts))
except:
print line
break
f = open(dest_dir + 'supplier.tbl.p','w')
for line in o:
f.write(line)
f.close()
print "process customers"
lines = open(source_dir + 'customer.tbl').readlines()
o = []
for line in lines:
try:
parts = line.split('|')
parts[4] = str(nations.index(parts[4]))
parts[5] = str(regions.index(parts[5]))
parts[3] = str(int(parts[4]) * 10 + int(parts[3][-1]))
o.append('|'.join(parts))
except:
print line
break
f = open(dest_dir + 'customer.tbl.p','w')
for line in o:
f.write(line)
f.close()
print "process parts"
lines = open(source_dir + 'part.tbl').readlines()
o = []
for line in lines:
try:
parts = line.split('|')
parts[2] = parts[2].split('#')[-1]
parts[3] = parts[3].split('#')[-1]
parts[4] = parts[4].split('#')[-1]
o.append('|'.join(parts))
except:
print line
break
f = open(dest_dir + 'part.tbl.p','w')
for line in o:
f.write(line)
f.close()