source: TI03-DataExtractor/branches/old_stuff/dx-webservice/requestCost.py @ 793

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/old_stuff/dx-webservice/requestCost.py@793
Revision 793, 2.3 KB checked in by astephen, 13 years ago (diff)

Put all the old code in the old_stuff branch.

  • Property svn:executable set to *
Line 
1"""
2requestCost.py
3==============
4
5Contains the class RequestCost that is used to estimate the cost (in
6data volume and processing time) of a user request.
7
8""" 
9
10# Import library modules
11import os, sys
12
13# Import package modules
14from config import *
15from common import *
16from localRules import *
17from errorHandler import *
18from extractMetadata import MetadataExtractor
19
20class RequestCost(MetadataExtractor):
21    """
22    Class used to estimate the cost of a request in terms of the data
23    volume produced and the processing time to produce the request.
24    There is also a localCostingRules method included for you to add your
25    own algorithms that relate to local rules or specific datasets.
26    """
27           
28    def localCostingRules(self, estimatedDuration):
29        """
30        Method to be defined by local extractor administrator. Essentially a
31        hook for your local rules and algorithms. It takes in the estimated
32        duration and allows you to alter it as you see fit.
33        """
34        # Scale factor depends on whether caching is involved (ERA-40 at BADC)
35        # If high then we estimate a request will take longer
36        scale_factor=1
37        if self.request["dataset_1"]=="ERA-40" or (self.request.has_key("dataset_2") and self.request["dataset_2"]=="ERA-40"):
38            scale_factor=3
39        return scale_factor*estimatedDuration
40
41    def checkRequestVolume(self):
42        """
43        Method to check that the volume of data requested is not over the limit set in config.py.
44        """
45        sizeLimitInBytes=REQUEST_SIZE_LIMIT*2L*20
46        size=self.getRequestSizeInBytes()
47       
48        # If size is over limit then send a tidy error to the user
49        if size>sizeLimitInBytes:
50            sizeInMB=size/(2L**20.)
51            errorString="""Your request of %.1f MB is over the current %s MB size limit.       
52The Data Extractor cannot yet deal with such large requests.
53Consider mailing <A HREF="mailto:%s">%s</A> for advice or submitting multiple smaller requests.""" % (sizeInMB, REQUEST_SIZE_LIMIT, ADMIN_MAIL_ADDRESS, ADMIN_MAIL_ADDRESS)
54        ErrorHandler(errorString, noheader=1, request_id=self.request["req_id"],
55                        user=self.request["user"])
56                       
57    def getDurationEstimate(self):
58        """
59        Method to estimate the time it will take to process a request.
60        """
61        size=self.getRequestSizeInBytes()       
62        estimatedDuration=size*TIMING_SCALE_FACTOR
63        return self.localCostingRules(estimatedDuration)
64       
65       
Note: See TracBrowser for help on using the repository browser.