def index(self):
     self.b = Bids()
     #data = group_by_minute_and_count()
     #print(data)
     #return data
     return open(os.path.join(STATIC_DIR, u'index.html'))
class Root(object):


    
    @cherrypy.expose
    def index(self):
        self.b = Bids()
        #data = group_by_minute_and_count()
        #print(data)
        #return data
        return open(os.path.join(STATIC_DIR, u'index.html'))









    @cherrypy.expose
    def histogram(self):
        
        engine = ds.bi_engine
        conn = engine.connect()
        s = bizdw_v6.lifecycle_events_subscribes.alias()
        
        df = group_by_minute_and_count(s,conn)
        sub = df['sub_count']
        
        print(sub)
        
        
        tmp_list_1 = []
        tmp_list_2 = []
        cum_1 = 0
        cum_2 = 0
        for row_num, i in enumerate(sub):
            if row_num < 1440:
            
                cum_1 = cum_1 + i
                tmp_list_1.append(cum_1)
                
            else:
                
                cum_2 = cum_2 + i
                tmp_list_2.append(cum_2)
                
        cumulative_1 = np.array(tmp_list_1) 
        cumulative_2 = np.array(tmp_list_2) 
    
        diff = []
        for row_num, i in enumerate(cumulative_1):
            try:
                diff.append(cumulative_1[row_num] - cumulative_2[row_num] + random.random())
            except:
                pass

        
        
        l = []
        for index, i in enumerate(diff):
            b = []
            b.append(index)
            b.append(i)
            l.append(b)
        
        
        
        
        
            
        self.diff = l

        time = []
        for index, i in enumerate(df['time']):
            if index % 60 == 0:
                b = []
                b.append(index)
                p = str(i).split(" ")[1].split(":")
                b.append(p[0]+":"+p[1])
                time.append(b)
        

        conn.close()
        
        print(l)
        
        hist_var = json.dumps(dict(title = self.diff, xaxis = time))
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return hist_var.encode('utf8')



    @cherrypy.expose
    def bid(self, a_name):
        cherrypy.session['a_name'] = a_name
        self.b.add_bid(a_name)
        current_bids = str(self.b.d)
        hist_var = json.dumps(dict(title = current_bids))
        cherrypy.response.headers['Content-Type'] = 'application/json'
        return hist_var.encode('utf8')