Skip to content

Commit

Permalink
add Batch model to error_log app with stats fields
Browse files Browse the repository at this point in the history
  • Loading branch information
copelco committed Dec 14, 2011
1 parent 8b75608 commit 214b7a1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
28 changes: 24 additions & 4 deletions openrural/error_log/admin.py
@@ -1,10 +1,30 @@
from django.contrib import admin

from openrural.error_log.models import Error
from openrural.error_log.models import Error, Batch


class BatchAdmin(admin.ModelAdmin):
list_display = ('start_time', 'scraper', 'end_time', 'num', 'num_added',
'num_changed', 'num_skipped', 'num_geocoded',
'num_geocoded_success', 'geocode_rate')
list_filter = ('start_time', 'scraper')
search_fields = ('batch__id', 'location', 'description')
ordering = ('-start_time',)

def geocode_rate(self, obj):
if obj.num_geocoded > 0:
rate = float(obj.num_geocoded_success) / obj.num_geocoded
else:
rate = 0.0
return '{:.2%}'.format(rate)

admin.site.register(Batch, BatchAdmin)


class ErrorAdmin(admin.ModelAdmin):
list_display = ('id', 'date', 'scraper', 'name', 'location', 'zipcode')
list_filter = ('date', 'name', 'scraper')
search_fields = ('location', 'description')
list_display = ('id', 'batch', 'date', 'name', 'location',
'zipcode')
list_filter = ('date', 'name', 'scraper', 'zipcode')
search_fields = ('batch__id', 'location', 'description')
ordering = ('-date',)
admin.site.register(Error, ErrorAdmin)
22 changes: 22 additions & 0 deletions openrural/error_log/models.py
@@ -1,10 +1,32 @@
from django.db import models


class Batch(models.Model):
scraper = models.CharField(max_length=255, db_index=True)
start_time = models.DateTimeField(auto_now_add=True, db_index=True)
end_time = models.DateTimeField(null=True, blank=True, db_index=True)
num = models.PositiveIntegerField(default=0)
num_added = models.PositiveIntegerField(default=0)
num_changed = models.PositiveIntegerField(default=0)
num_skipped = models.PositiveIntegerField(default=0)
num_geocoded = models.PositiveIntegerField(default=0)
num_geocoded_success = models.PositiveIntegerField(default=0)

class Meta(object):
verbose_name_plural = 'Batches'

def __unicode__(self):
return "{0} ({1})".format(self.scraper, self.id)


class Error(models.Model):
batch = models.ForeignKey(Batch, related_name='errors')
date = models.DateTimeField(auto_now_add=True, db_index=True)
scraper = models.CharField(max_length=255, db_index=True)
name = models.CharField(max_length=255, db_index=True)
location = models.CharField(max_length=1024)
zipcode = models.CharField(max_length=16, blank=True)
description = models.TextField()

def __unicode__(self):
return "{0}: {1}".format(self.name, self.location)

0 comments on commit 214b7a1

Please sign in to comment.