Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Batch model to error_log app with stats fields
- Loading branch information
Showing
2 changed files
with
46 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |