Skip to content

Commit de0ff61

Browse files
committed
PIOTEAM-41. Fix batch import.
1 parent 14a1487 commit de0ff61

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

examples/demo-movielens/batch_import.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
from appdata import AppData
33
import predictionio
44
import sys
5+
import pytz
56

6-
from app_config import APP_ID, API_URL, THREADS, REQUEST_QSIZE
7-
8-
def batch_import_task(app_data, client, all_info=False):
7+
def batch_import_task(app_id, app_data, client, all_info=False):
98

109
print "[Info] Importing users to PredictionIO..."
1110
count = 0
@@ -55,11 +54,6 @@ def batch_import_task(app_data, client, all_info=False):
5554
sys.stdout.write('\r[Info] %s' % count)
5655
sys.stdout.flush()
5756

58-
#client.identify(v.uid)
59-
#client.arecord_user_action_on_item("rate",
60-
# v.uid,
61-
# v.iid,
62-
# { "pio_rating": v.rating },)
6357
properties = { "pio_rating" : int(v.rating) }
6458
req = client.acreate_event({
6559
"event" : "rate",
@@ -68,10 +62,9 @@ def batch_import_task(app_data, client, all_info=False):
6862
"targetEntityType" : "pio_item",
6963
"targetEntityId": v.iid,
7064
"properties" : properties,
71-
"appId" : APP_ID,
72-
"eventTime" : v.t.isoformat() + 'Z'
65+
"appId" : app_id,
66+
"eventTime" : v.t.replace(tzinfo=pytz.utc).isoformat(),
7367
})
74-
#print req.get_response()
7568

7669
sys.stdout.write('\r[Info] %s rate actions were imported.\n' % count)
7770
sys.stdout.flush()
@@ -82,8 +75,10 @@ def batch_import_task(app_data, client, all_info=False):
8275
sys.exit("Usage: python -m examples.demo-movielens.batch_import "
8376
"<app_id> <url>")
8477

78+
app_id = int(sys.argv[1])
79+
8580
client = predictionio.EventClient(
86-
app_id=int(sys.argv[1]),
81+
app_id=app_id,
8782
url=sys.argv[2],
8883
threads=5,
8984
qsize=500)
@@ -92,5 +87,5 @@ def batch_import_task(app_data, client, all_info=False):
9287
print "Status:", client.get_status()
9388

9489
app_data = AppData()
95-
batch_import_task(app_data, client)
90+
batch_import_task(app_id, app_data, client)
9691
client.close()

0 commit comments

Comments
 (0)