def getManualInvoiceItems(mi_id):
    url = invoice_item_url
    body = {
        "operator":
        "AND",
        "negated":
        False,
        "displayOrder":
        0,
        "fieldFilters": [{
            "fieldMetaId": 18714,
            "relationshipId": 4460,
            "value": mi_id,
            "operator": "=",
            "negated": False,
            "displayOrder": 1
        }]
    }
    params = {
        'access_token': get_access_token(),
        'user_key': settings.TRACKVIA_USER_KEY
    }
    response = requests.post(url=url, params=params, json=body)

    if response.status_code != 200:
        logger.error(
            "getManualInvoiceItems | {0} | response status is {1}".format(
                mi_id, response.status_code))
        pass

    response = response.json()
    return invoiceItemsFormatter(response.get('records'))
def _get_item_ref(item_name, tv_invoice_id, is_manual):
    result = queryItem(item_name)
    if 'item' in result:
        ItemRef = {
            'name': result['item']['Name'],
            'value': result['item']['Id']
        }
    else:
        try:
            item = createItem(item_name)
            ItemRef = {
                'name': item['Item']['Name'],
                'value': item['Item']['Id']
            }
        except Exception as e:
            logger.error(
                'error creating item: {0} in Quickbooks while processing trackvia {2} invoice: {1}'.format(
                    item_name,
                    tv_invoice_id,
                    "manual" if is_manual else ""
                ))
            send_email('TV-QBO integeration error',
                       'We got an error creating item: {0} in Quickbooks while processing trackvia {2} invoice: {1}. Invoice creation/updation failed. Please check line items in trackvia and retry.'.format(
                           item_name, tv_invoice_id, "manual" if is_manual else ""))
            raise Exception()
    return ItemRef
def sent_email(message,
               sender=settings.config["email_notify"]["sender"],
               receivers=settings.config["email_notify"]["receivers"]):
    email = sender["email"]
    password = sender["password"]
    server = sender["server"]
    port = sender["port"]
    subject = sender["subject"]
    try:
        smtpObj = smtplib.SMTP(server, port)
        smtpObj.ehlo()
        try:
            smtpObj.starttls()
        except Exception as ex:
            pass
        smtpObj.login(email, password)  #.decode("rot13"))
        msg = MIMEMultipart('alternative')
        msg['Subject'] = subject
        msg['From'] = email
        for _email in receivers:
            msg['To'] = _email
            msg.attach(MIMEText(message, 'html', "utf-8"))
            smtpObj.sendmail(email, _email, msg.as_string())
            logger.log("Successfully sent email: " + str(_email),
                       plugin="email notify")
    except smtplib.SMTPException:
        logger.error("Error: unable to send email", plugin="email notify")
Exemple #4
0
def updateDesignFeeInQB(design_fee_dict, view_id):
    designFeeDict = mapDesignFeeToQBAndReturn(design_fee_dict)
    designFeeRef = DesignFeeRef().getDesignFeeRefByTvId(
        design_fee_dict.get('df_id'))

    if designFeeRef:
        designFeeDict['Id'] = designFeeRef.qb_id
        updateInvoice(designFeeDict)
        logger.info(
            'updateDesignFeeInQB | updated design fee  in qb {0}'.format(
                design_fee_dict))
    else:
        designFeeInQB = createInvoice(designFeeDict)
        designFeeRefObj = DesignFeeRef(
            tv_id=design_fee_dict.get('df_id'),
            qb_id=designFeeInQB.get('Invoice').get('Id'),
            view_id=view_id)
        try:
            designFeeRefObj.save()
            logger.info(
                'updateDesignFeeInQB | created Design Fee in qb {0}'.format(
                    design_fee_dict))
        except Exception as e:
            logger.error(
                "updateDesignFeeInQB | Error in updateDesignFeeInQB {0}".
                format(design_fee_dict))
            logger.error(str(e))
    return
 def _parse_warzone_news(self, news: Tag, parsed_news: list):
     title = news.select_one(
         'div > div.text > div.title > h2 > a').text.strip()
     url_news_str = news.select_one('a')['href']
     url = url_news_str if url_news_str.startswith(
         "http") else self.NEWS_URL + url_news_str
     soup = BeautifulSoup(self._get_html(url=url), 'html.parser')
     try:
         date = self._get_news_date(soup)
         contents = self._get_news_content(soup)
     except AttributeError:
         logger.error(f"Can't parse news with url: {url}")
         parsed_news.append(
             NEWS_TEMPLATE.format(game=self.GAME,
                                  title=title,
                                  url=url,
                                  contents=self.EMPTY_MSG_ATTR,
                                  date=self.EMPTY_MSG_ATTR))
         return
     parsed_news.append(
         NEWS_TEMPLATE.format(game=self.GAME,
                              title=title,
                              url=url,
                              contents=contents,
                              date=date))
Exemple #6
0
def process_DesignFee(design_fee_qb_id):
    design_fee_qb_obj = readInvoice(design_fee_qb_id)
    logger.info("process_DesignFee | {0}".format(design_fee_qb_id))

    if design_fee_qb_obj == None:
        logger.error('design_fee_qb_obj not found for id {0}'.format(design_fee_qb_id))
        return

    total_amt = design_fee_qb_obj['Invoice']['TotalAmt']
    balance = design_fee_qb_obj['Invoice']['Balance']
    logger.info("process_DesignFee | {0} | {1}".format(total_amt, balance))

    design_fee_ref = DesignFeeRef().getDesignFeeRefByQbId(design_fee_qb_id)

    if not design_fee_ref:
        logger.error('process_DesignFee | DesignFee not found for id | {0}'.format(design_fee_qb_id))
        return

    design_fee_tv_id = design_fee_ref.tv_id
    view_id = design_fee_ref.view_id

    if total_amt == balance:
        updateDesignFeeStatus(design_fee_tv_id, 'UNPAID', view_id)
    elif balance == 0:
        updateDesignFeeStatus(design_fee_tv_id, 'FULL', view_id)
    elif 0 < balance < total_amt:
        updateDesignFeeStatus(design_fee_tv_id, 'PARTIAL', view_id)

    return
Exemple #7
0
def deleteBillInQB(bill_id):
    bill = readBillFromQB(bill_id)
    if not bill:
        logger.error(
            "log unable to fetch bill in deleteBillInQB for {0}".format(
                bill_id))
        # print('log unable to fetch bill in deleteBillInQB ', bill_id)
        return
    access_token = get_access_token()
    url = _get_url() + '/' + bill_id + '?operation=delete'
    data = {
        'Id': bill_id,
        'SyncToken': bill.get('Bill').get('SyncToken'),
    }
    headers = _get_headers(access_token)
    resp = requests.post(url=url, json=data, headers=headers)
    if resp.status_code == 200:
        # confirm logic
        return
    else:
        logger.error("log delete bill API failed | {0} | {1} | {2}".format(
            bill_id, resp.json(), resp.status_code))
        # print('log delete bill API failed', bill_id, resp.json(), resp.status_code)
        # confirm logic
        return {'error': "Not found"}
Exemple #8
0
def predict_time_left(x : np.ndarray, y : np.ndarray, name : str, mode : str = "BAYESIAN") -> int:
    functions = {
        "OLS":OLS,
        "RANSAC":RANSAC,
        "BAYESIAN":BAYESIAN
    }

    # Reshape the array as a single feature array for the predictors
    x = x.reshape(-1, 1)

    if mode in functions.keys():
        logger.info("Predicting using the mode [%s]"%mode)
        with Timer("The prediction took {time}s"):
            m, q, p =  functions[mode](x, y)
            logger.info("The coefficents predicted are m [{m}] q[{q}]".format(**locals()))
        if m <= 0:
            logger.info("The predicted line is not growing so it will never reach the max")
            return "inf", p
        time_predicted = (1 - q)/m
        delta = time_predicted - x[-1]
        if delta > MAX_TIME:
            logger.info(f"The predicted time [{delta}] is over [{MAX_TIME}] so it's casted to [inf]")
            return "inf", p
        return delta[0], p
    logger.error("Mode [%s] not found, the available ones are %s"%(mode, functions.keys()))
    return None, 0
Exemple #9
0
def updateTvInvoiceStatus(invoice_id, status, view_id):

    logger.info("Updating invoice status for {0} as {1}".format(
        invoice_id, status))

    #if not view_id:
    view_id = '4027'
    url = 'https://go.trackvia.com/accounts/21782/apps/49/tables/740/records/{0}?formId=5429&viewId={1}'.format(
        invoice_id, view_id)
    params = {
        'access_token': get_access_token(),
        'user_key': settings.TRACKVIA_USER_KEY
    }
    body = {
        'id':
        invoice_id,
        'data': [{
            'fieldMetaId': 21443,
            'id': 279131,
            'type': 'dropDown',
            'value': status
        }]
    }
    resp = requests.put(url=url, params=params, json=body)
    if resp.status_code != 200:
        logger.error(
            'payment status not updated for invoice {0} | {1} | {2}'.format(
                invoice_id, resp.json(), resp.status_code))
Exemple #10
0
 def command(self,command):
     """
     #执行命令模块
     """
     #print (command)
     stdin,stdout,stderr = self.s.exec_command(command)
     a = stderr.read().decode()
     if 'already exists' in a:
         ret = True
     else:
         ret = False
     if len(a) == 0 or ret:
         print (self.remote_host_address,':OK')
         out = stdout.read()
         try:
             print (out.decode())
         except UnicodeDecodeError:
             print (out.decode('gb2312'))
         msg = "[%s] exec command [%s] success" % (self.remote_host_address,command)
         logger.info(msg)
     else:
         print (self.remote_host_address,':')
         print (stderr.read().decode())
         logger.error(stderr.read().decode())
         print (a)
         print ('Somethings is Wrong,Please sure.')
     self.s.close()
Exemple #11
0
def updateBIllInQB(bill_dict, view_id):
    bill_expense = billToExpense(bill_dict)
    bill_ref = BillExpenseReference().getBillExpenseReferanceByTvId(
        bill_id=bill_dict.get('bill_id'))
    if bill_ref:
        bill_expense['Id'] = bill_ref.qb_id
        updateBillInQB(bill_expense)
        logger.info(
            'updateBIllInQB | updated bill in qb {0}'.format(bill_dict))
    else:
        bill_in_qb = createBillInQB(bill_expense)
        # if bill_dict.get('BILL PDF LINK'):
        # downloadAndForwardAttachable(bill_dict, bill_in_qb)

        bill_expense_ref = BillExpenseReference(
            tv_id=bill_dict.get('bill_id'),
            qb_id=bill_in_qb.get('Bill').get('Id'),
            view_id=view_id)
        try:
            bill_expense_ref.save()
            logger.info(
                'updateBIllInQB | created bill in qb {0}'.format(bill_dict))
        except Exception as e:
            logger.error("updateBIllInQB | Error in updateBIllInQB {0}".format(
                bill_dict))
            logger.error(str(e))
    return
def updateManualInvoiceStatus(mi_id, status):
    logger.info("Updating manual invoice status for {0} as {1}".format(
        mi_id, status))
    view_id = '5374'
    url = 'https://go.trackvia.com/accounts/21782/apps/49/tables/740/records/{0}?formId=5249&viewId={1}'\
        .format(mi_id, view_id)
    params = {
        'access_token': get_access_token(),
        'user_key': settings.TRACKVIA_USER_KEY
    }
    body = {
        'id':
        mi_id,
        'data': [{
            'fieldMetaId': '18716',
            'id': '329344',
            'type': 'dropDown',
            'value': status
        }]
    }
    resp = requests.put(url=url, params=params, json=body)
    if resp.status_code != 200:
        logger.error(
            'payment status not updated for manual invoice, {0} | {1} | {2}'.
            format(mi_id, resp.json(), resp.status_code))
Exemple #13
0
 def get_bssrdf(self, ray):
     """Compute the BSSRDF."""
     if self.primitive is None:
         logger.error("Intersect.get_bssrddf() called with no primitive.")
         return 0.0
     self.dg.compute_differentials(ray)
     bssrdf = self.primitive.get_bssrdf(self.dg, self.object_to_world)
     return bssrdf
 async def _request_news_bunch(self, session: aiohttp.ClientSession, params: dict) -> Union[list, None]:
     async with session.get(self.NEWS_URL, params=params) as resp:
         if not resp.ok:
             text = await resp.text()
             logger.error(f"Can't get news for steam. code: {resp.status}, text: {text}")
             return
         response = await resp.json()
         return response['appnews']['newsitems']
Exemple #15
0
 def get_bssrdf(self, ray):
     """Compute the BSSRDF."""
     if self.primitive is None:
         logger.error("Intersect.get_bssrddf() called with no primitive.")
         return 0.0
     self.dg.compute_differentials(ray)
     bssrdf = self.primitive.get_bssrdf(self.dg, self.object_to_world)
     return bssrdf
Exemple #16
0
 def check_existance_optionals(self, name: str, value: str):
     logger.info("Checking the existance of ['%s']" % value)
     available = self.get_available(name)
     if value not in available:
         logger.error(
             "The {name} [{metric}] do not exist. The available one are [{metrics}]"
             .format(**locals()))
         return False
     return True
 def __init__(self, **extra):
     """
     Method for automatically logging the exception when it is raised.
     """
     log_msg = self.message
     if extra:
         log_msg += " Extra info: {0}".format(extra)
     logger.error(log_msg)
     super().__init__(extra)
Exemple #18
0
 def check_existance(self, name: str, value: str):
     logger.info("Checking the existance of ['%s']" % value)
     available = self.get_available(name)
     if value not in available:
         logger.error(
             "The {name} [{value}] do not exist. The available one are [{available}]"
             .format(**locals()))
         self.__del__()
         sys.exit(1)
 def _get_html(self, url=None):
     if not url:
         url = self.NEWS_URL + "/ru/blog"
     try:
         r = requests.get(url)
         return r.content
     except requests.exceptions.RequestException as err:
         logger.error(f"Can't get callofduty.com DOM: {err}")
         return
Exemple #20
0
 def Le(self, w):
     """Return the light emitted by the object."""
     if self.primitive is None:
         logger.error("Intersect.Le() called with no primitive.")
         return Spectrum(0.0)
     area = self.primitive.get_area_light()
     if area:
         return area.L(self.dg.p, self.dg.nn, w)
     else:
         return Spectrum(0.0)
Exemple #21
0
def parse_time_to_epoch(string):
    if re.match(rfc3339_pattern, string):
        return rfc3339_to_epoch(string)
    if string.isnumeric():
        return int(string)
    if re.match(time_pattern, string):
        return time_to_epoch(string)

    logger.error("Can't decode the time format [%s]" % string)
    sys.exit(1)
Exemple #22
0
 def Le(self, w):
     """Return the light emitted by the object."""
     if self.primitive is None:
         logger.error("Intersect.Le() called with no primitive.")
         return Spectrum(0.0)
     area = self.primitive.get_area_light()
     if area:
         return area.L(self.dg.p, self.dg.nn, w)
     else:
         return Spectrum(0.0)
Exemple #23
0
 async def set_bot_commands(self):
     """ Register all func startswith cmd_ as user command """
     bot_commands = [
         types.BotCommand(f.replace("cmd_", ""),
                          str(getattr(self, f).__doc__)) for f in dir(self)
         if f.startswith("cmd_")
     ]
     r = await self.set_my_commands(bot_commands)
     self.BOT_COMMANDS = {cmd.command for cmd in bot_commands}
     if not r:
         logger.error("Can't set command's list for bot")
def readBillPayment(payment_id):
    access_token = get_access_token()
    url = _get_url() + '/' + payment_id + '?minorversion=51'
    headers = _get_headers(access_token)
    r = requests.get(url=url, headers=headers)
    if r.status_code == 200:
        return r.json()
    else:
        logger.error('log read BillPayment API failed {0} | {1} | {2}'.format(
            payment_id, r.json(), r.status_code))
        return {'error': "Not found"}
async def start_bot_jobs(bot: Mailer):
    tasks = [
        asyncio.create_task(getattr(bot, f)())
        for f in ["set_bot_commands", "command_runner", "broadcaster"]
    ]
    try:
        await asyncio.gather(*tasks)
    except NetworkError as err:
        logger.error(f"Network error, rerun main jobs via 1 min:{err}")
        await asyncio.sleep(60)
        [t.cancel() for t in tasks]
        await start_bot_jobs(bot)
Exemple #26
0
def createBillInQB(data):
    access_token = get_access_token()
    url = _get_url()
    headers = _get_headers(access_token)
    resp = requests.post(url=url, json=data, headers=headers)
    if resp.status_code == 200:
        return resp.json()
    else:
        logger.error(
            'failed expense creation, data={0}, resp={1}, status_code={2}',
            data, resp.json(), resp.status_code)
        pass
Exemple #27
0
def _getVendorRef(name):
    vendorRef = getVendor(name)
    if not vendorRef:
        logger.error(
            'error finding customer: {0} in Quickbooks while processing trackvia bill'
            .format(name))
        send_email(
            'TV-QBO integeration error',
            'We got an error finding customer: {0} in Quickbooks while processing trackvia bill.'
            ' Bill creation/updation failed. Please create customer in quickbooks and retry.'
            .format(name))
        raise Exception()
    return {'value': vendorRef['Vendor']['Id']}
Exemple #28
0
def deleteBillFromQB(tv_bill_id):
    bill = BillExpenseReference().getBillExpenseReferanceByTvId(
        bill_id=tv_bill_id)
    if not bill:
        logger.error(
            "deleteBillFromQB: No bill found for {0}".format(tv_bill_id))
        return

    deleteBillInQB(bill.qb_id)

    bill.delete()
    bill.save()

    logger.info('deleted bill from qb: {0}'.format(bill.qb_id))
def _customer_ref(cust_name, tv_invoice_id, is_manual):
    result = queryCustomer(cust_name)
    if 'Customer' in result:
        return {'value': result['Customer']['Id']}
    else:
        logger.error(
            'error finding customer: {0} in Quickbooks while processing trackvia {2} invoice: {1}'.format(
                cust_name,
                tv_invoice_id,
                "manual" if is_manual else ""))
        send_email('TV-QBO integeration error',
                   'We got an error finding customer: {0} in Quickbooks while processing trackvia {2} invoice: {1}. Invoice creation/updation failed. Please create customer in quickbooks and retry.'.format(
                       cust_name, tv_invoice_id, "manual" if is_manual else ""))
        raise Exception()
def _customer_ref(cust_name, df_id):
    result = queryCustomer(cust_name)
    if 'Customer' in result:
        return {'value': result['Customer']['Id']}
    else:
        logger.error(
            'error finding customer: {0} in Quickbooks while processing trackvia design fee: {1}'
            .format(cust_name, df_id))
        send_email(
            'TV-QBO integeration error',
            'We got an error finding customer: {0} in Quickbooks while processing trackvia trackvia design fee:'
            ' {1}. design fee creation/updation failed. Please create customer in quickbooks and retry.'
            ''.format(cust_name, df_id))
        raise Exception()
Exemple #31
0
 def get(self,rpath,lpath):
     """
     #下载文件目录,调用get_dirs
     """
     self.get_dirs(rpath,lpath)
     print (self.remote_host_address)
     error_num = self.error_count(-1)
     msg_ok = 'Get Total files number: %s' % self.sucess_count(-1)
     msg_error = 'Get Error files number: %s' % error_num
     logger.info('%s %s %s' % (self.remote_host_address,rpath,msg_ok))
     if error_num > 0:
         logger.error('%s %s %s' % (self.remote_host_address,rpath,msg_error))
     print (msg_ok)
     print (msg_error)
Exemple #32
0
def processBills(payment_ids):
    bill_ids = []
    for payment_id in payment_ids:
        payment = readBillPayment(payment_id)
        if not payment:
            logger.error('processBills | payment not found for id | {0}'.format(payment_id))
            break
        lines = payment['BillPayment']['Line']
        for line in lines:
            for ltxn in line['LinkedTxn']:
                if ltxn['TxnType'] == 'Bill':  # Confirm this type
                    bill_ids.append(ltxn['TxnId'])
    bill_ids = list(set(bill_ids))
    for bill_id in bill_ids:
        process_bill(bill_id)
Exemple #33
0
 def put_file(self,lpath,rpath=None):
     """
     #Upload files
     """
     try:
         if re.match(r'd',str(self.sftp.stat(rpath))):
             rpath = rpath.rstrip('/') + '/' + os.path.split(lpath)[-1]
     except FileNotFoundError:
         pass
     try:
         self.sftp.put(lpath,rpath)
         self.sucess_count()
         if print_file_put:print ('%s Uploading complete.' % rpath.ljust(50))
     except Exception as e:
         self.error_count()
         logger.error(str(e) + ' ' + lpath)
Exemple #34
0
def processInvoices(payment_ids):
    invoice_ids = []
    for payment_id in payment_ids:
        payment = readPayment(payment_id)
        if payment == None:
            logger.error('payment not found for id {0}'.format(payment_id))
            break
        lines = payment['Payment']['Line']
        for line in lines:
            for ltxn in line['LinkedTxn']:
                if ltxn['TxnType'] == 'Invoice':
                    invoice_ids.append(ltxn['TxnId'])
    invoice_ids = list(set(invoice_ids))
    for invoice_id in invoice_ids:
        if checkIfDesignFee(invoice_id) != None:
            process_DesignFee(invoice_id)
        else:
            process_invoice(invoice_id)
def _get_item_ref(item_name, df_id):
    ItemRef = None
    result = queryItem(item_name)
    if 'item' in result:
        ItemRef = {
            'name': result['item']['Name'],
            'value': result['item']['Id']
        }
    else:
        logger.error(
            'error querying item: {0} in Quickbooks while processing trackvia DesignerFee: {1}'
            .format(item_name, df_id))
        send_email(
            'TV-QBO integeration error',
            'We got an error creating item: {0} in Quickbooks while processing trackvia DesignerFee: {1}.'
            ' Invoice creation/updation failed. Please check line items in trackvia and retry.'
            ''.format(item_name, df_id))
    return ItemRef
Exemple #36
0
 def put_dir(self,lpath,rpath=None):
     """
     #upload dirs
     """
     s_path = os.path.abspath(lpath)
     s_num = len(s_path)
     for path, dirname,filelist in os.walk(lpath):
         for dname in dirname:
             lpath_dirpath = os.path.abspath(os.path.join(path,dname))
             r_path = (rpath + lpath_dirpath[s_num:]).replace('\\', '/')
             command = 'mkdir -p %s' % r_path
             stdin,stdout,stderr = self.s.exec_command(command)
             if len(stderr.read().decode()) != 0:
                 logger.error(stderr.read().decode())
                 print ('%s command exec wrong!!!' % command)
         for fname in filelist:
             lfilepath = os.path.abspath(os.path.join(path,fname))
             rfilepath = (rpath + lfilepath[s_num:]).replace('\\', '/')
             yield lfilepath,rfilepath
Exemple #37
0
def hex_to_color(inp):
    ''' Converts a hex string into a libtcod Color object '''
    # Format the string for use
    fhex = inp.replace('#', '').strip()

    try:
        # Get string slices for each hex bit and convert them to numbers
        # NOTE: String slices are in base 16
        red_bit   = int(fhex[0:2], 16)
        green_bit = int(fhex[2:4], 16)
        blue_bit  = int(fhex[4:6], 16)

        logger.info('Color: (' + str(red_bit) + ', ' + str(green_bit) + ', ' + \
            str(blue_bit) + ')')

        return libtcod.Color(red_bit, green_bit, blue_bit);

    # If the color sting is mal-formatted
    except ValueError as e:
        logger.error('Problem converting hex to color! Is it `rrggbb` formatted?')
        return None
Exemple #38
0
 def put(self,lpath,rpath=None):
     if not rpath:
         print ('Please input remote file or dir')
     else:
         if os.path.isfile(lpath):
             self.put_file(lpath,rpath)
         else:
             if re.match(r'd',str(self.sftp.stat(rpath))):
                 for l,r in self.put_dir(lpath, rpath):
                     self.put_file(l,r)
             else:
                 print ('Remote path must be a dirname')
             self.s.close()
     print (self.remote_host_address)
     error_num = self.error_count(-1)
     msg_ok = 'Put Total files number: %s' % self.sucess_count(-1)
     msg_error = 'Put Error files number: %s' % error_num
     logger.info('%s %s %s' % (self.remote_host_address,rpath,msg_ok))
     if error_num > 0:
         logger.error('%s %s %s' % (self.remote_host_address,rpath,msg_error))
     print (msg_ok)
     print (msg_error)
    def run(self):
        """Execute the task."""

        print "executing task %d/%d" % (self.task_num, self.task_count)
        
        # get sub-sampler for SamplerRendererTask
        sampler = self.main_sampler.get_sub_sampler(self.task_num,
                                                    self.task_count)
        if not sampler:
            return
        
        # Declare local variables used for rendering loop
        rng = RNG(self.task_num)

        # allocate space for samples and intersections
        max_samples = sampler.maximum_sample_count()
        samples = self.orig_sample.duplicate(max_samples)
        rays = [None] * max_samples
        Ls = [None] * max_samples
        Ts = [None] * max_samples
        isects = [] # Intersection[max_samples]
        for i in range(max_samples):
            isects.append(Intersection())

        # get samples from Sampler and update image
        while True:
            sample_count = sampler.get_more_samples(samples, rng)

            # if no more samples to compute, exit
            if sample_count <= 0:
                break
            
            # generate camera rays and compute radiance along rays
            for i in range(sample_count):
                # find camera ray for samples[i]
                ray_weight, ray_diff = self.camera.generate_ray_differential(samples[i])
                
                rays[i] = ray_diff
                coeff = 1.0 / math.sqrt(sampler.samples_per_pixel)
                ray_diff.scale_differentials(coeff)
                
                # evaluate radiance along camera ray
                if ray_weight > 0.0:
                    radiance, intersection, Ts_i = \
                              self.renderer.Li(self.scene,
                                               ray_diff,
                                               samples[i],
                                               rng,
                                               isects[i])
                    Ls_i = ray_weight * radiance
                else:
                    Ls_i = Spectrum(0.0)
                    Ts_i = Spectrum(1.0)

                Ls[i] = Ls_i
                Ts[i] = Ts_i
                
                # check for unexpected radiance values
                if Ls_i.has_nan():
                    logger.error(
                        "Not-a-number radiance value returned for image sample.  Setting to black.")
                    Ls_i = Spectrum(0.0)
                elif Ls_i.y() < -1e-5:
                    logger.error(
                        "Negative luminance value, %f, returned for image sample.  Setting to black." % Ls_i.y())
                    Ls_i = Spectrum(0.0)
                elif Ls_i.y() == float('inf'):
                    logger.error(
                        "Infinite luminance value returned for image sample.  Setting to black.")
                    Ls_i = Spectrum(0.0)

            # report sample results to Sampler, add contributions to image
            if sampler.report_results(samples, rays, Ls, isects, sample_count):
                for i in range(sample_count):
                    self.camera.film.add_sample(samples[i], Ls[i])

        # clean up after SamplerRendererTask is done with its image region
        pass
Exemple #40
0
    def get_dirs(self,rpath,lpath):
        """
        #文件下载及目录下载
        """
        rpath = rpath.strip().rstrip('/')
        #判断get是文件or目录
        try:
            dir_or_file = str(self.sftp.stat(rpath))
            #如果是目录
            if re.match(r'd',dir_or_file):
                files_dirs = self.sftp.listdir(rpath)
                #判断目录下是否为空
                if not len(files_dirs) == 0:
                    for i in files_dirs:
                        r_files_dirs = rpath + '/' + i
                        try:
                            f_d = str(self.sftp.stat(r_files_dirs))
                        except Exception as e:
                            #将报错文件or目录写入日志
                            logger.error(e)
                        #对目录进程操作循环
                        if re.match(r'd',f_d):
                            rdir = rpath + '/' + i
                            lpath = lpath + os.sep + i
                            #本地创建递归目录结构
                            if not os.path.exists(lpath):
                                os.makedirs(lpath)
                            self.get_dirs(rdir,lpath)
                            #重新循环,格式lpath为原路径
                            lpath = os.path.split(lpath)[0]
                        #对目录下文件进行get
                        else:
                            rfile = rpath + '/' + i
                            lfile = lpath + os.sep + i
                            try:
                                self.sftp.get(rfile,lfile)
                                self.sucess_count()
                                if print_file_get:print ('%s Download complete.' % rfile.ljust(50))
                            except Exception as e:
                                self.error_count()
                                logger.error(str(e) + ' ' +rfile)
            #如果是文件
            else:
                #保存到指定目录
                if os.path.exists(lpath) and os.path.isdir(lpath):
                    filename = os.path.split(rpath)[-1]
                    lfile = lpath + os.sep + filename
                    try:
                        self.sftp.get(rpath,lfile)
                        self.sucess_count()
                        print ('%s Download complete.' % rpath.ljust(50))
                    except Exception as e:
                        self.error_count()
                        logger.error(str(e) + ' ' +rpath)
                #保存为指定文件名
                else:
                    try:
                        self.sftp.get(rpath,lpath)
                        self.sucess_count()
                        if print_file_get:print ('%s Download complete.' % rpath.ljust(50))
                    except Exception as e:
                        self.error_count()
                        logger.error(str(e) + ' ' +rpath)

        except FileNotFoundError as e:
            print (self.remote_host_address)
            print ("File or dir %s not found!" % rpath)