Converting input from non-integer bit rates into something workable

microsoft flow convert integer to string
bit rate formula
bit rate audio
bit rate formula in data communication
how to calculate bit rate
how to calculate data rate from frequency
bitrate for 1080p
bitrate video

I have a program whose input has changed. It originally worked when using integers and the integers had units like: "kbps", "Mbps", "Gbps". An example:

10kbps
20Mbps
20Gbps

I used "if/then" to convert all strings to bps:

if "kbps" in bandwidth:
    bw=bandwidth.replace('kbps', '000')
elif "Mbps" in bandwidth:
    bw=bandwidth.replace('Mbps', '000000')
elif "Gbps" in bandwidth:
    bw=bandwidth.replace('Gbps', '000000000')
else:
    bw='0'

I'd print "bw" as an integer "int(bw)", and it worked fine. Now, the input has changed. Here are samples of actual inputs:

3.838Mbps
100kbps
126.533kbps
5.23Mbps
100Mbps
1.7065Gbps
20Gbps

The numbers are not integers. Not only can I not print because it is not an integer, the unit conversion doesn't work with decimals. For example, 3.838Mbps becomes 3.838000000.

Can someone suggest an efficient way to work with these inputs? I can't find the right balance of splitting, regexp matching, etc. and am wondering if there are some methods I don't know about.

You can cast value before kbps, Mbps or Gbps to float and multiply it by 1000, 1000,000 and so on. That will work for either case.

For Example:

if "kbps" in bandwidth:
    bw = bandwidth.replace('kbps', '')
    bw = str(float(bw) * 1000)
elif "Mbps" in bandwidth:
    bw = bandwidth.replace('Mbps', '')
    bw = str(float(bw) * 1000* 1000)
elif "Gbps" in bandwidth:
    bw = bandwidth.replace('Gbps', '')
    bw = str(float(bw) * 1000 * 1000 * 1000)
else:
    bw='0'

Solved: Convert text to number, Yes, there is a way to convert it into Number in Microsoft Flow. Add another Compose Action, under the Input, copy and paste the With the two (2) compose functions, I attemped to convert my 'Total Cost' value from a string to an integer I already try String(item()[0]) in Select action, but not workable. SPOJ The Next Palindrome. What is taking a long time is converting strings of such length to Converting input from non-integer bit rates into something workable.

I think it might be better to use regular expressions here, and capture the "number part", and the "unit prefix part":

import re

bandwidth_rgx = re.compile(r'^(\d*(?:\.\d*)?)\s*([GMk]?)(?:bps)?$')

so now we can match a given string, and obtain the number part, and the unit prefix part:

>>> bandwidth_rgx.search('126.533kbps')[1]
'126.533'
>>> bandwidth_rgx.search('126.533kbps')[2]
'k'

so we can make a conversion dictionary, like:

unit_prefix = {
    '': 1,
    'k': 1000,
    'M': 1000000,
    'G': 1000000000
}

and use a function to obtain the bandwidth, for example as a float:

def get_bandwidth(text):
    m = bandwidth_rgx.search(text)
    return float(m[1]) * unit_prefix[m[2]]

for example:

>>> get_bandwidth('3.838Mbps')
3838000.0
>>> get_bandwidth('100kbps')
100000.0
>>> get_bandwidth('126.533kbps')
126533.0
>>> get_bandwidth('5.23Mbps')
5230000.0
>>> get_bandwidth('100Mbps')
100000000.0
>>> get_bandwidth('1.7065Gbps')
1706500000.0
>>> get_bandwidth('20Gbps')
20000000000.0

Bit rate, In telecommunications and computing, bit rate is the number of bits that are conveyed or The non-standard abbreviation "bps" is often used to replace the standard The gross bit rate is related to the symbol rate or modulation rate, which is of the input data, the listener's perceptions, the listener's familiarity with artifacts,  Previous Is returning the intermediate value in a recursive function a quirk of python? Next Converting input from non-integer bit rates into something workable

I'd do something like:

import re

UNITS = {
    'k': 1e3,
    'm': 1e6,
    'g': 1e9,
    't': 1e12,
}

def parse_bps(s):
    m = re.match(r'^([0-9]+(\.[0-9]*)?)([tgmk])?bps$', s, re.IGNORECASE)
    if not m:
        raise ValueError(f"unsupported value for parse_bps: {repr(s)}")
    val = float(m.group(1))
    unit = m.group(3)
    if unit:
        val *= UNITS[unit.lower()]
    return val


tests = [
    '10bps', '10kbps', '20Mbps', '20Gbps', '3.838Mbps',
    '3.838Mbps', '100kbps', '126.533kbps', '5.23Mbps',
    '100Mbps', '1.7065Gbps', '20Gbps',
]

for s in tests:
    print(f'  {repr(s)} = {parse_bps(s)}')

though it's probably better not to ignore case. SI units officially make big differences based on case, generally speaking capitals meaning multiply and lower case meaning divide.

Planning for Creative Change in Mental Health Services: A , Most research is done in parts and not related to the other parts of the problem. be constructed with feedback systems incorporated as integral parts of the model conditions enables one to telescope the past and to provide data essential in conversion process outlined in the article may be input for the construction of  Converting input from non-integer bit rates into something workable; Difference in Function typing in Haskell; Do rvalue references have the same overhead as lvalue references? Why do I need const copy constructor when compiling my code with converting constructor? Regexp to match every occurence after n occurences

Answer that requires bare minimum code changes and assumes your input is safe:

if "kbps" in bandwidth:
    bw=bandwidth.replace('kbps', '* 1e3')
elif "Mbps" in bandwidth:
    bw=bandwidth.replace('Mbps', '* 1e6')
elif "Gbps" in bandwidth:
    bw=bandwidth.replace('Gbps', '* 1e9')
else:
    bw='0'
bw_int = eval(bandwidth)

Of course, make sure your input is safe, and there are some security and performance considerations for eval (Why is using 'eval' a bad practice?), but sometimes, you just want to get something out quickly :)

High precision calculator - Keisan Online Calculator, Comment/Request Can you raise the limit on the output to something larger than E+100million? Purpose of use calculating/converting heat of fusion from tabulated data 98th Ed. Handbook Honestly it was not for anything important I just wanted to know if an online Purpose of use To calculate the 23179945 bit integer. If you have a team, you should get them involved in brainstorming too. Come up with 30 or so ideas that could increase your conversion rate and categorize them into ideas that are already working for you, ideas that will likely work, or ideas that are possible, but not probable. Keep reading for ideas about what to optimize, below.

Convert 8 bit png to 32 bit online, The only way I found was to save the 24-bit bitmap as a 32-bit PNG file using my graphics ICNS image, the original dimensions may not be retained after conversion. This free online image converter can convert images from over 120 input 32 Bit to 8 Bit Conversion. Int, uint. 1, 7 [64/32 bit] Download Convert PPT for  Obviously I would think that you want to get the figures you have into something that the computer can use, add them up etc. Expressing the results back as LSD might be a bit more tricky. I think that the easiest though perhaps not the prettiest way is to segregate the pounds from the shillings and the pennies.

What exactly does 'parsing' mean in programming?, I'll try to keep this answer as non-technical as possible so everyone can benefit Parsing means to make something understandable (by analysing its parts). For programming this means to convert information repre. split a file or other input into pieces of data that can be easily stored or manipulated. Parsing an integer. If the adapter says Input: 100 – 240 V (standard USA AC input voltage) and 50/60 Hz, then its the standard cycle rate of the power. But also many adapters say a maximum AMPS input.

How to Use Word Embedding Layers for Deep Learning with Keras, It requires that the input data be integer encoded, so that each word is layer is a 2D vector with one embedding for each word in the input sequence of words that it learned the training dataset perfectly (which is not surprising). is done on keras word2vec/globe or simply dense layer(or something else) ffmpeg -i input.mkv -codec copy output.mp4 It auto-detects a Matroska to MP4 container conversion based on input/output filenames.-codec copy stream copies, or "re-muxes", the streams from the input to the output without re-encoding. Think of it like a copy and paste.

Comments
  • Not a full answer: I think I'd split dots and digits from letters using regexp, look up multiplier in a table, convert digits to a float (or Decimal, if humans are going to look at it and will find the float precision offputing), and multiply.
  • What if you split your expression between the float part and the string part (regexp), and then multiply the float part by a power of 10 based on the value of the string part?