Changeset 3036

Show
Ignore:
Timestamp:
10/13/06 23:51:14 (18 years ago)
Author:
jerome
Message:

Charging for ink usage, finally !

Location:
pykota/trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/cupspykota

    r3023 r3036  
    574574        """Precomputes the job price with a software method.""" 
    575575        self.logdebug("Precomputing job's price...") 
    576         self.softwareJobPrice = self.UserPQuota.computeJobPrice(self.softwareJobSize) 
     576        self.softwareJobPrice = self.UserPQuota.computeJobPrice(self.softwareJobSize, self.preaccounter.inkUsage) 
    577577        self.logdebug("Precomputed job's price is %.3f credits." \ 
    578578                                   % self.softwareJobPrice) 
     
    12701270                # update the quota for the current user on this printer  
    12711271                self.printInfo(_("Updating user %s's quota on printer %s") % (self.UserName, self.PrinterName)) 
    1272                 self.JobPrice = self.UserPQuota.increasePagesUsage(self.JobSize) 
     1272                self.JobPrice = self.UserPQuota.increasePagesUsage(self.JobSize, self.accounter.inkUsage) 
    12731273             
    12741274            # adds the current job to history     
  • pykota/trunk/conf/pykota.conf.sample

    r3025 r3036  
    597597# Software accounting unfortunately may overcharge users in case of paper 
    598598# jams. 
     599# 
     600# Ink computes the price of a print job by parsing the job's datas 
     601# through pkpgcounter, and using the percents of ink coverage returned 
     602# for each color in the specified colorspace. 
     603 
     604# Supported colorspaces for ink accounting currently are : 
     605# 
     606#       bw      ===> Black & White 
     607#       cmyk    ===> Cyan, Magenta, Yellow, Black 
     608#       cmy     ===> Cyan, Magenta, Yellow 
     609#       rgb     ===> Red, Green, Blue 
     610# 
     611# Supported resolutions for ink accounting are any number of dots 
     612# per inch comprised between 72 and 1200.  
     613# IMPORTANT : increasing the resolution increases precision, but 
     614# increase CPU load a lot at the same time. The default resolution 
     615# if unset is 72, for 72 dpi. 
    599616#  
    600617# You can get hints on which configuration is best for your printers by 
     
    619636# accounter : software(/usr/bin/pkpgcounter)  
    620637# accounter : software() 
     638# accounter : ink(cmyk, 150) 
     639# accounter : ink(bw, 300) 
     640# accounter : ink(bw) 
     641# accounter : ink(cmy, 72) 
    621642#          
    622643# This directive can be set either globally or per printer or both. 
     
    648669#  preaccounter: software()        
    649670#  preaccounter: software(/path/to/your/script) 
     671#  preaccounter: ink(colorspace, resolution) 
    650672# 
    651673# NB : the preaccounter directive doesn't support hardware() for obvious  
     
    657679# in the case your printer supports an hardware accounter but pkpgcounter 
    658680# can't parse your printer driver's datas. 
     681# 
     682# Supported colorspaces for ink accounting currently are : 
     683# 
     684#       bw      ===> Black & White 
     685#       cmyk    ===> Cyan, Magenta, Yellow, Black 
     686#       cmy     ===> Cyan, Magenta, Yellow 
     687#       rgb     ===> Red, Green, Blue 
     688# 
     689# Supported resolutions for ink accounting are any number of dots 
     690# per inch comprised between 72 and 1200.  
     691# IMPORTANT : increasing the resolution increases precision, but 
     692# increase CPU load a lot at the same time. The default resolution 
     693# if unset is 72, for 72 dpi. 
    659694# 
    660695# This value can be set either globally or on a per printer basis 
  • pykota/trunk/NEWS

    r3032 r3036  
    2222PyKota NEWS : 
    2323        
     24    - 1.25alpha14 (2006-10-13) : 
     25       
     26        - First useable release with the computation of ink 
     27          usage, through the introduction of the 'ink(cspace, resolution)' 
     28          value for the 'preaccounter' and 'accounter' directives in 
     29          pykota.conf 
     30           
    2431    - 1.25alpha13 (2006-10-04) : 
    2532      
  • pykota/trunk/pykota/accounter.py

    r3000 r3036  
    4545        self.isSoftware = 1 # by default software accounting 
    4646        self.isPreAccounter = ispreaccounter  
     47        self.inkUsage = [] 
    4748         
    4849    def getLastPageCounter(self) :     
  • pykota/trunk/pykota/accounters/ink.py

    r3034 r3036  
    4242            # know the result. 
    4343            self.filter.logdebug("Precomputing pass told us that job is %s pages long." % self.filter.softwareJobSize) 
    44             return self.filter.softwareJobSize   # Optimize : already computed ! 
     44            self.inkUsage = self.filter.preaccounter.inkUsage   # Optimize : already computed ! 
     45            return self.filter.softwareJobSize                  # Optimize : already computed ! 
    4546             
    46         (colorspace, resolution) = [p.strip() for p in self.arguments.split(',')] 
     47        parameters = [p.strip() for p in self.arguments.split(',')] 
     48        if len(parameters) == 1 : 
     49            parameters.append("72") 
     50        (colorspace, resolution) = parameters 
    4751        colorspace = colorspace.lower() 
    4852        if colorspace not in ("cmyk", "bw", "cmy", "rgb") : 
     
    5761         
    5862        jobsize = 0 
    59         self.inkUsage = [] 
    6063        if self.filter.JobSizeBytes : 
    6164            try : 
  • pykota/trunk/pykota/storage.py

    r3033 r3036  
    308308        self.isDirty = True 
    309309         
    310     def computeJobPrice(self, jobsize) :     
     310    def computeJobPrice(self, jobsize, inkusage=[]) :     
    311311        """Computes the job price as the sum of all parent printers' prices + current printer's ones.""" 
    312312        totalprice = 0.0     
     
    314314            if self.User.OverCharge != 0.0 :    # optimization, but TODO : beware of rounding errors 
    315315                for upq in [ self ] + self.ParentPrintersUserPQuota : 
    316                     price = (float(upq.Printer.PricePerPage or 0.0) * jobsize) + float(upq.Printer.PricePerJob or 0.0) 
    317                     totalprice += price 
     316                    totalprice += float(upq.Printer.PricePerJob or 0.0) 
     317                    pageprice = float(upq.Printer.PricePerPage or 0.0) 
     318                    if not inkusage : 
     319                        totalprice += (jobsize * pageprice) 
     320                    else :     
     321                        for pageindex in range(jobsize) : 
     322                            try : 
     323                                usage = inkusage[pageindex] 
     324                            except IndexError :     
     325                                self.parent.tool.logdebug("No ink usage information. Using base cost of %f credits for page %i." % (pageprice, pageindex+1)) 
     326                                totalprice += pageprice 
     327                            else :     
     328                                coefficients = self.Printer.Coefficients 
     329                                for (ink, value) in usage.items() : 
     330                                    coefvalue = coefficients.get(ink, 1.0) 
     331                                    coefprice = (coefvalue * pageprice) / 100.0 
     332                                    inkprice = coefprice * value 
     333                                    self.parent.tool.logdebug("Applying coefficient %f for color %s (used at %f%% on page %i) to base cost %f gives %f" % (coefvalue, ink, value, pageindex+1, pageprice, inkprice)) 
     334                                    totalprice += coefprice 
    318335        if self.User.OverCharge != 1.0 : # TODO : beware of rounding errors 
    319336            overcharged = totalprice * self.User.OverCharge         
    320             self.parent.tool.logdebug("Overcharging %s by a factor of %s ===> User %s will be charged for %s units." % (totalprice, self.User.OverCharge, self.User.Name, overcharged)) 
     337            self.parent.tool.logdebug("Overcharging %s by a factor of %s ===> User %s will be charged for %s credits." % (totalprice, self.User.OverCharge, self.User.Name, overcharged)) 
    321338            return overcharged 
    322339        else :     
    323340            return totalprice 
    324341             
    325     def increasePagesUsage(self, jobsize) : 
     342    def increasePagesUsage(self, jobsize, inkusage=[]) : 
    326343        """Increase the value of used pages and money.""" 
    327         jobprice = self.computeJobPrice(jobsize) 
     344        jobprice = self.computeJobPrice(jobsize, inkusage) 
    328345        if jobsize : 
    329346            if jobprice : 
  • pykota/trunk/pykota/version.py

    r3025 r3036  
    2222# 
    2323 
    24 __version__ = "1.25alpha13_unofficial" 
     24__version__ = "1.25alpha14_unofficial" 
    2525 
    2626__doc__ = "PyKota : a complete Printing Quota Solution for CUPS." 
  • pykota/trunk/README

    r3015 r3036  
    119119        - Price per page and per job can be set differently   
    120120          on any printer. 
     121         
     122        - Price depending on ink/toner usage is supported 
     123          with many printer drivers. 
    121124         
    122125        - Low level of page quota or account balance are 
  • pykota/trunk/TODO

    r3033 r3036  
    5959          files at run time. 
    6060         
    61         - Ink accounting ala PrintBill. 
    62          
    6361        - Price and statistics per page format. 
    6462