import os
from spotlight.interactions import Interactions
from spotlight.factorization.explicit import ExplicitFactorizationModel
from movies.constants import *
from movies.helpers import *
from movies.logger import get_logger
from skafossdk import *

## Setup the logger and initialize Skafos
log = get_logger('recommender')
ska = Skafos()

## Extract Batch Size and Keyspace from the environment
if 'BATCH_SIZE' in os.environ:
    BATCH_SIZE = os.environ['BATCH_SIZE']
else:
    BATCH_SIZE = 10

## Set optional keypace (make sure data sharing rights have been activated if between two different organizations)
if 'KEYSPACE' in os.environ:
    KEYSPACE = os.environ['KEYSPACE']
else:
    KEYSPACE = None

## Set the recommendation schema
rec_schema = RECOMMEND_SCHEMA
if KEYSPACE:
    rec_schema["namespace"] = KEYSPACE

## VOTES TABLE SETUP
# In order to get recommendations from the model, a votes table must be created with a schema defined in constants.py
示例#2
0
if 'BATCH_SIZE' in os.environ:
    n = int(os.environ['BATCH_SIZE'])
else:
    n = 10

if 'BACKFILLED_DAYS' in os.environ:
    bd = os.environ['BACKFILLED_DAYS']
else:
    bd = None

if 'FILE_DATE' in os.environ:
    fd = os.environ['FILE_DATE']
else:
    fd = None

# Initialize the skafos sdk
ska = Skafos()

# Fetch movie data and write to cassandra using the Skafos Data Engine
ingest_log = get_logger('movie-fetch')
daily_movie_update = MovieData(api_key,
                               ingest_log,
                               batch_size=n,
                               backfilled_days=bd,
                               file_date=fd).fetch(skafos=ska, filter_pop=pop)

# Fetch additional movie info data for all new movies and write to cassandra using the Skafos Data Engine
info_log = get_logger('movie-info')
movie_info = MovieInfo(api_key, info_log, batch_size=n).fetch(skafos=ska)