How to validate user input of currency - reactjs

So I currently developing a website that support many languages. I have an input box where user can input the amount of currency inside. I need a function to validate if that input is legit or not.
however, because different countries use different format of number.
for example: England use '.' for decimal and ',' for thousand separator .
Where as Germany use ',' for decimal and '.' for thousand separator.
French use ',' for decimal and (space) for thousand separator...
And for Chinese/Jap , they even dont use number "1-9" to describe number
I can make a very big if-else function to do the validate base on the language they are using. something like this
number = userinput()
if "de":
return deValidator(number)
if "fr":
return frValidator(number)
if "en":
return enValidator(number)
if "zh":
return zhValidator(number)
However, is there any wiser way to do it?? what I am looking for is something like a already-built validator/library or an easier approach to solve this problem without having to writing different validator for different language

You can leverage on toLocaleString() method to help to build a validator; The toLocaleString() method returns a string with a language sensitive representation of the number.
const number = 123456.789;
// German uses comma as decimal separator and period for thousands
console.log(number.toLocaleString('de-DE'));
// → 123.456,789
// Arabic in most Arabic speaking countries uses Eastern Arabic digits
console.log(number.toLocaleString('ar-EG'));
// → ١٢٣٤٥٦٫٧٨٩
// India uses thousands/lakh/crore separators
console.log(number.toLocaleString('en-IN'));
// → 1,23,456.789
// the nu extension key requests a numbering system, e.g. Chinese decimal
console.log(number.toLocaleString('zh-Hans-CN-u-nu-hanidec'));
// → 一二三,四五六.七八九
// when requesting a language that may not be supported, such as
// Balinese, include a fallback language, in this case Indonesian
console.log(number.toLocaleString(['ban', 'id']));
// → 123.456,789
With this method, you can also format numbers with currency information:
const number = 10000000;
number.toLocaleString('it-IT', {style: 'currency', currency: 'EUR'})
// → 10.000.000,00 €
number.toLocaleString('it-IT', {style: 'currency', currency: 'USD'})
// → 10.000.000,00 US$
number.toLocaleString('en-US', {style: 'currency', currency: 'EUR'})
// → €10,000,000.00
number.toLocaleString('en-US', {style: 'currency', currency: 'USD'})
// → $10,000,000.00
For more details: toLocaleString https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

Related

How is this array of floats encoded?

I am trying to decode an array of data from a piece of legacy equipment in to a more useful format.
I have the following base64 encoded string:
iWGLvg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R/CLzWd4A+
kHVrvCtGgz5v5tq8
When adding trailing padding and decoding this from base64, it produces an unknown binary format.
What I know so far based on limited inspection of the application:
It is definitely base64.
This array describes a series of floating point data (with values between 19 and 50) that consists of 201 points.
The application that created this was likely written in .NET.
How is this data encoded, and can you provide psuedo-code to decode it?
Update #1:
This data describes a return loss measurement waveform from an old network analyser.
The expected values above are based on what the instrument displays, and it is possible that they are calculated from real and imaginary components.
Update #2:
I've found there was also a CSV version of the data for this series. Expected values are:
28.6740250379346, 26.031723427971, 26.6849726930916, 27.5095233036572, 27.9755283611409, 28.0419902829292, 27.9918713318024, 28.0331481409078, 28.2620361924923, 29.1899991143532, 30.4746778667205, 31.9841888600965, 32.7562027026775, 32.2032446202011, 31.0251062040461, 30.1158617686259, 29.5968352710132, 29.8991302542384, 30.7711739051407, 32.5985879649759, 35.465787543584, 38.4033014264434, 36.2400347268325, 33.230539516557, 30.816214031517, 29.493776099706, 28.9641221620517, 29.3271399473768, 30.5497479471498, 32.9092924040263, 36.23602780908, 36.6766990656565, 32.9072309537322, 29.8008349575816, 27.8506153462939, 26.8255601987161, 26.7773337706284, 27.6450826739213, 29.6698279365727, 32.925219461411, 34.9915552473819, 31.6841927998324, 28.219566759529, 25.990640197895, 24.8525028738483, 24.6159871249645, 25.2752655673475, 26.9870507463537, 29.9877735491643, 33.2675296198038, 31.6015986278861, 27.8240493530138, 25.2742229688217, 23.9448603205908, 23.5140204346426, 23.9914986842046, 25.5009034820686, 28.1555920133881, 31.3075467263927, 30.7066273219751, 27.2707536503799, 24.7348022011574, 23.2637028240862, 22.7794008043094, 23.1669728824416, 24.5474786226331, 26.9949958437379, 30.2488348819328, 30.6013906923573, 27.3394012893084, 24.6326441335966, 23.0411076555662, 22.4181795795548, 22.7062561945124, 23.8692711954611, 26.163804153602, 29.606819207681, 31.2543679681834, 28.1493119289191, 25.0924674969376, 23.2520785937701, 22.4092737645517, 22.5015858777069, 23.4763598655373, 25.5208843109912, 28.9618678298617, 32.6403317308031, 30.3536019856501, 26.5991532707429, 24.2773569962831, 23.1127901052235, 22.9043583677862, 23.6093457155953, 25.3499073692444, 28.4637157202952, 32.8016120624956, 32.4896370664701, 28.3239184297021, 25.5279166849078, 24.0185490655501, 23.5330605365427, 23.8948677486768, 25.2054578354006, 27.7143031565687, 31.5869657438201, 33.7333955992785, 30.3948949895062, 27.1037601765126, 25.2161101159979, 24.3558529725873, 24.3231491126384, 25.2139427454679, 27.1233066134797, 30.3453761997478, 34.4047437237606, 33.8064220094595, 29.9215033359328, 27.3307978071688, 25.8801149514006, 25.4718657467003, 25.8501031953971, 27.1888665858689, 29.5756748124031, 32.9812339884177, 35.3068159226901, 32.6414213429246, 29.5799546795568, 27.7291120251878, 26.9050286745762, 26.9075167887431, 27.7591889971496, 29.3670540494547, 31.7578198149182, 33.5065256564295, 32.6776622084245, 30.4203840091006, 28.688025867147, 27.7417192975661, 27.4916484304414, 27.9791419175041, 29.2902681126682, 31.4107407957172, 33.4602036884894, 33.9200015192937, 32.1201008630103, 30.1453133278815, 28.7841082718969, 28.136959973426, 28.109171467367, 28.8259362791248, 30.0289196496445, 31.326134345957, 32.0708833202456, 31.4950426416152, 30.1423739250155, 29.0036769811377, 28.2190253962644, 28.1086422581195, 28.4750473325836, 29.1942813484775, 29.7608412256926, 29.6876433997282, 28.689538924267, 27.2407586615062, 26.0067421520125, 25.1638342823008, 24.8250524294419, 24.9395261449731, 25.4584143514754, 25.8777584307235, 25.6465050536004, 24.5707670056442, 23.0511544464452, 21.7615681906835, 20.9761497089273, 20.7854547053249, 21.2816973223554, 22.253260423558, 23.2052378948627, 23.4706372938485, 23.2944515491774, 23.1680235174658, 23.5290621578115, 24.4333231530622, 25.8639616096787, 27.9401749621508, 30.7364242326027, 33.9420488375473, 35.6377896682262, 33.4869702934454, 30.5820901568128, 28.3404467791117, 26.8270077060156, 26.0018669972732, 25.9446717292131, 26.5828002183748, 28.0360464264943, 30.0958735279379, 31.2921110009257, 29.5253906387702, 26.6971475290807
To advance the c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v5tq8
Converts to hex dump
89618bbe 052317bd ffb56d3e 100643bd ff9c623e a93f0fbd 60b1633e a6029dbc e0be6e3e 044615bc 1bce7c3e 10b418bc cdd4823e 523b96bc e0ab823e 1d86f5bc cba97d3e 6c6f19bd 898c723e 1dc918bd c8206b3e a278fabc 19e1693e b241adbc 52b36e3e 2d355ebc 76da763e 3d932fbc c8b67e3e 64265bbc fe5f813e b755a3bc 13eb803e 0638dfbc bd527c3e 78e502bd 8b5f753e 265704bd 13b36f3e b3f7e7bc a9e86d3e 306fb2bc ccea703e 51f283bc 4631763e 2ac550bc 79d77c3e c4745ebc cfef803e a54796bc 6b4f813e 901bcebc 3db57e3e 7061ffbc 22d2773e 866b08bd 6105713e fd52fcbc 5e4c6d3e 6125c9bc 4d736e3e 2d458dbc 8f44743e 6ac545bc 30937c3e a6b53fbc 1ab2813e 082189bc 4bc8823e cf5dcdbc a7da803e e08408bd d349793e db5318bd f9e86f3e f1230fbd 0c486a3e 5eb1dfbc 27f36a3e e82391bc e3fc713e a6bd2cbc 63a67c3e 4ae818bc a4fa823e 73987bbc 88a5843e b62bd8bc c23b823e f12818bd 8a92793e ee282ebd 4cb96d3e 637f23bd d860663e 5c70fabc 85da663e 9f1498bc d4246f3e 20e720bc 2cd87b3e 72630abc 2c52833e 998080bc 70fc843e a6cbeabc 23da813e 96d126bd aae8763e e3973cbd 276d693e 09492cbd d4c6613e fb49fabc 8c87633e 47b28bbc 20df6d3e 3728fcbb 28487c3e 3cb4eabb daf1833e b88885bc e837853e 5507fdbc c44d813e 547b33bd 5807743e d52f47bd e9bd653e ae4c31bd 40615e3e eb26f8bc 8319613e a5cf82bc 54b86c3e 1b86d8bb ab087c3e 9a2fe0bb e2da833e 45578cbc d5c5843e 2c7505bd 5542803e b59e3abd bb3e713e c5d34bbd 0eda623e 30f331bd d0d55b3e 4072f6bc 8e245f3e 8b377dbc 87466b3e abadd1bb 2ea77a3e f984e9bb 57f8823e 2d328fbc 5ec1833e 06ab06bd 7b7f7e3e f04b3abd 746d6f3e ddf94abd 966a613e 6bc331bd 677d5a3e bca9f8bc 5a675d3e b30f85bc 67b6683e a464efbb b022773e 85b9f9bb 82fa803e c60c8bbc 3fea813e b542febc bedb7b3e 9c382fbd d8186e3e 137f3fbd ef02613e af7029bd 4c6f5a3e 0fabf1bc a7d55c3e 806585bc eb06673e 707100bc 777a743e 3b88f7bb beb37e3e 05ec80bc b88a803e dedae8bc d53d7a3e 201922bd 00e56d3e cc6c33bd 46af613e f46d21bd f2e85a3e e809ecbc 58495c3e fa5e88bc 2332653e c54e00bc d69c713e 81ead5bb 73057c3e ded255bc 0a8e7f3e 4beac8bc 84bd7a3e 55c811bd 0e19703e d68927bd 5f66643e 0ebc1dbd 72b85c3e 4e69f4bc 213c5c3e bfd797bc c0d3623e b7d81bbc b1996d3e ea9ad1bb 22e7773e a51d2bbc 71f37c3e 9ddda1bc c8c97a3e 7ab3f5bc 8a78723e 1ea114bd 8419683e 993614bd 4b30603e ba3ff2bc 4f025e3e 299da3bc 7169623e 6c1935bc f46b6b3e 93e8d7bb 532c753e 16d908bc d5747b3e f68281bc 07857b3e 843dcebc d9a6753e 79f503bd 97826c3e 0f360bbd 9b6f643e 74f4f3bc 4bb6603e 9e3bb0bc e40f633e 892351bc 44536a3e d6f1e8bb 0ec8733e e2b7e6bb 1a6c7b3e a3c04dbc 13ca7d3e e497afbc 0d377a3e f4a9f3bc bd49723e 71260bbd d381693e cf3905bd 7e85633e fc4ed8bc 5b90623e af3d92bc e533673e 184f2ebc 595a6f3e 4148febb b0b3773e 872324bc 1eb27c3e e7a489bc 8b647c3e 6ae1cebc 77e2763e 1d4401bd c8956e3e a61208bd f408673e 349ff2bc 1927633e ee08b7bc 64c4643e e01165bc ff356b3e 427e04bc ddec733e e437e4bb 40e07b3e 165039bc 36977f3e 05e59ebc 9ba67d3e 8d41e6bc 9a95763e 004a0abd bb6c6d3e 10130cbd e6ec653e 6f65ebbc e258633e 547ba3bc e2d6663e 363035bc 72a16f3e b5b9b4bb ecaa7a3e 1393d4bb 1da5813e 27cc68bc f0cb823e 9dbdd4bc 2eab7f3e 154c18bd d783733e 1ff22ebd a5f3653e 98f221bd 16f05c3e 5099e8bc a6255d3e 6a955cbc 4881673e ff146dba f71b793e 2b61313b f448853e f880dbbb 2000893e 769fdbbc 9644843e fa1445bd 8502713e 09926bbd 7489583e bb3243bd 9f6d4e3e 6052bbbc 7ae2593e 577de73a f83e743e b4aa293c 86c6853e 0ffb0bbb 15b4883e 331bcfbc 9d37833e 57ac30bd fc51753e b6a844bd 63d4673e 6bd62dbd 9a93613e b06804bd 6634623e f3a8b6bc 7a7f673e 3ff17abc 85e86e3e 447247bc a95b763e f16356bc d37d7c3e 97298fbc 91817f3e 3f2ec8bc bb3b7e3e 226904bd c471783e 9c561ebd dbb56f3e 0f7c27bd 2abe663e 8d2e19bd 8d5d613e 869fefbc f010623e f4c59abc c47a693e 25902cbc 1773753e c47f08bc d677803e 90756bbc 2b46833e 6fe6dabc
402 32-bits.
Or more nicely formatted and re-endian-ized.
Looks like values are encoded as IEEE 32-bit float scaled up by about 122 or some magic number - depending on which values first expected value is 28.62 and the last is 31.32 map to.
0 BE8B6189 BD172305 -0.272229 -0.036899*
1 3E6DB5FF BD430610 0.232140* -0.047613
2 3E629CFF BD0F3FA9 0.221302 -0.034973
3 3E63B160 BC9D02A6 0.222356 -0.019166
4 3E6EBEE0 BC154604 0.233150 -0.009111
5 3E7CCE1B BC18B410 0.246880 -0.009320
6 3E82D4CD BC963B52 0.255530 -0.018339
7 3E82ABE0 BCF5861D 0.255218 -0.029971
8 3E7DA9CB BD196F6C 0.247718 -0.037460
9 3E728C89 BD18C91D 0.236864 -0.037301
10 3E6B20C8 BCFA78A2 0.229617 -0.030575
...
195 3E615D8D BCEF9F86 0.220083 -0.029251
196 3E6210F0 BC9AC5F4 0.220768 -0.018893
197 3E697AC4 BC2C9025 0.228007 -0.010532
198 3E757317 BC087FC4 0.239697 -0.008331
199 3E8077D6 BC6B7590 0.250914 -0.014371*
200 3E83462B BCDAE66F 0.256395* -0.026721
... it is possible that they are calculated from real and imaginary components.
Note, with ignoring the first data value:
last complex pair magnitude / first complex pair magnitude
|-0.014371 + 0.256395 * i| / | -0.036899 + 0.232140 * i| is 1.093...
Much like 31.32/28.62 is 1.094...

How to implement input text masking in React-Native?

The mask is needed: 90.99%, where:
9 - optional digit
0 - required
%,. - relevant characters '%' and '.'
For example:
Input / Result
1 ---> 1%
12 ---> 12%
12.1 ---> 12.1%
12.12 ---> 12.12%
I'm using redux-form
I've tried react-native-text-input-mask and react-native-masked-text already, however, there is no similar functionality in these packages (in the first one there is something similar, but '%' is correctly displayed only if it is used before the number but this char should be after)
The best way here is to provide masking next to the input itself.
It highly depends on how do you use the Field component (do you even use it?).
You can try to use the format prop on the Field.
Or you can provide your own component to render a field and provide own format functionality:
const renderPercentagedInput = (field) => {
function onChange(evt) {
const value = evt.target.value;
const numbers = value.replace(/[^0-9.,]/g, '')
field.input.onChange(numbers + '%')
}
return (
<TextInput
{...field.input}
onChangeText={onChange}
/>
);
}

How to get a list of Coinbase CryptoCurrency Coins

I've been trying to figure out a way to get a list of all the Coins that Coinbase has listed (not necessarily for trade) but can't figure it out, in the early days it was easy as you could just login and see the list of 4 basic coins that were supported (and could hard code those values in a program and/or script).
But now they have a list of many coins listed, some as I understand, which are not available to actually trade but are listed for educational purposes (as stated on their site when looking at such coins).
I was wondering if anyone has figured out a way to get a list those coins (all supported and simply listed) perhaps with a tag of which are actually supported for trade.
I looked at the API and the REST API (using a simple GET request over HTTPS or using cURL for testing) has the following endpoints:
curl https://api.coinbase.com/v2/currencies - This lists all the Fiat currencies.
and:
curl https://api.pro.coinbase.com/products - This lists all the supported trading pairs (which is not what I'm looking for....)
Any ideas, short of logging in and parsing the html? (which could break since the site can be reformatted etc at any time).
Any help would be greatly appreciated!
perhaps not really what you asked, but you could also use https://api.pro.coinbase.com/currencies
import requests
import json
uri = 'https://api.pro.coinbase.com/currencies'
response = requests.get(uri).json()
for i in range(len(response)):
if response[i]['details']['type'] == 'crypto':
print(response[i]['id])
This will return the coins available for trading.
I'm not sure if I this is the response that you want or not. I first used the first URL that you have listed... The response from that looked like it didn't have the available coins. I then tried the below URL instead and the response does have a lot of curriencies listed on it. You can parse it by loading with JSON and looking for the fields that you want.
Also I didn't see a language posted with your question. I'm using python3 below. If you're a Linux person you can also just use curl GET from the command line. It doesn't matter the language... you just need to make a GET request to that URL and parse the response however you see fit.
To get 1 particular field you can use a line like response['data']['rates']['BTC'] to extract '0.00029200' out of the response/JSON string.
>>> r = requests.get("https://api.coinbase.com/v2/exchange-rates")
>>> response = json.loads(r.text)
>>> pprint.pprint(response)
{'data': {'currency': 'USD',
'rates': {'AED': '3.67',
'AFN': '75.22',
'ALL': '108.84',
'AMD': '487.59',
'ANG': '1.79',
'AOA': '311.37',
'ARS': '37.32',
'AUD': '1.38',
'AWG': '1.80',
'AZN': '1.70',
'BAM': '1.71',
'BAT': '9.00418244',
'BBD': '2.00',
'BCH': '0.00879160',
'BDT': '83.80',
'BGN': '1.71',
'BHD': '0.377',
'BIF': '1824',
'BMD': '1.00',
'BND': '1.58',
'BOB': '6.90',
'BRL': '3.65',
'BSD': '1.00',
'BTC': '0.00029200',
'BTN': '71.11',
'BWP': '10.41',
'BYN': '2.15',
'BYR': '21495',
'BZD': '2.02',
'CAD': '1.31',
'CDF': '1631.00',
'CHF': '0.99',
'CLF': '0.0242',
'CLP': '656',
'CNH': '6.71',
'CNY': '6.70',
'COP': '3174.95',
'CRC': '608.98',
'CUC': '1.00',
'CVE': '96.90',
'CZK': '22.50',
'DJF': '178',
'DKK': '6.52',
'DOP': '50.44',
'DZD': '118.30',
'EEK': '14.61',
'EGP': '17.68',
'ERN': '15.00',
'ETB': '28.52',
'ETC': '0.25542784',
'ETH': '0.00944599',
'EUR': '0.87',
'FJD': '2.10',
'FKP': '0.76',
'GBP': '0.76',
'GEL': '2.66',
'GGP': '0.76',
'GHS': '4.98',
'GIP': '0.76',
'GMD': '49.52',
'GNF': '9210',
'GTQ': '7.74',
'GYD': '208.55',
'HKD': '7.85',
'HNL': '24.49',
'HRK': '6.49',
'HTG': '78.37',
'HUF': '276',
'IDR': '13940.00',
'ILS': '3.63',
'IMP': '0.76',
'INR': '70.93',
'IQD': '1190.000',
'ISK': '120',
'JEP': '0.76',
'JMD': '132.72',
'JOD': '0.710',
'JPY': '109',
'KES': '100.60',
'KGS': '68.70',
'KHR': '4015.00',
'KMF': '429',
'KRW': '1114',
'KWD': '0.303',
'KYD': '0.83',
'KZT': '380.63',
'LAK': '8559.50',
'LBP': '1511.15',
'LKR': '178.40',
'LRD': '160.75',
'LSL': '13.53',
'LTC': '0.03208728',
'LTL': '3.22',
'LVL': '0.66',
'LYD': '1.385',
'MAD': '9.53',
'MDL': '17.05',
'MGA': '3465.0',
'MKD': '53.78',
'MMK': '1519.04',
'MNT': '2453.75',
'MOP': '8.08',
'MRO': '357.0',
'MTL': '0.68',
'MUR': '34.23',
'MVR': '15.49',
'MWK': '728.47',
'MXN': '19.14',
'MYR': '4.10',
'MZN': '61.87',
'NAD': '13.53',
'NGN': '361.50',
'NIO': '32.60',
'NOK': '8.43',
'NPR': '113.78',
'NZD': '1.45',
'OMR': '0.385',
'PAB': '1.00',
'PEN': '3.33',
'PGK': '3.36',
'PHP': '52.13',
'PKR': '139.30',
'PLN': '3.73',
'PYG': '6084',
'QAR': '3.64',
'RON': '4.14',
'RSD': '103.53',
'RUB': '65.47',
'RWF': '886',
'SAR': '3.75',
'SBD': '8.06',
'SCR': '13.67',
'SEK': '9.05',
'SGD': '1.35',
'SHP': '0.76',
'SLL': '8390.00',
'SOS': '582.00',
'SRD': '7.46',
'SSP': '130.26',
'STD': '21050.60',
'SVC': '8.75',
'SZL': '13.52',
'THB': '31.23',
'TJS': '9.43',
'TMT': '3.50',
'TND': '2.968',
'TOP': '2.26',
'TRY': '5.18',
'TTD': '6.77',
'TWD': '30.72',
'TZS': '2317.00',
'UAH': '27.70',
'UGX': '3670',
'USD': '1.00',
'USDC': '1.000000',
'UYU': '32.58',
'UZS': '8380.00',
'VEF': '248487.64',
'VND': '23287',
'VUV': '111',
'WST': '2.60',
'XAF': '573',
'XAG': '0',
'XAU': '0',
'XCD': '2.70',
'XDR': '1',
'XOF': '573',
'XPD': '0',
'XPF': '104',
'XPT': '0',
'YER': '250.30',
'ZAR': '13.27',
'ZEC': '0.02056344',
'ZMK': '5253.08',
'ZMW': '11.94',
'ZRX': '4.04721481',
'ZWL': '322.36'}}}
The following code:
import requests
uri = 'https://api.pro.coinbase.com/currencies'
response = requests.get(uri).json()
for i in range(len(response)):
if response[i]['details']['type'] == 'crypto':
print(response[i]['id'])
Will provide this output:
COTI
BTC
ETH
LTC
BCH
ZEC
XTZ
XRP
XLM
EOS
ALGO
DASH
ATOM
CGLD
FIL
ADA
ICP
SOL
DOT
DOGE
OXT
KNC
MIR
REP
COMP
NMR
ACH
BAND
ZRX
BAT
LOOM
UNI
YFI
LRC
CVC
DNT
MANA
GNT
REN
LINK
BAL
ETC
USDC
RLC
DAI
WBTC
NU
AAVE
SNX
BNT
GRT
SUSHI
MLN
ANKR
CRV
STORJ
SKL
AMP
1INCH
ENJ
NKN
OGN
FORTH
GTC
TRB
CTSI
MKR
UMA
USDT
CHZ
SHIB
BOND
LPT
QNT
KEEP
CLV
MASK
MATIC
OMG
POLY
FARM
FET
PAX
RLY
PLA
RAI
IOTX
ORN
AXS
QUICK
TRIBE
UST
REQ
TRU
WLUNA
you can use
curl -X GET https://api.exchange.coinbase.com/products
refer to
https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducts

using lookup tables to plot a ggplot and table

I'm creating a shiny app and i'm letting the user choose what data that should be displayed in a plot and a table. This choice is done through 3 different input variables that contain 14, 4 and two choices respectivly.
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput(inputId = "DataSource", label = "Data source", choices =
c("Restoration plots", "all semi natural grasslands")),
selectInput(inputId = "Variabel", label = "Variable", choices =
choicesVariables)),
#choicesVariables definition is omitted here, because it's very long but it
#contains 14 string values
selectInput(inputId = "Factor", label = "Factor", choices = c("Company
type", "Region and type of application", "Approved or not approved
applications", "Age group" ))
),
dashboardBody(
plotOutput("thePlot"),
tableOutput("theTable")
))
This adds up to 73 choices (yes, i know the math doesn't add up there, but some choices are invalid). I would like to do this using a lookup table so a created one with every valid combination of choices like this:
rad1<-c(rep("Company type",20), rep("Region and type of application",20),
rep("Approved or not approved applications", 13), rep("Age group", 20))
rad2<-choicesVariable[c(1:14,1,4,5,9,10,11, 1:14,1,4,5,9,10,11, 1:7,9:14,
1:14,1,4,5,9,10,11)]
rad3<-c(rep("Restoration plots",14),rep("all semi natural grasslands",6),
rep("Restoration plots",14), rep("all semi natural grasslands",6),
rep("Restoration plots",27), rep("all semi natural grasslands",6))
rad4<-1:73
letaLista<-data.frame(rad1,rad2,rad3, rad4)
colnames(letaLista) <- c("Factor", "Variabel", "rest_alla", "id")
Now its easy to use subset to only get the choice that the user made. But how do i use this information to plot the plot and table without using a 73 line long ifelse statment?
I tried to create some sort of multidimensional array that could hold all the tables (and one for the plots) but i couldn't make it work. My experience with these kind of arrays is limited and this might be a simple issue, but any hints would be helpful!
My dataset that is the foundation for the plots and table consists of dataframe with 23 variables, factors and numerical. The plots and tabels are then created using the following code for all 73 combinations
s_A1 <- summarySE(Samlad_info, measurevar="Dist_brukcentrum",
groupvars="Companytype")
s_A1 <- s_A1[2:6,]
p_A1=ggplot(s_A1, aes(x=Companytype,
y=Dist_brukcentrum))+geom_bar(position=position_dodge(), stat="identity") +
geom_errorbar(aes(ymin=Dist_brukcentrum-se,
ymax=Dist_brukcentrum+se),width=.2,position=position_dodge(.9))+
scale_y_continuous(name = "") + scale_x_discrete(name = "")
where summarySE is the following function, burrowed from cookbook for R
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=TRUE,
conf.interval=.95, .drop=TRUE) {
# New version of length which can handle NA's: if na.rm==T, don't count them
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
# This does the summary. For each group's data frame, return a vector with
# N, mean, and sd
datac <- ddply(data, groupvars, .drop=.drop,
.fun = function(xx, col) {
c(N = length2(xx[[col]], na.rm=na.rm),
mean = mean (xx[[col]], na.rm=na.rm),
sd = sd (xx[[col]], na.rm=na.rm)
)
},
measurevar
)
# Rename the "mean" column
datac <- rename(datac, c("mean" = measurevar))
datac$se <- datac$sd / sqrt(datac$N) # Calculate standard error of the mean
# Confidence interval multiplier for standard error
# Calculate t-statistic for confidence interval:
# e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
ciMult <- qt(conf.interval/2 + .5, datac$N-1)
datac$ci <- datac$se * ciMult
return(datac)
}
The code in it's entirety is a bit to large but i hope this may clarify what i'm trying to do.
Well, thanks to florian's comment i think i might have found a solution my self. I'll present it here but leave the question open as there is probably far neater ways of doing it.
I rigged up the plots (that was created as lists by ggplot) into a list
plotList <- list(p_A1, p_A2, p_A3...)
tableList <- list(s_A1, s_A2, s_A3...)
I then used subset on my lookup table to get the matching id of the list to select the right plot and table.
output$thePlot <-renderPlot({
plotValue<-subset(letaLista, letaLista$Factor==input$Factor &
letaLista$Variabel== input$Variabel & letaLista$rest_alla==input$DataSource)
plotList[as.integer(plotValue[1,4])]
})
output$theTable <-renderTable({
plotValue<-subset(letaLista, letaLista$Factor==input$Factor &
letaLista$Variabel== input$Variabel & letaLista$rest_alla==input$DataSource)
skriva <- tableList[as.integer(plotValue[4])]
print(skriva)
})

How to receive variables in a post in google app engine that contains string with chars like: õ á?

email = self.request.get('email')
name = self.request.get('name')
mail.send_mail(sender="myemail", email=email, body=name, subject="sss " + name + "sdafsaã")
// added ã: the problem was that "sdafsaã" should be u"sdafsaã". with a "u" before the string. and now it works
then i get this
main.py", line 85, in post
subject="sss " + name + "sdafsa",
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 36: ordinal not in range(128)
the might have chars like õ ó and something like that.
for more details:
the code to run the worker(the code before)
the name is the one that is received from the datastore and contains chars like õ and ó...
taskqueue.add(url='/emailworker', params={'email': e.email, 'name': e.name})
thanks
Try reading a little about how unicode works in Python:
Dive Into Python - Unicode
Unicode In Python, Completely Demystified
Also, make sure you're running Python 2.5 if you are seeing this error on the development server.
You should use:
email = self.request.get('email')
name = self.request.get('name')
mail.send_mail(sender="myemail",
email=email,
body=name,
subject="hello " + name.encode('utf-8') + " user!")
The variable name is a unicode string and should encoded in utf-8 or in the kind of encode you are using in you web application before concatenating to other byte strings.
Without name.encode(), Python uses the default 7 bits ascii codec that can't encode that specific character.
the problem is joining 2 strings: ||| body = name + "ã" => error ||| body = name + u"ã" => works!!! |||
Try with encode
t ='việt ứng '
m = MyModel()
m.data = t.encode('utf-8')
m.put() #success!

Resources