def enrollment_nvd3(self): """ Enrollment Plots using python-nvd3. Parameters ---------- None Output ------ Figures and respective formats. Returns ------- None """ from nvd3 import linePlusBarChart def date2epoch(x): return int( (datetime.combine(x, datetime.min.time()) - datetime(1970,1,1)).total_seconds()*1000 ) ### Output File figsavename = self.figpath+'interactive_enrollment_'+self.nickname+'.html' output_file = open(figsavename, 'w') print figsavename type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, x_is_date=True, x_axis_format="%d %b %Y") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") DATA = self.enrollment_df.copy() xdata = [date2epoch(x) for x in DATA.index] ydata = DATA['Enroll Count'].values ydata2 = DATA['Enroll Cumulative'].values #print type(xdata),type(ydata),type(ydata2) #Series 1 kwargs1 = {'bar':True} extra_serie1 = {"tooltip": {"y_start": "", "y_end": ""}, "color":"CornFlowerBlue" } chart.add_serie(name="Enrollment", y=ydata, x=xdata, extra=extra_serie1, **kwargs1) #Series 2 kwargs2 = {'color':'Orange'} extra_serie2 = {"tooltip": {"y_start": "", "y_end": ""}, "color":"Orange" } chart.add_serie(name="Cumulative Enrollment", y=ydata2, x=xdata, extra=extra_serie2, **kwargs2) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close() return None#self.enrollment_df
def graphic_cost_activity_week(): """ :return: """ xdata = [] ydata = [] ydata2 = [] output_file = open(_cost_activity_week, 'w') type = "Time activity" start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 _chart_activ = cumulativeLineChart(name=type, height=350, width=750, x_is_date=True) _chart_activ.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [x * 2 for x in ydata] extra_serie = {"tooltip": {"y_start": "", "y_end": " Calls"}} _chart_activ.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie) extra_serie = {"tooltip": {"y_start": "", "y_end": " Min"}} _chart_activ.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) type = "Cost vs reserve week" _weeks = WeekNumber.objects.all().order_by('-date_init') for _num_week in range(0, this_week()): _time = int(time.mktime(_weeks[_num_week].date_final.timetuple()) * 1000) _credit = float(_weeks[_num_week].value_week + _weeks[_num_week].value_invest) _debit = float(_weeks[_num_week].value_debit_week + _weeks[_num_week].cost_fixed_week) xdata.append(_time) ydata.append(_debit) ydata2.append(_credit) _chart_cost = linePlusBarChart( name=type, height=350, width=750, x_is_date=True, x_axis_format="%d %b %Y", focus_enable=True ) _chart_cost.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": " week"}} _chart_cost.add_serie(name="Cost", y=ydata, x=xdata, extra=extra_serie, **kwargs) _chart_cost.add_serie(name="Reserve", y=ydata2, x=xdata, extra=extra_serie) _chart_activ.buildhtml() _chart_cost.buildcontent() output_file.write(_chart_activ.htmlcontent + _chart_cost.htmlcontent) output_file.close() graphic_view(_cost_activity_week)
def test_linePlusBarChart(self): """Test line Plus Bar Chart""" type = "linePlusBarChart" chart = linePlusBarChart(name=type, date=True, height=350) start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True chart.add_serie(y=ydata, x=xdata, **kwargs) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml()
ydata = [i + random.randint(1, 10) for i in list(range(nb_element))] ydata2 = [x * 2 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S %p"} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) # --------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(height=400, width=800, x_is_date=True, x_axis_format="%d %b %Y", jquery_on_ready=True, focus_enable=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent()
xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in list(range(nb_element))] ydata2 = [x * 2 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S %p"} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, date=True, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent()
def lastday_nvd3(self): """ Last Day Plots using python-nvd3. Parameters ---------- None Output ------ Figures and respective formats. Returns ------- None """ from nvd3 import linePlusBarChart def date2epoch(x): return int( (datetime.combine(x, datetime.min.time()) - datetime(1970,1,1)).total_seconds()*1000 ) ### Generalized Plotting functions figsavename = self.figpath+'interactive_last_activity_'+self.nickname+'.html' output_file = open(figsavename, 'w') print figsavename type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, x_is_date=True, x_axis_format="%d %b %Y") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") ### Set Date Limits col = self.lastact_df.columns[0] tmp = self.lastact_df[col][self.lastact_df[col]>100] mindate = tmp.index[0] - timedelta(days=21) maxdate = tmp.index[-1] + timedelta(days=21) TRIM = self.lastact_df[(self.lastact_df.index>=mindate) & (self.lastact_df.index<=maxdate) ] xdata = [date2epoch(x) for x in TRIM.index] ydata = TRIM['Last Activity Count'].values ydata2 = TRIM['Last Activity Survival'].values #print type(xdata),type(ydata),type(ydata2) #Series 1 kwargs1 = {'bar':True} extra_serie1 = {"tooltip": {"y_start": "", "y_end": ""}, "color":"Silver" } chart.add_serie(name="Last Activity Day", y=ydata, x=xdata, extra=extra_serie1, **kwargs1) #Series 2 kwargs2 = {'color':'Orange'} extra_serie2 = {"tooltip": {"y_start": "", "y_end": ""}, "color":"Crimson" } chart.add_serie(name="Survival Function", y=ydata2, x=xdata, extra=extra_serie2, **kwargs2) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close() return None#self.enrollment_df
Project location : https://github.com/areski/python-nvd3 """ from nvd3 import linePlusBarChart import random import datetime import time start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 output_file = open('test_linePlusBarChart.html', 'w') type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, x_is_date=True, x_axis_format="%d %b %Y") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildhtml() output_file.write(chart.htmlcontent)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: 100 + x, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, date=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(range(nb_element))] kwargs = {} kwargs['bar'] = True chart.add_serie(y=ydata, x=xdata, **kwargs) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent)
xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in list(range(nb_element))] ydata2 = [x * 2 for x in ydata] extra_serie = {"tooltip": {"y_start": "There is ", "y_end": " calls"}, "date_format": "%d %b %Y %I:%M:%S %p"} chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(height=350, x_is_date=True, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent()
"y_start": "There is ", "y_end": " calls" }, "date_format": "%d %b %Y %I:%M:%S %p" } chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(height=350, x_is_date=True, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent()
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: 100 + x, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = map(lambda x: x * 2, ydata) chart.add_serie(y=ydata, x=xdata) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent) # --------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, date=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 xdata = range(nb_element) xdata = map(lambda x: start_time + x * 1000000000, xdata) ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(range(nb_element))] kwargs = {} kwargs["bar"] = True chart.add_serie(y=ydata, x=xdata, **kwargs) chart.add_serie(y=ydata2, x=xdata) chart.buildhtml() output_file.write(chart.htmlcontent)
def lastday_nvd3(self): """ Last Day Plots using python-nvd3. Parameters ---------- None Output ------ Figures and respective formats. Returns ------- None """ from nvd3 import linePlusBarChart def date2epoch(x): return int((datetime.combine(x, datetime.min.time()) - datetime(1970, 1, 1)).total_seconds() * 1000) ### Generalized Plotting functions figsavename = self.figpath + 'interactive_last_activity_' + self.nickname + '.html' output_file = open(figsavename, 'w') print figsavename type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, x_is_date=True, x_axis_format="%d %b %Y") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") ### Set Date Limits col = self.lastact_df.columns[0] tmp = self.lastact_df[col][self.lastact_df[col] > 100] mindate = tmp.index[0] - timedelta(days=21) maxdate = tmp.index[-1] + timedelta(days=21) TRIM = self.lastact_df[(self.lastact_df.index >= mindate) & (self.lastact_df.index <= maxdate)] xdata = [date2epoch(x) for x in TRIM.index] ydata = TRIM['Last Activity Count'].values ydata2 = TRIM['Last Activity Survival'].values #print type(xdata),type(ydata),type(ydata2) #Series 1 kwargs1 = {'bar': True} extra_serie1 = { "tooltip": { "y_start": "", "y_end": "" }, "color": "Silver" } chart.add_serie(name="Last Activity Day", y=ydata, x=xdata, extra=extra_serie1, **kwargs1) #Series 2 kwargs2 = {'color': 'Orange'} extra_serie2 = { "tooltip": { "y_start": "", "y_end": "" }, "color": "Crimson" } chart.add_serie(name="Survival Function", y=ydata2, x=xdata, extra=extra_serie2, **kwargs2) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close() return None #self.enrollment_df
def enrollment_nvd3(self): """ Enrollment Plots using python-nvd3. Parameters ---------- None Output ------ Figures and respective formats. Returns ------- None """ from nvd3 import linePlusBarChart def date2epoch(x): return int((datetime.combine(x, datetime.min.time()) - datetime(1970, 1, 1)).total_seconds() * 1000) ### Output File figsavename = self.figpath + 'interactive_enrollment_' + self.nickname + '.html' output_file = open(figsavename, 'w') print figsavename type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, x_is_date=True, x_axis_format="%d %b %Y") chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") DATA = self.enrollment_df.copy() xdata = [date2epoch(x) for x in DATA.index] ydata = DATA['Enroll Count'].values ydata2 = DATA['Enroll Cumulative'].values #print type(xdata),type(ydata),type(ydata2) #Series 1 kwargs1 = {'bar': True} extra_serie1 = { "tooltip": { "y_start": "", "y_end": "" }, "color": "CornFlowerBlue" } chart.add_serie(name="Enrollment", y=ydata, x=xdata, extra=extra_serie1, **kwargs1) #Series 2 kwargs2 = {'color': 'Orange'} extra_serie2 = { "tooltip": { "y_start": "", "y_end": "" }, "color": "Orange" } chart.add_serie(name="Cumulative Enrollment", y=ydata2, x=xdata, extra=extra_serie2, **kwargs2) chart.buildhtml() output_file.write(chart.htmlcontent) #--------------------------------------- #close Html file output_file.close() return None #self.enrollment_df
"y_end": " calls" }, "date_format": "%d %b %Y %I:%M:%S %p" } chart.add_serie(name="serie 1", y=ydata, x=xdata, extra=extra_serie) chart.add_serie(name="serie 2", y=ydata2, x=xdata, extra=extra_serie) chart.buildcontent() output_file.write(chart.htmlcontent) #--------------------------------------- type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, date=True, x_axis_format="%d %b %Y", jquery_on_ready=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie)
""" from nvd3 import linePlusBarChart import random import datetime import time start_time = int(time.mktime(datetime.datetime(2012, 6, 1).timetuple()) * 1000) nb_element = 100 output_file = open('test_linePlusBarChart.html', 'w') type = "linePlusBarChart" chart = linePlusBarChart(name=type, height=350, width=750, x_is_date=True, x_axis_format="%d %b %Y", focus_enable=True) chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n") xdata = list(range(nb_element)) xdata = [start_time + x * 1000000000 for x in xdata] ydata = [i + random.randint(1, 10) for i in range(nb_element)] ydata2 = [i + random.randint(1, 10) for i in reversed(list(range(nb_element)))] kwargs = {} kwargs['bar'] = True extra_serie = {"tooltip": {"y_start": "$ ", "y_end": ""}} chart.add_serie(name="Count", y=ydata, x=xdata, extra=extra_serie, **kwargs) extra_serie = {"tooltip": {"y_start": "", "y_end": " min"}} chart.add_serie(name="Duration", y=ydata2, x=xdata, extra=extra_serie) chart.buildhtml()