Skip to content

Instantly share code, notes, and snippets.

@bradwright
Created September 23, 2010 12:44
Show Gist options
  • Save bradwright/593559 to your computer and use it in GitHub Desktop.
Save bradwright/593559 to your computer and use it in GitHub Desktop.
all_possible_plays = Play.objects.filter(preview_only=False, play_start__gte=start_date,
play_start__lt=end_date, users__is_staff=False)
for play in all_possible_plays:
if play_history.has_key(play.song.pk):
#increment tallies
play_history[play.song.pk]['plays'] += 1
if play.credit_taken:
play_history[play.song.pk]['credit_plays'] += 1
else:
# determine if a subscription or free play
if is_play_within_subscription(play):
play_history[play.song.pk]['sub_plays'] += 1
else:
play_history[play.song.pk]['free_plays'] += 1
else:
#create a new one
credit_play = sub_play = free_play = 0
if play.credit_taken:
credit_play = 1
else:
# determine if a subscription or free play
if is_play_within_subscription(play):
sub_play = 1
else:
free_play = 1
play_history[play.song.pk] = { 'title' : play.song.title.encode('utf-8'),
'artist' : play.song.denormed_artist_name.encode('utf-8'),
'duration' : convert_duration_to_MCPS_time(play.song.duration),
'country_code' : '0826',
'streaming' : 'ST',
'price' : '0.00',
'plays' : 1,
'credit_plays': credit_play,
'sub_plays': sub_play,
'free_plays': free_play,
}
for key in play_history.keys():
writer.writerow(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment