I have one input file which is given below.
Values,series,setupresultcode,nameofresultcode,resultcode
2,9184200,,serviceSetupResultempty,2001
11,9184200,0,successfulReleasedByService,2001
194,9184200,1,successfulDisconnectedByCallingParty,2001
101,9184200,2,successfulDisconnectByCalledParty,2001
2,9184201,0,successfulReleasedByService,2001
78,9184201,1,successfulDisconnectedByCallingParty,2001
32,9184201,2,successfulDisconnectByCalledParty,2001
4,9184202,0,successfulReleasedByService,2001
63,9184202,1,successfulDisconnectedByCallingParty,2001
37,9184202,2,successfulDisconnectByCalledParty,2001
I want output as given below:
Series,successfulReleasedByService,successfulDisconnectedByCallingParty,successfulDisconnectByCalledParty,serviceSetupResultempty
9184200,11,194,101,2
9184202,4,63,37,
Keep series as common print value of series.i.e. first column with respect to result code.i.e third(integer) or fourth(string) column in input file.
For example: the second column of the data has n number of series; take 9184200. That series having 4 setupresultcode (empty,0,1,2). Name of each result code is given in 4th column. I want to print if resultcode is 0; i.e. successfulReleasedByService then print value 11 with respect to series 9184200.
Something like this might work although I haven't tested it, regard it as some kind of pseudo code.
#!/bin/awk -f
BEGIN
{
number_of_series=0;
}
{
#This part will be executed for every line
if ($3 =="0" || $3 == "1" || $3 == "2")
{
for (i=1; i<=number_of_series; i++)
{
#If the series has already been added
if(seriesarray[i] == $2)
{
#Concat the results
seriesarray[$2]=seriesarray[$2]","$1;
}
#If it's a new series
else
{
number_of_series++;
seriesarray[$2]=$1;
}
}
}
}
END
{
#Iterate over the series and print the series id and the concatenated results
for (series in seriesarray)
{
print series, seriesarray[series];
}
}
This would yield something like
9184200,11,194,101
9184201,2,78,32
9184202,4,63,37
Related
I have a collection of transactions with relations and I would like to sum column separated by condition of relation column. Right now I have this:
$delegatedProvision = 0;
$ownProvision = 0;
foreach ($transactions as $transaction) {
if ($transaction->discount->consider_improvement) {
$delegatedProvision += $transaction->stats->$column;
continue;
}
$ownProvision += $transaction->stats->$column;
}
$this->salesCollection->put('delegatedProvision', $delegatedProvision);
$this->salesCollection->put('ownProvision', $ownProvision);
It works but I would like to use Laravel collections. So far I have just this:
$provision = $transactions->sum(function ($transaction) use ($column) {
return $transaction->stats->$column;
});
And I don't know how to use condition in sum() method and according column $transaction->discount->consider_improvement (which is boolean) have sum in separated variables. I can use filter each for different consider_improvement but it means that I have to iterate all transactions twice.
Try this:
$collection->where(/* your condition */)->sum($column);
So i have a TelerikUigrid and im trying to use serverside filtering and i have a very weird issue.
So when i filter 1 single column of the grid everything works as intended but when i filter 2 or more columns at the same time i encounter it doesn't work.
The problem happens because the my 2 filtered columns both get saved in a single object that is not loopable so in this example below if i filter 2 columns filter will have a count of 2 but is not loopable so i can't "split" the objects.
So when there is a single object in filter it works fine because there is only 1 to choose from but when there is 2 or more Visual Studio doesn't know which one it should choose so my variable remails a null.
if (request.filter != null && request.filter.Any())
{
foreach(var filter in request.filter)
{
var filterDescriptor = filter as FilterDescriptor;
if (filterDescriptor.Value != null)
{
//Code
}
}
If you have two filters then the filter comes in as an object called CompositeFilterDescriptor.
You'll need something like this:
for (var i = 0; i < filters.Count; i++)
{
if (filters[i] is CompositeFilterDescriptor)
{
var outerCompositeFilter = (CompositeFilterDescriptor)filters[i];
for (var j = 0; j < outerCompositeFilter.FilterDescriptors.Count; j++)
{
if (outerCompositeFilter.FilterDescriptors[j] is FilterDescriptor)
{
// Do something with this filter
}
}
}
if (filters[i] is FilterDescriptor)
{
// Only 1 filter - do something with it
}
}
I am using RStudio, I have a programm and I want to see the value of each parameter in each iteration. I am seeing only value of parameters on the last iteration.
Here is my R code:
k<-read.csv("D:\\Testc.csv")[,1:5]
window<-64
stelle<-""
spalte<-1
co<-0
r<-1
l<-(2/sqrt(window))
while(spalte < 3)
{
datalist<-matrix(k[,spalte])
while(r+window<=length(datalist[,1]))
{
m<-acf(as.numeric(datalist[r:(r+window),1]),lag.max=32,plot=FALSE)$acf[-1]
for(i in (1:32))
{
if(m[i]>l)
{
co<-co+1
}
}
if(co>5)
{
row<-as.character(r)
spalte<-as.character(spalte)
pos<-rbind(row,spalte)
stelle<-c(stelle,"-",pos)
}
r<-r+30
co<-0
}
spalte<-spalte+1
}
stelle
I want to see the value of co ,spalte, stelle on each iteration. On the left side of RStudio on Workspace tab I see values only for last iteration.
place the following code into your loop at the end:
print(paste("co=", co))
print(paste("spalte=", spalte))
print(paste("stelle=", stelle))
I have a simple button and i want to make some transitions.
If current frame is 1 I want to play frame 2.
If current frame is 2 I want to play frame 3.
If current frame is 3 I want to play frame 1.
Why my script doesn't work in ActionScript 3.0? Thanks.
buton1.addEventListener(MouseEvent.CLICK, buton1Click);
function buton1Click(event:MouseEvent):void{
if(currentFrame == 1){
gotoAndStop(2);
}
if(currentFrame == 2){
gotoAndStop(3);
}
if(currentFrame == 3){
gotoAndStop(1);
}
}
Your if blocks are always true - you move to the next frame and than test if you're on that frame.
Given your button spans timeline, like so:
Your code would be:
stop();
button1.addEventListener(MouseEvent.CLICK, button1Click);
function button1Click(event:MouseEvent):void
{
switch (currentFrame)
{
case 1:
gotoAndStop(2);
break;
case 2:
gotoAndStop(3);
break;
case 3:
gotoAndStop(1);
break;
}
}
stop();
stage.addEventListener(MouseEvent.CLICK, button1Click);
function button1Click(event:MouseEvent):void {
this.gotoAndStop((this.currentFrame % this.totalFrames) + 1);
}
//this way you can change the timeline without changing code
Here is what I have so far, this is returning two columns, but each counter is stopping and then duplicating the same value over and over...
if(lLogisticsControlTable.APMJobTypeId)
select count (RecID) from jobTypeCheck where jobTypeCheck.APMJobTypeId == lLogisticsControlTable.APMJobTypeId;
{
counter = jobTypeCheck.RecId;
}
while select jobTypeCheck where jobTypeCheck.APMJobTypeId == lLogisticsControlTable.APMJobTypeId
{
counter1 = counter / 2;
halfCount1 = counter - counter1;
if(halfcount <= counter1)
{
halfCount++;
jobListCheck1 = jobTypeCheck.Name;
}
if (halfCount1 > halfCount)
{
halfCount1++;
jobListCheck2 = jobTypeCheck.Name;
}
element.execute(2);
}
}
As Michael Brown indicated, it's difficult to understand the problem with half of the code ;)
However, I would suggest that you call the element.execute(2) method on every second pass through the loop? That way jobListCheck1 would be on the left, and jobListCheck2 would be on the right hand side. Finally you would then need to check immediately outside of your loop if you had an odd number of jobTypeCheck elements, and call the element.execute(2) method one last time remembering to set the jobListCheck2 variable as empty beforehand.
Regards