Kapacitor Tickscript aggregate and combine collection of multiple instance of the processes into one

This is an important use case for us.

How can one write a stream tickscript which will aggregate and combine collection of multiple (instance#) of the same Process into one and calculate average Percent_Processor_Time.

Example: measurement Process has instance tag which stores name of the .exe like:

instance, Percent_Processor_Time
WmiPrvSE#1, 1.0
WmiPrvSE#2, 0.1
WmiPrvSE#3, 0.3
instance, Percent_Processor_Time
Chrome#1, 1.0
Chrome#2, 0.0
Chrome#3, 2.0

Goal is to combine same Process into one and get the Average:

instance, Percent_Processor_Time
WmiPrvSE, 0.46
Chrome, 1.00

I tried the creating a stream tickscript but it was not giving any output.
So i tried batch and it is yielding an output but not grouping the instance into one.
Do i have to use regex explicitly on instance?

Objective is to get .exe cpu usage divided by the number of cpu present on the server.

// Get Percent_Processor_Time for each process
        var process = batch
            |query('SELECT Percent_Processor_Time as cpu_time FROM "test"."autogen"."Process"')
                .groupBy('instance', 'host')

    // This is to get number of cpus from each host
        var system = batch
            |query('SELECT n_cpus as n_cpus FROM "test"."autogen"."system"')

        var joined_data = process
                .as('process', 'system')

        var perform = joined_data
            |eval(lambda: "process.cpu_time" / "system.n_cpus")