In [8]:
import plotly
import numpy as np
import plotly.graph_objs as go
import plotly.offline as py
import math
from plotly.graph_objs import *
plotly.offline.init_notebook_mode()
import time
from IPython.display import display
from IPython.display import HTML
import IPython.core.display as di # Example: di.display_html('<h3>%s:</h3>' % str, raw=True)



from IPython.display import display
from IPython.display import HTML
import IPython.core.display as di # Example: di.display_html('<h3>%s:</h3>' % str, raw=True)

# This line will hide code by default when the notebook is exported as HTML
di.display_html('<script>jQuery(function() {if (jQuery("body.notebook_app").length == 0) { jQuery(".input_area").toggle(); jQuery(".prompt").toggle();}});</script>', raw=True)



def hide_numbers(a):
    return a[0] + ''.join(['x' for i in range(len(a)-1)])

data = {}
for line in open('ceu_kol.dat'):
        
    if 'horizon' not in line:    
        
        fields = line.strip().split('\t')
        user = fields[1]
        horizon = float(fields[5])
        popularity = float(fields[6])
        time = float(fields[-1])
        size = 10*int(math.log(float(fields[2])))
     
        #if horizon > 10000 and popularity > 10 and int(fields[2]) > 7:
        day = int(time/24.0)
        if day not in data:
            data[day] = [horizon]
        else:
            data[day].append(horizon)

            
            
                

    
    
    
#data.sort(key=lambda tup: tup[1])             

x_ = []
y_ = []
z_ = []
for day, hs in data.items():
    x_.append(day)
    z_.append(np.sum(y_))
    y_.append(np.sum(hs))
    



day_date0 = {29 : '03/28\nFirst report of \nlegislation', 30 : '03/29', 31 : '03/30', 32 : '03/31', 
            33 : '04/01', 34 : '04/02\nFirst \ndemonstration', 
            35 : '04/03',  
            36 : '04/04\nLegislation passed', 
            37 : '04/05\Chain of solidarity', 
            38 : '04/06', 39 : '04/07', 
            40 : '04/08', 
            41 : '04/09\nSecond demonstration', 
            42 : '04/10\nLaw signed \ninto effect'}

day_date = {29 : '03/28 First report of legislation', 30 : '03/29', 31 : '03/30', 32 : '03/31', 
            33 : '04/01', 34 : '04/02 First demonstration', 
            35 : '04/03',  
            36 : '04/04 Legislation passed', 
            37 : '04/05 Chain of solidarity', 
            38 : '04/06', 39 : '04/07', 
            40 : '04/08', 
            41 : '04/09 Second demonstration', 
            42 : '04/10 Law signed into effect',
            43 : '04/11',
            44 : '04/12'}


days_x = []
days_all = []
for line in open('kol_days.dat'):
    
    fields = line.strip().split(' ')
    date = int(fields[0])-27

    days_x.append(date)
    days_all.append(int(fields[1]))
  



days_first = []
for line in open('kol_first_days.dat'):
    fields = line.strip().split(' ')
    days_first.append(int(fields[1]))
    

layout=Layout(
    yaxis1=YAxis(
        type = 'log'
    )
)


data = [go.Bar(
        x=days_x,
        y=days_all
)]


datess =  [day_date[i+29] for i in range(len(day_date))]
                                            
timestamps = datess


 
#map(lambda x:x[1], sorted(map(lambda a:[map(int,a.split('/')),a], timestamps)))    
    

total_cum = np.cumsum(days_all)
news_cum = np.cumsum(days_first)

total_full =[]#= [int(total_cum[i+1]) + int(days_first[i])  for i in range(len(days_first)-1)]  
for i in range(len(news_cum)):
   
    new = news_cum[i]
    if i > 0:
        total_full.append( new + total_cum[i-1])
    
    
    
total_full.append(total_cum[-1]+news_cum[-1]-days_first[-1])    


nnn =[0,566309,3512604,10044213,15765560,18664906,33529502,51340426,62933897,69256620,71394147,72692204,74974694,85606424]


trace1 = go.Bar(
    x = timestamps,
    y= days_all,#nnn,
    marker=dict(
        color='rgba(55, 128, 191, 0.7)',
        line=dict(
            color='rgba(55, 128, 191, 1.0)',
            width=2,
        )
    ),
    name='Old users'
)


trace2 = go.Bar(
    x = timestamps,
    y=days_first,
    marker=dict(
        color='rgba(219, 64, 82, 0.7)',
        line=dict(
            color='rgba(219, 64, 82, 1.0)',
            width=2,
        )
    ),
    name='New users'
)


data = [trace1, trace2]
layout = go.Layout(
    title = 'Daily activity on Twitter   #IstandwithCEU',
    barmode='stack',
    bargap = 0.5,
    xaxis = dict(
        tickangle = 30
    ),
    yaxis=dict(
        title ='Potential reach'
    ),
    margin=go.Margin(
    b = 110
    )
    #plot_bgcolor='rgba(245, 246, 249, 1)'
)


fig = go.Figure(data=data, layout=layout)                 
py.iplot(fig, filename='axes-range-type')


#31k tweet 
#py.iplot(data, filename='basic-bar')