this question is simple.
¿Why i can't use the next code?
select apex_web_service.make_rest_request(
--p_url => 'https://api.exchangeratesapi.io/history?start_at=2018-01-01\&\end_at=2018-09-01',
p_url => 'https://api.exchangeratesapi.io/history?',
p_http_method => 'GET',
p_parm_name => APEX_UTIL.string_to_table('start_at:end_at'),
--p_parm_value => APEX_UTIL.string_to_table('"2018-01-01":"2018-09-01"')
--p_parm_value => APEX_UTIL.string_to_table('"2018-01-01"' || ':' || '"2018-09-01"')
--p_parm_value => APEX_UTIL.string_to_table('2018-01-01:2018-09-01', ':')
p_parm_value => APEX_UTIL.string_to_table('2018-01-01:2018-09-01')
) as test
from dual;
This is the error:
ORA-00902: tipo de dato no válido
00902. 00000 - "invalid datatype"
*Cause:
*Action:
Error en la línea: 20, columna: 22
I also try with this form:
declare
l_clob clob;
begin
l_clob := APEX_WEB_SERVICE.make_rest_request(
p_url => 'https://api.exchangeratesapi.io/history',
p_http_method => 'GET',
--p_parm_name => APEX_UTIL.string_to_table('"start_at"' || ':' ||'"end_at"'),
p_parm_name => APEX_UTIL.string_to_table('start_at:end_at'),
--p_parm_value => APEX_UTIL.string_to_table('"2018-01-01"' || ':' || '"2018-09-01"')
p_parm_value => APEX_UTIL.string_to_table('2018-01-01' || ':' || '2018-09-01')
--p_parm_value => APEX_UTIL.string_to_table(2018-01-01 || ':' || 2018-09-01)
--p_parm_value => APEX_UTIL.string_to_table('2018-01-01:2018-09-01')
) ;
dbms_output.put_line(l_clob);
end;
/
and this is the error:
Informe de error -
ORA-06502: PL/SQL: error numérico o de valor
ORA-06512: en línea 14
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause: An arithmetic, numeric, string, conversion, or constraint error
occurred. For example, this error occurs if an attempt is made to
assign the value NULL to a variable declared NOT NULL, or if an
attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).
*Action: Change the data, how it is manipulated, or how it is declared so
that values do not violate constraints.
I want get this json:
https://api.exchangeratesapi.io/history?start_at=2018-01-01&end_at=2018-09-01
I try with postman, and works
There are several comments, are test's but doesn't work.
Does really works p_parm_name and p_parm_value?
Can somebody help me?
Regards
The problem is with your dbms_output.put_line. dbms_output.put_line is limited to a VARCHAR2, or 32,767 bytes. If you use the following code, you'll see that you're getting a result. The size I got was 74,037.
declare
l_clob clob;
begin
l_clob := APEX_WEB_SERVICE.make_rest_request(
p_url => 'https://api.exchangeratesapi.io/history',
p_http_method => 'GET',
p_parm_name => APEX_UTIL.string_to_table('start_at:end_at'),
p_parm_value => APEX_UTIL.string_to_table('2018-01-01' || ':' || '2018-09-01')
) ;
dbms_output.put_line(dbms_lob.getlength(l_clob));
end;
/
Related
Is it possible to find the cakephp with additional condition or can we multiply the sum() field with conditional variable?
I don't know, what could be a best question to let you guys know what I'm asking. so I'm giving a more detail about question. I'm able to find similar data with single array with some trick. but I'm unable to find for this. Please help me or give me an idea to do such task. Thanks.
Using CakePhp 2.6
I want to find data from first table here..
$incentiveweekly=$this->Incentive->find('all',
array('conditions' =>
array(
"AND"=>array(
"Incentive.fromdate >=" => $from,
"Incentive.todate <=" => $to
)
)
)
);
according to number of rows. I have to find another table
Here is the result of above find condition.
Array
(
[Incentive] => Array
(
[id] => 2
[target1] => 3000
[price1] => 1.5
[target2] => 6000
[price2] => 2.5
[target3] => 8000
[price3] => 3.5
[formonth] =>
[type] => 1
[fromdate] => 2016-11-13
[todate] => 2016-11-21
[updatedby] => 1
[created] => 2016-11-15 23:57:21
[modified] => 2016-11-15 23:57:21
)
)
Array
(
[Incentive] => Array
(
[id] => 3
[target1] => 3000
[price1] => 1.5
[target2] => 6000
[price2] => 2.5
[target3] => 8000
[price3] => 3.5
[formonth] =>
[type] => 1
[fromdate] => 2016-11-24
[todate] => 2016-11-28
[updatedby] => 1
[created] => 2016-11-15 23:57:21
[modified] => 2016-11-15 23:57:21
)
)
Now I want to find the array according to number of array record.
$byweek=array(); // Storing Customer data by Target dates in array()
foreach ($incentiveweekly as $weekly){
print_r($weekly);
$target3=$weekly['Incentive']['target3'];
$target2=$weekly['Incentive']['target2'];
$target1=$weekly['Incentive']['target1'];
$price3=$weekly['Incentive']['price3'];
$price2=$weekly['Incentive']['price2'];
$price1=$weekly['Incentive']['price1'];
$byweek[]=$customers=$this->Customer->find('all',array(
'fields'=>array(
'SUM(amount) AS amount',
'created_by'
),
'group' => 'Customer.created_by',
'conditions' => array(
"AND" =>array(
"Customer.created >=" => $weekly['Incentive']['fromdate'],
"Customer.created <=" => $weekly['Incentive']['todate']
)
),
'recursive'=>-1 )
);
//print_r($byweek);
}
I'm getting result like ...
Array
(
[0] => Array
(
[0] => Array
(
[Customer] => Array
(
[created_by] => 3
)
)
)
)
Array
(
[0] => Array
(
[0] => Array
(
[Customer] => Array
(
[created_by] => 3
)
)
)
[1] => Array
(
[0] => Array
(
[Customer] => Array
(
[created_by] => 1
)
)
[1] => Array
(
[Customer] => Array
(
[created_by] => 2
)
)
)
)
But I want that amount would multiply with on the if else condition where I'm using ternary operator.
$value[0]['amount']>=$valuem['Incentive']['target3']?"Target Third":($value[0]['amount']>=$valuem['Incentive']['target2']?"Target Second":($value[0]['amount']>=$valuem['Incentive']['target1']?"Target First":"None"))
Main purpose to find the details are. I want to create an incentive amount where total sales amount should be match with given target amount. If target1 amount one match then incentive would be total amount*price1 and same with target2 and target3. where i'm using tenantry operator. Target price should be multiply(by condition) with the same find condition data.
I search on google and stack overflow but can't find it's solutions. However I'm thankful to stack overflow and all you gusy that i'm able to find a lots of trick and solutions.
I haven't got exactly though you can try with below solution as per my thought,
You need to use WHEN close in MYSQL,
$incenve = 'CASE WHEN amount>5000 THEN "FIRST Target" WHEN amount>3000 THEN "Second Target" ELSE 0 '
and inside fields in above query
'incentive' => $incentive
Thanks Oldskool for this solution Virtualfields with If Condition
Finaly I, Got my solutions by this code bellow. I'm getting result as expected. :)
$this->Customer->virtualFields=array(
'incentive' => "if(SUM(Customer.amount)>=$target3,(SUM(Customer.amount))*$price3,if(SUM(Customer.amount)>=$target2,(SUM(Customer.amount))*$price2,if(SUM(Customer.amount)>=$target1,(SUM(Customer.amount))*$price1,0)))",
);
Now I can use Virtualfied to get the Incentive value.
I am new to unit testing in PHP and I'm having a little trouble. Whether that is because I'm using the Cake framework or because I'm used to the Java way, point it I'm having issues.
I'm writing tests for a Model function that gets called on the submit of a form. The function receives two parameters, which I think I'm passing through correctly, and a data object that is not received as a parameter. My question is how do I populate that "data" object? I keep getting and "undefined index" error when I run the tests.
I've tried both mocking the data and using fixtures, but in all honesty, I don't get this stuff. Below is my model function, followed by my test code.
public function isUniqueIfVerified($check, $unverified){
$found = false;
if ($this->data['Client']['client_type_id'] == 5) {
$found = $this->find ( 'first', array (
'conditions' => array (
$check,
$this->alias . '.' . $this->primaryKey . ' !=' => $this->id,
'client_type_id <>' => 5
),
'fields' => array (
'Client.id'
)
) );
} else {
$found = $this->find ( 'first', array (
'conditions' => array (
$check,
$this->alias . '.' . $this->primaryKey . ' !=' => $this->id
),
'fields' => array (
'Client.id'
)
) );
}
if ($found) {
return false;
} else {
return true;
}
}
This is like the 52 version of my test function, so feel free to just do whatever you want with it. I was thinking that mocking the data would be easier and faster, since I only really need the 'client_type_id' for the condition inside my Model function, but I couldn't get that 'data' object to work, so I switched to fixtures... with no success.
public function testIsUniqueIfVerified01() {
$this->Client = $this->getMock ( 'Client', array (
'find'
) );
$this->Client->set(array(
'client_type_id' => 1,
'identity_no' => 1234567890123
));
//$this->Client->log($this->Client->data);
$check = array (
'identity_no' => '1234567890123'
);
$unverified = null;
$this->Client = $this->getMockforModel("Client",array('find'));
$this->Client->expects($this->once())
->method("find")
->with('first', array (
'conditions' => array (
"identity_no" => "1234567890123",
"Client.id" => "7711883306236",
'client_type_id <>' => 5
),
'fields' => array (
'Client.id'
)
))
->will($this->returnValue(false));
$this->assertTrue($this->Client->isUniqueIfVerified($check, $unverified));
unset ( $this->Client );
}
Again, I'm very green when it comes to Cake, and more specifically PHP Unit Testing, so feel free to explain where I went wrong.
Thanks!
You'll need to make a slight adjustment to your model function (which I'll show below) but then you should be able to do something like this to pass through data in the data object:
$this->Client->data = array(
'Client' => array(
'client_type_id' => 5,
'identity_no' => 1234567890123
));
This is instead of the "set" you used, as below:
$this->Client->set(array( ...
Also, you mocked the Client model, then "set" a few things, but then just before you do the test, you mock it again. This means you're throwing away all the thins you set for the mock you did right at the top. You can do something as below which should solve you problem:
public function testIsUniqueIfVerified01() {
$this->Client = $this->getMock ( 'Client', array (
'find'
) );
$this->Client->data = array(
'Client' => array(
'client_type_id' => 5,
'identity_no' => 1234567890123
));
$check = array (
'identity_no' => '1234567890123'
);
$unverified = null;
$this->Client->expects($this->once())
->method("find")
->with($this->identicalTo('first'), $this->identicalTo(array(
'conditions' => array (
$check,
"Client.id !=" => 1,
'client_type_id <>' => 5
),
'fields' => array (
'Client.id'
)
)))
->will($this->returnValue(false));
$this->assertTrue($this->Client->isUniqueIfVerified($check, $unverified));
unset ( $this->Client );
}
This should at least give you an idea of what to do. Hope it helps!
I need to obtain something like this:
However, I cannot know how to continue... now I have this:
In other words... I cannot know how to add tags and the corresponding transcripts, CDS, etc.
My code right now is the following one:
#!/usr/bin/perl
#use strict;
use Bio::Graphics;
use Bio::SeqFeature::Generic;
my $panel = Bio::Graphics::Panel->new(
-length => 20000,
-width => 800
);
my $full_length = Bio::SeqFeature::Generic->new(
-start => 1,
-end => 20000,
);
$panel->add_track($full_length,
-key => "hola",
-glyph => 'arrow',
-tick => 2,
-fgcolor => 'black',
-double => 1,
);
my $track = $panel->add_track(
-glyph => 'generic',
-label => 1
);
my $track = $panel->add_track(
-glyph => 'generic',
-label => 1
);
$seq = "";
$seqlength = length($seq);
$count = 0;
while (<>) {
chomp;
next if /^\#/;
my #gff_data = split /\t+/;
next if ($gff_data[2] ne "gene");
my $feature = Bio::SeqFeature::Generic->new(
-display_name => $gff_data[8],
-score => $gff_data[5],
-start => $gff_data[3],
-end => $gff_data[4],
);
$track->add_feature($feature);
}
print $panel->png;
I've read as well the CPAN information but no clue... There is a lot of information for NCBI files but nothing for GFF...
My data:
313-9640000-9660000:19634:fwd maker gene 1978 7195 . + . ID=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10;Name=maker-313-9640000-9660000%253A19634%253Afwd-augustus-gene-0.10
313-9640000-9660000:19634:fwd maker mRNA 1978 7195 . + . ID=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1;Name=maker-313-9640000-9660000%253A19634%253Afwd-augustus-gene-0.10-mRNA-1;Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10
313-9640000-9660000:19634:fwd maker exon 1978 2207 0.48 + . Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1
313-9640000-9660000:19634:fwd maker exon 3081 3457 0.48 + . Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1
313-9640000-9660000:19634:fwd maker exon 3535 3700 0.48 + . Parent=maker-313-9640000-9660000%3A19634%3Afwd-augustus-gene-0.10-mRNA-1
Any help will be very wellcome.
use Bio::Graphics;
use Bio::Tools::GFF;
use Bio::SeqFeature::Generic;
$gfffile = shift;
my $gff = Bio::Tools::GFF->new(-file => $gfffile, -gff_version => 3);
while($feature = $gff->next_feature()) {
$tag = $feature->primary_tag;
push #{$hash{$tag}}, $feature;
}
$gff->close();
my $panel = Bio::Graphics::Panel->new(
-length => 20000,
-width => 800,
-key_style => 'between',
);
my $full_length = Bio::SeqFeature::Generic->new(
-start => 1,
-end => 20000,
);
$panel->add_track($full_length,
-key => "hola",
-glyph => 'arrow',
-tick => 2,
-fgcolor => 'black',
-double => 1,
);
my #colors = qw(cyan orange blue);
my $idx = 0;
for my $tag (sort keys %hash) {
my $features = $hash{$tag};
$panel->add_track($features,
-glyph => 'generic',
-bgcolor => $colors[$idx++ % #colors],
-fgcolor => 'black',
-font2color => 'red',
-key => "${tag}s",
-bump => +1,
-height => 8,
-label => 1,
-description => 1,
);
}
print $panel->png;
What you are showing in the first screen capture is likely from GBrowse, and the track labels (I think this is what you mean by 'tags') are defined in the configuration file. The feature label can be turned on/off by setting the 'label' and 'label_feat' attributes when you create the object. You will have to manually edit the file if you don't like those long strings set as the ID by MAKER.
You can change the appearance of each feature by choosing a different glyph. For example, you chose the 'generic' glyph, so what you get is a pretty generic looking box which just shows you the location of the feature. For nice looking transcripts, take a look at the 'processed_transcript' and 'decorated_transcript' glyphs.
There are also some problems with your code, such duplication of certain sections, but that may be from doing a copy and paste of the code.
I had the same problem than you. The thing is not very easy to explain. Finally I solved it and mi figure is pretty much similar at yours.
In my case I wanted to connect some encode data in the 5' UTR of several genes. And this encode data should be connected with dashed lines.
So I create a Bio::SeqFeature::Generic object and the information to plot inside are my encode regions, so this encode regions need to be sub_located inside :
my $splitlocation = Bio::Location::Split->new();
foreach $encode_regions ....{
$splitlocation->add_sub_Location(Bio::Location::Simple->new(-start=>$start,-end=>$end,- strand=>$strand,-splittype=>"join"));
}
$exones = new Bio::SeqFeature::Generic(
-primary_tag => 'Encode Regions',
-location=>$splitlocation
);
I am trying to read all the status messages of a user. I have used the following code.
//gets statusid, message and uid of the user
function get_status_message($access_token){
// Run fql query
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=SELECT+message+,+status_id+,+uid+FROM+status+WHERE+uid=me()'
. '&access_token=' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
//display results of fql query
echo '<pre>';
print_r("query results:");
print_r($fql_query_obj);
echo '</pre>';
return $fql_query_obj;
}
It returns the following
query results:Array
(
[data] => Array
(
[0] => Array
(
[message] => test3
[status_id] => 5.0606879274642E+14
[uid] => 1.0000029926744E+14
)
[1] => Array
(
[message] => test2
[status_id] => 5.060443560822E+14
[uid] => 1.0000029926744E+14
)
[2] => Array
(
[message] => testing !
[status_id] => 5.0304255638238E+14
[uid] => 1.0000029926744E+14
)
)
)
I have to retrieve the status id and put it in mysql db. I tried foreach but I am unable to loop. The code below works
but I need to explicitly give the first index value as $value*[0]*["status_id"]. Can someone please help
You need to check if the Facebook call actually retrieved data for you to process then loop through the result and insert to your DB, with something like:
if(!empty($fql_query_obj['data'])) {
foreach($fql_query_obj['data'] as $status) {
$status_id = $status['status_id'];
// create SQL insert batch
}
// Run the insert batch
}
I have a Problem with the Querybuilder,
$qb = $this->_em->createQueryBuilder();
$qb->select('k, l')
-> i got a array such as
Array
(
[0] => Array
(
[id] => 15
-> ok
when i do
$qb->select('k.id, l.title')->add('from', 'Base\Entities\Company k')
i get
Array
(
[0] => Array
(
[id] => 15
[title] =>
)
-> ok
ISSUE:
When id do:
$qb->select('k, l.title')->add('from', 'Base\Entities\Company k')
i get:
Array
(
[0] => Array
(
[0] => Array
(
[id] => 15
i always do $result = $query->getArrayResult(); at the End
how can i remove the array in the array? i only want title as part of the array in k (like above)
I believe it's not really possible to do so, You'll have to iterate over the results to achieve this. You can read more about it in documentation.