def google_chart_url(iteration_or_project): """Returns a URL for either a project or an iteration that corresponds to the burn up chart generated by google charts. The url will be to an image format. If no chart can be drawn, a 1x1 image is returned. This should be used for quick summary charts, not detailed pretty ones. We only use it in emails right now. """ try: total_points = [] claimed_points = [] max_val = 0 claimed_dates = [] claimed_values = [] total_dates = [] total_values = [] # Chart Size... if hasattr(iteration_or_project,"slug"): size = "550x120" # Project charts are bigger than iteration charts. else: size = "550x80" # Gather up all the points_log entries. for log in iteration_or_project.points_log.all(): total_points.append( [log.timestamp(), log.points_total] ) claimed_points.append( [log.timestamp(), log.points_claimed] ) if log.points_total > max_val: max_val = log.points_total # If we don't have enough points to draw a chart, bail. if len(total_points) <= 1: return "cht=lxy&chs=1x1" # Remove redundant data in chart data. total_points = reduce_burndown_data(total_points) claimed_points = reduce_burndown_data(claimed_points) # Some helper values. start_date = total_points[0][0] end_date = total_points[-1][0] start_date_s = date.fromtimestamp( start_date/1000 ).strftime('%Y-%m-%d') end_date_s = date.fromtimestamp( end_date/1000 ).strftime('%Y-%m-%d') date_range = end_date - start_date # Create the entries for the total points series. for piece in total_points: total_dates.append( _googleChartValue(piece[0], start_date, end_date) ) total_values.append( _googleChartValue( piece[1] ,0, max_val) ) # Create the entries for the claimed points series. for piece in claimed_points: claimed_dates.append( _googleChartValue(piece[0], start_date, end_date) ) claimed_values.append( _googleChartValue( piece[1] ,0, max_val) ) # Put it all together in google chart format. (Docs: http://code.google.com/apis/chart/) data = "http://chart.googleapis.com/chart?chxr=0,0,%d&cht=lxy&chs=%s&chd=s:%s,%s,%s,%s&chxt=y,x&chxs=0,444444,8,0,lt&chxl=1:|%s|%s&chco=9ED147,197AFF&chm=B,7EAEE3,1,0,0|B,99CBB0,0,0,0" % ( max_val,size,"".join(claimed_dates), "".join(claimed_values), "".join(total_dates), "".join(total_values), start_date_s, end_date_s ) #logger.debug(data) return data except: return "cht=lxy&chs=1x1"
def _google_chart(iteration_or_project, project_size="550x120", iteration_size="550x80", label_axis="y", bg_color="ffffff", axis_color="444444", title=False): """Returns a URL for either a project or an iteration that corresponds to the burn up chart generated by google charts. The url will be to an image format. If no chart can be drawn, a 1x1 image is returned. This should be used for quick summary charts, not detailed pretty ones. We only use it in emails right now. """ try: total_points = [] claimed_points = [] max_val = 0 claimed_dates = [] claimed_values = [] total_dates = [] total_values = [] # Chart Size... if hasattr(iteration_or_project, "slug"): size = project_size # Project charts are bigger than iteration charts. else: size = iteration_size # Gather up all the points_log entries. for log in iteration_or_project.points_log.all(): total_points.append([log.timestamp(), log.points_total]) claimed_points.append([log.timestamp(), log.points_claimed]) if log.points_total > max_val: max_val = log.points_total # If we don't have enough points to draw a chart, bail. if len(total_points) <= 1: return "https://chart.googleapis.com/chart?cht=lxy&chs=1x1" # Remove redundant data in chart data. total_points = reduce_burndown_data(total_points) claimed_points = reduce_burndown_data(claimed_points) # Some helper values. start_date = total_points[0][0] end_date = total_points[-1][0] start_date_s = date.fromtimestamp(start_date / 1000).strftime('%Y-%m-%d') try: end_date_s = iteration_or_project.end_date.strftime('%Y-%m-%d') end_date = int( datetime.combine(iteration_or_project.end_date, time()).strftime("%s")) * 1000 # logger.debug("!!!!") # logger.debug(end_date) except: end_date_s = date.fromtimestamp(end_date / 1000).strftime('%Y-%m-%d') # logger.debug("END DATE" % end_date_s) date_range = end_date - start_date # Create the entries for the total points series. for piece in total_points: total_dates.append( _googleChartValue(piece[0], start_date, end_date)) total_values.append(_googleChartValue(piece[1], 0, max_val)) # Create the entries for the claimed points series. for piece in claimed_points: claimed_dates.append( _googleChartValue(piece[0], start_date, end_date)) claimed_values.append(_googleChartValue(piece[1], 0, max_val)) if title: title_snippet = "chtt=%s&chts=000000,8&" % urllib.quote( iteration_or_project.name) else: title_snippet = "" # Put it all together in google chart format. (Docs: http://code.google.com/apis/chart/) data = "https://chart.googleapis.com/chart?%schf=bg,s,%s&chxr=0,0,%d&cht=lxy&chs=%s&chd=s:%s,%s,%s,%s&chxt=%s,x&chxs=0,%s,8,0,lt&chxl=1:|%s|%s&chco=9ED147,30B6EB&chm=B,eef5fb,1,0,0|B,99CBB0,0,0,0" % ( title_snippet, bg_color, max_val, size, "".join(claimed_dates), "".join(claimed_values), "".join(total_dates), "".join(total_values), label_axis, axis_color, start_date_s, end_date_s) #logger.debug(data) return data except: return "https://chart.googleapis.com/chart?cht=lxy&chs=1x1"
def _google_chart(iteration_or_project, project_size="550x120", iteration_size="550x80", label_axis="y", bg_color="ffffff", axis_color="444444", title=False): """Returns a URL for either a project or an iteration that corresponds to the burn up chart generated by google charts. The url will be to an image format. If no chart can be drawn, a 1x1 image is returned. This should be used for quick summary charts, not detailed pretty ones. We only use it in emails right now. """ try: total_points = [] claimed_points = [] max_val = 0 claimed_dates = [] claimed_values = [] total_dates = [] total_values = [] # Chart Size... if hasattr(iteration_or_project,"slug"): size = project_size # Project charts are bigger than iteration charts. else: size = iteration_size # Gather up all the points_log entries. for log in iteration_or_project.points_log.all(): total_points.append( [log.timestamp(), log.points_total] ) claimed_points.append( [log.timestamp(), log.points_claimed] ) if log.points_total > max_val: max_val = log.points_total # If we don't have enough points to draw a chart, bail. if len(total_points) <= 1: return "https://chart.googleapis.com/chart?cht=lxy&chs=1x1" # Remove redundant data in chart data. total_points = reduce_burndown_data(total_points) claimed_points = reduce_burndown_data(claimed_points) # Some helper values. start_date = total_points[0][0] end_date = total_points[-1][0] start_date_s = date.fromtimestamp( start_date/1000 ).strftime('%Y-%m-%d') try: end_date_s = iteration_or_project.end_date.strftime('%Y-%m-%d') end_date = int(datetime.combine(iteration_or_project.end_date, time()).strftime("%s")) * 1000 # logger.debug("!!!!") # logger.debug(end_date) except: end_date_s = date.fromtimestamp( end_date/1000 ).strftime('%Y-%m-%d') # logger.debug("END DATE" % end_date_s) date_range = end_date - start_date # Create the entries for the total points series. for piece in total_points: total_dates.append( _googleChartValue(piece[0], start_date, end_date) ) total_values.append( _googleChartValue( piece[1] ,0, max_val) ) # Create the entries for the claimed points series. for piece in claimed_points: claimed_dates.append( _googleChartValue(piece[0], start_date, end_date) ) claimed_values.append( _googleChartValue( piece[1] ,0, max_val) ) if title: title_snippet = "chtt=%s&chts=000000,8&" % urllib.quote(iteration_or_project.name) else: title_snippet = "" # Put it all together in google chart format. (Docs: http://code.google.com/apis/chart/) data = "https://chart.googleapis.com/chart?%schf=bg,s,%s&chxr=0,0,%d&cht=lxy&chs=%s&chd=s:%s,%s,%s,%s&chxt=%s,x&chxs=0,%s,8,0,lt&chxl=1:|%s|%s&chco=9ED147,30B6EB&chm=B,eef5fb,1,0,0|B,99CBB0,0,0,0" % ( title_snippet, bg_color, max_val,size,"".join(claimed_dates), "".join(claimed_values), "".join(total_dates), "".join(total_values), label_axis, axis_color, start_date_s, end_date_s ) #logger.debug(data) return data except: return "https://chart.googleapis.com/chart?cht=lxy&chs=1x1"