示例#1
0
 def extractSpec(self, sheet, header, footer, column_mapping):
     ''' Exctract one sheet to list of dictionaries
     :param sheet:
     :param header:
     :param footer:
     :param column_mapping:
     :return:
     '''
     result = []
     for row in range(header + 1, footer):
         line = {}
         #num_field = sheet.cell(row, column_mapping[self.CAT_PN]).ctype
         # If number field type doesn't contain value - skip line
         if (sheet.isCellEmpty(row, column_mapping[self.CAT_PN])
             ):  # 0 - XL_CELL_EMPTY, 6 - XL_CELL_BLANK
             continue
         for cat in self.mapping:
             value = sheet.cell(row, column_mapping[cat]).value
             line[cat] = value
         if (self.CAT_PRICE in self.mapping):
             tmp = price(line[self.CAT_PRICE])
             #print "Price = ", tmp, type(tmp)
             line[self.CAT_PRICE] = tmp
         result.append(line)
     return result
示例#2
0
    def calculateSpecResources(session, hash):
        ''' The function calculate spec resources and return "reach" format of specification
        :return: dict { 'stat' : dict {resource statistics}
                        'spec' : [ dict {line: resource, isRecogized, resourceType, resourceType, resourceValue}]
                                    - array of lines with resources
                }
        '''
        result = []
        return_data = {}
        stat = {
            ResourseFactory.PROD_CPU: 0,
            ResourseFactory.PROD_MEM: 0,
            ResourseFactory.PROD_HDD: 0,
            ResourseFactory.PROD_SSD: 0,
            ResourseFactory.PROD_SOCKET: 0
        }
        total_price = 0
        spec = SpecFactory.getSpecFromDatabase(session,
                                               hash)  # load specification
        if (spec == None):
            raise NoResultFound(
                "Specification 'hash' found but it's empty") % hash
        # We got specification, let's process it
        for line in spec:
            final_line = line  # copy all paramemters to final line
            res = SpecFactory.getResourseFromLine(line)
            if (res):
                final_line[
                    'isRecognized'] = True  # add resource data to final line
                final_line.update(res)
                if (res.has_key('WARNING')):  # pop warning
                    return_data['WARNING'] = True
                    res.pop('WARNING', None)
                for key in res:
                    #print "DEBUG calculateSpecResources: res[key] = '%s', type: %s", res[key], type(res[key])
                    stat[key] += int(res[key])  # summarize statistics
            result.append(final_line)
            if (line[SpecFactory.CAT_PN] != ''):
                #print "Line: ", line #, type(line[SpecFactory.CAT_PRICE])
                p = price(line[SpecFactory.CAT_PRICE])

                #print "item= ", int(line[SpecFactory.CAT_QUANTITY]) * line[SpecFactory.CAT_PRICE]
                total_price += int(line[SpecFactory.CAT_QUANTITY]) * line[
                    SpecFactory.CAT_PRICE]
        #print "Price: ", total_price
        name = SpecFactory.getSpecName(session, hash)

        return_data.update({
            'stat': stat,
            'spec': result,
            'price': total_price,
            'name': name
        })
        #print return_data
        return return_data
示例#3
0
    def calculateSpecResources(session, hash):
        ''' The function calculate spec resources and return "reach" format of specification
        :return: dict { 'stat' : dict {resource statistics}
                        'spec' : [ dict {line: resource, isRecogized, resourceType, resourceType, resourceValue}]
                                    - array of lines with resources
                }
        '''
        result = []
        return_data = {}
        stat= {ResourseFactory.PROD_CPU : 0,
               ResourseFactory.PROD_MEM : 0,
               ResourseFactory.PROD_HDD : 0,
               ResourseFactory.PROD_SSD : 0,
               ResourseFactory.PROD_SOCKET : 0
               }
        total_price = 0
        spec = SpecFactory.getSpecFromDatabase(session, hash)        # load specification
        if (spec == None):
            raise NoResultFound("Specification 'hash' found but it's empty")%hash
        # We got specification, let's process it
        for line in spec:
            final_line = line                       # copy all paramemters to final line
            res = SpecFactory.getResourseFromLine(line)
            if (res):
                final_line['isRecognized']  = True      # add resource data to final line
                final_line.update(res)
                if (res.has_key('WARNING')):      # pop warning
                    return_data['WARNING'] = True
                    res.pop('WARNING', None)
                for key in res:
                    #print "DEBUG calculateSpecResources: res[key] = '%s', type: %s", res[key], type(res[key])
                    stat[key] += int(res[key])               # summarize statistics
            result.append(final_line)
            if (line[SpecFactory.CAT_PN] !=''):
                #print "Line: ", line #, type(line[SpecFactory.CAT_PRICE])
                p = price(line[SpecFactory.CAT_PRICE])

                #print "item= ", int(line[SpecFactory.CAT_QUANTITY]) * line[SpecFactory.CAT_PRICE]
                total_price +=  int(line[SpecFactory.CAT_QUANTITY]) * line[SpecFactory.CAT_PRICE]
        #print "Price: ", total_price
        name = SpecFactory.getSpecName(session, hash)

        return_data.update({'stat' : stat, 'spec': result, 'price' : total_price, 'name' :name})
        #print return_data
        return return_data
示例#4
0
 def extractSpec(self, sheet, header, footer, column_mapping):
     ''' Exctract one sheet to list of dictionaries
     :param sheet:
     :param header:
     :param footer:
     :param column_mapping:
     :return:
     '''
     result=[]
     for row in range(header+1, footer):
         line = {}
         #num_field = sheet.cell(row, column_mapping[self.CAT_PN]).ctype
         # If number field type doesn't contain value - skip line
         if (sheet.isCellEmpty(row, column_mapping[self.CAT_PN])):      # 0 - XL_CELL_EMPTY, 6 - XL_CELL_BLANK
             continue
         for cat in self.mapping:
             value = sheet.cell(row,column_mapping[cat]).value
             line[cat] = value
         if (self.CAT_PRICE in self.mapping):
             tmp = price(line[self.CAT_PRICE])
             #print "Price = ", tmp, type(tmp)
             line[self.CAT_PRICE] = tmp
         result.append(line)
     return result