splitting text file into array correctly with -split operator - regex

I have a text file that looks like this:
      ;MPV_F4(isHold, taps, state)
      MPV_F5(isHold, taps, state)
         {
            if (taps == 1)
            {
                  if (isHold == 0)
                  {
                   ;[HV] T1 | cycle  mute | This is long LONG
                     Sendinput, {U+0398}  ;Θ ;   ;[rr] [cycle mute         ]
                  }
                  else
                  {
                    if (state)
                                          {
                                             while GetKeyState("f5", "p"){
                                                   Sendinput, {U+0399}  ;Ι ;   ;[rr] [add volume 10    ]  
                                                     sleep, 55
                                                 }  
                                          }
                          ; else
                          ;           {
                          ;           }
                  }
            }
         }      
      MPV_F6(isHold, taps, state)
      ;MPV_F7(isHold, taps, state)
      ;MPV_F8(isHold, taps, state)
      ;MPV_F9(isHold, taps, state)
      ;MPV_F11(isHold, taps, state)
      MPV_N2(isHold, taps, state)
         {
            if (taps == 1)
            {
                  if (isHold == 0)
                  {
                   ;[HV] T1 | cycle  mute | This is long LONG
                     Sendinput, {U+0398}  ;Θ ;   ;[rr] [cycle mute         ]
                  }
                  else
                  {
                    if (state)
                                          {
                                             while GetKeyState("f5", "p"){
                                                   Sendinput, {U+0399}  ;Ι ;   ;[rr] [add volume 10    ]  
                                                     sleep, 55
                                                 }  
                                          }
                          ; else
                          ;           {
                          ;           }
                  }
            }
         }
      ;MPV_N3(isHold, taps, state)
      ;MPV_N4(isHold, taps, state)
      ;MPV_N5(isHold, taps, state)
which essentially consists of a repeating pattern of:
FunctionName(isHold, taps, state)
{
<Function Body>
}
I am trying to break it down into arrays that consists of the function name and body. I cant use the string MPV in my regex as there are other similar texts files whose function names does not contain MPV.
My exepected output is:
$MyVar [0] :
      MPV_F5(isHold, taps, state)
         {
            if (taps == 1)
            {
                  if (isHold == 0)
                  {
                   ;[HV] T1 | cycle  mute | This is long LONG
                     Sendinput, {U+0398}  ;Θ ;   ;[rr] [cycle mute         ]
                  }
                  else
                  {
                    if (state)
                                          {
                                             while GetKeyState("f5", "p"){
                                                   Sendinput, {U+0399}  ;Ι ;   ;[rr] [add volume 10    ]  
                                                     sleep, 55
                                                 }  
                                          }
                          ; else
                          ;           {
                          ;           }
                  }
            }
         }
$MyVar [1] :
      MPV_N2(isHold, taps, state)
         {
            if (taps == 1)
            {
                  if (isHold == 0)
                  {
                   ;[HV] T1 | cycle  mute | This is long LONG
                     Sendinput, {U+0398}  ;Θ ;   ;[rr] [cycle mute         ]
                  }
                  else
                  {
                    if (state)
                                          {
                                             while GetKeyState("f5", "p"){
                                                   Sendinput, {U+0399}  ;Ι ;   ;[rr] [add volume 10    ]  
                                                     sleep, 55
                                                 }  
                                          }
                          ; else
                          ;           {
                          ;           }
                  }
            }
         }
At first I tried to use Get-Content's -Delimeter parameter:
$mytextfile = "c:\temp\mytextfile.txt"
Get-content $mytextfile -Delimiter '.*[^;]\(isHold, taps, state\)'
It keeps returning the entire content as a single object, After a few more variations I resorted to just using Get-Content -Raw and then -Split operator:
$MyVar = $mytextfile -Split (?m).*[^;]\(isHold, taps, state\)(?s).*\}
I continue to get unexpected results, most commonly the entire content being returned instead of arrays.
I am using RegEx101*, and options are closesly aligned to what powershell expects. I have tried many variations with no desired results.
Here is a link my RegEx101 page.
What could I be doing wrong here?
Any help would be truelly wellcome.

Try the following:
$MyVar =
[regex]::Matches(
(Get-Content -Raw $mytextfile),
'(?sm)\w+\(isHold, taps, state\)\s*\{(?:.(?!\w+\(\w))+\}'
).Value
Note that this approach is computation-intensive and relies on detecting the end of a function not by properly detecting nested { / } pairs, but by assuming that the presence of any subsequent <funcname>(<wordcharacter> substring (e.g. 'MPV_F6(i') implies that the most recent } ended the function body.
See this regex101.com page.

Related

How do i change process relations from PIPE to FIFO?

There is a task:
Write a program to calculate the sum of matrix elements. The matrix is entered from a file. The calculation of the sums of the elements
of each row is performed in separate processes. To transfer data to the parent process, use
the named pipe mechanism (FIFO).
I found this solution, however it does not meet all the requirements:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
 
 
using namespace std;
 
 
 
int main(){
    int fd[2];
    int i,j;
    int p[2];
    int arr[2][2];
    int marr[2];
    FILE *file = fopen("matrix","r");
    if (!file)
        printf("NO FILE");
    for(i = 0; i < 2; i++){
        for(j = 0; j < 2; j++){
            fscanf(file, "%d", &arr[i][j]);
            printf("%d ", arr[i][j]);
        }
        printf("\n");
    }
 
    if(pipe(fd) < 0) {
        printf("Pipe error!\n");
        return 1;
    }
    int max=arr[0][0];
 
    for (int i=0; i<2; i+=1){
        p[i]=fork();
        if(p[i]==0){
        printf("%d subprocess\n", i);
        max=arr[i][0];
            for(j=0; j<2; j++){
                if(max<arr[i][j]){
                    max=arr[i][j];
                    }
                }
            close(fd[0]);
        printf("write to pipe: max=%d i=%d\n", max, i);
            write(fd[1],&max,sizeof(int));
            write(fd[1],&i,sizeof(int));
            exit(0);
        }
        else{
           
        }
    }
 close(fd[1]);
            for(int k=0; k<2; k++){
                read(fd[0],&max,sizeof(int));
                read(fd[0],&i,sizeof(int));
        printf("read from pipe: max=%d i=%d\n", max, i);
                marr[i]=max;
            }
   printf("massiv max:\n");
    for(i=0; i<2; i++){
        printf("%d\n",marr[i]);
    }
    fclose(file);
    return 0;
}
I tried to somehow change the relationship between the processes from pipe to fifo, but I can't check, because the
code needs to be run on a linux virtual machine, and in QT the SIGSEGV error appears on the line
fscanf(file, "%d", &arr[i][j]);
, the reasons for which,
as I understand it, can be very different.
The test file for this code will look like:
3 4
5 6
and it finds the maximum of each row. It won't be difficult for me to redo it for my task, the main problem is in fifo.
I will be grateful for any hints.

AUv3 extension based on AVAudioUnitSampler not registered

I created a multi-timbral instrument application based on multiple AVAudioUnitSampler instances (one per Midi channel), wrapped in a custom AVSampler class.
I want to expose it also as an AUv3. I followed some articles and samples and put the view controller and other classes in a Framework target, created an AudioUnit extension target (with a dummy/empty class file as I've no implementation to provide).
In the extension's Info.plist (NSExtensionAttributes) I added AudioComponentBundle (points to the AUFramework) and AudioComponents item with factoryFunction (points to $(PRODUCT_MODULE_NAME).MultiSamplerViewController), aumu type. Also added NSExtensionPrincipalClass pointing to AUFramework.MultiSamplerViewController.
In the shared MultiSamplerViewController I implemented
(AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
return [[[multiSampler engine] outputNode] AUAudioUnit];
}
It also contains an - (id)initWithCoder:(NSCoder*)decoder method, that instantiates the wrapping MultiSampler and starts an enclosed MidiManager.
The host application target runs fine, however the AU extension plugin isn't listed in GarageBand (even after runnig the host application once). The target platform is iPad.
I added code to load the appex plugin bundle, however it doesn't seem enough to register the plugin. Also I cannot use the AUAudioUnit registerSubclass as I've no concrete AU implementation class (only my wrapper class).
I'm in the same configuration as an application built on AudioKit framework (that originally wrapped AVAudioUnitSampler - and now uses a custom implementation). I looked into AudioKit code and found they implemented AudioUnit protocols methods in their wrapper class (https://github.com/AudioKit/AUv3-Example-App/blob/master/Example%20Plugin%20App%20AU/Audio%20Unit/ExampleApp_AudioUnit.swift). However I don't know what to do in AUAudioUnit methods implementation (setOutputBusArrays, allocateRenderResources, internalRenderBlock, etc.)
EDIT :
I may have to implement AUaudioUnit callbacks.
To pass mainMixerNode buffers to AUaudioUnit render callback I could store (in memory, so would grow over time... not ideal) these through installTapOnBus, and then access these from render callback.
AVSampler : AUAudioUnit
createAudioEngine
  ...
 [mixerNode installTapOnBus:0
                    bufferSize:4096
                        format:[[AVAudioFormat alloc]initWithStreamDescription:&audioFormat]
                         block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
                            
[self.timeToBuffer addObject:buffer forKey:when];
}];
(AUInternalRenderBlock)internalRenderBlock {
  return ^AUAudioUnitStatus(AudioUnitRenderActionFlags    *actionFlags,
                              const AudioTimeStamp     *timestamp,
                              AVAudioFrameCount     frameCount,
                              NSInteger     outputBusNumber,
                              AudioBufferList     *outputBufferListPtr,
                              const AURenderEvent     *realtimeEventListHead,
                              AURenderPullInputBlock     pullInputBlock ) {
        
        int outputNumBuffers = outputBufferListPtr->mNumberBuffers;
float *ptrLeft  = (float*)outputBufferListPtr->mBuffers[0].mData;
        float *ptrRight = NULL;
        if (outputNumBuffers == 2) {
            ptrRight = (float*)outputBufferListPtr->mBuffers[1].mData;
        }
AVAudioPCMBuffer *mixerNodeBuffer = [self.timeToBuffer objectForKey:timestamp];
mixerNodeBuffer.audioBufferList.pointee.mBuffers
int n = frameCount;
if(mixerNodeBuffer.frameLength == frameCount)
for (int i=0;i<n;i++) {
    ptrLeft[i] = mixerNodeBuffer.floatChannelData[0].pointee[n];
    ptrRight[i] = mixerNodeBuffer.floatChannelData[1].pointee[n];
}
  }
}

Sum up Rows with same ID and Ignore Smaller Category

I have a very large dataset with multiple columns to sum and categories, but here is an example of what i am trying to do:
I want to sum up the "dollars" column to the total Account Number level based on which line with account number has the highest number in the "people" column.  So there is just 1 line for every account number, and the State column will have whichever state has the higher people in it.
Account Number       State        Dollars          People
1                      MA             200             5
1                     NY             100             2
2                      CT            150             3
3                      OH             100             3
4                     VA             300             7
4                      FL             100             3
and it will look like this after the code:
Account Number       State        Dollars          People
1                     MA             300             7
2                      CT             150            3
3                      OH             100             3
4                      VA             400            10
I think this may be a simple fix but please help!
Thanks in advance!!
proc sql;
create table T2 as
select 'Account Number'n, State, sum(Dollars) as Dollars, sum(People) as People, People as People_Order
from T1
group by 'Account Number'n
order by People_Order desc
;quit;
/* keep the first row within previously performed Order By: */
proc sort data=T2 (drop=People_Order) nodupkey; by 'Account Number'n;run;

Power Bi , Average constant values in column rather than rolling average?

Sorry I'm lost I really appreciate if you can help me calculate the follwoing
So I've a table two fy data LY(Last Year) FY2020 and (This Year) or FY2021, 
 I would like to compare this year we spent on Agency vs Avg Spent on LY
Agency spend vs last year average; expressed as % of total people costs spend in month
The table output is like
                       2020                                              2021
F_Month  AgencyPaid2020  msrAgencyPayPrv  AgencyPay        msrAgencyPayPrv
1                217922                  18161                  37930                 18161
2                296460                   24705                56155                  24705
3                298863                  24905                     0                       24905
.                   xxxx                     xxxxx                       0                       xxxx
.
12               110166                   9181                      0           
---             ---------              ------------         -------------         --------------
Total         169955                 141630                18225                      141630
I'm expecting 141630 should show in all rows for above table(Col2) but when I drag the measure into table its calculating differently 
The measure I've calculated is 
> msrAgencyPayPrvYearAvg =
> CALCULATE(SUM(Data[IM_Actual_Positive]),Data[EBITDA]="2
> Pay",Data[PayCat_1]="Agency",Data[int_fyear]=2020)/12'''
Thanks for you help
The 4th column should not show 2021 is there a way I can hide as its coming because in the 'Visualization' under column I've put 'int_fyear' column
and vales I've (Agency Pay and msrAvgAgencyPay) , sorry I 've lost the plot
Kind regards,
Farhan
I've found the answer I should use the following function
msrAgencyPaySheet =
CALCULATE(Sum(Sheet1[Actual]),filter(ALLSELECTED(Sheet1), Sheet1[FY]=2020))/12

Creating Soap Request WSDL

Im new in soap request, my client send me sample request format but he told me that I was'nt able to pass the parameter correctly. I dont know if my codes are the problem, I paste the sample request and my code
Thanks
here is the sample request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:card="http://placeholder/CARD">
   <soapenv:Header/>
   <soapenv:Body>
      <card:CardPrinting>
         <!--Optional:-->
         <WebRequestCommon>
            <!--Optional:-->
            <company></company>
            <password></password>
            <userName>CARDPRINTING</userName>
         </WebRequestCommon>
         <!--Optional:-->
         <PSSLAICARDPRINTINGType>
            <!--Zero or more repetitions:-->
            <enquiryInputCollection>
               <!--Optional:-->
               <columnName>CUSTOMER.CODE</columnName>
               <!--Optional:-->
               <criteriaValue>100115</criteriaValue>
               <!--Optional:-->
               <operand>EQ</operand>
            </enquiryInputCollection>
         </PSSLAICARDPRINTINGType>
      </card:CardPrinting>
   </soapenv:Body>
</soapenv:Envelope>
Here is my code is
$client = new SoapClient('http://placeholder/CARD/services?wsdl');
$params = array(
'WebRequestCommon'=>array(
'company'=>'',
'password'=>'123456',
'userName'=>'TAMIZH4'
),
'PSSLAICARDPRINTINGType'=>array(
'enquiryInputCollection'=>array(
'columnName'=>'CUSTOMER.CODE',
'criteriaValue'=>'100115',
'operand'=>'EQ'
)
)
);
$students = $client->CardPrinting($params);