-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
31 lines (29 loc) · 1.01 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
from utils import *
import pandas as pd
import sys
import json
from convert_traffic import *
from convert_weather import *
def preprocess(convert_type):
while True:
# Convert JSON to dataframe
jsonString = sys.stdin.readline()
inputDict = json.loads(jsonString)
input_temp = pd.DataFrame.from_dict(inputDict)
# Choose the type of preprocessing
if convert_type == 'traffic':
outputDict = convert_traffic(input_temp)
elif convert_type == 'weather':
outputDict = convert_weather(input_temp)
else:
print('Invalid convert type -- '+convert_type)
# Convert dict to JSON
jsonString = json.dumps(outputDict)
sys.stdout.write(jsonString + "\n")
sys.stdout.flush()
if __name__ == '__main__':
# Argument:
# traffic : stands for traffic prediction project
# weather : stands for weather prediction project
convert_type = sys.argv[1]
preprocess(convert_type)