My raku Inline::Python code module unexpectedly prints output even when the rs_str method is disabled.
use Inline::Python;
role Series {
has $args;
has $!py = Inline::Python.new;
has $.po; #each instance has own Python Series obj
method TWEAK {
my $py-str = qq{
class RakuSeries:
def __init__(self):
self.series = pd.Series($args)
#`[
def rs_str(self):
return(str(self.series))
#]
};
$!py.run($py-str);
$!po = $!py.call('__main__', 'RakuSeries');
}
method Str {
$!po.rs_str()
}
}
say ~Series.new( args => "[1, 3, 5, 6, 8]" );
>>>
0 1
1 3
2 5
3 6
4 8
Name: anon, dtype: int64
Is this a special tunnelling mode?
Poisson d'Avril
April Fool
першоквітневий дурень
Aprilscherz
Related
Lets say I have this test:
class test extends TestCase
{
use RefreshDatabase;
/** #test */
public function test_ids_example()
{
$courses = factory(Post::class, 3)->create();
$this->assertEquals([1, 2, 3], $courses->pluck('id')->toArray());
}
/** #test */
public function test_ids_example_2()
{
$courses = factory(Post::class, 4)->create();
$this->assertEquals([1, 2, 3, 4], $courses->pluck('id')->toArray());
}
}
When I run the the test one by one, it passes..
but when I run the whole test file I get this error:
test::test_ids_example_2
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
## ##
Array (
- 0 => 1
- 1 => 2
- 2 => 3
- 3 => 4
+ 0 => 4
+ 1 => 5
+ 2 => 6
+ 3 => 7
)
Because the tests doesn't reset the auto increment "id" even though I added "RefreshDatabase" trait. How to solve this? How can I rest the id for each test?
PLEASE NEED HELP
This is what I'm doing:
var my_array_W:Array = new Array();
my_array_W.push({cor:Acorrect, tem:AnewTime, tab: "TB_A", nom:Aoseasnnombre});
my_array_W.push({cor:Bcorrect, tem:BnewTime, tab: "TB_B", nom:Boseasnnombre});
my_array_W.push({cor:Ccorrect, tem:CnewTime, tab: "TB_C", nom:Coseasnnombre});
my_array_W.push({cor:Dcorrect, tem:DnewTime, tab: "TB_D", nom:Doseasnnombre});
my_array_W.push({cor:Ecorrect, tem:EnewTime, tab: "TB_E", nom:Eoseasnnombre});
my_array_W.push({cor:Fcorrect, tem:FnewTime, tab: "TB_F", nom:Foseasnnombre});
This Output:
[tab] | [cor] | [tem]
TB_A 3 8.6877651541
TB_B 4 12.9287651344
TB_C 1 6199.334999999999923
TB_D 4 33.6526718521
TB_E 4 31.90468496844
TB_F 1 6.334999999923
So then I sort:
my_array_W.sortOn("tem", Array.NUMERIC);
my_array_W.sortOn("cor", Array.NUMERIC | Array.DESCENDING);
And Geting this T_T :
[tab] | [cor] | [tem]
TB_E 4 31.90468496844
TB_D 4 33.6526718521
TB_B 4 12.9287651344
TB_A 3 8.6877651541
TB_F 1 31.90468496844
TB_C 1 6199.334999999999923
I just wanna sort a Winner Table by Time(the less) and Correct(the high)
So the Winner is the One who make more correct answers in less time.
I really try so hard to get a sort like this:
[tab] | [cor] | [tem]
TB_B 4 12.9287651344
TB_E 4 31.90468496844
TB_D 4 33.6526718521
TB_A 3 8.6877651541
TB_F 1 6.334999999923
TB_C 1 6199.334999999999923
But couldn't achieve it
Your mistake is that you sort it 2 times. The second time does not additionally sort the sorted, it just sorts the whole Array anew. What you need is to use the Array.sort(...) method with a compareFunction argument:
my_array_W.sort(sortItems);
// Should return -1 if A < B, 0 if A == B, or 1 if A > B.
function sortItems(A:Object, B:Object):Number
{
// First, the main criteria.
if (A.cor > B.cor) return -1;
if (A.cor < B.cor) return 1;
// If A.cor == B.cor, then secondary criteria.
if (A.tem < B.tem) return -1;
if (A.tem > B.tem) return 1;
// Items seem to be equal.
return 0;
}
#Organis was so close.
But Finally I do the trick :D
With this line
my_array_W.sortOn(['cor', 'tem'],[ Array.NUMERIC | Array.DESCENDING, Array.NUMERIC ]);
I get the result I was looking for
Thanks
In your case you have to write a costume sorter function. to do that check my example:
Your first data:
var arr:Array = [];
arr.push({cor:4,tem:13});
arr.push({cor:3,tem:12});
arr.push({cor:2,tem:1});
arr.push({cor:3,tem:16});
arr.push({cor:1,tem:11});
The sorting function and sort result for sample one based on tem:
arr.sort(scrollSorter);
function temSorter(a,b):int
{
if(a.tem<b.tem)
return 1 ;//To pass a forward
else(a.tem>b.tem)
return -1;//To pass a backward
return 0;//a and b are same.
}
And the result is:
The result is this:
[
{
"cor": 3,
"tem": 16
},
{
"cor": 4,
"tem": 13
},
{
"cor": 3,
"tem": 12
},
{
"cor": 1,
"tem": 11
},
{
"cor": 2,
"tem": 1
}
]
Now the sample based on something close you need:
arr.sort(scrollSorter);
function userScoreCalculator(a):Number
{
return a.cor/a.tem;
}
function winnerSorter(a,b):int
{
var aScore:Number = userScoreCalculator(a);
var bScore:Number = userScoreCalculator(b);
if(aScore<bScore)
return 1 ;
else(aScore>bScore)
return -1
return 0
}
And the result is:
[
{
"cor": 2,
"tem": 1
},
{
"cor": 4,
"tem": 13
},
{
"cor": 3,
"tem": 12
},
{
"cor": 3,
"tem": 16
},
{
"cor": 1,
"tem": 11
}
]
Than means the person with score of 2 is winner because he made it in only 1 second. but other players are close to gather in tem parameter, so the next winner is the person with highest score. it comes from the userScoreCalculator() output. the higher output of that function is the winner.
Now take your time and change the userScoreCalculator() function to show the winner.
https://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7fa4.html
I need to parse a field from a CSV column which is a string:
TXDAT - SnpRespData_SC or SnpRespData_SC_PD (7)
I need to extract:
type_0 = SnpRespData
resp_0 = SC
pd_0 = 0
type_1 = SnpRespData
resp_1 = SC
pd_1 = 1
from this string. I want to pass the whole string to a function and be able to return these six values.
The string could be any of the following:
a) TXDAT - SnpRespData_SC_PD
b) TXRSP - SnpResp_SC
c) TXDAT - SnpRespData_SC or SnpRespData_SC_PD (7)
d) TXRSP - SnpResp_UC or TXDAT - SnpRespData_UC_PD (7)
So I created a function which receives this string and returns the following:
def map_rxsnp_transaction(rxsnp_transaction)
tx_dat = []
tx_rsp = []
case rxsnp_transaction
when (/SnpRespData.*SnpRespData/)
tx_dat = rxsnp_transaction.split(/or/)
(tx_dat_0, dat_0_resp, dat_0_pd) = tx_dat[0].split(/_/)
(tx_dat_1, dat_1_resp, dat_1_pd) = tx_dat[1].split(/_/)
return [tx_dat_0, dat_0_resp, dat_0_pd, tx_dat_1, dat_1_resp, dat_1_pd]
when (/SnpResp.*SnpRespData/)
(tx_rsp, tx_dat) = rxsnp_transaction.split(/or/)
(tx_rsp, rsp_resp, rsp_pd) = tx_rsp.split(/_/)
(tx_dat, dat_resp, dat_pd) = tx_dat.split(/_/)
return [tx_rsp, rsp_resp, rsp_pd, tx_dat, dat_resp, dat_pd]
when (/SnpRespData_{1}/)
return rxsnp_transaction.split(//)
when (/SnpResp{1}/)
return rxsnp_transaction.split(/_/)
end
end
Function call:
(tx_rsp[0],tx_rsp[1],tx_rsp[2],tx_rsp[3],tx_rsp[4],tx_rsp[5]) = map_rxsnp_transaction table_col[5]
Just wondering if I can optimize this code better...don't like the way it
I assume that you are looking for a specific string, namely, "SnpRespData". If so, you could do this:
str = "TXDAT - SnpRespData_SC or SnpRespData_SC_PD (7)"
f, l = str.scan(/SnpRespData\w+/).sort
#=> ["SnpRespData_SC", "SnpRespData_SC_PD"]
type_0, resp_0, pd_0 = f.split('_') << 0
#=> ["SnpRespData", "SC", 0]
type_1, resp_1, pd_1 = f.split('_').first(2) << 1
#=> ["SnpRespData", "SC", 1]
type_0 #=> "SnpRespData"
resp_0 #=> "SC"
pd_0 #=> 0
type_1 #=> "SnpRespData"
resp_1 #=> "SC"
pd_1 #=> 1
I have a file outputted from a TCL script, which has a TCL syntax'ed array, as below.
set data(item1) {
xyz {
a { one two three 1 2 3}
b { three one two 3 2 4}
}
lmn {
z { "something" 1 2 3}
d { "samething" 3 2 4}
}
};
set data(item2) {
xyz {
ss { 100 }
sd { "sdss" 200 300}
}
lmn {
ee { "xdf" 1 "2dsd" 3}
pp { "dd" "fsdf" 3 2 4}
}
};
Now I need to read this file in a Ruby program and build them into a Hash of Hashes, similar to something below, before I start consuming the required data:
data = {
'item1' => {
'xyz' => {
'a' => %w{one two three 1 2 3},
'b' => %w{three one two 3 2 4}
},
'lmn' => {
'z' => %w{something 1 2 3},
'd' => %w{samething 3 2 4}
}
},
'item2' => {
'xyz' => {
'ss' => %w{100 },
'sd' => %w{sdss 200 300}
},
'lmn' => {
'ee' => %w{xdf 1 2dsd 3},
'pp' => %w{dd fsdf 3 2 4}
}
}
}
Is there any Ruby utility or method that I can use for this purpose?
Thanks in advance for your support.
No. You will have to build a parser. Take a look at treetop.
It will help a lot to have some early basic knowledge of compilers like compiling phases (lexical analyzer and syntax analyzer, you don't need semantic analyzer for this project).
Also, some basic understanding of grammars will help, since is pre-requisite for compilers - but most likely you will stumble upon grammars while trying to figure out compilers.
I'm just trying to get my head around a multidimensional array creation from a perl script i'm currently converting to Ruby, I have 0 experience in Perl, as in i opened my first Perl script this morning.
Here is the original loop:
my $tl = {};
for my $zoom ($zoommin..$zoommax) {
my $txmin = lon2tilex($lonmin, $zoom);
my $txmax = lon2tilex($lonmax, $zoom);
# Note that y=0 is near lat=+85.0511 and y=max is near
# lat=-85.0511, so lat2tiley is monotonically decreasing.
my $tymin = lat2tiley($latmax, $zoom);
my $tymax = lat2tiley($latmin, $zoom);
my $ntx = $txmax - $txmin + 1;
my $nty = $tymax - $tymin + 1;
printf "Schedule %d (%d x %d) tiles for zoom level %d for download ...\n",
$ntx*$nty, $ntx, $nty, $zoom
unless $opt{quiet};
$tl->{$zoom} = [];
for my $tx ($txmin..$txmax) {
for my $ty ($tymin..$tymax) {
push #{$tl->{$zoom}},
{ xyz => [ $tx, $ty, $zoom ] };
}
}
}
and what i have so far in Ruby:
tl = []
for zoom in zoommin..zoommax
txmin = cm.tiles.xtile(lonmin,zoom)
txmax = cm.tiles.xtile(lonmax,zoom)
tymin = cm.tiles.ytile(latmax,zoom)
tymax = cm.tiles.ytile(latmin,zoom)
ntx = txmax - txmin + 1
nty = tymax - tymin + 1
tl[zoom] = []
for tx in txmin..txmax
for ty in tymin..tymax
tl[zoom] << xyz = [tx,ty,zoom]
puts tl
end
end
end
The part i'm unsure of is nested right at the root of the loops, push #{$tl->{$zoom}},{ xyz => [ $tx, $ty, $zoom ] };
I'm sure this will be very simple for a seasoned Perl programmer, thanks! `
The Perl code is building up a complex data structure in $tl -- hash, array, hash, array:
$tl{$zoom}[i]{xyz}[j] = $tx # j = 0
$tl{$zoom}[i]{xyz}[j] = $ty # j = 1
$tl{$zoom}[i]{xyz}[j] = $zoom # j = 2
So I think the key line in your Ruby code should be like this:
tl[zoom] << { 'xzy' => [tx,ty,zoom] }
Note also that the root item ($tl) refers to a hash in the Perl code, while your Ruby code initializes it to be an array. That difference might cause problems for you, depending on the values that $zoom takes.