Skip to content
This repository has been archived by the owner on Jun 12, 2019. It is now read-only.

Commit

Permalink
add skafos
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Hutcherson authored Mar 13, 2018
1 parent d927a79 commit 51f509b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions movies/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pandas as pd
from random import randint
from datetime import datetime
from constants import VOTES_SCHEMA
from movies.constants import VOTES_SCHEMA

def make_indicies(col_type, unique_list):
"""Given a list of unique things, create and map an ascending index."""
Expand All @@ -19,13 +19,12 @@ def make_indicies(col_type, unique_list):

def write_data(data, schema, skafos):
"""Write data out to the data engine."""
# Save out using the data engine
log.info('Saving {} records with the data engine'.format(len(data)))
print('Saving {} records with the data engine'.format(len(data)), flush=True)
res = skafos.engine.save(schema, data).result()
log.debug(res)
print(res, flush=True)


def make_fake_votes(num_movies, num_users):
def make_fake_votes(num_movies, num_users, skafos):
"""Generate fake votes as a starter set for recommendations."""
users = [uuid.uuid4() for u in range(0, num_users)]
movies = np.array(range(0, num_movies), dtype=np.int)
Expand All @@ -36,5 +35,5 @@ def make_fake_votes(num_movies, num_users):
time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
fake_votes.append({'user_id': str(u), 'movie_id': str(m), 'vote': randint(1, 2), 'vote_time': time})
print("Writing %s votes to cassandra.." % len(fake_votes), flush=True)
write_data(fake_votes, VOTES_SCHEMA, ska)
fake_votes.clear()
write_data(fake_votes, VOTES_SCHEMA, skafos)
fake_votes.clear()

0 comments on commit 51f509b

Please sign in to comment.