Skip to content

Commit

Permalink
ep and raw coverage vizulazation on stats page.
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlFK committed Feb 11, 2016
1 parent 976d53d commit 2458903
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
3 changes: 3 additions & 0 deletions dj/main/templates/show_stats.html
Expand Up @@ -102,6 +102,9 @@

<span class="right">{{item.variance}} g</span>

<span class="left">{{item.ep.times_display}}</span>
<span class="left">{{item.raw.times_display}}</span>

<span class="left">
<a style="display: inline-block;" href="{% url "raw_file_audio" %}?show_id={{show.id}}&location_slug={{loc.loc.slug}}&start_date={{item.date|date:"Y-m-d"}}">audio</a>
<a style="display: inline-block;" href="{% url "public_play_list" %}playlist.m3u?client={{client.slug}}&show={{show.slug}}&location_slug={{loc.loc.slug}}&date={{item.date|date:"Y-m-d"}}">encs</a>
Expand Down
71 changes: 50 additions & 21 deletions dj/main/views.py
Expand Up @@ -884,11 +884,20 @@ def show_stats(request, show_id, ):
raw_files=Raw_File.objects.filter(show=show,location__active=True)
locations=show.locations.filter(active=True).order_by('sequence')

empty_stat = {'count':0,'minutes':0,
# needs better organazation. refactor please.
empty_stat = {
'ep':{
'times': [False] * 24,
},
'count':0,'minutes':0,
'start':None, 'end':None, 'states':[0]*len(STATES),
'files':0, 'bytes':0,
'loc':None, 'date':None,
'raw':{'start':None, 'end':None,},
'raw':{
'start':None,
'end':None,
'times': [False] * 24,
},
'files':0, 'bytes':0,
}

# get the range of dates used by this show
Expand Down Expand Up @@ -936,7 +945,20 @@ def show_stats(request, show_id, ):

# gather episode stats
# func to update one:


def set_times(times,s,e):
# times: list of bools
# s,e: start/end datetimes
sh = s.hour
eh = (e + datetime.timedelta(minutes=59)).hour # bump up to next h
times[sh:eh] = [True]*(eh-sh)


def add_ep_to_stat(ep,stat):

set_times( stat['ep']['times'], ep.start, ep.end)

stat['count']+=1
duration=ep.end-ep.start
stat['minutes']+=duration.seconds/60
Expand Down Expand Up @@ -967,6 +989,7 @@ def add_ep_to_stat(ep,stat):


def add_rf_to_stat(rf,stat):
set_times( stat['raw']['times'], rf.start, rf.end)
stat['files'] += 1
stat['bytes'] += rf.filesize

Expand All @@ -989,25 +1012,31 @@ def add_rf_to_stat(rf,stat):

# and do some more calcs
def calc_stat(stat):
stat['hours']=int( stat['minutes']/60.0 + .9)

stat['talk_gig']=int(stat['minutes']*13/60)
stat['gig']=stat['bytes']/(1024**3)

stat['variance'] = stat['talk_gig'] - stat['gig']

# alarm is % of expected gig, 0=perfect, 20 or more = wtf?
stat['alarm']= int(
stat['variance'] / (stat['minutes']/60.0*13 + 1) * 100 )
if stat['alarm'] > 0: # red
stat['alarm_color'] = "%02x%02x%02x" % (
255, 255-stat['alarm'], 255-stat['alarm'] )
else: # yellow
# 250, 255, 189
stat['alarm_color'] = "%02x%02x%02x" % (
250, 255, 189-stat['alarm'] )
return stat

stat['ep']['times_display'] = ''.join(
'x' if t else 'o' for t in stat['ep']['times'])
stat['raw']['times_display'] = ''.join(
'x' if t else 'o' for t in stat['raw']['times'])

stat['hours']=int( stat['minutes']/60.0 + .9)

stat['talk_gig']=int(stat['minutes']*13/60)
stat['gig']=stat['bytes']/(1024**3)

stat['variance'] = stat['talk_gig'] - stat['gig']

# alarm is % of expected gig, 0=perfect, 20 or more = wtf?
stat['alarm']= int(
stat['variance'] / (stat['minutes']/60.0*13 + 1) * 100 )
if stat['alarm'] > 0: # red
stat['alarm_color'] = "%02x%02x%02x" % (
255, 255-stat['alarm'], 255-stat['alarm'] )
else: # yellow
# 250, 255, 189
stat['alarm_color'] = "%02x%02x%02x" % (
255, 255, 255 + stat['alarm'] )
return stat

show_stat = calc_stat(show_stat)
l = []
for dt in dates:
Expand Down

0 comments on commit 2458903

Please sign in to comment.