Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #163 from alphagov/add_timers
Browse files Browse the repository at this point in the history
Add timers
  • Loading branch information
robyoung committed Oct 22, 2013
2 parents 94224ec + f326249 commit 2ff3537
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backdrop/core/upload/parse_excel.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import xlrd
import datetime
from backdrop import statsd
from backdrop.core.errors import ParseError
from backdrop.core.timeutils import utc


class ExcelError(object):

def __init__(self, description):
self.description = description

Expand All @@ -19,22 +21,26 @@ def __ne__(self, other):
EXCEL_ERROR = ExcelError("error in cell")


@statsd.timer('parse_excel.parse_excel')
def parse_excel(incoming_data):
book = xlrd.open_workbook(file_contents=incoming_data.read())

for sheet in book.sheets():
yield _extract_rows(sheet, book)


@statsd.timer('parse_excel._extract_rows')
def _extract_rows(sheet, book):
for i in range(sheet.nrows):
yield _extract_values(sheet.row(i), book)
yield _extract_values(sheet.row(i), book)


@statsd.timer('parse_excel._extract_values')
def _extract_values(row, book):
return [_extract_cell_value(cell, book) for cell in row]


@statsd.timer('parse_excel._extract_cell_value')
def _extract_cell_value(cell, book):
if cell.ctype == xlrd.XL_CELL_DATE:
time_tuple = xlrd.xldate_as_tuple(cell.value, book.datemode)
Expand Down
3 changes: 3 additions & 0 deletions backdrop/write/uploaded_file.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from backdrop.write.scanned_file import ScannedFile, VirusSignatureError
from backdrop import statsd


class FileUploadException(IOError):
Expand Down Expand Up @@ -29,6 +30,7 @@ def _is_content_type_valid(self):
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
]

@statsd.timer('uploaded_file.save')
def save(self, bucket, parser):
if not self.valid:
self.file_stream().close()
Expand All @@ -39,6 +41,7 @@ def save(self, bucket, parser):
bucket.parse_and_store(data)
self.file_stream().close()

@statsd.timer('uploaded_file.perform_virus_scan')
def perform_virus_scan(self):
if ScannedFile(self.file_object).has_virus_signature:
self.file_stream().close()
Expand Down

0 comments on commit 2ff3537

Please sign in to comment.