In [1]:
import sys
import os
sys.path.append(os.getcwd()+'/../')
# other
import numpy as np
import glob
import pandas as pd
import ntpath
#keras
from keras.preprocessing import image
# plotting
import seaborn as sns
sns.set_style('white')
import matplotlib.pyplot as plt
%matplotlib inline
%load_ext autoreload
# debuggin
from IPython.core.debugger import Tracer
#stats
import scipy.stats as stats
In [2]:
%autoreload 2
In [6]:
folder='../data_img_sample_item_view_sequences/'
In [34]:
from src.data_management import get_meta_data_from_sequence_data
df = get_meta_data_from_sequence_data(folder)
df.head()
Out[34]:
In [45]:
def make_html(user_set,newfile):
with open(newfile, 'w') as outfile:
outfile.write("<!DOCTYPE html><html><head><style>")
outfile.write("table.app {border:1px solid #d4d4d4;}")
# open table
outfile.write("#circle {border-radius:50% 50% 50% 50%;}</style></head><body background-color: transparent;><table class='app'>")
# loop through users #
for user_id in user_set:
print(user_id)
outfile.write("<tr>") # new row
# loop through his/her views
view_positions = np.sort(df.loc[df.user_id==user_id,'view_position'].unique())
for view_pos in view_positions:
# get info
view_seconds = df.loc[(df.user_id==user_id)&(df.view_position==view_pos),'view_seconds'].as_matrix()[0]
tag = df.loc[(df.user_id==user_id)&(df.view_position==view_pos),'tag'].as_matrix()[0]
spu = df.loc[(df.user_id==user_id)&(df.view_position==view_pos),'spu'].as_matrix()[0]
# get img path
img_path = glob.glob(folder+str(user_id)+'_'+str(view_pos)+'_'+str(spu)+'_'+str(view_seconds)+'_'+str(tag)+'*')[0]
outfile.write("<td><img id='circle' src='" + img_path + "' style='height:150px; width:150px' /><p>user_id: "+str(user_id)+' pos: '+str(view_pos)+' '+str(view_seconds)+'secs '+tag+"</p></td>")
outfile.write("</tr>") # close row
# close table.
outfile.write("</table></body>")
In [44]:
for i,user_set in enumerate(np.split(df.user_id.unique(),10)): #split into 10 sets
print(i)
# create HTML file
newfile = '../figures/Sample_View_Sequences_set_'+str(i)+'.html'
make_html(user_set,newfile)
In [50]:
# from src.s3_data_management import push_results_to_s3
# for i,user_set in enumerate(np.split(df.user_id.unique(),10)):
# newfile = '../figures/Sample_View_Sequences_set_'+str(i)+'.html'
# newname = 'Sample_View_Sequences_set_'+str(i)+'.html'
# push_results_to_s3(newname,newfile)
# doesn't work because pictures don't get pushed up as well
In [47]:
user_set = ['1411185938']
newfile = '../figures/Sample_View_Sequences_user_'+user_set[0]+'.html'
make_html(user_set,newfile)
# this user seems to like patterned things and is searching within a restricted set.
In [47]:
user_set = ['...']
newfile = '../figures/Sample_View_Sequences_user_'+user_set[0]+'.html'
make_html(user_set,newfile)
# this user seems to like patterned things and is searching within a restricted set.
In [38]:
%%bash
jupyter nbconvert --to html Sample_Item_View_Sequences.ipynb && mv Sample_Item_View_Sequences.html ../notebook_htmls/Sample_Item_View_Sequences_v1.html
cp Sample_Item_View_Sequences.ipynb ../notebook_versions/Sample_Item_View_Sequences.ipynb_v1.ipynb
In [ ]: