def ClicksWhichCorrespondToSessionsWithOneClick(): sess = clickdb.get_clicksession_db_session() pix_sess = clickdb.get_pixel_db_session() qry = sess.query(ClickSession.firstclick).filter(and_(ClickSession.click_count==1,ClickSession.qualification_certainty==1)).limit(10) for cl in qry: print cl.firstclick cl_qry = pix_sess.query(Click).filter(Click.id==cl.firstclick).first() print cl_qry print "Ref {0} \n Time spent: {1}\n Url: {2}".format(cl_qry.ref,cl_qry.time_spent,cl_qry.url)
def query_and_plot(and_statement_query_pairs): session = clickdb.get_clicksession_db_session() for tuple in and_statement_query_pairs: qry = session.query(ClickSession.time_spent).filter(tuple[0]) dat = [x[0] for x in qry] print "Data size {0} for histogram {1} ".format(len(dat),tuple[1]) plt.figure() plt.hist(dat,bins=200) plt.savefig(tuple[1])
def query_and_plot_histogram_for_all(path): session = clickdb.get_clicksession_db_session() qry = session.query(ClickSession.time_spent).filter(and_(ClickSession.qualification_certainty>=0,ClickSession.time_spent<=2000)) print "{0} data points queried ".format(qry.count()) dat = [x[0] for x in qry] plt.hist(dat,bins=200) qry = session.query(ClickSession.time_spent).filter(and_(ClickSession.qualification_certainty>=0.5,ClickSession.time_spent<=2000)) print "{0} data points queried ".format(qry.count()) dat = [x[0]*100 for x in qry] plt.hist(dat,bins=200) qry = session.query(ClickSession.time_spent).filter(and_(ClickSession.qualification_certainty>=1,ClickSession.time_spent<=2000)) print "{0} data points queried ".format(qry.count()) dat = [x[0]*1000 for x in qry] plt.hist(dat,bins=200) plt.savefig(path)