Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
zeroing out values when there is no incadata
Browse files Browse the repository at this point in the history
  • Loading branch information
buzztroll committed Mar 9, 2012
1 parent 594c3c0 commit ef388da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
33 changes: 17 additions & 16 deletions nimstat/cli.py
Expand Up @@ -5,7 +5,7 @@
from nimstat.cmdopts import bootOpts
from nimstat.db import NimStatDB
from nimstat.graph import max_pie_data, make_pie, make_bar, make_bar_percent, make_stack_bar_percent
from nimstat.inca_uptime import get_url_load_db, get_uptime_in_period, get_uptime_Ntime_buckets
from nimstat.inca_uptime import get_url_load_db, get_uptime_in_period, get_uptime_week_buckets
from nimstat.parser import *
from optparse import OptionParser, SUPPRESS_HELP
import os
Expand Down Expand Up @@ -260,25 +260,26 @@ def main(argv=sys.argv[1:]):
if opts.graph == "percent":
# get the denominator
if opts.aggregator == "weekly":
w_l = get_uptime_Ntime_buckets(db, opts.starttime, opts.endtime)
w_l = get_uptime_week_buckets(db, opts.starttime, opts.endtime)
demon = [i * float(opts.percenttotal) for i in w_l]
total_denom = 7 * 24 * 60 * float(opts.percenttotal)
total_denom_list = [total_denom for i in demon]
elif opts.aggregator == "monthly":
m_l = get_uptime_Ntime_buckets(db, opts.starttime, opts.endtime, ntime="%m%y")
demon = [i * float(opts.percenttotal) for i in m_l]
# figure out the length of this month

total_denom_list = []
m = opts.starttime.month
y = opts.starttime.year
for i in range(0, len(demon)):
mins = _mins_in_month(m, y) * float(opts.percenttotal)
total_denom_list.append(mins)
m = m + 1
if m > 12:
m = 1
y = y + 1
pass
# m_l = get_uptime_Ntime_buckets(db, opts.starttime, opts.endtime, ntime="%m%y")
# demon = [i * float(opts.percenttotal) for i in m_l]
# # figure out the length of this month
#
# total_denom_list = []
# m = opts.starttime.month
# y = opts.starttime.year
# for i in range(0, len(demon)):
# mins = _mins_in_month(m, y) * float(opts.percenttotal)
# total_denom_list.append(mins)
# m = m + 1
# if m > 12:
# m = 1
# y = y + 1
else:
demon = []
total_mins = get_uptime_in_period(db, opts.starttime, opts.endtime) * float(opts.percenttotal)
Expand Down
2 changes: 0 additions & 2 deletions nimstat/graph.py
Expand Up @@ -135,8 +135,6 @@ def make_bar_percent(data, labels, filename, denom, maxdenom, title=None, xlabel

def make_stack_bar_percent(data, labels, filename, uptime, maxdenom, title=None, xlabel=None, ylabel=None, legend=None, subtitle=None):
if len(uptime) != len(data):
print data
print denom
raise Exception("The numerator and demonimator have different lengths %d %d" % (len(denom), len(data)))

pdata = []
Expand Down
11 changes: 9 additions & 2 deletions nimstat/inca_uptime.py
Expand Up @@ -99,17 +99,24 @@ def get_uptime_in_period(db, start_date, end_date, test_name="nimbus-clientStatu
total = total + buckets[k]
return total


def get_uptime_Ntime_buckets(db, start_date, end_date, ntime="%W%y", test_name="nimbus-clientStatus"):
def get_uptime_week_buckets(db, start_date, end_date, test_name="nimbus-clientStatus"):
res = db.get_tests_in_period(start_date, end_date, test_name)

ntime="%W%y"
# bucket the results into hours to avoid repeats
buckets = {}
for e in res:
tm_str = e.time.strftime("%m%d%y%H-"+ntime)
buckets[tm_str] = 60

week_buckets = {}
# zero allentries out
start_week = start_date.isocalendar()[1]
end_week = end_date.isocalendar()[1]
y = start_date.year
for i in range(start_week, end_week):
nk = "%s%s" % (i, y)
week_buckets[nk] = 0
for k in buckets:
nk = k.split('-')[1]
if nk not in week_buckets:
Expand Down

0 comments on commit ef388da

Please sign in to comment.