Exemple #1
0
    def site_statistics(cls):
        # first check the cache
        stats = Cache.get_site_statistics()
        if stats is not None:
            return stats

        # we didn't get anything from the cache, so we need to generate and
        # cache a new set

        # prep the query and result objects
        q = JournalArticleQuery()
        stats = {
            "articles" : 0,
            "journals" : 0,
            "countries" : 0,
            "searchable" : 0
        }

        # do the query
        res = cls.query(q=q.site_statistics())

        # pull the journal and article facets out
        terms = res.get("facets", {}).get("type", {}).get("terms", [])

        # can't use the Python , option when formatting numbers since we
        # need to be compatible with Python 2.6
        # otherwise we would be able to do "{0:,}".format(t.get("count", 0))

        if sys.version_info[0] == 2 and sys.version_info[1] < 7:
            locale.setlocale(locale.LC_ALL, 'en_US')
            for t in terms:
                if t.get("term") == "journal":
                    stats["journals"] = locale.format("%d", t.get("count", 0), grouping=True)
                if t.get("term") == "article":
                    stats["articles"] = locale.format("%d", t.get("count", 0), grouping=True)

            # count the size of the countries facet
            stats["countries"] = locale.format("%d", len(res.get("facets", {}).get("countries", {}).get("terms", [])), grouping=True)

            # count the size of the journals facet (which tells us how many journals have articles)
            stats["searchable"] = locale.format("%d", len(res.get("facets", {}).get("journals", {}).get("terms", [])), grouping=True)

            locale.resetlocale()
        else:
            for t in terms:
                if t.get("term") == "journal":
                    stats["journals"] = "{0:,}".format(t.get("count", 0))
                if t.get("term") == "article":
                    stats["articles"] = "{0:,}".format(t.get("count", 0))

            # count the size of the countries facet
            stats["countries"] = "{0:,}".format(len(res.get("facets", {}).get("countries", {}).get("terms", [])))

            # count the size of the journals facet (which tells us how many journals have articles)
            stats["searchable"] = "{0:,}".format(len(res.get("facets", {}).get("journals", {}).get("terms", [])))

        # now cache and return
        Cache.cache_site_statistics(stats)

        return stats
Exemple #2
0
    def test_float__format__locale(self):
        # test locale support for __format__ code 'n'

        for i in range(-10, 10):
            x = 1234567890.0 * (10.0 ** i)
            self.assertEqual(locale.format('%g', x, grouping=True), format(x, 'n'))
            self.assertEqual(locale.format('%.10g', x, grouping=True), format(x, '.10n'))
Exemple #3
0
    def tooltipText(self):
        d = {}
        for rwy in self.runways():
            if rwy.type not in d:
                d[rwy.type] = []

            d[rwy.type].append(rwy.name)

        rl = []         # one element per runway type
        for rwyType in sorted(d.keys(), key=lambda x: x.value):
            runwayTypeName = rwyType.capitalizedName(len(d[rwyType]))

            s = _("{rwyType}: {runways}").format(
                rwyType=runwayTypeName,
                runways=", ".join(sorted(d[rwyType])))
            rl.append(
                textwrap.fill(s, width=40, subsequent_indent='  '))

        l = [self.type.capitalizedName(),
              _("Latitude: {latitude}").format(latitude=self.lat),
              _("Longitude: {longitude}").format(longitude=self.lon),
              _("Elevation: {elev_feet} ft ({elev_meters} m)").format(
                  elev_feet=locale.format("%d", round(self.elevation)),
                  elev_meters=locale.format("%.01f", self.elevation*0.3048))]

        if magField is not None:
            magVar = locale.format("%.01f", magField.decl(self.lat, self.lon))
            l.append(_("Magnetic variation: {}°").format(magVar))

        return '\n'.join(l + rl)
Exemple #4
0
def format_amount(amount, trim=True, grouping=True, precision=2):
    """
        return a pretty printable amount
    """
    resp = u""
    if amount is not None:
        dividor = 10.0 ** precision

        # Limit to 2 trailing zeros
        if isinstance(amount, float) and precision <= 2:
            if amount == int(amount):
                trim = True
        elif precision > 2:
            if math_utils.floor_to_precision(
                amount,
                precision=2,
                dialect_precision=precision
            ) == amount:
                trim = True

        if trim:
            formatter = "%.2f"
            amount = int(amount) / dividor
            resp = locale.format(formatter, amount, grouping=grouping)
        else:
            formatter = "%.{0}f".format(precision)
            amount = amount / dividor
            resp = locale.format(formatter, amount, grouping=grouping)
            resp = resp.rstrip('0')
            resp = add_trailing_zeros(resp)

    if grouping:
        resp = resp.replace(' ', '&nbsp;')
    return resp
    def draw(self):
        # the cursor should be at the beginning of the first line when this
        # starts

        num_ticks = int(50 * float(self.count) / self.total)
        empty_ticks = 50 - num_ticks
        progress_bar = '[' + '#' * num_ticks + ' ' * empty_ticks + ']'

        now = time.time()
        self.last_update_time = now

        try:
            rate = self.count / (now - self.start_time)
            to_go = self.total - self.count
            time_to_go = to_go / rate
            eta_str = self.__format_time(time_to_go)
        except ZeroDivisionError:
            eta_str = "N/A"

        rate_info = "%s items/sec, %s of %s (ETA: %s)" %  (
            locale.format('%0.02f', rate, grouping=True), 
            locale.format('%d', self.count, grouping=True),
            locale.format('%d', self.total, grouping=True),
            eta_str)
        
        self.paint_line(self.message)
        sys.stderr.write("\n")
        self.paint_line(progress_bar)
        sys.stderr.write("\n")
        self.paint_line(rate_info)

        if self.count == self.total:
            sys.stderr.write("\n")
        else:
            sys.stderr.write(chr(27) + '[2F') # up two lines, back to the start
    def report(self, fileName = None):
        """Reports the Median Center results as a message or to a file.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results
        """

        header = ARCPY.GetIDMessage(84190)
        columns = [ARCPY.GetIDMessage(84191), ARCPY.GetIDMessage(84192), 
                   ARCPY.GetIDMessage(84193)]
        if self.attFields:
            for attField in self.attFields:
                columns.append(ARCPY.GetIDMessage(84194).format(attField))
        results = [ columns ]
        for case in self.uniqueCases:
            if not self.caseField:
                strCase = "ALL"
            else:
                strCase = UTILS.caseValue2Print(case, self.caseIsString)
            medX, medY = self.medianCenter[case]
            rowResult = [ strCase, LOCALE.format("%0.6f", medX),
                          LOCALE.format("%0.6f", medY) ]
            if self.attFields:
                for attInd, attField in enumerate(self.attFields):
                    medAtt = self.attCenter[case][attInd]
                    rowResult.append(LOCALE.format("%0.6f", medAtt))
            results.append(rowResult)

        outputTable = UTILS.outputTextTable(results, header = header)
        if fileName:
            f = open(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)
Exemple #7
0
def update_global_stats(website):
    stats = website.db.one("""
        SELECT nactive, transfer_volume FROM paydays
        ORDER BY ts_end DESC LIMIT 1
    """, default=(0, 0.0))
    website.gnactive = locale.format("%d", round(stats[0], -2), grouping=True)
    website.gtransfer_volume = locale.format("%d", round(stats[1], -2), grouping=True)
    def report(self, fileName = None):
        """Reports the Standard Distance results as a message or to a file.

        INPUTS:
        fileName {str, None}: path to a text file to populate with results
        """

        header = ARCPY.GetIDMessage(84224)
        columns = [ARCPY.GetIDMessage(84191), ARCPY.GetIDMessage(84211),
                   ARCPY.GetIDMessage(84212), ARCPY.GetIDMessage(84225),
                   ARCPY.GetIDMessage(84226)]
        results = [columns]
        for case in self.uniqueCases:
            if not self.caseField:
                strCase = "ALL"
            else:
                strCase = UTILS.caseValue2Print(case, self.caseIsString)
            meanX, meanY = self.meanCenter[case]
            rowResult = [ strCase, LOCALE.format("%0.6f", meanX),
                          LOCALE.format("%0.6f", meanY),
                          LOCALE.format("%0.6f", self.sd[case]),
                          LOCALE.format("%0.1f", self.stdDeviations) ]
            results.append(rowResult)

        outputTable = UTILS.outputTextTable(results, header = header)
        if fileName:
            f = UTILS.openFile(fileName, "w")
            f.write(outputTable)
            f.close()
        else:
            ARCPY.AddMessage(outputTable)
    def update_children(self):
        ids = self.sel_ids_get()
        for child in self.children:
            value = 0
            value_selected = 0
            loaded = True
            child_fieldname = self.children[child][0]
            for record in self.screen.group:
                if not record.get_loaded([child_fieldname]):
                    loaded = False
                    break
                field_value = record.fields_get()[child_fieldname].get(record,
                    check_load=False)
                if field_value is not None:
                    value += field_value
                    if record.id in ids or not ids:
                        value_selected += field_value

            if loaded:
                label_str = locale.format(
                    '%.' + str(self.children[child][3]) + 'f', value_selected,
                    True)
                label_str += ' / '
                label_str += locale.format(
                    '%.' + str(self.children[child][3]) + 'f', value, True)
            else:
                label_str = '-'
            self.children[child][2].set_text(label_str)
    def row(self, request, tag):
        locale.setlocale(locale.LC_ALL, 'en_CA.UTF-8' )
        for asset in self.assets:
            timestamp = float(asset.createTimestamp)

            price = db.query(Price).filter(Price.currencyId == 'USD').first()

            askingPriceFiat = float(asset.askingPrice)
            pricePerUnitFiat = float(asset.askingPrice) / float(asset.totalUnits) 

            askingPriceBTC = float(asset.askingPrice) / float(price.last)
            pricePerUnitBTC = (float(asset.askingPrice) / float(price.last)) / float(asset.totalUnits)

            slots = {}
            slots['htmlAssetId'] = str(asset.id)
            slots['htmlTimestamp'] = config.convertTimestamp(timestamp)
            slots['htmlTitle'] = str(asset.title)
            slots['htmlAssetUrl'] = '../%s' % str(asset.id)
            slots['htmlImageUrl'] = '../images/%s.jpg' % str(asset.id)
            slots['htmlTotalUnits'] = str(asset.totalUnits)

            slots['htmlAskingPriceFiat'] = locale.format("%d", askingPriceFiat, grouping=True) 
            slots['htmlPricePerUnitFiat'] = locale.format("%d", pricePerUnitFiat, grouping=True)
            slots['htmlAskingPriceBTC'] = locale.format("%d", askingPriceBTC, grouping=True)
            slots['htmlPricePerUnitBTC'] = locale.format("%d", pricePerUnitBTC, grouping=True)
            self.asset = asset
            yield tag.clone().fillSlots(**slots)
Exemple #11
0
def current_status():

    load = "%.2f %.2f %.2f" % os.getloadavg()

    process = subprocess.Popen(
        [
            config.KAFKA_RUN_CLASS_BINARY,
            "kafka.tools.ConsumerOffsetChecker",
            "--topic",
            "listens",
            "--group",
            "listen-group",
        ],
        stdout=subprocess.PIPE,
    )
    out, err = process.communicate()

    print out

    lines = out.split("\n")
    data = []
    for line in lines:
        if line.startswith("listen-group"):
            data = line.split()

    if len(data) >= 6:
        kafka_stats = {
            "offset": locale.format("%d", int(data[3]), grouping=True),
            "size": locale.format("%d", int(data[4]), grouping=True),
            "lag": locale.format("%d", int(data[5]), grouping=True),
        }
    else:
        kafka_stats = {"offset": "(unknown/empty)", "size": "-", "lag": "-"}

    return render_template("index/current-status.html", load=load, kstats=kafka_stats)
Exemple #12
0
def runLocalhostBenchmark():
    serverName = 'async_server'
    serverPort = '22380'
    clientName = 'bench_client'
    hostName   = 'localhost'
    localhostCount = count / 50
    p1 = Popen(['./'+serverName, serverPort], stdout=PIPE, stderr=PIPE, env=env)

    then = time.time()
    p2 = Popen(['./'+clientName, hostName+':'+serverPort, str(localhostCount)], stdout=PIPE, stderr=PIPE, env=env)
    out2, err2 = p2.communicate()
    t = time.time() - then

    p1.kill()
    out1, err1 = p1.communicate()

    if p2.returncode != 0:
        print '%s error. returncode: %d' % (executableName, p2.returncode)
        print clientName, 'stdout:'
        print out2
        print clientName, 'stderr:'
        print err2

        print serverName, 'stdout:'
        print out1
        print serverName, 'stderr:'
        print err1
        sys.exit(1)

    print('%s: Made %s AMP calls (back-to-back in series - over '
          'localhost TCP socket) in %.4f seconds (%s calls/s)' %
          (clientName, locale.format("%d", localhostCount, grouping=True),
           t, locale.format("%d", int(localhostCount/t), grouping=True)))
    def linesForYear(self,form):
        temp=0
        years={}

        global pattern
        global show
        global perc
        global bal_zero
        global ref_bal

        pattern=form['compare_pattern']

        if form['show_columns']!=1:
            show=0
        else:
            show=form['show_columns']

        if form['format_perc']!=1:
            perc=0
        else:
            perc=form['format_perc']

        if form['account_choice']=='bal_zero':
            bal_zero=0
        else:
            bal_zero=1

        ctx = self.context.copy()

        if perc==1:
            if form['select_account']!=False:
                ref_ac=self.pool.get('account.account').browse(self.cr, self.uid,form['select_account'],ctx.copy())
                if ref_ac.balance<>0.00:
                    ref_bal=ref_ac.balance
                else:
                    ref_bal=1.00
            else:
                ref_bal='nothing'
        else:
            ref_bal='nothing'


        total_for_perc=[]
#       if perc==1:
        self.done_total=1
        self.total_for_perc=self.linesForTotal(form,ids={},doneAccount={},level=1)
        self.done_total=0

        for t1 in range(0,len(form['fiscalyear'][0][2])):
            locale.setlocale(locale.LC_ALL, '')
            self.result_total["sum_credit" + str(t1)]=locale.format("%.2f", self.result_total["sum_credit" + str(t1)], grouping=True)
            self.result_total["sum_debit" + str(t1)]=locale.format("%.2f", self.result_total["sum_debit" + str(t1)], grouping=True)
#           self.flag=1
#           self.result_total = {}

        for temp in range(0,len(form['fiscalyear'][0][2])):
            fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][0][2][temp])
            years["year"+str(temp)]=fy[0][1][12:16]

        return [years]
Exemple #14
0
  def start(self):
    self._sent = 0
    self._received = 0

    self.engine.eventManager.triggerEvent(events.CONNECT)
    previousLine = ''

    while self.running():
      if not select.select([self._telnet], [], [], 0.2)[0]:
        continue
      try:
        data = self._telnet.read_eager()
      except (EOFError, socket.error):
        logging.info('Connection closed')
        self.disconnect()
        break
      if not data:
        continue
      self._received += len(data)
      data = previousLine + data.replace('\r', '')
      lines = data.split('\n')
      previousLine = lines[-1]
      currentLines = lines[0:-1]

      for line in currentLines:
        self.engine.eventManager.triggerEvent(events.READ, line)

    self._telnet.close()

    self.engine.eventManager.triggerEvent(events.DISCONNECT)

    logging.info('Sent: %s bytes, Received: %s bytes',
      locale.format('%d', self._sent, grouping=True),
      locale.format('%d', self._received, grouping=True))
def _print_size(prefix, total):
    """Print size formatted with commas and estimated to the largest XB.

    prefix[in]        The preamble to the size. e.g. "Total XXX ="
    total[in]         Integer value to format.
    """
    msg = "{0}{1} bytes".format(prefix, locale.format("%d", total,
                                                      grouping=True))

    # Calculate largest XByte...
    if total > _TB:
        converted = total / _TB
        print("{0} or {1} TB".format(msg, locale.format("%.2f", converted,
                                                        grouping=True)))
    elif total > _GB:
        converted = total / _GB
        print("{0} or {1} GB".format(msg, locale.format("%.2f", converted,
                                                        grouping=True)))
    elif total > _MB:
        converted = total / _MB
        print("{0} or {1} MB".format(msg, locale.format("%.2f", converted,
                                                        grouping=True)))
    elif total > _KB:
        converted = total / _KB
        print("{0} or {1} KB".format(msg, locale.format("%.2f", converted,
                                                        grouping=True)))
    else:
        print(msg)
Exemple #16
0
def formatNumber(number, fixed, format_locale):
    '''
    Format the number based on format_locale passed.
    '''

    # get the current locale
    current_locale = locale.getlocale()
    new_locale = ''
    # set passed locale and set new_locale to same value.
    if format_locale:
        new_locale = locale.setlocale(locale.LC_ALL, format_locale)

    # Based on type of number use the correct formatter
    if isinstance(number, float):
        if fixed:
            formatted = locale.format('%' + '.%df' % fixed, number, True)
        else:
            formatted = locale.format('%f', number, True)
    if isinstance(number, int):
        formatted = locale.format('%d', number, True)
    # After formatting is done as per locale, reset the locale if changed.
    if (new_locale and not current_locale[0] and not current_locale[1]):
        locale.setlocale(locale.LC_ALL, 'C')
    elif (new_locale):
        locale.setlocale(locale.LC_ALL, current_locale[0] + "." +
                         current_locale[1])

    return formatted
Exemple #17
0
def getkill(value):
    curs = g.db.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
    killid = value
    retVal={}
    retVal['killers'] = {}
    retVal['victim'] = {}
    retVal['items'] = {}
    curs.execute("""select * from killlist where killid = %s""", (killid,))
    for key, value in curs.fetchall()[0].iteritems():
        if key == "time":
            retVal[key] = value.strftime("%Y-%m-%d %H:%M")
        elif key == "systemid":
            for syskey, sysvalue in systemInfo(value).iteritems():
                retVal[syskey] = sysvalue
            retVal[key] = value
        elif key == "price":
            value = locale.format("%.2f", value, grouping=True, monetary=True)
            retVal[key] = value
        else:
            retVal[key] = value
    curs.execute("""select * from killattackers where killid = %s order by damagedone desc""", (killid,))
    i = 0
    for data in curs:
        retVal['killers'][i] = {}
        retVal['killers'][i]['weap'] = {}
        for key, value in data.iteritems():
            if key == "shiptypeid":
                for syskey, sysvalue in itemMarketInfo(value).iteritems():
                    retVal['killers'][i][syskey] = sysvalue
            elif key == "damagedone":
                value = locale.format("%d", value, grouping=True)
            elif key == "weapontypeid":
                for syskey, sysvalue in itemMarketInfo(value).iteritems():
                    retVal['killers'][i]['weap'][syskey] = sysvalue
            retVal['killers'][i][key] = value
        i += 1
    curs.execute("""select * from killitems where killid = %s""", (killid,))
    i = 0
    for data in curs:
        retVal['items'][i] = {}
        for key, value in data.iteritems():
            if key == "typeid":
                for syskey, sysvalue in itemMarketInfo(value).iteritems():
                    retVal['items'][i][syskey] = sysvalue
            elif key == "itemprice":
                value = locale.format("%.2f", value, grouping=True, monetary=True)
            retVal['items'][i][key] = value
        i += 1
    curs.execute("""select * from killvictim where killid = %s""", (killid,))
    for data in curs:
        for key, value in data.iteritems():
            if key == "shipprice":
                value = locale.format("%.2f", value, grouping=True, monetary=True)
            elif key == "damagetaken":
                value = locale.format("%d", value, grouping=True)
            elif key == "shiptypeid":
                for syskey, sysvalue in itemMarketInfo(value).iteritems():
                    retVal['victim'][syskey] = sysvalue
            retVal['victim'][key] = value
    return retVal
Exemple #18
0
    def paint(self):
        """paint the complete status"""
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Currency: " + self.gox.currency + " | "
        line1 += "Account: "
        if len(self.gox.wallet):
            for currency in self.gox.wallet:
                line1 += currency + " " \
                + goxapi.int2str(self.gox.wallet[currency], currency).strip() \
                + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

        str_btc = locale.format('%d', self.gox.orderbook.total_ask, 1)
        str_fiat = locale.format('%d', self.gox.orderbook.total_bid, 1)
        if self.gox.orderbook.total_ask:
            str_ratio = locale.format('%1.2f',
                self.gox.orderbook.total_bid / self.gox.orderbook.total_ask, 1)
        else:
            str_ratio = "-"

        line2 = "total bid: " + str_fiat + " " + self.gox.currency + " | "
        line2 += "total ask: " +str_btc + " BTC | "
        line2 += "ratio: " + str_ratio + " " + self.gox.currency + "/BTC | "
        line2 += "lag: " + self.order_lag_txt
        self.addstr(0, 0, line1, COLOR_PAIR["status_text"])
        self.addstr(1, 0, line2, COLOR_PAIR["status_text"])
Exemple #19
0
    def processPrices(self, prices):
        shipPrice = prices[0].price
        if shipPrice == None:
            if not self._timer:
                self._timer = wx.Timer(self.parent, self._timerId)
            self._timer.Start(1000)
            self._timerRuns = 0
        else:
            if self._timer:
                self._timer.Stop()

            self.labelEMStatus.SetLabel("")

        if shipPrice == None:
            shipPrice = 0
        modPrice = sum(map(lambda p: p.price or 0, prices[1:]))
        if self._cachedShip != shipPrice:
            self.labelPriceShip.SetLabel("%s ISK" % formatAmount(shipPrice, 3, 3, 9, currency=True))
            self.labelPriceShip.SetToolTip(wx.ToolTip(locale.format('%.2f', shipPrice, 1)))
            self._cachedShip = shipPrice
        if self._cachedFittings != modPrice:
            self.labelPriceFittings.SetLabel("%s ISK" % formatAmount(modPrice, 3, 3, 9, currency=True))
            self.labelPriceFittings.SetToolTip(wx.ToolTip(locale.format('%.2f', modPrice, 1)))
            self._cachedFittings = modPrice
        if self._cachedTotal != (shipPrice+modPrice):
            self.labelPriceTotal.SetLabel("%s ISK" % formatAmount(shipPrice + modPrice, 3, 3, 9, currency=True))
            self.labelPriceTotal.SetToolTip(wx.ToolTip(locale.format('%.2f', (shipPrice + modPrice), 1)))
            self._cachedTotal = shipPrice + modPrice
        self.panel.Layout()
Exemple #20
0
    def paint(self):
        """paint the complete status"""
        cbase = self.gox.curr_base
        cquote = self.gox.curr_quote
        self.sort_currency_list_if_changed()
        self.win.bkgd(" ", COLOR_PAIR["status_text"])
        self.win.erase()
        line1 = "Market: %s%s | " % (cbase, cquote)
        line1 += "Account: "
        if len(self.sorted_currency_list):
            for currency in self.sorted_currency_list:
                if currency in self.gox.wallet:
                    line1 += currency + " " \
                    + goxapi.int2str(self.gox.wallet[currency], currency).strip() \
                    + " + "
            line1 = line1.strip(" +")
        else:
            line1 += "No info (yet)"

        str_btc = locale.format('%d', self.gox.orderbook.total_ask, 1)
        str_fiat = locale.format('%d', self.gox.orderbook.total_bid, 1)
        if self.gox.orderbook.total_ask:
            str_ratio = locale.format('%1.2f',
                self.gox.orderbook.total_bid / self.gox.orderbook.total_ask, 1)
        else:
            str_ratio = "-"

        line2 = "sum_bid: %s %s | " % (str_fiat, cquote)
        line2 += "sum_ask: %s %s | " % (str_btc, cbase)
        line2 += "ratio: %s %s/%s | " % (str_ratio, cquote, cbase)
        line2 += "o_lag: %s | " % self.order_lag_txt
        line2 += "s_lag: %.3f s" % (self.gox.socket_lag / 1e6)
        self.addstr(0, 0, line1, COLOR_PAIR["status_text"])
        self.addstr(1, 0, line2, COLOR_PAIR["status_text"])
Exemple #21
0
 def get_freed_space (self) :
   locale.setlocale(locale.LC_ALL, 'en_US')
   n_kb = self.n_bytes / 1000
   if (n_kb > 10000) :
     return locale.format("%.1f", n_kb / 1000, grouping=True) + " MB"
   else :
     return locale.format("%.1f", n_kb, grouping=True) + " KB"
Exemple #22
0
def filter_single(infile, out, minlen, maxlen, limit, minqual, qual64offset, qseq, \
                  stripHeaders, outformat, pi):
    """Filter single reads."""
    #define parser
    fqparser = fqtrimmer(infile, minlen, maxlen, limit, minqual, qual64offset, qseq, stripHeaders, outformat, pi)
    #process output of subprocesses
    both = filtered = 0
    for i, rec in enumerate(fqparser, pi+1):
        #write pair if F & R passed filtering
        if rec:
            out.write(rec)
            both += 1
        #nothing if both didn't pass filtering
        else:
            filtered += 1
        #print stats
        if not i % 10e3:
            info = "%9s processed [%6.2f%s ok]      \r" % (locale.format("%d", \
                i, grouping=True), (i-filtered)*100.0/i, '%')
            logFile.write(info)
            logFile.flush()
    info = "%9s processed [%6.2f%s ok]       \n" % (locale.format("%d", i, \
        grouping=True), (i-filtered)*100.0/i, '%')
    logFile.write(info)
    logFile.flush()

    return i, filtered
Exemple #23
0
def buildranges_withFormat(amin, amax, rangeval):
    """Retunrs a list of tuples, with the string-range first and then
	 the numbers in a tuple: 
	[('990-1020', (990, 1020)), ('1020-1050', (1020, 1050))]  

	This is an enhanced version of the code below. 
	It includes numbers formatting (good for big numbers) and support for int/float too
	"""
    r = []
    allvalues = range(amin, amax, rangeval)
    for index, item in enumerate(allvalues):
        if (index + 1) < len(allvalues):
            if type(rangeval) == type(1.5):  # float: will allow 5 decimal digit (todo: less?)
                a = "%s-%s" % (format_float_nice(item), format_float_nice(allvalues[index + 1]))
            elif type(rangeval) == type(1) or type(rangeval) == type(1L):  # int or Long: will cut decimal values
                a = "%s-%s" % (
                    locale.format("%d", item, grouping=True),
                    locale.format("%d", allvalues[index + 1], grouping=True),
                )
            else:
                djfacetlog("<buildranges_withFormat>: Number Type not recognized [%s]" % str(type(rangeval)))
                a = "%s-%s" % (
                    locale.format("%d", item, grouping=True),
                    locale.format("%d", allvalues[index + 1], grouping=True),
                )

            r.append((a, (item, allvalues[index + 1])))
    return r
Exemple #24
0
def format_value(value, type_desc, str_format=None):
	type_desc = str(type_desc).lower()
	if value is not None:
		if type_desc == 'integer' or type_desc == 'int' or type_desc == 'bigint' or type_desc == 'seconds':
			return locale.format('%d', value, grouping=True)
		elif type_desc == 'float' or type_desc == 'decimal' or type_desc == 'numeric':
			return locale.format('%.4f', Decimal(str(value).replace(',', '')), grouping=True).rstrip('0').rstrip('.')
		elif type_desc == 'percent':
			value = value * 100
			s = str(value)
			return '{}%'.format(locale.format('%g', Decimal(s.rstrip('0').rstrip('.')), grouping=True) if '.' in s else locale.format('%g', Decimal(s), grouping=True))
		elif type_desc == 'money':
			if value < 0:
				result = '-{}'.format(locale.currency(abs(value), grouping=True))
			else:
				result = locale.currency(value, grouping=True)
			return result
		elif type_desc == 'date':
			if 'month' in type_desc:
				return value.strftime('%m/%Y')
			elif 'quarter' in type_desc:
				return datetime_to_quarter(value)
			else:
				return value.strftime('%m/%d/%Y')
		elif type_desc == 'timestamp' or type_desc == 'time' or type_desc == 'interval':
			return value.strftime(str_format)
	return str(value)
Exemple #25
0
def to_human(value, radix=1024.0):
    """Convert a value to a string using SI suffixes.

    Example output:

    >>> to_human(20)
    '20.0 '
    >>> to_human(20 * 1024)
    '20.0k'
    >>> to_human(20 * 1024 ** 2)
    '20.0M'
    >>> to_human(20 * 1024 ** 3)
    '20.0G'
    >>> to_human(20 * 1024 ** 4)
    '20480G'
    """

    i = 0
    while value >= radix and i < 3:
        value /= radix
        i += 1
    suffix = " kMG"[i]
    if value > 100:
        value = locale.format('%d', value)
    elif value < 10:
        value = locale.format('%.2f', value)
    else:
        value = locale.format('%.1f', value)
    return "%s%s" % (value, suffix)
def Number_Format(num, places=0, bCommas=True):
    # Format a number according to locality and given places
    import locale

    try:
        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8') #use locale.format for commafication

    except locale.Error:
        locale.setlocale(locale.LC_ALL, '') #set to default locale (works on windows)

    try:

        import locale


        if bCommas:
            theNumber = locale.format("%.*f", (places, num), True)

        else:
            theNumber = locale.format("%.*f", (places, num), False)

        return theNumber

    except:
        PrintMsg("Unhandled exception in Number_Format function (" + str(num) + ")", 2)
        return False
Exemple #27
0
def main():
	ACTList = getACTList()
	fines = defaultdict(int)
	allFines = 0
	locale.setlocale(locale.LC_ALL, 'en_US')
	
	
	for root, _, files in os.walk("study_fields_xml"):
		for index, file in enumerate(files):
			fullpath = os.path.join(root, file)

			trial = Trial(fullpath)
			trial.populate()
			
			if index == 0:
				print trial.outputHeader()
			
			if trial.isACT():
				print trial.outputLine()
				
				# calculate fines
				fine = trial.fine()
				fines[trial.sponsorClass] += fine
				allFines += fine
		
		print "\n"
		
		# print fines by class
		for key, value in fines.iteritems():
			percent = (float(value) / float(allFines)) * 100
			print percent
			print "%s = %d%% (%s)" % (key, percent, locale.format("%d", value, grouping=True))
		
		print "Total Fines: $" + locale.format("%d", allFines, grouping=True)
		print "\n" # end the file with a newline
Exemple #28
0
def float_to_metric(n, approx=0.01):
    """Returns a formatted string in metric format, using locale-specific formatting"""
    decimals_to_preserve = int(round(math.log(float(1) / approx, 10)))
    if decimals_to_preserve > 0:
        format_string = "%." + str(decimals_to_preserve) + "f"
    else:
        format_string = "%i"
    if n is not None:
        if int(n) != n:
            if (n - int(n) < approx) or ((n - int(n) + approx) > 1):
                rounded = round(n)
                if rounded == 0:
                    return float_to_metric(n, approx * 0.01)
                return locale.format("%i", int(rounded), True)
            else:
                rounded = round(n, decimals_to_preserve)
                if rounded == 0:
                    return float_to_metric(n, approx * 0.01)
                return locale.format(
                    "%." + str(decimals_to_preserve) + "f", rounded, True
                )  # format(formatstring, number, use_thousands_separator)
        else:
            return locale.format("%i", n, True)
    else:
        return ""
Exemple #29
0
    def render_sizes(self, sizes, times):

        line = _('+-----------------------+-----------+')

        yield line
        yield _('| Format    Amount (Mb) | Ratio (%) |')
        yield line
        for mediatype in ["Ogg", "MP3", "MPC", "AAC", "FLAC"]:
            if sizes[mediatype]:
                amount = locale.format(_('%12.2f'),
                    sizes[mediatype] / (1024 * 1024))
                ratio = locale.format(_('%9.2f'),
                    sizes[mediatype] * 100 / sizes["Total"])
                yield _('| %-8s %s | %s |') % (mediatype, amount, ratio)
        yield line
        total_megs = sizes["Total"] / (1024 * 1024)
        total_megs_s = locale.format(_('%10.2f'), total_megs)
        if times['elapsed_time']:
            speed = locale.format(_('%10.2f'),
                total_megs / times['elapsed_time'])
        else:
            speed = locale.format(_('%10.2f'), 0)
        yield _('| Total %s Mb   |') % total_megs_s
        yield _('| Speed %s Mb/s |') % speed
        yield _('+-----------------------+')
Exemple #30
0
    def send_due_invoice_report(self,cr,uid,emailto):
		#find invoices
	invoice_obj=self.pool.get('account.invoice')
	user_obj=self.pool.get('res.users')
	invoices=invoice_obj.search(cr,uid,[('type','=','out_invoice'),('state','=','open'),('date_due','<=',time.strftime('%Y-%m-%d'))])
	invoices=invoice_obj.browse(cr,uid,invoices)
	#send invoice per user
	users=user_obj.search(cr,uid,[])
	users=user_obj.browse(cr,uid,users)
	users_total=""
	subject="Impayes client  au :" + time.strftime('%Y-%m-%d')
	for user in users:
		amount=0
		line=""
		user_body=""
		user_total=""
		for invoice in invoices:
			if invoice.user_id.id==user.id:
				amount+=invoice.amount_to_pay
				line+="<tr><td>"+invoice.date_invoice+"</td><td>"+invoice.number+"</td><td>"+invoice.partner_id.name+"</td>"
				line+=invoice.date_due+"<td>"+locale.format('%.2f', invoice.amount_to_pay, True)+"</td></tr>"
		user_total="<tr><td>"+user.name+"</td><td>"+locale.format('%.2f', amount, True)+"</td></tr>"
		users_total+=user_total
		user_body+=user_total
		user_body+=line
		email=user.user_email or '*****@*****.**'
		if amount>0:
			self.send_email(cr,uid,1,[email],subject,user_body)
	self.send_email(cr,uid,1,emailto,subject,users_total)
Exemple #31
0
def format_number(number):
    import locale
    locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
    return locale.format("%.d", number, True)
# -*- coding: utf-8 -*-

import pandas as pd
import locale

pd.set_option('max_columns', 120)
pd.set_option('max_colwidth', 5000)
pd.set_option('display.float_format', lambda x: locale.format('%.2f', x, grouping=True))

locale.setlocale(locale.LC_ALL, 'pt_br.utf-8')

loans = pd.read_csv('loan_2007_2016Q4_old.csv', low_memory=False)


loans = loans[[
        'loan_status',
        'int_rate',
        'grade',
        'annual_inc',
        'loan_amnt'
]];

loans_defaulted = loans[loans.loan_status == 0];
loans_ok = loans[loans.loan_status == 1]

    fluf_norm = fluf / nanmean(fluf)
    fef = fef / nanmean(fluf)
    #    fef[np.where(np.isnan(fef))]=1.0

    # Interpolate red spectra onto field spectra
    flur = np.interp(waf, war, flur)
    #    fer = np.interp(waf, war, fer)
    # Normalize if comparing to field object
    flur_norm = flur / nanmean(flur)

    # Calculate chi squared
    chi2_lg = chisq(fluf_norm, flur_norm, fef)
    if np.isnan(chi2_lg):
        chi2_lg = 0

    locale.format("%d", chi2_lg, grouping=True)
    chi_lg.append(chi2_lg)

    # Deredden low-g object & calculate chi squared
    Qint = griddata((a, b), Q_grid, (a_mcmc[0], b_mcmc[0]), method='linear')
    Qint = n_mcmc[0] * np.pi * Qint * a_mcmc[0]**2 + c_mcmc[0]
    Qint = np.interp(waf, w, Qint)
    flur_der = flur * np.exp(Qint)
    flur_der_norm = flur_der / nanmean(flur_der)
    chi2_lg_der = chisq(fluf_norm, flur_der_norm, fef)
    dofh = len(waf) - 5
    if np.isnan(chi2_lg_der):
        chi2_lg_der = 0

    chi_lg_der.append(chi2_lg_der)
Exemple #34
0
        total_param_count = 0
        for g, v in grads_and_vars:
            shape = v.get_shape()
            shape_str = ",".join([str(x) for x in v.get_shape()])

            param_count = 1
            for dim in shape:
                param_count *= int(dim)
            total_param_count += param_count

            if g == None:
                print "\t{} ({}) [no grad!]".format(v.name, shape_str)
            else:
                print "\t{} ({})".format(v.name, shape_str)
        print "Total param count: {}".format(
            locale.format("%d", total_param_count, grouping=True)
        )

    session.run(tf.initialize_all_variables())

    gen = inf_train_gen()

    min_iscore = 8.0
    saver = tf.train.Saver(max_to_keep=None)
    for iteration in xrange(ITERS):
        start_time = time.time()
        sys.stdout.flush()

        if iteration > 0:
            _ = session.run([gen_train_op], feed_dict={_iteration:iteration})
def pp(_int):  # For nice number formatting
    locale.setlocale(locale.LC_ALL, '')
    return locale.format('%d', _int, True)
Exemple #36
0
def format_number(number):
    return locale.format('%.2f', number)
Exemple #37
0
					return {"text": "Error requesting post list for %s: %s" % (subpage, e)}
			all_posts.sort(key=lambda x: x.get(sortmetric), reverse=True)
		else:
			return {"text": "Page not found. Try the pages command for a list."}

                    # "value": "%s :thumbsup:, %s :speech_balloon:, %s :arrow_heading_up:" % (
		for x in range(count):
			top = all_posts[x]
			message = {
				"fallback": "Fallback",
				"text": "%s http://www.facebook.com/%s" % (top['message'], top['id']),
				"fields": [
	                {
	                    "title": "Social",
	                    "value": "%s Likes, %s Comments, %s Shares" % (
	                    		locale.format("%d", top['likes'], grouping=True),
	                    		locale.format("%d", top['comments'], grouping=True),
	                    		locale.format("%d", top['shares'], grouping=True)),
	                    "short": True
	                },
	                {
	                    "title": "Performance",
	                    "value": "%%%s of page average (%s)" % (
	                    		locale.format("%d", top['perfper'], grouping=True),
	                    		locale.format("%d", top['average'], grouping=True)),
	                    "short": True
	                }

	            ],
				"thumb_url": "%s" % top['picture']
			}
Exemple #38
0
 def format_valor_unit(self):
     return locale.format(u'%.2f', self.valor_unit, 1)
Exemple #39
0
 def format_desconto(self):
     return '{0}'.format(locale.format(u'%.2f', self.get_valor_desconto(), 1))
Exemple #40
0
 def format_total(self):
     return locale.format(u'%.2f', self.subtotal, 1)
Exemple #41
0
 def format_total_sem_desconto(self):
     total_sem_desconto = self.valor_total - self.desconto
     return locale.format(u'%.2f', total_sem_desconto, 1)
Exemple #42
0
 def format_quantidade(self):
     return locale.format(u'%.2f', self.quantidade, 1)
Exemple #43
0
 def format_seguro(self):
     return locale.format(u'%.2f', self.seguro, 1)
Exemple #44
0
 def format_total_com_imposto(self):
     return locale.format(u'%.2f', self.get_total_com_impostos(), 1)
Exemple #45
0
 def format_vicms(self):
     return locale.format(u'%.2f', self.total_icms, 1)
Exemple #46
0
 def format_despesas(self):
     return locale.format(u'%.2f', self.despesas, 1)
Exemple #47
0
 def format_frete(self):
     return locale.format(u'%.2f', self.frete, 1)
Exemple #48
0
 def format_vipi(self):
     return locale.format(u'%.2f', self.total_ipi, 1)
Exemple #49
0
 def format_total_produtos(self):
     return locale.format(u'%.2f', self.get_total_produtos(), 1)
Exemple #50
0
 def format_impostos(self):
     return locale.format(u'%.2f', self.impostos, 1)
Exemple #51
0
 def format_vprod(self):
     return locale.format(u'%.2f', self.vprod, 1)
Exemple #52
0
 def format_valor_total(self):
     return locale.format(u'%.2f', self.valor_total, 1)
Exemple #53
0
class DictData(OrdDict):
    """
    DictData.__init__(raw) --> DictData object

    Modified OrdDict, with a pre-defined item order. Allows processing of
        raw input data.
    """
    _field_order = None
    _field_type = None
    _trans = [  int,
                locale.atof,
                lambda x: bool(int(x)),
                lambda x: x,
                lambda x: datetime.fromtimestamp(x if x != '4294967295' else '0', datetime.UTCTZ())\
                                  .astimezone(datetime.localTZ()),
                lambda x: date(*[int(y) for y in x.split('-')]),
                lambda x: datetime.fromRfc(x, datetime.UTCTZ())\
                                  .astimezone(datetime.localTZ())]
    _inv_trans = [
        str, lambda x: locale.format("%0.6f", x), lambda x: str(int(x)),
        lambda x: x, lambda x: str(int(x.timestamp())),
        lambda x: x.isoformat(), lambda x: x.utcrfcformat()
    ]

    def __setattr__(self, name, value):
        if name in self._localvars:
            self.__dict__[name] = value
        elif name not in self._field_order:
            object.__setattr__(self, name, value)
        else:
            try:
                self[name] = value
            except KeyError:
                raise AttributeError(str(name))

    def __setitem__(self, key, value):
        if key not in self._field_order:
            raise KeyError(str(key))
        if self._field_type != 'Pass':
            ind = self._field_order.index(key)
            if self._field_type[ind] in (4, 6):
                value = datetime.duck(value)
        dict.__setitem__(self, key, value)

    def __delattr__(self, name):
        if name in self.__dict__:
            del self.__dict__[name]
        else:
            raise AttributeError(str(name))

    def __delitem__(self, name):
        raise NotImplementedError

    def __init__(self, data, _process=True):
        dict.__init__(self)
        if _process:
            data = self._process(data)
        dict.update(self, data)

    def _process(self, data):
        """
        Accepts a list of data, processes according to specified types,
            and returns a dictionary
        """
        if self._field_type != 'Pass':
            if len(data) != len(self._field_type):
                raise MythError('Incorrect raw input length to DictData()')
            data = list(data)
            for i, v in enumerate(data):
                if v == '':
                    data[i] = None
                else:
                    data[i] = self._trans[self._field_type[i]](v)
        return dict(zip(self._field_order, data))

    def _deprocess(self):
        """
        Returns the internal data back out in the format
            of the original raw list.
        """
        data = self.values()
        if self._field_type != 'Pass':
            for i, v in enumerate(data):
                if v is None:
                    data[i] = ''
                else:
                    data[i] = self._inv_trans[self._field_type[i]](v)
        return data

    def _fillNone(self):
        """Fills out dictionary fields with empty data."""
        field_order = self._field_order
        dict.update(self, zip(field_order, [None] * len(field_order)))

    def copy(self):
        """Returns a deep copy of itself."""
        return self.__class__(zip(self.iteritems()), _process=False)

    def __getstate__(self):
        return dict(self)

    def __setstate__(self, state):
        for k, v in state.iteritems():
            self[k] = v
Exemple #54
0
 def format_valor_attr(self, nome_attr):
     valor = getattr(self, nome_attr)
     if valor is not None:
         return locale.format(u'%.2f', valor, 1)
Exemple #55
0
def vanity():
    """Parse args, verify package, retrieve details, return download count."""
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('package', help='pypi package name', nargs='+')
    parser.add_argument('-q',
                        '--quiet',
                        help='only show total downloads',
                        action='store_true')
    parser.add_argument('-j',
                        '--json',
                        help='use pypi json api instead of xmlrpc',
                        action='store_true')
    parser.add_argument('-p',
                        '--pattern',
                        help='only show files matching a regex pattern')
    args = parser.parse_args()
    packages = args.package
    verbose = not (args.quiet)
    version = None
    grand_total = 0
    package_list = []
    json = args.json
    for package in packages:
        if package.find('==') >= 0:
            package, version = package.split('==')
        try:
            package = normalize(package)
        except ValueError:
            logger.debug('No such module or package %r', package)
            continue

        # Count downloads
        total = count_downloads(package,
                                json=json,
                                version=version,
                                verbose=verbose,
                                pattern=args.pattern)
        if total != 0:
            if version:
                logger.debug('%s %s has been downloaded %s times!', 
                             package, version, locale.format("%d",
                                                              total,
                                                              grouping=True))
            else:
                logger.debug('%s has been downloaded %s times!',
                             package, locale.format("%d",
                                                     total,
                                                     grouping=True))
        else:
            if version:
                logger.debug('No downloads for %s %s.', package, version)
            else:
                logger.debug('No downloads for %s.', package)
        grand_total += total
        package_list.append(package)
    if len(package_list) > 1:
        package_string = (
            ', '.join(package_list[:-1]) + " and " + package_list[-1])
        logger.debug("%s have been downloaded %s times!", 
                     package_string, locale.format("%d",
                                                    grand_total,
                                                    grouping=True))

    logger.debug("\n\n\t *** Note: PyPI stats are broken again; we're now"
                 "waiting for warehouse. https://github.com/aclark4life/"
                 "vanity/issues/22 ***\n\n")
    def __init__(self, db, expire_db_secs=3600):
        """
        expire_db_secs: how long before refresh database
        """
        self.db = db
        self.fields = 'iso', 'country_or_district', 'capital', 'area', 'population', 'continent', 'tld', 'currency_code', 'currency_name', 'phone', 'postal_code_format', 'postal_code_regex', 'languages', 'neighbours'
        self.numeric_fields = 'area', 'population'
        db.define_table(
            'places',
            Field('created_on',
                  'datetime',
                  writable=False,
                  readable=False,
                  default=datetime.now),
            Field('country_or_district_id',
                  'integer',
                  writable=False,
                  readable=False),
            Field('flag_img',
                  label='Flag',
                  writable=False,
                  represent=lambda path: IMG(_src=path)),
            Field('area',
                  'double',
                  represent=lambda area: locale.format(
                      "%d", area, grouping=True) + ' square kilometres'),
            Field(
                'population',
                'integer',
                represent=lambda pop: locale.format("%d", pop, grouping=True)),
            #Field('population', 'integer', represent=lambda pop: '{0:,d}'.format(pop)),
            Field('iso', writable=False),
            Field('country_or_district',
                  label='Country (District)',
                  writable=False),
            *[
                Field(field, 'string') for field in self.fields
                if field not in self.numeric_fields
            ]
            #format=lambda record: XML('<a href="%(pretty_url)s">%(country_or_district)s (%(iso)s)</a>' % record)
        )
        # define user friendly url for accessing a place
        db.places.pretty_url = Field.Virtual(
            'pretty_url', lambda record: URL(
                c='default',
                f='view',
                extension=False,
                args=safe(record.places.country_or_district, record.places.
                          country_or_district_id)))
        db.places.pretty_link = Field.Virtual('pretty_link', lambda record: str(\
            DIV(
                A(
                    IMG(_src=record.places.flag_img),
                    #db.places.flag_img.represent(record.flag_img),
                    ' %s' % (record.places.country_or_district),
                    _href=URL(c='default', f='view', extension=False, args=safe(record.places.country_or_district, record.places.country_or_district_id))
                )
            )
        ))
        db.places.continent.represent = lambda continent: A(
            continent, _href=URL(f='continent', args=continent))
        db.places.neighbours.represent = lambda neighbours: DIV([
            A(neighbour + ' ', _href=URL(f='iso', args=neighbour))
            for neighbour in neighbours.split(',')
        ])
        #db.places.pretty_url = Field.Virtual('pretty_url', lambda record: URL(c='default', f='view', extension=False, args=safe(record.places.country_or_district, record.places.country_or_district_id)))

        if db(db.places).count() == 0:
            self.load()
        else:
            created_on = db(db.places).select().first().created_on
            if created_on is None or created_on + timedelta(
                    seconds=expire_db_secs) < datetime.now():
                self.load()
Exemple #57
0
def sc_format_size_local(size, double_precision=False):
    """ Get the locale appropriate representation of the size """
    numeric, code = sc_format_size(size)
    fmt = "%.1f" if not double_precision else "%.2f"
    dlSize = "%s %s" % (locale.format(fmt, numeric, grouping=True), code)
    return dlSize
Exemple #58
0
 def str_numerator(self):
     """Returns the numerator as a formatted string."""
     return locale.format('%d', self.numerator, grouping=True)
Exemple #59
0
def currency_default(value, decimals=True):
    if decimals:
        return locale.currency(value, symbol=True,
                               grouping=True).decode('utf8')
    else:
        return currency_symbol() + locale.format("%d", value, grouping=True)
def formatoPorcentaje(value):
    value = round(value)
    if value - int(value) > 0:
        return locale.format("%.1f", value, grouping=True) + '%'
    else:
        return locale.format("%.0f", value, grouping=True) + '%'