-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
executable file
·74 lines (55 loc) · 1.71 KB
/
preprocess.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 sql_functions
import os
'''
Author : Sebastien Boyer
Pre-processing database before feature extraction
'''
def preprocess(dbName, userName, passwd, host, port, dirName, startDate, currentDate):
# fileName, wordsToBeReplaced, wordsToReplace
preprocessing_files = [
#[
#'create_longitudinal_features.sql',
#['moocdb'],
#[dbName]
#],
#[
#'populate_longitudinal_features.py',
#[],
#[]
#],
#[
#'create_models_table.sql',
#['moocdb'],
#[dbName]
#],
#[
#'create_experiments_table.sql',
#['moocdb'],
#[dbName]
#],
[
'create_user_longitudinal_feature_values.sql',
['moocdb'],
[dbName]
],
[
'users_populate_dropout_week.sql',
['START_DATE_PLACEHOLDER','moocdb'],
[startDate,dbName]
]
]
conn = sql_functions.openSQLConnectionP(dbName, userName, passwd, host,port)
for fileName, toBeReplaced, replaceBy in preprocessing_files:
if fileName[-2:] == 'py':
print "executing: ", fileName
sql_functions.runPythonFile(conn,conn,dirName,
fileName[:-3],dbName,startDate, currentDate)
else:
this_file = os.path.dirname(os.path.realpath(__file__))
fileLocation = dirName+'/'+fileName
fileLocation = this_file+'/'+fileLocation
newFile = sql_functions.replaceWordsInFile(fileLocation, toBeReplaced, replaceBy)
print "executing: ", fileName
sql_functions.executeSQL(conn, newFile)
conn.commit()
sql_functions.closeSQLConnection(conn)