pmap data format (Julia 1.1.0) - output

I have a function which I run using pmap. I would like the output to be a vector - p - whose entries are the output of each iteration run parallel. For illustration, the code is as below:
#everywhere function addo(mc,mcf)
p = zeros(Int64,mcf) ;
p[mc] = mc ;
return p
end
pmap(mc -> addo(mc,mcf),1:1:mcf) ;
The output I get is
100-element Array{Array{Int64,1},1}:
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 2, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 3, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
⋮
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 98, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 99, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 100]
Instead, I need something like this, p = [1,2,3,4,...,100];
How do I get the output in the desired format?

pmap, similar to map, applies your transformation function,mc -> addo(mc, mcf), to each element in the collection 1:1:mcf. The problem in your code is that for each element in the collection you are creating a new vector of size mcf and the overall result becomes an array of the arrays you create in each transformation, whereas what you want is the result of pmap to be of size mcf. Therefore, for each element in the collection, you should return only one element. pmap already gives you a collection grouping the results of each transformation.
#everywhere function addo(mc)
return mc
end
p = pmap(mc -> addo(mc), 1:1:mcf)
This will give you p = [1,2,3,4,...,100].

Related

Typecasting a json tuple into a string Python

How would I be able to turn a JSON of class type tuple into a string without turning the numbers into strings as well. I am getting a json object in the form of a tuple from a websocket and I am trying to convert it into a string form like data.
data= '''
({
'ext_code': '',
'ext_info': '',
'rate_limit': 120,
'rate_limit_reset_ms': 1620081183677,
'rate_limit_status': 117,
'result': {
'BTC': {'available_balance': 0.00087168, 'cum_realised_pnl': 7.288e-05, 'equity': 0.00087168, 'given_cash': 0, 'occ_closing_fee': 0, 'occ_funding_fee': 0, 'order_margin': 0, 'position_margin': 0, 'realised_pnl': 0, 'service_cash': 0, 'unrealised_pnl': 0, 'used_margin': 0, 'wallet_balance': 0.00087168},
'EOS': {'available_balance': 0, 'cum_realised_pnl': 0, 'equity': 0, 'given_cash': 0, 'occ_closing_fee': 0, 'occ_funding_fee': 0, 'order_margin': 0, 'position_margin': 0, 'realised_pnl': 0, 'service_cash': 0, 'unrealised_pnl': 0, 'used_margin': 0, 'wallet_balance': 0},
'ETH': {'available_balance': 0.03362706, 'cum_realised_pnl': -7.41e-06, 'equity': 0.03362706, 'given_cash': 0, 'occ_closing_fee': 0, 'occ_funding_fee': 0, 'order_margin': 0, 'position_margin': 0, 'realised_pnl': 0, 'service_cash': 0, 'unrealised_pnl': 0, 'used_margin': 0, 'wallet_balance': 0.03362706}
},
'ret_code': 0,
'ret_msg': 'OK',
'time_now': '1620081183.700541'},
<bravado.requests_client.RequestsResponseAdapter object at 0x0000016DC011F888>)
'''

How to embed a google chart (a html file) into a html webpage in adaptive width and height

I just learned to use google chart api to draw chart as follows:
Demo chart
The chart is now an html file named "demo_chart.html" whose code is:
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript", charset="utf-8">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number','Annual Compensation');
data.addColumn('number','count');
data.addColumn({type:"string",role:"tooltip", 'p':{'html': true}});
var a = [[10, 1, '0.3%'], [12, 2, '0.9%'], [14, 2, '1.6%'], [16, 4, '2.8%'], [18, 5, '4.3%'], [20, 14, '8.7%'], [22, 22, '15.5%'], [24, 40, '28.0%'], [26, 15, '32.6%'], [28, 28, '41.3%'], [30, 26, '49.4%'], [32, 22, '56.2%'], [34, 15, '60.9%'], [36, 17, '66.1%'], [38, 9, '68.9%'], [40, 17, '74.2%'], [42, 5, '75.8%'], [44, 14, '80.1%'], [46, 7, '82.3%'], [48, 3, '83.2%'], [50, 16, '88.2%'], [52, 6, '90.1%'], [54, 4, '91.3%'], [56, 3, '92.2%'], [58, 1, '92.5%'], [60, 3, '93.5%'], [62, 6, '95.3%'], [64, 2, '96.0%'], [66, 0, '96.0%'], [68, 1, '96.3%'], [70, 2, '96.9%'], [72, 1, '97.2%'], [74, 0, '97.2%'], [76, 0, '97.2%'], [78, 0, '97.2%'], [80, 1, '97.5%'], [82, 0, '97.5%'], [84, 1, '97.8%'], [86, 0, '97.8%'], [88, 0, '97.8%'], [90, 1, '98.1%'], [92, 0, '98.1%'], [94, 0, '98.1%'], [96, 0, '98.1%'], [98, 0, '98.1%'], [100, 1, '98.4%'], [102, 0, '98.4%'], [104, 0, '98.4%'], [106, 0, '98.4%'], [108, 0, '98.4%'], [110, 2, '99.1%'], [112, 0, '99.1%'], [114, 0, '99.1%'], [116, 0, '99.1%'], [118, 0, '99.1%'], [120, 1, '99.4%'], [122, 0, '99.4%'], [124, 0, '99.4%'], [126, 0, '99.4%'], [128, 0, '99.4%'], [130, 0, '99.4%'], [132, 0, '99.4%'], [134, 0, '99.4%'], [136, 0, '99.4%'], [138, 0, '99.4%'], [140, 1, '99.7%'], [142, 0, '99.7%'], [144, 0, '99.7%'], [146, 0, '99.7%'], [148, 0, '99.7%'], [150, 1, '100.0%']];
var b = HTML_format(a);
data.addRows(b);
var options = {
title: 'Demo Column Chart',
legend: { position: 'none' },
tooltip: {isHtml: true}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
function HTML_format(a)
{
var b = [];
var scale = a[1][0] - a[0][0];
for(var i=0; i<a.length; i++)
{
var text;
if(i < a.length - 1)
{
text = "demo";
}
else
{
text = "demo";
}
b.push([a[i][0], a[i][1], text]);
}
return b;
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
I want to embed the chart into another webpage and used iframe:
<tbody><tr><td class ='x text-center' style='align-items:center'><iframe src='demo_chart.html' style='width:900px;height:500px; border:0;max-width:100%' scrolling='no'></iframe></td><td class ='y' style=''><iframe src='demo_chart.html' style='width:900px;height:500px; border:0; max-width:100% ' scrolling='no'></iframe></td></tr></tbody>
It works well in my desktop but looks ugly in the mobile:
mobile_chart.
Could anyone help me to figure out how to correctly embed the html file so that it could be appropriately shown regardless of the width?
your problem seems to be that there is something wrong with your visualization options. You need to set the chartArea property to left:0 in your options.
After messing around with the properties I came up with these options: chartArea: {left: 0,top: 25}
so your options should look like:
var options =
{
title: 'Demo Column Chart',
legend: { position: 'none' },
tooltip: {isHtml: true},
chartArea: {left: 0,top: 25}
};
I would also suggest adding margin: auto; to your chart div to add the white space left on the main file:
<div id="chart_div" style="width: 900px; height: 500px;margin: auto;"></div>
so your demo_chart.html file should look something like this:
demo_chart.html
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript", charset="utf-8">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('number','Annual Compensation');
data.addColumn('number','count');
data.addColumn({type:"string",role:"tooltip", 'p':{'html': true}});
var a = [[10, 1, '0.3%'], [12, 2, '0.9%'], [14, 2, '1.6%'], [16, 4, '2.8%'], [18, 5, '4.3%'], [20, 14, '8.7%'], [22, 22, '15.5%'], [24, 40, '28.0%'], [26, 15, '32.6%'], [28, 28, '41.3%'], [30, 26, '49.4%'], [32, 22, '56.2%'], [34, 15, '60.9%'], [36, 17, '66.1%'], [38, 9, '68.9%'], [40, 17, '74.2%'], [42, 5, '75.8%'], [44, 14, '80.1%'], [46, 7, '82.3%'], [48, 3, '83.2%'], [50, 16, '88.2%'], [52, 6, '90.1%'], [54, 4, '91.3%'], [56, 3, '92.2%'], [58, 1, '92.5%'], [60, 3, '93.5%'], [62, 6, '95.3%'], [64, 2, '96.0%'], [66, 0, '96.0%'], [68, 1, '96.3%'], [70, 2, '96.9%'], [72, 1, '97.2%'], [74, 0, '97.2%'], [76, 0, '97.2%'], [78, 0, '97.2%'], [80, 1, '97.5%'], [82, 0, '97.5%'], [84, 1, '97.8%'], [86, 0, '97.8%'], [88, 0, '97.8%'], [90, 1, '98.1%'], [92, 0, '98.1%'], [94, 0, '98.1%'], [96, 0, '98.1%'], [98, 0, '98.1%'], [100, 1, '98.4%'], [102, 0, '98.4%'], [104, 0, '98.4%'], [106, 0, '98.4%'], [108, 0, '98.4%'], [110, 2, '99.1%'], [112, 0, '99.1%'], [114, 0, '99.1%'], [116, 0, '99.1%'], [118, 0, '99.1%'], [120, 1, '99.4%'], [122, 0, '99.4%'], [124, 0, '99.4%'], [126, 0, '99.4%'], [128, 0, '99.4%'], [130, 0, '99.4%'], [132, 0, '99.4%'], [134, 0, '99.4%'], [136, 0, '99.4%'], [138, 0, '99.4%'], [140, 1, '99.7%'], [142, 0, '99.7%'], [144, 0, '99.7%'], [146, 0, '99.7%'], [148, 0, '99.7%'], [150, 1, '100.0%']];
var b = HTML_format(a);
data.addRows(b);
var options = {
title: 'Demo Column Chart',
legend: { position: 'none' },
tooltip: {isHtml: true},
chartArea: {left: 0,top: 25}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
function HTML_format(a)
{
var b = [];
var scale = a[1][0] - a[0][0];
for(var i=0; i<a.length; i++)
{
var text;
if(i < a.length - 1)
{
text = "demo";
}
else
{
text = "demo";
}
b.push([a[i][0], a[i][1], text]);
}
return b;
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;margin: auto;"></div>
</body>
</html>
This should fix your problem.

Google Apps Script equivalent for JS typed arrays (Uint8Array and Uint16Array)

When I try to run the following code in google apps script
var numArray = [31, -117, 8, 8, -102, -124, 75, 88, 2, 0, 106, 117, 108, 121, 46, 116, 120, 116, 0, 1, 4, 0, -5, -1, 106, 117, 108, 121, -13, -113, 116, -57, 4, 0, 0, 0];
var typedArray = new Uint8Array(numArray);
...I get:
ReferenceError: "Uint8Array" is not defined.
At the same time
var numArray = [31, -117, 8, 8, -102, -124, 75, 88, 2, 0, 106, 117, 108, 121, 46, 116, 120, 116, 0, 1, 4, 0, -5, -1, 106, 117, 108, 121, -13, -113, 116, -57, 4, 0, 0, 0];
var typedArray = new Array(numArray);
...works just fine. Is there a clever workaround way to implement a Uint8Array in google apps script?
OK, so thanks to the comment from #Xepoch, here is the answer to my original question.
The equivalent to
var numArray = [31, -117, 8, 8, -102, -124, 75, 88, 2, 0, 106, 117, 108, 121, 46, 116, 120, 116, 0, 1, 4, 0, -5, -1, 106, 117, 108, 121, -13, -113, 116, -57, 4, 0, 0, 0];
var typedArray = new Uint8Array(numArray);
is (in the absence of Uint8Array):
var numArray = [31, -117, 8, 8, -102, -124, 75, 88, 2, 0, 106, 117, 108, 121, 46, 116, 120, 116, 0, 1, 4, 0, -5, -1, 106, 117, 108, 121, -13, -113, 116, -57, 4, 0, 0, 0];
var typedArray = [];
for(var i=0;i<numArray .length;i++) {
typedArray.push(numArray [i]<0?numArray [i]+256:numArray [i]);
}

as3 Changing dynamic text in a symbol

I have a symbol tile with multiple keyframes. One of the keyframes has a dynamic text box with the instance name pTwo.
I want to change the text in pTwo to an empty string and have tried:
pTwo.text = String(""); //Atempt One
MovieClip.pTwo.text = String(""); //Attempt two
Any help would be appreciated. Thanks in advance
EDIT: Im making a tile game and using an array to make the map - my array is as follows:
public var myMap: Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 3, 2, 2, 2, 0, 1],
[1, 0, 0, 0, 0, 0, 2, 0, 0, 1],
[1, 0, 2, 0, 2, 0, 0, 0, 0, 1],
[1, 0, 2, 2, 0, 3, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 2, 2, 0, 1],
[1, 0, 2, 0, 2, 0, 2, 0, 0, 1],
[1, 0, 2, 2, 2, 0, 2, 0, 2, 1],
[1, 0, 0, 0, 0, 0, 2, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
All the arrays are made from the symbol called 'tile' which consists of different key frames. So each number in the array references a different key frame. I have a character and when the character walks over the tile- I want the dynamic text to change to empty to imitate an empty tile- alternatively if theres a way to replace the tile with a [0] , that would also be good.
my code that generates the board:
var mapWidth = 10;
var mapHeight = 10;
var tileSide = 32;
var totalTiles = mapWidth * mapHeight;
var myMap: Array = [
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 3, 2, 2, 2, 0, 1],
[1, 0, 0, 0, 0, 0, 2, 0, 0, 1],
[1, 0, 2, 0, 2, 0, 0, 0, 0, 0],
[1, 0, 2, 2, 0, 3, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 2, 2, 0, 1],
[1, 0, 2, 0, 2, 0, 2, 0, 0, 1],
[1, 0, 2, 2, 2, 0, 2, 0, 2, 1],
[1, 0, 0, 0, 0, 0, 2, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
];
for (var i: int = 0; i < mapHeight; i++) {
for (var u: int = 0; u < mapWidth; u++) {
var cell: MovieClip = new tile();
cell.gotoAndStop(myMap[i][u] + 1);
cell.x = tileSide * u;
cell.y = tileSide * i;
addChild(cell);
};
};
Sorry i was not clear from the start. New at actionscript so i apologise in advance if my terminology is unclear.
Is this "tile" symbol available in all frames? If the playhead is moving, then the symbols within the MovieClip may become dereferenced. Add the "pTwo" object to your Watch list in debug and determine if it object exists as the "tile" symbol plays.
You may need to create a single frame symbol with 2 layers. One with the animated symbol and the other with the text.
If the TextField only exists on a particular frame, and you're sure that it's the current frame, you can use this:
TextField(getChildByName("pTwo")).text = "";
If you're not always sure, just wrap it in a try block:
try {
TextField(getChildByName("pTwo")).text = "";
} catch(error:Error) {
trace("text field doesn't exist on this frame");
}
If pTwo lives inside of a Movieclip, the code might look something like this:
try {
TextField(YourMovieclipsName.getChildByName("pTwo")).text = "";
} catch(error:Error) {
trace("text field doesn't exist on this frame");
}
Hope this helps!
Edit based on new info:
for (var i: int = 0; i < mapHeight; i++) {
for (var u: int = 0; u < mapWidth; u++) {
var cell: MovieClip = new tile();
cell.gotoAndStop(myMap[i][u] + 1);
cell.x = tileSide * u;
cell.y = tileSide * i;
try {
TextField(cell.getChildByName("pTwo")).text = "";
} catch(error:Error) {
trace("text field doesn't exist on this frame");
}
addChild(cell);
};
};

Parsing JSON without square brackets around the arrays

I need to parse a live feed but each array has no brackets around it so I am slightly confused. It is also valid JSON as I used an online service to check. I want to specify the context and then grab the data. does anyone know how I can do this and what the context might be?
In this case I want the "Name", "competitor" and a few other fields. Any help gratefully received.
{
"604377": {
"competitors": {
"3521278": {
"Name": "Brazil",
"Jockey": null,
"Weight": null,
"Saddle": 0,
"Barrier": null,
"QLDWin": 0,
"VICWin": 0,
"NSWWin": 0,
"QLDPlace": 0,
"VICPlace": 0,
"NSWPlace": 0,
"DetailedPricing": {
"winTotePlus": false,
"placeTotePlus": false,
"topFluc": false,
"bestOfBest": false,
"bestOrSP": false,
"fixedOdds": false,
"fixedWin": true,
"doubleFixedWin": 0,
"bestOfEverythingWin": 0,
"bestAnytimeWin": 0,
"fixedPlace": true,
"startPriceGuarantee": 0,
"fixedEachWay": true,
"placePrices": [
0
],
"startPrice": false,
"internationalStartPrice": false,
"midToteWin": false,
"midTotePlace": true,
"topToteWin": true,
"topTotePlace": false,
"top2ToteWin": false,
"top2TotePlace": false,
"vicToteWinPlus1": false,
"vicTotePlacePlus1": false,
"vicToteWinPlus2": false,
"vicTotePlacePlus2": false,
"vicToteWinPlus5": false,
"vicTotePlacePlus5": false,
"vicToteWinPlus10": false,
"vicTotePlacePlus10": false,
"exoticBet": true,
"exoticMidTote": false,
"exoticBest2Tote": false,
"exoticBest3Tote": false,
"pickYourOdds": false,
"firstfour": true,
"midToteWinPrice": 0,
"midTotePlacePrice": 0,
"topToteWinPrice": 0,
"top2ToteWinPrice": 0,
"top2ToteOrSPWinPrice": 0,
"vicToteWinPlus1Price": 0,
"vicToteWinPlus2Price": 0,
"vicToteWinPlus5Price": 0,
"vicToteWinPlus10Price": 0,
"topTotePlacePrice": 0,
"top2TotePlacePrice": 0,
"vicTotePlacePlus1Price": 0,
"vicTotePlacePlus2Price": 0,
"vicTotePlacePlus5Price": 0,
"vicTotePlacePlus10Price": 0,
"topFlucPrice": 0,
"lastFlucPrice": 0,
"bestOfBestPrice": 0,
"bestOrSPPrice": 0,
"bestOrSPPlacePrice": 0.75,
"winDeduction": 0,
"placeDeduction": 0,
"competitor": 11863763,
"sport": "Soccer",
"saddle": 0,
"description": "Brazil 2014 - World Cup Winner ",
"team": "Jordan",
"win": 0,
"place": 0,
"numOutcomes": 24,
"numPlacings": 1,
"numWinners": 1
},
"Scratched": "no",
"RisaSilkID": null
},
"3521279": {
"Name": "Argentina",
"Jockey": null,
"Weight": null,
"Saddle": 0,
"Barrier": null,
"QLDWin": 0,
"VICWin": 0,
"NSWWin": 0,
"QLDPlace": 0,
"VICPlace": 0,
"NSWPlace": 0,
"DetailedPricing": {
"winTotePlus": false,
"placeTotePlus": false,
"topFluc": false,
"bestOfBest": false,
"bestOrSP": false,
"fixedOdds": false,
"fixedWin": true,
"doubleFixedWin": 0,
"bestOfEverythingWin": 0,
"bestAnytimeWin": 0,
"fixedPlace": true,
"startPriceGuarantee": 0,
"fixedEachWay": true,
"placePrices": [
0
],
"startPrice": false,
"internationalStartPrice": false,
"midToteWin": false,
"midTotePlace": true,
"topToteWin": true,
"topTotePlace": false,
"top2ToteWin": false,
"top2TotePlace": false,
"vicToteWinPlus1": false,
"vicTotePlacePlus1": false,
"vicToteWinPlus2": false,
"vicTotePlacePlus2": false,
"vicToteWinPlus5": false,
"vicTotePlacePlus5": false,
"vicToteWinPlus10": false,
"vicTotePlacePlus10": false,
"exoticBet": true,
"exoticMidTote": false,
"exoticBest2Tote": false,
"exoticBest3Tote": false,
"pickYourOdds": false,
"firstfour": true,
"midToteWinPrice": 0,
"midTotePlacePrice": 0,
"topToteWinPrice": 0,
"top2ToteWinPrice": 0,
"top2ToteOrSPWinPrice": 0,
"vicToteWinPlus1Price": 0,
"vicToteWinPlus2Price": 0,
"vicToteWinPlus5Price": 0,
"vicToteWinPlus10Price": 0,
"topTotePlacePrice": 0,
"top2TotePlacePrice": 0,
"vicTotePlacePlus1Price": 0,
"vicTotePlacePlus2Price": 0,
"vicTotePlacePlus5Price": 0,
"vicTotePlacePlus10Price": 0,
"topFlucPrice": 0,
"lastFlucPrice": 0,
"bestOfBestPrice": 0,
"bestOrSPPrice": 0,
"bestOrSPPlacePrice": 0.75,
"winDeduction": 0,
"placeDeduction": 0,
"competitor": 11863763,
"sport": "Soccer",
"saddle": 0,
"description": "Brazil 2014 - World Cup Winner ",
"team": "Jordan",
"win": 0,
"place": 0,
"numOutcomes": 24,
"numPlacings": 1,
"numWinners": 1
},
"Scratched": "no",
"RisaSilkID": null
},
"3521280": {
"Name": "Spain",
You haven't specified which language/platform you want to do this in. I'll assume .NET...
http://www.nuget.org/packages/newtonsoft.json/
WebRequest request = WebRequest.Create(query);
using (var response = request.GetResponse())
{
using (var responseStream = response.GetResponseStream())
{
using (var streamReader = new StreamReader(responseStream))
{
try
{
JsonReader reader = new JsonTextReader(streamReader);
dynamic result = JObject.Load(reader);
There's lots of other JSON parsers out there for .NET and other platforms