问:
hotkey does not close Seleinum Webdriver session when pressed (python)
im practically a fetus when it comes to python programming and i hope some of you gods would be able to help me. basically i have a loop set up that pulls values from a website but i need it run indefinitely until i press the specified hotkey which is q, the loop runs and pulls the data needed, but whenever i press q, the loop simply keeps running and i have to close the browser manually.

here is the piece of code in question:

```<code>from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
import time
import keyboard

PATH = r"C:\Users\username"
options = Options()
options.binary_location = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
ser = Service(executable_path=ChromeDriverManager().install())
cweb = webdriver.Chrome(service=ser, options=options)

class Coin:
    def __init__(self, coinname, datasource):
         self.coinname = coinname
         self.datasource = datasource

    def pulldata(self):
         self.values = []
         time.sleep(5)
         cweb.get(self.datasource)
         time.sleep(5)

         price = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div[1]/div/span')
         percent = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div[1]/span')
         upordown = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div[1]/span/span')
         caret = upordown.get_attribute('class')

         if caret == 'icon-Caret-up':
             daychange = ('' + percent.text)

         elif caret == 'icon-Caret-down':
             daychange2 = ('-' + percent.text)

         vol = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[3]/div[1]/div[3]/div[1]/div[2]/div')
         mkcap = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[3]/div[1]/div[1]/div/div[2]/div')
         circsupply = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[3]/div[1]/div[4]/div[2]/div[1]')
         self.values.append(price.text)

         if caret == 'icon-Caret-up':
               self.values.append(daychange)
         elif caret == 'icon-Caret-down':
               self.values.append(daychange2)

         self.values.append(vol.text)
         self.values.append(mkcap.text)
         self.values.append(circsupply.text)
         print(self.values)

def kill_chromedriver():
  for proc in psutil.process_iter():
       if proc.name() == "chromedriver.exe":
            proc.kill()
       if proc.name() == "chrome.exe":
            proc.kill()

while True:
   btc = Coin('Bitcoin','https://coinmarketcap.com/currencies/bitcoin/')
   btc.pulldata()
   btc2 = Coin('Bitcoin','https://coinmarketcap.com/currencies/tether/')
   btc2.pulldata()

   if keyboard.is_pressed('q'):
        kill_chromedriver()
        break

</code>```

print('done reading')

so how do i edit this code, so that the driver closes and the loop stops on command?
ive tried positioning the break statement in different places, and also placing the cweb.close() function out of the loops. ill continue running through other options. i would be extremely grateful for any tips or help.

edits: took some help from an extremely useful lad, but it seems as if pressing the hotkey is recognized by the computer and python, but not recognized by selenium or the browser session itself.
wish i knew more about code like yall do lmao

G-man

答:
I've found .quit() to fail sometimes with selenium. You can use psutil instead. Call this function in the if keyboard.is_pressed('q'): block.

```<code>import psutil

def kill_chromedriver():
    for proc in psutil.process_iter():
        if proc.name() == "chromedriver.exe":
            proc.kill()
</code>```

Edit: I think your issue might be related to read_key() not executing until the data are pulled. I tested this on my cpu in Jupyter and it worked.

```<code>while True:
    btc = Coin('Bitcoin','https://coinmarketcap.com/currencies/bitcoin/')
    btc.pulldata()
    btc2 = Coin('Bitcoin','https://coinmarketcap.com/currencies/tether/')
    btc2.pulldata()

    print("You can press q now.")
    if keyboard.read_key() == "q":

        kill_chromedriver()
        break
</code>```

Body:
im practically a fetus when it comes to python programming and i hope some of you gods would be able to help me. basically i have a loop set up that pulls values from a website but i need it run indefinitely until i press the specified hotkey which is q, the loop runs and pulls the data needed, but whenever i press q, the loop simply keeps running and i have to close the browser manually.

here is the piece of code in question:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
import time
import keyboard

PATH = r"C:\Users\username"
options = Options()
options.binary_location = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
ser = Service(executable_path=ChromeDriverManager().install())
cweb = webdriver.Chrome(service=ser, options=options)

class Coin:
    def __init__(self, coinname, datasource):
         self.coinname = coinname
         self.datasource = datasource

    def pulldata(self):
         self.values = []
         time.sleep(5)
         cweb.get(self.datasource)
         time.sleep(5)

         price = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div[1]/div/span')
         percent = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div[1]/span')
         upordown = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[2]/div[1]/span/span')
         caret = upordown.get_attribute('class')

         if caret == 'icon-Caret-up':
             daychange = ('' + percent.text)

         elif caret == 'icon-Caret-down':
             daychange2 = ('-' + percent.text)

         vol = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[3]/div[1]/div[3]/div[1]/div[2]/div')
         mkcap = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[3]/div[1]/div[1]/div/div[2]/div')
         circsupply = cweb.find_element(By.XPATH, '//*[@id="__next"]/div[1]/div[1]/div[2]/div/div[1]/div[2]/div/div[3]/div[1]/div[4]/div[2]/div[1]')
         self.values.append(price.text)

         if caret == 'icon-Caret-up':
               self.values.append(daychange)
         elif caret == 'icon-Caret-down':
               self.values.append(daychange2)

         self.values.append(vol.text)
         self.values.append(mkcap.text)
         self.values.append(circsupply.text)
         print(self.values)

def kill_chromedriver():
  for proc in psutil.process_iter():
       if proc.name() == "chromedriver.exe":
            proc.kill()
       if proc.name() == "chrome.exe":
            proc.kill()

while True:
   btc = Coin('Bitcoin','https://coinmarketcap.com/currencies/bitcoin/')
   btc.pulldata()
   btc2 = Coin('Bitcoin','https://coinmarketcap.com/currencies/tether/')
   btc2.pulldata()

   if keyboard.is_pressed('q'):
        kill_chromedriver()
        break

print('done reading')

so how do i edit this code, so that the driver closes and the loop stops on command?
ive tried positioning the break statement in different places, and also placing the cweb.close() function out of the loops. ill continue running through other options. i would be extremely grateful for any tips or help.

edits: took some help from an extremely useful lad, but it seems as if pressing the hotkey is recognized by the computer and python, but not recognized by selenium or the browser session itself.
wish i knew more about code like yall do lmao

G-man

Body:
I've found .quit() to fail sometimes with selenium. You can use psutil instead. Call this function in the if keyboard.is_pressed('q'): block.

import psutil

def kill_chromedriver():
    for proc in psutil.process_iter():
        if proc.name() == "chromedriver.exe":
            proc.kill()

Edit: I think your issue might be related to read_key() not executing until the data are pulled. I tested this on my cpu in Jupyter and it worked.

while True:
    btc = Coin('Bitcoin','https://coinmarketcap.com/currencies/bitcoin/')
    btc.pulldata()
    btc2 = Coin('Bitcoin','https://coinmarketcap.com/currencies/tether/')
    btc2.pulldata()

    print("You can press q now.")
    if keyboard.read_key() == "q":

        kill_chromedriver()
        break


来源: stackexchange

问:
How can i use placeholder after send buttons to user concurrently
In Python Telegram bot i was using this code to make placeholder and replymarkup but I don't see like that in telethon.

```<code>reply_keyboard = [
        ['test']
    ]
    reply_keyboard_markup = ReplyKeyboardMarkup(keyboard=reply_keyboard,one_time_keyboard=True,resize_keyboard=True,input_field_placeholder='pm')
    update.message.reply_text('''test
''',reply_markup = reply_keyboard_markup)
</code>```

答:
You can build a reply markup in telethon nesting lists too, but instead of strings you must storage telethon.tl.custom.button.Button instances, check the documentation here to get a better understanding of Button methods.

Building a simple keyboard as the showed in your image:

from telethon import Button

async def handler(event):
    await event.respond(
        'Hello!',
        buttons=Button.text(
            text=' Hello, World!',
            resize=True,
            single_use=True
        )
    )
```
<p>You get this.</p>
<p>I think you cannot mix placeholder with a text keyboard in <code>telethon</code>. You can make a placeholder using <code>Button.force_reply</code>:</p>
<pre class="lang-py prettyprint-override"><code>async def handler(event):
    await event.respond(
        'Hello!',
        buttons=Button.force_reply(
            single_use=True,
            placeholder='Say something'
        )
    )
</code>```

This is the result.

ContentLicense: CC BY-SA 4.0

Body:
In Python Telegram bot i was using this code to make placeholder and replymarkup but I don't see like that in telethon.

reply_keyboard = [
        ['test']
    ]
    reply_keyboard_markup = ReplyKeyboardMarkup(keyboard=reply_keyboard,one_time_keyboard=True,resize_keyboard=True,input_field_placeholder='pm')
    update.message.reply_text('''test
''',reply_markup = reply_keyboard_markup)

Body:
You can build a reply markup in telethon nesting lists too, but instead of strings you must storage telethon.tl.custom.button.Button instances, check the documentation here to get a better understanding of Button methods.

Building a simple keyboard as the showed in your image:

from telethon import Button

async def handler(event):
    await event.respond(
        'Hello!',
        buttons=Button.text(
            text=' Hello, World!',
            resize=True,
            single_use=True
        )
    )

You get this.

I think you cannot mix placeholder with a text keyboard in telethon. You can make a placeholder using Button.force_reply:

async def handler(event):
    await event.respond(
        'Hello!',
        buttons=Button.force_reply(
            single_use=True,
            placeholder='Say something'
        )
    )

This is the result.


问:
"Undefined symbol" error with my functions when using classes
I'm writing a program that calculates the area and diameter using classes and functions. My issue is that I'm getting an undefined symbol error with my functions. I'm sure it's probably an easy fix ... I just can't figure it out.

(Writing the code on a mac)

Here's the code:

```<code>#include<iostream>
using namespace std;

class Circle
{
  public:
  int radius;

    void printArea();
    void printDiameter();
};

void Circle::printArea()
{
   double area;

   area = radius * radius * 3.14159;
   cout<<"A circle with radius "<<radius<<" has an area of "<<area<<endl;
}

void Circle::printDiameter()
{
    int diam;
   diam = radius * 2;
   cout<<"A circle with radius "<<radius<<" has a diameter of "<<diam<<endl;

}

int main()
{

   void printArea(Circle);
   void printDiameter(Circle);
   Circle aBigCircle, aLittleCircle;
   aBigCircle.radius = 50;
   aLittleCircle.radius = 4;
   printArea(aBigCircle);
   printDiameter(aBigCircle);
   printArea(aLittleCircle);
   printDiameter(aLittleCircle);

}
</code>```

答:
The printArea() and printDiameter() methods are encapsulated within the Circle class, so you must call them from an object.

#include<iostream>
using namespace std;

class Circle
{
  public:
    int radius;
    void printArea();
    void printDiameter();
};

void Circle::printArea()
{
   double area;
   area = radius * radius * 3.14159;
   cout<<"A circle with radius "<< radius <<" has an area of "<< area << endl;
}

void Circle::printDiameter()
{
   int diam;
   diam = radius * 2;
   cout<<"A circle with radius "<< radius <<" has a diameter of " << diam << endl;
}

int main()
{
   Circle aBigCircle, aLittleCircle;

   aBigCircle.radius = 50;
   aLittleCircle.radius = 4;

   aBigCircle.printArea();
   aBigCircle.printDiameter();

   aLittleCircle.printArea();
   aLittleCircle.printDiameter();

   return 0;
}
```
<p>Result:</p>
```A circle with radius 50 has an area of 7853.97
A circle with radius 50 has a diameter of 100
A circle with radius 4 has an area of 50.2654
A circle with radius 4 has a diameter of 8
```

Body:
I'm writing a program that calculates the area and diameter using classes and functions. My issue is that I'm getting an undefined symbol error with my functions. I'm sure it's probably an easy fix ... I just can't figure it out.

(Writing the code on a mac)

Here's the code:

#include<iostream>
using namespace std;

class Circle
{
  public:
  int radius;

    void printArea();
    void printDiameter();
};

void Circle::printArea()
{
   double area;

   area = radius * radius * 3.14159;
   cout<<"A circle with radius "<<radius<<" has an area of "<<area<<endl;
}

void Circle::printDiameter()
{
    int diam;
   diam = radius * 2;
   cout<<"A circle with radius "<<radius<<" has a diameter of "<<diam<<endl;

}

int main()
{

   void printArea(Circle);
   void printDiameter(Circle);
   Circle aBigCircle, aLittleCircle;
   aBigCircle.radius = 50;
   aLittleCircle.radius = 4;
   printArea(aBigCircle);
   printDiameter(aBigCircle);
   printArea(aLittleCircle);
   printDiameter(aLittleCircle);

}

Body:
The printArea() and printDiameter() methods are encapsulated within the Circle class, so you must call them from an object.

#include<iostream>
using namespace std;

class Circle
{
  public:
    int radius;
    void printArea();
    void printDiameter();
};

void Circle::printArea()
{
   double area;
   area = radius * radius * 3.14159;
   cout<<"A circle with radius "<< radius <<" has an area of "<< area << endl;
}

void Circle::printDiameter()
{
   int diam;
   diam = radius * 2;
   cout<<"A circle with radius "<< radius <<" has a diameter of " << diam << endl;
}

int main()
{
   Circle aBigCircle, aLittleCircle;

   aBigCircle.radius = 50;
   aLittleCircle.radius = 4;

   aBigCircle.printArea();
   aBigCircle.printDiameter();

   aLittleCircle.printArea();
   aLittleCircle.printDiameter();

   return 0;
}

Result:

A circle with radius 50 has an area of 7853.97
A circle with radius 50 has a diameter of 100
A circle with radius 4 has an area of 50.2654
A circle with radius 4 has a diameter of 8


问:
Socat hangs when piping stdin to tcp server
I have an embedded linux system running a tcp server.
Telnet can connect to and use the tcp server interactively just fine.

I am trying to use socat to make the same connection, by linking stdin to the tcp server, like so:

socat - tcp:localhost:8088

I get the initial response from the server, and I can type, but as soon as I press enter, the terminal hangs (I can get out of this with Ctrl + C as long as I am not using the raw socat option.)

If I do the same thing but with readline, everything mostly works as expected:

socat readline tcp:localhost:8088

However, with readline, the terminal echoes my input, and then the response from the server also echoes it. This is more than just an annoyance, since things like passwords (which should not even be echoed once) are now visible.

Ideally, I would just use stdin instead of readline, so that I could send each character as soon as I type it, and turn off stdin echo. That way, when I type a character, the tcp server receives it and echoes it immediately, but only if it is supposed to.

But socat is hanging with the stdin option for reasons I don't understand.

I'm looking for an explanation as to why stdin is locking up the thread, or a workaround possibly using readline or similar.

EDIT: Here is the dddd debug output from the socat command when I use stdin:

sh-5.0# socat -d -d -d -d -lu - tcp:localhost:8088

2022/02/04 01:34:58.805536 socat[1074] D getpid()

2022/02/04 01:34:58.807631 socat[1074] D getpid() -> 1074

2022/02/04 01:34:58.807667 socat[1074] D setenv("SOCAT_PID", "1074",
1)

2022/02/04 01:34:58.807687 socat[1074] D setenv() -> 0

2022/02/04 01:34:58.807704 socat[1074] D setenv("SOCAT_PPID", "1074",
1)

2022/02/04 01:34:58.807724 socat[1074] D setenv() -> 0

2022/02/04 01:34:58.807737 socat[1074] I socat by Gerhard Rieger and
contributors - see www.dest-unreach.org

2022/02/04 01:34:58.807752 socat[1074] I This product includes
software developed by the OpenSSL Project for use in the OpenSSL
Toolkit. (http://www.openssl.org/)

2022/02/04 01:34:58.807767 socat[1074] I This product includes
software written by Tim Hudson (tjh@cryptsoft.com)

2022/02/04 01:34:58.807781 socat[1074] D socat version 1.7.3.3 on May
25 2021 13:47:29

2022/02/04 01:34:58.807795 socat[1074] D setenv("SOCAT_VERSION",
"1.7.3.3", 1)

2022/02/04 01:34:58.807811 socat[1074] D setenv() -> 0

2022/02/04 01:34:58.807827 socat[1074] D running on Linux version #1
SMP Mon Jan 31 20:48:32 UTC 2022, release 5.4.0, machine aarch64

2022/02/04 01:34:58.807845 socat[1074] D argv[0]: "socat"

2022/02/04 01:34:58.807857 socat[1074] D argv[1]: "-d"

2022/02/04 01:34:58.807870 socat[1074] D argv[2]: "-d"

2022/02/04 01:34:58.807883 socat[1074] D argv[3]: "-d"

2022/02/04 01:34:58.807895 socat[1074] D argv[4]: "-d"

2022/02/04 01:34:58.807907 socat[1074] D argv[5]: "-lu"

2022/02/04 01:34:58.807920 socat[1074] D argv[6]: "-"

2022/02/04 01:34:58.807932 socat[1074] D argv[7]: "tcp:localhost:8088"

2022/02/04 01:34:58.807945 socat[1074] D sigaction(1, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.807960 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.807973 socat[1074] D sigaction(2, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.807987 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808000 socat[1074] D sigaction(3, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808014 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808026 socat[1074] D sigaction(4, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808040 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808053 socat[1074] D sigaction(6, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808067 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808079 socat[1074] D sigaction(7, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808092 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808105 socat[1074] D sigaction(8, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808119 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808132 socat[1074] D sigaction(11, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808146 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808158 socat[1074] D sigaction(15, 0xffffc8d63a18,
0x0)

2022/02/04 01:34:58.808172 socat[1074] D sigaction() -> 0

2022/02/04 01:34:58.808185 socat[1074] D signal(13, 0x1)

2022/02/04 01:34:58.808200 socat[1074] D signal() -> 0x0

2022/02/04 01:34:58.808213 socat[1074] D atexit(0xaaaaba73c4a0)

2022/02/04 01:34:58.808226 socat[1074] D atexit() -> 0

2022/02/04 01:34:58.808267 socat[1074] D calloc(1, 848)

2022/02/04 01:34:58.808284 socat[1074] D calloc() -> 0xaaaadd2cc680

2022/02/04 01:34:58.808304 socat[1074] D malloc(1024)

2022/02/04 01:34:58.808318 socat[1074] D malloc() -> 0xaaaadd2cca00

2022/02/04 01:34:58.808333 socat[1074] D calloc(1, 848)

2022/02/04 01:34:58.808350 socat[1074] D calloc() -> 0xaaaadd2cce10

2022/02/04 01:34:58.808364 socat[1074] D calloc(1, 848)

2022/02/04 01:34:58.808377 socat[1074] D calloc() -> 0xaaaadd2cd170

2022/02/04 01:34:58.808391 socat[1074] D isatty(0)

2022/02/04 01:34:58.808411 socat[1074] D isatty() -> 1

2022/02/04 01:34:58.808424 socat[1074] D tcgetattr(0, 0xaaaadd2ccf6c)

2022/02/04 01:34:58.808461 socat[1074] D tcgetattr(,
{00005400,00000005,00001cb2,0000083b, 4098,4098,
03,1c,7f,15,04,00,01,00,11,13,1a,00,12,0f,17,16,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00})
-> 0

2022/02/04 01:34:58.808480 socat[1074] D isatty(1)

2022/02/04 01:34:58.808494 socat[1074] D isatty() -> 1

2022/02/04 01:34:58.808507 socat[1074] D tcgetattr(1, 0xaaaadd2cd2cc)

2022/02/04 01:34:58.808542 socat[1074] D tcgetattr(,
{00005400,00000005,00001cb2,0000083b, 4098,4098,
03,1c,7f,15,04,00,01,00,11,13,1a,00,12,0f,17,16,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00})
-> 0

2022/02/04 01:34:59.141868 socat[1074] D malloc(128)

2022/02/04 01:34:59.141888 socat[1074] D malloc() -> 0xaaaadd2cd4d0

2022/02/04 01:34:59.141903 socat[1074] D malloc(128)

2022/02/04 01:34:59.141916 socat[1074] D malloc() -> 0xaaaadd2cd560

2022/02/04 01:34:59.141931 socat[1074] N reading from and writing to
stdio

2022/02/04 01:34:59.141946 socat[1074] D calloc(1, 848)

2022/02/04 01:34:59.141959 socat[1074] D calloc() -> 0xaaaadd2cd5f0

2022/02/04 01:34:59.141983 socat[1074] D malloc(1024)

2022/02/04 01:34:59.141997 socat[1074] D malloc() -> 0xaaaadd2cd9b0

2022/02/04 01:34:59.142015 socat[1074] D getaddrinfo("localhost",
NULL, {1,0,1,6,0,0x0,0x0,0x0}, 0xffffc8d63538)

2022/02/04 01:34:59.142789 socat[1074] D getaddrinfo(,,,{{AF=10
[0000:0000:0000:0000:0000:0000:0000:0001]:0, }) -> 0

2022/02/04 01:34:59.142815 socat[1074] D malloc(128)

2022/02/04 01:34:59.142830 socat[1074] D malloc() -> 0xaaaadd2ce610

2022/02/04 01:34:59.142847 socat[1074] N opening connection to AF=2
127.0.0.1:8088

2022/02/04 01:34:59.142861 socat[1074] I starting connect loop

2022/02/04 01:34:59.142876 socat[1074] D socket(2, 1, 6)

2022/02/04 01:34:59.142900 socat[1074] I socket(2, 1, 6) -> 5

2022/02/04 01:34:59.142919 socat[1074] D fcntl(5, 2, 1)

2022/02/04 01:34:59.142935 socat[1074] D fcntl() -> 0

2022/02/04 01:34:59.142954 socat[1074] D connect(5, {2,AF=2
127.0.0.1:8088}, 16)

2022/02/04 01:34:59.145199 socat[1074] D connect() -> 0

2022/02/04 01:34:59.145246 socat[1074] D getsockname(5,
0xffffc8d635b8, 0xffffc8d6359c{112})

2022/02/04 01:34:59.145269 socat[1074] D getsockname(, {AF=2
127.0.0.1:46294}, {16}) -> 0

2022/02/04 01:34:59.145286 socat[1074] N successfully connected from
local address AF=2 127.0.0.1:46294

2022/02/04 01:34:59.145306 socat[1074] I resolved and opened all sock
addresses

2022/02/04 01:34:59.145321 socat[1074] D malloc(16385)

2022/02/04 01:34:59.145344 socat[1074] D malloc() -> 0xaaaadd2cf400

2022/02/04 01:34:59.145360 socat[1074] N starting data transfer loop
with FDs [0,1] and [5,5]

2022/02/04 01:34:59.145375 socat[1074] D data loop: sock1->eof=0,
sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}

2022/02/04 01:34:59.145395 socat[1074] D select(6, &0x21, &0x22, &0x0,
NULL/0.000000)

2022/02/04 01:34:59.145426 socat[1074] D select -> (, 0x0, 0x20, 0x0,
NULL/0.000000), 1

2022/02/04 01:34:59.145443 socat[1074] D data loop: sock1->eof=0,
sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}

2022/02/04 01:34:59.145461 socat[1074] D select(6, &0x21, &0x2, &0x0,
NULL/0.000000)

2022/02/04 01:34:59.157132 socat[1074] D select -> (, 0x20, 0x0, 0x0,
NULL/0.000000), 1

2022/02/04 01:34:59.157178 socat[1074] D data loop: sock1->eof=0,
sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}

2022/02/04 01:34:59.157198 socat[1074] D select(2, &0x1, &0x2, &0x0,
NULL/0.000000)

2022/02/04 01:34:59.401692 socat[1074] D select -> (, 0x0, 0x2, 0x0,
NULL/0.000000), 1

2022/02/04 01:34:59.401732 socat[1074] D read(5, 0xaaaadd2cf400, 8192)

2022/02/04 01:34:59.401765 socat[1074] D read -> 48

2022/02/04 01:34:59.401782 socat[1074] D write(1, 0xaaaadd2cf400, 48)

ÿûÿû

Connect to IP address 169.254.12.16

2022/02/04 01:34:59.401809 socat[1074] D write -> 48

2022/02/04 01:34:59.401823 socat[1074] I transferred 48 bytes from 5
to 1

2022/02/04 01:34:59.401838 socat[1074] D data loop: sock1->eof=0,
sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}

2022/02/04 01:34:59.401856 socat[1074] D select(6, &0x21, &0x2, &0x0,
NULL/0.000000)

2022/02/04 01:34:59.462969 socat[1074] D select -> (, 0x0, 0x2, 0x0,
NULL/0.000000), 1

2022/02/04 01:34:59.463017 socat[1074] D data loop: sock1->eof=0,
sock2->eof=0, closing=0, wasaction=1, total_to={0.000000}

2022/02/04 01:34:59.463036 socat[1074] D select(6, &0x21, &0x0, &0x0,
NULL/0.000000)

At this point, I can still type, but no matter what I do, I get nothing in response.

答: Probably it is not Socat that hangs but the server. Use options -v -x to see what data Socat transfers in both situations and compare; maybe there are different line termination characters involved.</p>


问:
Metamask automation with Selenium webdriver
I'm trying to get to a Dapp that needs Metamask extension to access it. I added it through chrome extension. I know how to add the extension to the chrome instance in selenium but I don't know how to add a password etc..Could anyone download Metamask and give me an example of how I could pass credentials through selenium using it? </p>

```<code> ChromeOptions options = new ChromeOptions();
 options.addArguments("--start-maximized");
 options.addExtensions(newFile("//Applications//chrome//MetaMask_v3.13.8.crx"));
 driver = new ChromeDriver(options);
</code>```

答:
Here is simple example how you can easily create different profiles and load them. Automating extension is not that hard you simple have to open it as page and interact with it like another page.</p>
```<code>headless_options = Options()
headless_options.add_argument("--start-maximized");
headless_options.add_extension("extension_10_9_0_0.crx");
headless_options.add_argument("user-data-dir=C:/Users/V/Documents/STACKS OVERFLOW/Test")  # Save Profile
headless_options.add_argument("--profile-directory=test")  # Choose witch profile you would like to use
driver = webdriver.Chrome(options=headless_options)
driver.get(
    'chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/create-password')  # Go straight to creating Metamaks wallet

driver.switch_to.window(driver.window_handles[1])  # Switch to main tab

driver.find_element(By.ID, "create-password").send_keys("IlovePython")
driver.find_element(By.ID, "confirm-password").send_keys("IlovePython")
driver.find_element(By.CLASS_NAME, "first-time-flow__checkbox").click()

driver.find_element(By.XPATH, "//*[@id=\"app-content\"]/div/div[2]/div/div/div[2]/form/button").click()
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm trying to get to a Dapp that needs Metamask extension to access it. I added it through chrome extension. I know how to add the extension to the chrome instance in selenium but I don't know how to add a password etc..Could anyone download Metamask and give me an example of how I could pass credentials through selenium using it?

 ChromeOptions options = new ChromeOptions();
 options.addArguments("--start-maximized");
 options.addExtensions(newFile("//Applications//chrome//MetaMask_v3.13.8.crx"));
 driver = new ChromeDriver(options);

Body:
Here is simple example how you can easily create different profiles and load them. Automating extension is not that hard you simple have to open it as page and interact with it like another page.

headless_options = Options()
headless_options.add_argument("--start-maximized");
headless_options.add_extension("extension_10_9_0_0.crx");
headless_options.add_argument("user-data-dir=C:/Users/V/Documents/STACKS OVERFLOW/Test")  # Save Profile
headless_options.add_argument("--profile-directory=test")  # Choose witch profile you would like to use
driver = webdriver.Chrome(options=headless_options)
driver.get(
    'chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#initialize/create-password')  # Go straight to creating Metamaks wallet

driver.switch_to.window(driver.window_handles[1])  # Switch to main tab

driver.find_element(By.ID, "create-password").send_keys("IlovePython")
driver.find_element(By.ID, "confirm-password").send_keys("IlovePython")
driver.find_element(By.CLASS_NAME, "first-time-flow__checkbox").click()

driver.find_element(By.XPATH, "//*[@id=\"app-content\"]/div/div[2]/div/div/div[2]/form/button").click()


答:
```<code>int main()
{
   // delete printArea() and printDiameter() lines
   // void printArea(Circle);
   // void printDiameter(Circle);
   Circle aBigCircle, aLittleCircle;
   aBigCircle.radius = 50;
   aLittleCircle.radius = 4;
   aBigCircle.printArea();
   aBigCircle.printDiameter();
   aLittleCircle.printArea();
   aLittleCircle.printDiameter();

}
</code>```

Delete printArea() and printDiameter() declare in main(). It should fix your problem.

Title: "Undefined symbol" error with my functions when using classes

Body:
int main()
{
   // delete printArea() and printDiameter() lines
   // void printArea(Circle);
   // void printDiameter(Circle);
   Circle aBigCircle, aLittleCircle;
   aBigCircle.radius = 50;
   aLittleCircle.radius = 4;
   aBigCircle.printArea();
   aBigCircle.printDiameter();
   aLittleCircle.printArea();
   aLittleCircle.printDiameter();

}

Delete printArea() and printDiameter() declare in main(). It should fix your problem.


问:
Splitting CSV at each header and passing each split sequentially
I am trying to split the below CSV File based on occurrence of "Header" i.e. for the payload below , two separate CSV should pass after the application of Script. Any help for this case using Groovy/JavaScript would be helpful.

```<code>Header|1000|SA|20210902|20210902|header text-01|USD| Line|6101200|WTAppUpload-02|2000|40005001| Line|1110100|WTAppUpload-03|2000| Line|6101200|WTAppUpload-04|1500|40005002| Line|1110100|WTAppUpload-05|1500| Line|6101200|WTAppUpload-06|1500|40005003| Line|1110100|WTAppUpload-07|1500| Header|1100|SA|20210902|20210902|header text-02|USD| Line|6101200|WTAppUpload-12|2000|40005001| Line|1110100|WTAppUpload-13||2000| Line|6101200|WTAppUpload-14|1500|40005002| Line|1110100|WTAppUpload-15|1500| Line|6101200|WTAppUpload-16|1500|40005003| Line|1110100|WTAppUpload-17|1500|
</code>```

Only the last value for each Split is getting displayed by below script, we require all to be populated respectively in each split. Can someone please suggest.

```<code>def body= message.getBody(String.class);
String[] value = body.split("Header");

def arrayLength = value.size();

message.setHeader("value",arrayLength);
for(int i=1; i<=arrayLength-1;i++) {
def str = value[i];
message.setBody(str);
}
return message;
</code>```

答:
There must be a simpler way but this should do what you want for the sample string you sent

where toMod is your string

```<code>def split = toMod.splitEachLine("\\|") { it }

int counter = 0
split.each {
    def tmpMap = [:]
    def val = it.trim()
    if (val.contains("Header") || val.contains("header")) {
        counter++
    } else {
        tmpMap[counter] = val
    }
    arr.add(tmpMap)
}

def finalArr = []

for (int i = 1; i <= counter; i++) {
    def tmp = []
    arr.each {
        if (it[i] != null) {
            tmp.add(it[i])
        }

    }
    finalArr.add(tmp)
}
</code>```

Output:

```<code>[[1000, SA, 20210902, 20210902], [USD, Line, 6101200, WTAppUpload-02, 2000, 40005001, Line, 1110100, WTAppUpload-03, 2000, Line, 6101200, WTAppUpload-04, 1500, 40005002, Line, 1110100, WTAppUpload-05, 1500, Line, 6101200, WTAppUpload-06, 1500, 40005003, Line, 1110100, WTAppUpload-07, 1500], [1100, SA, 20210902, 20210902], [USD, Line, 6101200, WTAppUpload-12, 2000, 40005001, Line, 1110100, WTAppUpload-13, , 2000, Line, 6101200, WTAppUpload-14, 1500, 40005002, Line, 1110100, WTAppUpload-15, 1500, Line, 6101200, WTAppUpload-16, 1500, 40005003, Line, 1110100, WTAppUpload-17, 1500]]
</code>```

Body:
I am trying to split the below CSV File based on occurrence of "Header" i.e. for the payload below , two separate CSV should pass after the application of Script. Any help for this case using Groovy/JavaScript would be helpful.

Header|1000|SA|20210902|20210902|header text-01|USD| Line|6101200|WTAppUpload-02|2000|40005001| Line|1110100|WTAppUpload-03|2000| Line|6101200|WTAppUpload-04|1500|40005002| Line|1110100|WTAppUpload-05|1500| Line|6101200|WTAppUpload-06|1500|40005003| Line|1110100|WTAppUpload-07|1500| Header|1100|SA|20210902|20210902|header text-02|USD| Line|6101200|WTAppUpload-12|2000|40005001| Line|1110100|WTAppUpload-13||2000| Line|6101200|WTAppUpload-14|1500|40005002| Line|1110100|WTAppUpload-15|1500| Line|6101200|WTAppUpload-16|1500|40005003| Line|1110100|WTAppUpload-17|1500|

Only the last value for each Split is getting displayed by below script, we require all to be populated respectively in each split. Can someone please suggest.

def body= message.getBody(String.class);
String[] value = body.split("Header");

def arrayLength = value.size();

message.setHeader("value",arrayLength);
for(int i=1; i<=arrayLength-1;i++) {
def str = value[i];
message.setBody(str);
}
return message;

Body:
There must be a simpler way but this should do what you want for the sample string you sent

where toMod is your string

def split = toMod.splitEachLine("\\|") { it }

int counter = 0
split.each {
    def tmpMap = [:]
    def val = it.trim()
    if (val.contains("Header") || val.contains("header")) {
        counter++
    } else {
        tmpMap[counter] = val
    }
    arr.add(tmpMap)
}

def finalArr = []

for (int i = 1; i <= counter; i++) {
    def tmp = []
    arr.each {
        if (it[i] != null) {
            tmp.add(it[i])
        }

    }
    finalArr.add(tmp)
}

Output:

[[1000, SA, 20210902, 20210902], [USD, Line, 6101200, WTAppUpload-02, 2000, 40005001, Line, 1110100, WTAppUpload-03, 2000, Line, 6101200, WTAppUpload-04, 1500, 40005002, Line, 1110100, WTAppUpload-05, 1500, Line, 6101200, WTAppUpload-06, 1500, 40005003, Line, 1110100, WTAppUpload-07, 1500], [1100, SA, 20210902, 20210902], [USD, Line, 6101200, WTAppUpload-12, 2000, 40005001, Line, 1110100, WTAppUpload-13, , 2000, Line, 6101200, WTAppUpload-14, 1500, 40005002, Line, 1110100, WTAppUpload-15, 1500, Line, 6101200, WTAppUpload-16, 1500, 40005003, Line, 1110100, WTAppUpload-17, 1500]]


问:
How do I get a particular InnerText in this XML file?
I need to parse out the Amount node inside the first TotalNetChargeWithDutiesAndTaxes parent node in the sample XML below. How do I do this? I've tried a bunch of stuff but I can't figure out a way to specifically get the value by name of nodes.

The code below is what I have so far, but this is a really hacky way of doing this. I don't know if I can rely on the Amount node always being the second element of the TotalNetChargeWithDutiesAndTaxes node, so I need a way to search this XML doc specifically by the names of the nodes.

```<code>Dim elemList as XmlNodeList = Doc.GetElementsByTagName("TotalNetChargeWithDutiesAndTaxes")

MsgBox(elemList(0).ChildNodes(1).InnerText)
</code>```

The full XML:

```<code><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <RateReply xmlns="http://fedex.com/ws/rate/v31">
         <HighestSeverity>SUCCESS</HighestSeverity>
         <Notifications>
            <Severity>SUCCESS</Severity>
            <Source>crs</Source>
            <Code>0</Code>
            <Message>Request was successfully processed. </Message>
            <LocalizedMessage>Request was successfully processed. </LocalizedMessage>
         </Notifications>
         <TransactionDetail>
            <CustomerTransactionId>94c345b5-55d6-4a44-9c97-d5809179eaa4</CustomerTransactionId>
         </TransactionDetail>
         <Version>
            <ServiceId>crs</ServiceId>
            <Major>31</Major>
            <Intermediate>0</Intermediate>
            <Minor>0</Minor>
         </Version>
         <RateReplyDetails>
            <ServiceType>FEDEX_GROUND</ServiceType>
            <ServiceDescription>
               <ServiceType>FEDEX_GROUND</ServiceType>
               <Code>92</Code>
               <Names>
                  <Type>long</Type>
                  <Encoding>utf-8</Encoding>
                  <Value>FedEx GroundÂ®</Value>
               </Names>
               <Names>
                  <Type>long</Type>
                  <Encoding>ascii</Encoding>
                  <Value>FedEx Ground</Value>
               </Names>
               <Names>
                  <Type>medium</Type>
                  <Encoding>utf-8</Encoding>
                  <Value>GroundÂ®</Value>
               </Names>
               <Names>
                  <Type>medium</Type>
                  <Encoding>ascii</Encoding>
                  <Value>Ground</Value>
               </Names>
               <Names>
                  <Type>short</Type>
                  <Encoding>utf-8</Encoding>
                  <Value>FG</Value>
               </Names>
               <Names>
                  <Type>short</Type>
                  <Encoding>ascii</Encoding>
                  <Value>FG</Value>
               </Names>
               <Names>
                  <Type>abbrv</Type>
                  <Encoding>ascii</Encoding>
                  <Value>SG</Value>
               </Names>
               <Description>FedEx Ground</Description>
               <AstraDescription>FXG</AstraDescription>
            </ServiceDescription>
            <PackagingType>YOUR_PACKAGING</PackagingType>
            <DestinationAirportId>ORD</DestinationAirportId>
            <IneligibleForMoneyBackGuarantee>false</IneligibleForMoneyBackGuarantee>
            <SignatureOption>SERVICE_DEFAULT</SignatureOption>
            <ActualRateType>PAYOR_ACCOUNT_PACKAGE</ActualRateType>
            <RatedShipmentDetails>
               <EffectiveNetDiscount>
                  <Currency>USD</Currency>
                  <Amount>0.0</Amount>
               </EffectiveNetDiscount>
               <ShipmentRateDetail>
                  <RateType>PAYOR_ACCOUNT_PACKAGE</RateType>
                  <RateZone>5</RateZone>
                  <RatedWeightMethod>DIM</RatedWeightMethod>
                  <DimDivisor>139</DimDivisor>
                  <FuelSurchargePercent>11.75</FuelSurchargePercent>
                  <TotalBillingWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalBillingWeight>
                  <TotalDimWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalDimWeight>
                  <TotalBaseCharge>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalBaseCharge>
                  <TotalFreightDiscounts>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalFreightDiscounts>
                  <TotalNetFreight>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalNetFreight>
                  <TotalSurcharges>
                     <Currency>USD</Currency>
                     <Amount>1.98</Amount>
                  </TotalSurcharges>
                  <TotalNetFedExCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetFedExCharge>
                  <TotalTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalTaxes>
                  <TotalNetCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetCharge>
                  <TotalRebates>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalRebates>
                  <TotalDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesAndTaxes>
                  <TotalAncillaryFeesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalAncillaryFeesAndTaxes>
                  <TotalDutiesTaxesAndFees>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesTaxesAndFees>
                  <TotalNetChargeWithDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetChargeWithDutiesAndTaxes>
                  <Surcharges>
                     <SurchargeType>FUEL</SurchargeType>
                     <Level>PACKAGE</Level>
                     <Description>FedEx Ground Fuel</Description>
                     <Amount>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </Amount>
                  </Surcharges>
               </ShipmentRateDetail>
               <RatedPackages>
                  <GroupNumber>1</GroupNumber>
                  <EffectiveNetDiscount>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </EffectiveNetDiscount>
                  <PackageRateDetail>
                     <RateType>PAYOR_ACCOUNT_PACKAGE</RateType>
                     <RatedWeightMethod>DIM</RatedWeightMethod>
                     <BillingWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </BillingWeight>
                     <DimWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </DimWeight>
                     <BaseCharge>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </BaseCharge>
                     <TotalFreightDiscounts>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalFreightDiscounts>
                     <NetFreight>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </NetFreight>
                     <TotalSurcharges>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </TotalSurcharges>
                     <NetFedExCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetFedExCharge>
                     <TotalTaxes>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalTaxes>
                     <NetCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetCharge>
                     <TotalRebates>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalRebates>
                     <Surcharges>
                        <SurchargeType>FUEL</SurchargeType>
                        <Level>PACKAGE</Level>
                        <Description>FedEx Ground Fuel</Description>
                        <Amount>
                           <Currency>USD</Currency>
                           <Amount>1.98</Amount>
                        </Amount>
                     </Surcharges>
                  </PackageRateDetail>
               </RatedPackages>
            </RatedShipmentDetails>
            <RatedShipmentDetails>
               <ShipmentRateDetail>
                  <RateType>PAYOR_LIST_PACKAGE</RateType>
                  <RateZone>5</RateZone>
                  <RatedWeightMethod>DIM</RatedWeightMethod>
                  <DimDivisor>139</DimDivisor>
                  <FuelSurchargePercent>11.75</FuelSurchargePercent>
                  <TotalBillingWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalBillingWeight>
                  <TotalDimWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalDimWeight>
                  <TotalBaseCharge>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalBaseCharge>
                  <TotalFreightDiscounts>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalFreightDiscounts>
                  <TotalNetFreight>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalNetFreight>
                  <TotalSurcharges>
                     <Currency>USD</Currency>
                     <Amount>1.98</Amount>
                  </TotalSurcharges>
                  <TotalNetFedExCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetFedExCharge>
                  <TotalTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalTaxes>
                  <TotalNetCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetCharge>
                  <TotalRebates>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalRebates>
                  <TotalDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesAndTaxes>
                  <TotalAncillaryFeesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalAncillaryFeesAndTaxes>
                  <TotalDutiesTaxesAndFees>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesTaxesAndFees>
                  <TotalNetChargeWithDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetChargeWithDutiesAndTaxes>
                  <Surcharges>
                     <SurchargeType>FUEL</SurchargeType>
                     <Level>PACKAGE</Level>
                     <Description>FedEx Ground Fuel</Description>
                     <Amount>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </Amount>
                  </Surcharges>
               </ShipmentRateDetail>
               <RatedPackages>
                  <GroupNumber>1</GroupNumber>
                  <PackageRateDetail>
                     <RateType>PAYOR_LIST_PACKAGE</RateType>
                     <RatedWeightMethod>DIM</RatedWeightMethod>
                     <BillingWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </BillingWeight>
                     <DimWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </DimWeight>
                     <BaseCharge>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </BaseCharge>
                     <TotalFreightDiscounts>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalFreightDiscounts>
                     <NetFreight>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </NetFreight>
                     <TotalSurcharges>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </TotalSurcharges>
                     <NetFedExCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetFedExCharge>
                     <TotalTaxes>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalTaxes>
                     <NetCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetCharge>
                     <TotalRebates>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalRebates>
                     <Surcharges>
                        <SurchargeType>FUEL</SurchargeType>
                        <Level>PACKAGE</Level>
                        <Description>FedEx Ground Fuel</Description>
                        <Amount>
                           <Currency>USD</Currency>
                           <Amount>1.98</Amount>
                        </Amount>
                     </Surcharges>
                  </PackageRateDetail>
               </RatedPackages>
            </RatedShipmentDetails>
         </RateReplyDetails>
      </RateReply>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
</code>```

答:
Like this:

Public Sub test()
    Dim xDoc, nodes, oNode

    Set xDoc = CreateObject("MSXML2.DOMDocument.6.0")
    xDoc.setProperty "SelectionLanguage", "XPath"

    'Note: added an `x=` to the default namespace so we can reference it later
    xDoc.setProperty "SelectionNamespaces", _
                     "xmlns:x='http://fedex.com/ws/rate/v31'"

    xDoc.LoadXML GetContent("C:\temp\tmp.xml") 'load XML from file

    Set nodes = xDoc.SelectNodes("//x:TotalNetChargeWithDutiesAndTaxes/x:Amount")
    Debug.Print "Found: " & nodes.Length

    For Each oNode In nodes
        Debug.Print oNode.nodeTypedValue
    Next oNode
End Sub

'read all content from a text file
Function GetContent(f As String) As String
    GetContent = CreateObject("scripting.filesystemobject"). _
                  opentextfile(f, 1).readall()
End Function
```

Body:
I need to parse out the Amount node inside the first TotalNetChargeWithDutiesAndTaxes parent node in the sample XML below. How do I do this? I've tried a bunch of stuff but I can't figure out a way to specifically get the value by name of nodes.

The code below is what I have so far, but this is a really hacky way of doing this. I don't know if I can rely on the Amount node always being the second element of the TotalNetChargeWithDutiesAndTaxes node, so I need a way to search this XML doc specifically by the names of the nodes.

Dim elemList as XmlNodeList = Doc.GetElementsByTagName("TotalNetChargeWithDutiesAndTaxes")

MsgBox(elemList(0).ChildNodes(1).InnerText)

The full XML:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <RateReply xmlns="http://fedex.com/ws/rate/v31">
         <HighestSeverity>SUCCESS</HighestSeverity>
         <Notifications>
            <Severity>SUCCESS</Severity>
            <Source>crs</Source>
            0
            <Message>Request was successfully processed. </Message>
            <LocalizedMessage>Request was successfully processed. </LocalizedMessage>
         </Notifications>
         <TransactionDetail>
            <CustomerTransactionId>94c345b5-55d6-4a44-9c97-d5809179eaa4</CustomerTransactionId>
         </TransactionDetail>
         <Version>
            <ServiceId>crs</ServiceId>
            <Major>31</Major>
            <Intermediate>0</Intermediate>
            <Minor>0</Minor>
         </Version>
         <RateReplyDetails>
            <ServiceType>FEDEX_GROUND</ServiceType>
            <ServiceDescription>
               <ServiceType>FEDEX_GROUND</ServiceType>
               92
               <Names>
                  <Type>long</Type>
                  <Encoding>utf-8</Encoding>
                  <Value>FedEx GroundÂ®</Value>
               </Names>
               <Names>
                  <Type>long</Type>
                  <Encoding>ascii</Encoding>
                  <Value>FedEx Ground</Value>
               </Names>
               <Names>
                  <Type>medium</Type>
                  <Encoding>utf-8</Encoding>
                  <Value>GroundÂ®</Value>
               </Names>
               <Names>
                  <Type>medium</Type>
                  <Encoding>ascii</Encoding>
                  <Value>Ground</Value>
               </Names>
               <Names>
                  <Type>short</Type>
                  <Encoding>utf-8</Encoding>
                  <Value>FG</Value>
               </Names>
               <Names>
                  <Type>short</Type>
                  <Encoding>ascii</Encoding>
                  <Value>FG</Value>
               </Names>
               <Names>
                  <Type>abbrv</Type>
                  <Encoding>ascii</Encoding>
                  <Value>SG</Value>
               </Names>
               <Description>FedEx Ground</Description>
               <AstraDescription>FXG</AstraDescription>
            </ServiceDescription>
            <PackagingType>YOUR_PACKAGING</PackagingType>
            <DestinationAirportId>ORD</DestinationAirportId>
            <IneligibleForMoneyBackGuarantee>false</IneligibleForMoneyBackGuarantee>
            <SignatureOption>SERVICE_DEFAULT</SignatureOption>
            <ActualRateType>PAYOR_ACCOUNT_PACKAGE</ActualRateType>
            <RatedShipmentDetails>
               <EffectiveNetDiscount>
                  <Currency>USD</Currency>
                  <Amount>0.0</Amount>
               </EffectiveNetDiscount>
               <ShipmentRateDetail>
                  <RateType>PAYOR_ACCOUNT_PACKAGE</RateType>
                  <RateZone>5</RateZone>
                  <RatedWeightMethod>DIM</RatedWeightMethod>
                  <DimDivisor>139</DimDivisor>
                  <FuelSurchargePercent>11.75</FuelSurchargePercent>
                  <TotalBillingWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalBillingWeight>
                  <TotalDimWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalDimWeight>
                  <TotalBaseCharge>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalBaseCharge>
                  <TotalFreightDiscounts>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalFreightDiscounts>
                  <TotalNetFreight>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalNetFreight>
                  <TotalSurcharges>
                     <Currency>USD</Currency>
                     <Amount>1.98</Amount>
                  </TotalSurcharges>
                  <TotalNetFedExCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetFedExCharge>
                  <TotalTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalTaxes>
                  <TotalNetCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetCharge>
                  <TotalRebates>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalRebates>
                  <TotalDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesAndTaxes>
                  <TotalAncillaryFeesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalAncillaryFeesAndTaxes>
                  <TotalDutiesTaxesAndFees>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesTaxesAndFees>
                  <TotalNetChargeWithDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetChargeWithDutiesAndTaxes>
                  <Surcharges>
                     <SurchargeType>FUEL</SurchargeType>
                     <Level>PACKAGE</Level>
                     <Description>FedEx Ground Fuel</Description>
                     <Amount>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </Amount>
                  </Surcharges>
               </ShipmentRateDetail>
               <RatedPackages>
                  <GroupNumber>1</GroupNumber>
                  <EffectiveNetDiscount>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </EffectiveNetDiscount>
                  <PackageRateDetail>
                     <RateType>PAYOR_ACCOUNT_PACKAGE</RateType>
                     <RatedWeightMethod>DIM</RatedWeightMethod>
                     <BillingWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </BillingWeight>
                     <DimWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </DimWeight>
                     <BaseCharge>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </BaseCharge>
                     <TotalFreightDiscounts>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalFreightDiscounts>
                     <NetFreight>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </NetFreight>
                     <TotalSurcharges>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </TotalSurcharges>
                     <NetFedExCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetFedExCharge>
                     <TotalTaxes>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalTaxes>
                     <NetCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetCharge>
                     <TotalRebates>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalRebates>
                     <Surcharges>
                        <SurchargeType>FUEL</SurchargeType>
                        <Level>PACKAGE</Level>
                        <Description>FedEx Ground Fuel</Description>
                        <Amount>
                           <Currency>USD</Currency>
                           <Amount>1.98</Amount>
                        </Amount>
                     </Surcharges>
                  </PackageRateDetail>
               </RatedPackages>
            </RatedShipmentDetails>
            <RatedShipmentDetails>
               <ShipmentRateDetail>
                  <RateType>PAYOR_LIST_PACKAGE</RateType>
                  <RateZone>5</RateZone>
                  <RatedWeightMethod>DIM</RatedWeightMethod>
                  <DimDivisor>139</DimDivisor>
                  <FuelSurchargePercent>11.75</FuelSurchargePercent>
                  <TotalBillingWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalBillingWeight>
                  <TotalDimWeight>
                     <Units>LB</Units>
                     <Value>13.0</Value>
                  </TotalDimWeight>
                  <TotalBaseCharge>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalBaseCharge>
                  <TotalFreightDiscounts>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalFreightDiscounts>
                  <TotalNetFreight>
                     <Currency>USD</Currency>
                     <Amount>16.87</Amount>
                  </TotalNetFreight>
                  <TotalSurcharges>
                     <Currency>USD</Currency>
                     <Amount>1.98</Amount>
                  </TotalSurcharges>
                  <TotalNetFedExCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetFedExCharge>
                  <TotalTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalTaxes>
                  <TotalNetCharge>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetCharge>
                  <TotalRebates>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalRebates>
                  <TotalDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesAndTaxes>
                  <TotalAncillaryFeesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalAncillaryFeesAndTaxes>
                  <TotalDutiesTaxesAndFees>
                     <Currency>USD</Currency>
                     <Amount>0.0</Amount>
                  </TotalDutiesTaxesAndFees>
                  <TotalNetChargeWithDutiesAndTaxes>
                     <Currency>USD</Currency>
                     <Amount>18.85</Amount>
                  </TotalNetChargeWithDutiesAndTaxes>
                  <Surcharges>
                     <SurchargeType>FUEL</SurchargeType>
                     <Level>PACKAGE</Level>
                     <Description>FedEx Ground Fuel</Description>
                     <Amount>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </Amount>
                  </Surcharges>
               </ShipmentRateDetail>
               <RatedPackages>
                  <GroupNumber>1</GroupNumber>
                  <PackageRateDetail>
                     <RateType>PAYOR_LIST_PACKAGE</RateType>
                     <RatedWeightMethod>DIM</RatedWeightMethod>
                     <BillingWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </BillingWeight>
                     <DimWeight>
                        <Units>LB</Units>
                        <Value>13.0</Value>
                     </DimWeight>
                     <BaseCharge>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </BaseCharge>
                     <TotalFreightDiscounts>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalFreightDiscounts>
                     <NetFreight>
                        <Currency>USD</Currency>
                        <Amount>16.87</Amount>
                     </NetFreight>
                     <TotalSurcharges>
                        <Currency>USD</Currency>
                        <Amount>1.98</Amount>
                     </TotalSurcharges>
                     <NetFedExCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetFedExCharge>
                     <TotalTaxes>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalTaxes>
                     <NetCharge>
                        <Currency>USD</Currency>
                        <Amount>18.85</Amount>
                     </NetCharge>
                     <TotalRebates>
                        <Currency>USD</Currency>
                        <Amount>0.0</Amount>
                     </TotalRebates>
                     <Surcharges>
                        <SurchargeType>FUEL</SurchargeType>
                        <Level>PACKAGE</Level>
                        <Description>FedEx Ground Fuel</Description>
                        <Amount>
                           <Currency>USD</Currency>
                           <Amount>1.98</Amount>
                        </Amount>
                     </Surcharges>
                  </PackageRateDetail>
               </RatedPackages>
            </RatedShipmentDetails>
         </RateReplyDetails>
      </RateReply>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


问:
The speed of training is reduced using a custom method in tensorflow.keras.layers
I'm using tensorflow.data and custom layers to solve the bottleneck of data augmentation, but I found that using tensorflow.data alone is faster than mixing, I don't know what's going on in the custom layers, can someone please tell me?

Thanks in advance!

This is my data augmentation code, mainly to do standardization and resize.

```<code>def random_normalization(data, mean, std):
    mean = tf.multiply(mean, tf.random.uniform(shape=(), minval=0.5,maxval=0.9, dtype=tf.float64))
    std = tf.multiply(std, tf.random.uniform(shape=(), minval=0.5,maxval=0.9, dtype=tf.float64))
    return tf.divide((tf.subtract(data, mean)), std)

def random_resize(data):
    def resizing(index, data, choice, enable, new_data, number, overlap):
        FrontEnd = tf.cond(tf.math.greater_equal(tf.subtract(index, overlap), tf.constant(0)),
                           lambda: tf.subtract(index, overlap),
                           lambda: index)

        BackEnd = tf.cond(tf.math.less(tf.add(tf.add(index, 10),overlap),tf.constant(2000)),
                          lambda: tf.add(tf.add(index, 10),overlap),
                          lambda: index)

        z1 = tf.gather(data, indices=[0], axis=1)
        z1 = tf.gather(z1, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z2 = tf.gather(data, indices=[1], axis=1)
        z2 = tf.gather(z2, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z3 = tf.gather(data, indices=[2], axis=1)
        z3 = tf.gather(z3, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z4 = tf.gather(data, indices=[3], axis=1)
        z4 = tf.gather(z4, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z5 = tf.gather(data, indices=[4], axis=1)
        z5 = tf.gather(z5, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z6 = tf.gather(data, indices=[5], axis=1)
        z6 = tf.gather(z6, indices=tf.range(FrontEnd, BackEnd), axis=0)

        new_data = tf.tensor_scatter_nd_update(new_data, [[number, 0], [number, 1], [number, 2],
                                                          [number, 3], [number, 4], [number, 5]],
                                               [tf.math.reduce_mean(z1), tf.math.reduce_mean(z2),
                                                tf.math.reduce_mean(z3), tf.math.reduce_mean(z4),
                                                tf.math.reduce_mean(z5), tf.math.reduce_mean(z6)])

        return tf.add(index, 10), data, choice, enable, new_data, tf.add(number, 1), overlap

    choice = tf.random.uniform(shape=(), minval=0,maxval=4,dtype=tf.int32)
    enable = tf.random.uniform(shape=(), minval=0,maxval=1,dtype=tf.float64)
    overlap = tf.random.uniform(shape=(), minval=5,maxval=21,dtype=tf.int32)

    new_data = tf.zeros((200,6), dtype=tf.float64)
    index = tf.constant(0)
    number = tf.constant(0)
    condition = lambda index, data, choice, enable, new_data, number, overlap: tf.less(index, 2000)
    r = tf.while_loop(condition, resizing, loop_vars=(index, data, choice, enable, new_data, number, overlap))
    return r[4]

def normal_resize(data):
    data = tf.reshape(data, (2000,6,1))
    data = tf.image.resize(data, size=[200,6])
    return tf.cast(tf.reshape(data, (200,6)),dtype=tf.float64)

def augmentation(data, labels):
    mean = tf.math.reduce_mean(data,axis=0)
    std = tf.math.reduce_std(data,axis=0)
    data = tf.cond(tf.random.uniform(shape=(), minval=0, maxval=1,dtype=tf.float64) < tf.constant(0.8,dtype=tf.float64),
                   lambda: random_normalization(data, mean, std),
                   lambda: tf.divide((tf.subtract(data, mean)), std))

    # 2000 resize to 200
    data = tf.cond(tf.random.uniform(shape=(), minval=0, maxval=1,dtype=tf.float64) < tf.constant(0.8,dtype=tf.float64),
                   lambda: random_resize(data),
                   lambda: normal_resize(data))

    return data, labels
</code>```

Main code, including tf.data and model

```<code>if __name__ == '__main__':
    trainDS = tf.data.Dataset.from_tensor_slices((np.random.rand(3000,2000,6),
                                                  np.concatenate((np.zeros((1500)),np.ones((1500))))))
    trainDS = (
        trainDS
        .cache()
        .shuffle(1000, reshuffle_each_iteration=False)
        .map(augmentation, num_parallel_calls=tf.data.AUTOTUNE)
        .batch(128, drop_remainder=True)
        .prefetch(tf.data.AUTOTUNE))

    input = Input((200,6))
    x = LSTM(64, return_sequences=True)(input)
    output = Dense(1,activation='sigmoid')(x)
    model = Model(input, output)
    model.compile(optimizer='adam', loss='BinaryCrossentropy')
    model.fit(trainDS, epochs=3)
</code>```

Then this is the code of my custom layer, although it is a bit cumbersome, it still achieves the result I want.

```<code>import tensorflow as tf
from tensorflow.keras.layers import LSTM, Dense, Input
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Layer
import numpy as np

class CustomLayer(Layer):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def execute(self, data, batch_size, new_data, _type):
        def _fun(index, data, _type, new_data):
            resized = tf.cond(_type,
                              lambda:augmentation(tf.reshape(tf.gather(data,[index]), (2000,6))),
                              lambda:normal_resize(tf.reshape(tf.gather(data,[index]), (2000,6))))
            values = tf.reshape(resized, (1,-1))[0]
            _Indices = self.createIndices(index)
            new_data = tf.tensor_scatter_nd_update(new_data, _Indices, values)
            return tf.add(index,1), data, _type, new_data

        index = tf.constant(0)
        condition = lambda index, data, _type, new_data: tf.less(index, batch_size)
        r = tf.while_loop(condition, _fun, loop_vars=(index, data, _type, new_data))
        return r[-1]

    def createIndices(self, BatchSizeIndex):
        def loop1(_i, BatchSizeIndex, col_num, _Indices):
            def loop2(_i, _j, BatchSizeIndex, col_num, _Indices):
                _Indices = tf.tensor_scatter_nd_update(_Indices, [[col_num, 0], [col_num, 1], [col_num, 2]],
                                                        [BatchSizeIndex, _i, _j])
                return _i, tf.add(_j,1), BatchSizeIndex, tf.add(col_num,1), _Indices

            _j = tf.constant(0)
            condition_loop2 = lambda _i, _j, BatchSizeIndex, col_num, _Indices: tf.less(_j, 6)
            r_loop2 = tf.while_loop(condition_loop2, loop2, loop_vars=(_i, _j, BatchSizeIndex, col_num, _Indices))
            return tf.add(_i,1), BatchSizeIndex, r_loop2[3], r_loop2[4]

        _Indices = tf.zeros((1200,3), dtype=tf.int32)
        col_num = tf.constant(0)
        _i = tf.constant(0)
        condition_loop1 = lambda _i, BatchSizeIndex, col_num, _Indices: tf.less(_i, 200)
        r_loop1 = tf.while_loop(condition_loop1, loop1, loop_vars=(_i, BatchSizeIndex, col_num, _Indices))
        return r_loop1[-1]

    def call(self, images, training):
        batch_size = tf.shape(images)[0]
        new_data = tf.zeros((batch_size, 200, 6), dtype=tf.float64)
        images = tf.cast(images, dtype=tf.float64)
        if training:
            data = self.execute(images, batch_size, new_data, tf.constant(True))
        else:
            data = self.execute(images, batch_size, new_data, tf.constant(False))

        return data
</code>```

The final code can be modified to execute like this.

```<code>def augmentation(data):
    .....
    return data

if __name__ == '__main__':
    trainDS = tf.data.Dataset.from_tensor_slices((np.random.rand(3000,2000,6),
                                                  np.concatenate((np.zeros((1500)),np.ones((1500))))))
    trainDS = (
        trainDS
        .cache()
        .shuffle(1000, reshuffle_each_iteration=False)
        .batch(128, drop_remainder=True)
        .prefetch(tf.data.AUTOTUNE))

    input = Input((2000,6))
    x = CustomLayer()(input)
    x = LSTM(64, return_sequences=True)(x)
    output = Dense(1,activation='sigmoid')(x)
    model = Model(input, output)
    model.compile(optimizer='adam', loss='BinaryCrossentropy')
    model.fit(trainDS, epochs=3)
</code>```

Results: Alone tf.data spend about 18s, tf.data+CustomLayer spend about 38s.

The thing I want to clarify is that the use of map in tf.data to run augmentation is on the CPU, but if I write augmentation in the Layer, it should theoretically run on the GPU. Why is there such a big gap between the two?

Environment: python3.6, tensorflow2.4.0

答: I reduced the tf.gather method in the code, and used tf.TensorArray instead of the tf.tensor_scatter_nd_update method, which really optimized my training speed, from 2min to 2s.

Body:
I'm using tensorflow.data and custom layers to solve the bottleneck of data augmentation, but I found that using tensorflow.data alone is faster than mixing, I don't know what's going on in the custom layers, can someone please tell me?

Thanks in advance!

This is my data augmentation code, mainly to do standardization and resize.

def random_normalization(data, mean, std):
    mean = tf.multiply(mean, tf.random.uniform(shape=(), minval=0.5,maxval=0.9, dtype=tf.float64))
    std = tf.multiply(std, tf.random.uniform(shape=(), minval=0.5,maxval=0.9, dtype=tf.float64))
    return tf.divide((tf.subtract(data, mean)), std)

def random_resize(data):
    def resizing(index, data, choice, enable, new_data, number, overlap):
        FrontEnd = tf.cond(tf.math.greater_equal(tf.subtract(index, overlap), tf.constant(0)),
                           lambda: tf.subtract(index, overlap),
                           lambda: index)

        BackEnd = tf.cond(tf.math.less(tf.add(tf.add(index, 10),overlap),tf.constant(2000)),
                          lambda: tf.add(tf.add(index, 10),overlap),
                          lambda: index)

        z1 = tf.gather(data, indices=[0], axis=1)
        z1 = tf.gather(z1, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z2 = tf.gather(data, indices=[1], axis=1)
        z2 = tf.gather(z2, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z3 = tf.gather(data, indices=[2], axis=1)
        z3 = tf.gather(z3, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z4 = tf.gather(data, indices=[3], axis=1)
        z4 = tf.gather(z4, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z5 = tf.gather(data, indices=[4], axis=1)
        z5 = tf.gather(z5, indices=tf.range(FrontEnd, BackEnd), axis=0)

        z6 = tf.gather(data, indices=[5], axis=1)
        z6 = tf.gather(z6, indices=tf.range(FrontEnd, BackEnd), axis=0)

        new_data = tf.tensor_scatter_nd_update(new_data, [[number, 0], [number, 1], [number, 2],
                                                          [number, 3], [number, 4], [number, 5]],
                                               [tf.math.reduce_mean(z1), tf.math.reduce_mean(z2),
                                                tf.math.reduce_mean(z3), tf.math.reduce_mean(z4),
                                                tf.math.reduce_mean(z5), tf.math.reduce_mean(z6)])

        return tf.add(index, 10), data, choice, enable, new_data, tf.add(number, 1), overlap

    choice = tf.random.uniform(shape=(), minval=0,maxval=4,dtype=tf.int32)
    enable = tf.random.uniform(shape=(), minval=0,maxval=1,dtype=tf.float64)
    overlap = tf.random.uniform(shape=(), minval=5,maxval=21,dtype=tf.int32)

    new_data = tf.zeros((200,6), dtype=tf.float64)
    index = tf.constant(0)
    number = tf.constant(0)
    condition = lambda index, data, choice, enable, new_data, number, overlap: tf.less(index, 2000)
    r = tf.while_loop(condition, resizing, loop_vars=(index, data, choice, enable, new_data, number, overlap))
    return r[4]

def normal_resize(data):
    data = tf.reshape(data, (2000,6,1))
    data = tf.image.resize(data, size=[200,6])
    return tf.cast(tf.reshape(data, (200,6)),dtype=tf.float64)

def augmentation(data, labels):
    mean = tf.math.reduce_mean(data,axis=0)
    std = tf.math.reduce_std(data,axis=0)
    data = tf.cond(tf.random.uniform(shape=(), minval=0, maxval=1,dtype=tf.float64) < tf.constant(0.8,dtype=tf.float64),
                   lambda: random_normalization(data, mean, std),
                   lambda: tf.divide((tf.subtract(data, mean)), std))

    # 2000 resize to 200
    data = tf.cond(tf.random.uniform(shape=(), minval=0, maxval=1,dtype=tf.float64) < tf.constant(0.8,dtype=tf.float64),
                   lambda: random_resize(data),
                   lambda: normal_resize(data))

    return data, labels

Main code, including tf.data and model

if __name__ == '__main__':
    trainDS = tf.data.Dataset.from_tensor_slices((np.random.rand(3000,2000,6),
                                                  np.concatenate((np.zeros((1500)),np.ones((1500))))))
    trainDS = (
        trainDS
        .cache()
        .shuffle(1000, reshuffle_each_iteration=False)
        .map(augmentation, num_parallel_calls=tf.data.AUTOTUNE)
        .batch(128, drop_remainder=True)
        .prefetch(tf.data.AUTOTUNE))

    input = Input((200,6))
    x = LSTM(64, return_sequences=True)(input)
    output = Dense(1,activation='sigmoid')(x)
    model = Model(input, output)
    model.compile(optimizer='adam', loss='BinaryCrossentropy')
    model.fit(trainDS, epochs=3)

Then this is the code of my custom layer, although it is a bit cumbersome, it still achieves the result I want.

import tensorflow as tf
from tensorflow.keras.layers import LSTM, Dense, Input
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Layer
import numpy as np

class CustomLayer(Layer):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def execute(self, data, batch_size, new_data, _type):
        def _fun(index, data, _type, new_data):
            resized = tf.cond(_type,
                              lambda:augmentation(tf.reshape(tf.gather(data,[index]), (2000,6))),
                              lambda:normal_resize(tf.reshape(tf.gather(data,[index]), (2000,6))))
            values = tf.reshape(resized, (1,-1))[0]
            _Indices = self.createIndices(index)
            new_data = tf.tensor_scatter_nd_update(new_data, _Indices, values)
            return tf.add(index,1), data, _type, new_data

        index = tf.constant(0)
        condition = lambda index, data, _type, new_data: tf.less(index, batch_size)
        r = tf.while_loop(condition, _fun, loop_vars=(index, data, _type, new_data))
        return r[-1]

    def createIndices(self, BatchSizeIndex):
        def loop1(_i, BatchSizeIndex, col_num, _Indices):
            def loop2(_i, _j, BatchSizeIndex, col_num, _Indices):
                _Indices = tf.tensor_scatter_nd_update(_Indices, [[col_num, 0], [col_num, 1], [col_num, 2]],
                                                        [BatchSizeIndex, _i, _j])
                return _i, tf.add(_j,1), BatchSizeIndex, tf.add(col_num,1), _Indices

            _j = tf.constant(0)
            condition_loop2 = lambda _i, _j, BatchSizeIndex, col_num, _Indices: tf.less(_j, 6)
            r_loop2 = tf.while_loop(condition_loop2, loop2, loop_vars=(_i, _j, BatchSizeIndex, col_num, _Indices))
            return tf.add(_i,1), BatchSizeIndex, r_loop2[3], r_loop2[4]

        _Indices = tf.zeros((1200,3), dtype=tf.int32)
        col_num = tf.constant(0)
        _i = tf.constant(0)
        condition_loop1 = lambda _i, BatchSizeIndex, col_num, _Indices: tf.less(_i, 200)
        r_loop1 = tf.while_loop(condition_loop1, loop1, loop_vars=(_i, BatchSizeIndex, col_num, _Indices))
        return r_loop1[-1]

    def call(self, images, training):
        batch_size = tf.shape(images)[0]
        new_data = tf.zeros((batch_size, 200, 6), dtype=tf.float64)
        images = tf.cast(images, dtype=tf.float64)
        if training:
            data = self.execute(images, batch_size, new_data, tf.constant(True))
        else:
            data = self.execute(images, batch_size, new_data, tf.constant(False))

        return data

The final code can be modified to execute like this.

def augmentation(data):
    .....
    return data

if __name__ == '__main__':
    trainDS = tf.data.Dataset.from_tensor_slices((np.random.rand(3000,2000,6),
                                                  np.concatenate((np.zeros((1500)),np.ones((1500))))))
    trainDS = (
        trainDS
        .cache()
        .shuffle(1000, reshuffle_each_iteration=False)
        .batch(128, drop_remainder=True)
        .prefetch(tf.data.AUTOTUNE))

    input = Input((2000,6))
    x = CustomLayer()(input)
    x = LSTM(64, return_sequences=True)(x)
    output = Dense(1,activation='sigmoid')(x)
    model = Model(input, output)
    model.compile(optimizer='adam', loss='BinaryCrossentropy')
    model.fit(trainDS, epochs=3)

Results: Alone tf.data spend about 18s, tf.data+CustomLayer spend about 38s.

The thing I want to clarify is that the use of map in tf.data to run augmentation is on the CPU, but if I write augmentation in the Layer, it should theoretically run on the GPU. Why is there such a big gap between the two?

Environment: python3.6, tensorflow2.4.0


问:
Google Sheets to Google Calendar - Prevent Duplicate Events
I am working on the development of a shared Google calendar that will pull information from a single, shared Google sheet. The following script was developed based on this video:

```<code>function createCalendarEvent() {
  let communitycalendar = CalendarApp.getCalendarById("c_73m54912a5skrufq4junc9qnag@group.calendar.google.com");
  let sheet = SpreadsheetApp.getActiveSheet();

  let schedule = sheet.getDataRange().getValues();
  schedule.splice(0,2);

  schedule.forEach(function(entry) {
    communitycalendar.createEvent(entry[0], entry[1], entry[2]);

});
}

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Sync to Calendar')
      .addItem('Add appointments', 'createCalendarEvent')
      .addSeparator()
      .addSubMenu(ui.createMenu('Delete')
          .addItem('Delete shifts from Calendar', 'clearCalendar'))
      .addToUi();
function createCalendarEvent() {
}

function clearCalendar() {
}};
</code>```

This script pulls data from a basic test sheet, for now.
The issue is that this creates duplicate entries every time the script is run. I understand this is a common issue that has been resolved in other stack overflow threads, but these solutions prevent this issue by having the script check an eventID and replace the prior calendar invite rather than duplicating. Since my calendar is a shared calendar with events that people will be signing up for, this would get confusing to my coworkers and instead, it would be best to have a script that checks for preexisting calendar invites and does not create a new invite if a prior one already exists (based on say, unique event ID or title).

The basic logical structure for this piece of code would be

```<code>IF eventID/title is on calendar already, DONT create new event.
</code>```

Does such a solution exist? I am a novice programmer so I am not sure how to write such a script but I have done my due diligence to check around stack overflow and I cannot find a solution.

Thank you for your help!

答:
About your logic of IF eventID/title is on calendar already, DONT create new event., from your showing sheet image, I cannot see the event ID. And from based on say, unique event ID or title, in this answer, I used the event title for checking the duplicate events. When your script is modified, how about the following modification?

Modified script:

In this modified script, in order to retrieve all events, Calendar API is used. So please enable Calendar API at Advanced Google services.

function createCalendarEvent() {
  const calendarId = "c_73m54912a5skrufq4junc9qnag@group.calendar.google.com";
  let communitycalendar = CalendarApp.getCalendarById(calendarId);
  let sheet = SpreadsheetApp.getActiveSheet();
  let schedule = sheet.getDataRange().getValues();
  schedule.splice(0, 2);
  const events = {};
  let pageToken = "";
  do {
    const {items, nextPageToken} = Calendar.Events.list(calendarId, {maxResults: 2500, pageToken});
    if (items.length > 0) items.forEach(o => events[o.summary] = true);
    pageToken = nextPageToken || "";
  } while (pageToken);
  schedule.forEach(function (entry) {
    if (!events[entry[0]]) {
      communitycalendar.createEvent(entry[0], entry[1], entry[2]);
    }
  });
}
```

When this script is run, at first, all events are retrieved and create an object for searching the event title. And, when the event title has already been existing, the event is not created.

Reference:

Events: list

Body:
I am working on the development of a shared Google calendar that will pull information from a single, shared Google sheet. The following script was developed based on this video:

function createCalendarEvent() {
  let communitycalendar = CalendarApp.getCalendarById("c_73m54912a5skrufq4junc9qnag@group.calendar.google.com");
  let sheet = SpreadsheetApp.getActiveSheet();

  let schedule = sheet.getDataRange().getValues();
  schedule.splice(0,2);

  schedule.forEach(function(entry) {
    communitycalendar.createEvent(entry[0], entry[1], entry[2]);

});
}

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Sync to Calendar')
      .addItem('Add appointments', 'createCalendarEvent')
      .addSeparator()
      .addSubMenu(ui.createMenu('Delete')
          .addItem('Delete shifts from Calendar', 'clearCalendar'))
      .addToUi();
function createCalendarEvent() {
}

function clearCalendar() {
}};

This script pulls data from a basic test sheet, for now.
The issue is that this creates duplicate entries every time the script is run. I understand this is a common issue that has been resolved in other stack overflow threads, but these solutions prevent this issue by having the script check an eventID and replace the prior calendar invite rather than duplicating. Since my calendar is a shared calendar with events that people will be signing up for, this would get confusing to my coworkers and instead, it would be best to have a script that checks for preexisting calendar invites and does not create a new invite if a prior one already exists (based on say, unique event ID or title).

The basic logical structure for this piece of code would be

IF eventID/title is on calendar already, DONT create new event.

Does such a solution exist? I am a novice programmer so I am not sure how to write such a script but I have done my due diligence to check around stack overflow and I cannot find a solution.

Thank you for your help!

Body:
About your logic of IF eventID/title is on calendar already, DONT create new event., from your showing sheet image, I cannot see the event ID. And from based on say, unique event ID or title, in this answer, I used the event title for checking the duplicate events. When your script is modified, how about the following modification?

Modified script:

In this modified script, in order to retrieve all events, Calendar API is used. So please enable Calendar API at Advanced Google services.

function createCalendarEvent() {
  const calendarId = "c_73m54912a5skrufq4junc9qnag@group.calendar.google.com";
  let communitycalendar = CalendarApp.getCalendarById(calendarId);
  let sheet = SpreadsheetApp.getActiveSheet();
  let schedule = sheet.getDataRange().getValues();
  schedule.splice(0, 2);
  const events = {};
  let pageToken = "";
  do {
    const {items, nextPageToken} = Calendar.Events.list(calendarId, {maxResults: 2500, pageToken});
    if (items.length > 0) items.forEach(o => events[o.summary] = true);
    pageToken = nextPageToken || "";
  } while (pageToken);
  schedule.forEach(function (entry) {
    if (!events[entry[0]]) {
      communitycalendar.createEvent(entry[0], entry[1], entry[2]);
    }
  });
}

When this script is run, at first, all events are retrieved and create an object for searching the event title. And, when the event title has already been existing, the event is not created.

Reference:

Events: list


问:
Django ImportError
I created my own Django application with directory structure

```<code>/appname
    __init__.py
    models.py
    /submodule1
        __init__.py
        a.py
</code>```

Inside a.py I have the following import

```<code>from ..models import Something
</code>```

This works okay if I have /appname inside my /djangoproject folder, but when I install the app to Python's site-packages (via setup.py which I created), all hell breaks loose and a.py can no longer import Something, with the following error:

```<code>ImportError: cannot import name Something
</code>```

Here is the setup.py:

```<code>from distutils.core import setup

setup(name='appname',
      version='0.1',
      packages=['appname', 'appname.contrib'],
)
</code>```

答: Put empty file named: __init__.py inside /submodule1 so Python can parse it as module. It should help. The same in /appname - there should be also __init__.py file

Title: Django ImportError

Body:
I created my own Django application with directory structure

/appname
    __init__.py
    models.py
    /submodule1
        __init__.py
        a.py

Inside a.py I have the following import

from ..models import Something

This works okay if I have /appname inside my /djangoproject folder, but when I install the app to Python's site-packages (via setup.py which I created), all hell breaks loose and a.py can no longer import Something, with the following error:

ImportError: cannot import name Something

Here is the setup.py:

from distutils.core import setup

setup(name='appname',
      version='0.1',
      packages=['appname', 'appname.contrib'],
)


问:
Why does deploying my smart contract fail with : Failure: Tx Failed: Keyset failure (keys-any):
Despite using a unique module name (e.g. THIS was not the issue at hand), deploying my smart contract on kadena's testnet failed with the following error message:

: Failure: Tx Failed: Keyset failure (keys-any): '[my keyset name]

The only way to achieve a success was to assign a separate account that I control as the gas payer.
To elaborate for new developers:

When you hit "Deploy" in Chainweaver and fill out the form on the first page of the pop-up, you move to the SIGN tab and choose an account separate from the SENDER to pay for the gas fee.

In the following image we have two keys, red and green. Green is the sender, red is the gas payer. This is a configuration that has worked for me.

It is not clear to me, however, why this is the case or if there is a better solution.

Thank you in advance.

答:
This seems to be just a Chainweaver web client issue.
On the non-web client, you can grant the capability and sign with the same key without issues</p>


问:
Convert PST to UTC using Moment?
Is it possible to convert
Mon, Feb 07, 2022 08:30:30 PM Pacific Time
to UTC time format using moment?

I've tried doing this

```<code>const endTime = timezone(filteredTimeLeft, "ddd, MMM DD, YYYY hh:mm:ss a").utcOffset(-8);'
</code>```

But how does Moment know the inserted date parameter is pacific time ?

答:
You could read the documentation, which will lead you to Moment Timezone, a decorator for Moment.js that adds support for timezones.

But you also might notice that Moment.js is essentially deprecated:

We now generally consider Moment to be a legacy project in maintenance mode. It is not dead, but it is indeed done.

In practice, this means:

We will not be adding new features or capabilities.

We will not be changing Moment's API to be immutable.

We will not be addressing tree shaking or bundle size issues.

We will not be making any major changes (no version 3).

We may choose to not fix bugs or behavioral quirks, especially if they are long-standing known issues.

And that you might to consider using instead a more modern library such as Luxon, written by one of Moment's maintainers, and maintained by the Moment team.

Title: Convert PST to UTC using Moment?

Body:
Is it possible to convert
Mon, Feb 07, 2022 08:30:30 PM Pacific Time
to UTC time format using moment?

I've tried doing this

const endTime = timezone(filteredTimeLeft, "ddd, MMM DD, YYYY hh:mm:ss a").utcOffset(-8);'

But how does Moment know the inserted date parameter is pacific time ?


问:
Getting datetime count range in SQL Server
I try to get the date range between the data changes in SQL Server
my query is

```<code>select count(1) as qty, Info, convert(char,dFError,100) dErr
from TableData
group by Info, convert(char,dFError,100)
order by dErr asc
</code>```

I have this
qty has the number of reques to a server, info are the servers ip and the date it's when a request it's sended to another server.

qty
Info
dErr

1
1.97
Aug 11 2021  9:01AM

1
1.97
Aug 11 2021  9:06AM

88
1.33
Dec 21 2021  2:04PM

1
1.95
Dec 22 2021  9:44PM

9
1.95
Dec 22 2021  9:45PM

1
1.33
Dec 22 2021  9:51PM

19
1.33
Dec 22 2021  9:52PM

3
1.33
Dec 22 2021  9:53PM

6
1.33
Dec 27 2021  7:10PM

17
1.33
Dec 27 2021  7:11PM

15
1.95
Dec 27 2021  7:17PM

8
1.95
Dec 27 2021  7:18PM

and I want this, in Aug 11 at 9:06AM all are going to 1.97, at Dec 21 at 2:04PM all are going to 1.33, that means the date and the info

qty
Info
dErr

2
1.97
Aug 11 2021  9:06AM

88
1.33
Dec 21 2021  2:04PM

10
1.95
Dec 22 2021  9:45PM

46
1.33
Dec 27 2021  7:11PM

23
1.95
Dec 27 2021  7:18PM

in the same day can be the same group of numbers on distinct hour

qty
Info
dErr

1
1.97
Jan 24 2022  9:39AM

1
1.97
Jan 24 2022  9:51AM

1
1.97
Jan 24 2022  9:58AM

4
1.97
Jan 24 2022 10:08AM

1
1.97
Jan 24 2022 10:12AM

8
1.95
Jan 24 2022 10:24AM

2
1.95
Jan 24 2022 10:32AM

10
1.33
Jan 24 2022 10:33AM

1
1.33
Jan 24 2022 11:37AM

8
1.95
Jan 24 2022 11:59AM

1
1.95
Jan 24 2022 12:00PM

2
1.95
Jan 24 2022 12:08PM

and need to be displayed like

qty
Info
dErr

8
1.97
Jan 24 2022  10:12AM

10
1.95
Jan 24 2022 10:32AM

11
1.33
Jan 24 2022 11:37AM

11
1.95
Jan 24 2022 12:08PM

答:
A double row_number can be used to calculate a ranking.

Then the ranking can be used in the aggregation to solve this Gaps-And-Islands type of problem.

```<code>select sum(qty) as qty, Info, max(dFError) as dErr
from (
  select Info, dFError, qty
  , convert(date, dFError) as dErrorDate
  , Rnk = row_number() over (order by dFError)
  + row_number() over (partition by Info order by dFError desc)
  from TableData
) q
group by Info, Rnk
order by dErr;
</code>```

qty
Info
dErr

2
1.97
2021-08-11 09:06:00.000

88
1.33
2021-12-21 14:04:00.000

10
1.95
2021-12-22 21:45:00.000

46
1.33
2021-12-27 19:11:00.000

23
1.95
2021-12-27 19:18:00.000

8
1.97
2022-01-24 10:12:00.000

10
1.95
2022-01-24 10:32:00.000

11
1.33
2022-01-24 11:37:00.000

11
1.95
2022-01-24 12:08:00.000

Demo on db<>fiddle here

Body:
I try to get the date range between the data changes in SQL Server
my query is

select count(1) as qty, Info, convert(char,dFError,100) dErr
from TableData
group by Info, convert(char,dFError,100)
order by dErr asc

I have this
qty has the number of reques to a server, info are the servers ip and the date it's when a request it's sended to another server.

qty
Info
dErr

1
1.97
Aug 11 2021  9:01AM

1
1.97
Aug 11 2021  9:06AM

88
1.33
Dec 21 2021  2:04PM

1
1.95
Dec 22 2021  9:44PM

9
1.95
Dec 22 2021  9:45PM

1
1.33
Dec 22 2021  9:51PM

19
1.33
Dec 22 2021  9:52PM

3
1.33
Dec 22 2021  9:53PM

6
1.33
Dec 27 2021  7:10PM

17
1.33
Dec 27 2021  7:11PM

15
1.95
Dec 27 2021  7:17PM

8
1.95
Dec 27 2021  7:18PM

and I want this, in Aug 11 at 9:06AM all are going to 1.97, at Dec 21 at 2:04PM all are going to 1.33, that means the date and the info

qty
Info
dErr

2
1.97
Aug 11 2021  9:06AM

88
1.33
Dec 21 2021  2:04PM

10
1.95
Dec 22 2021  9:45PM

46
1.33
Dec 27 2021  7:11PM

23
1.95
Dec 27 2021  7:18PM

in the same day can be the same group of numbers on distinct hour

qty
Info
dErr

1
1.97
Jan 24 2022  9:39AM

1
1.97
Jan 24 2022  9:51AM

1
1.97
Jan 24 2022  9:58AM

4
1.97
Jan 24 2022 10:08AM

1
1.97
Jan 24 2022 10:12AM

8
1.95
Jan 24 2022 10:24AM

2
1.95
Jan 24 2022 10:32AM

10
1.33
Jan 24 2022 10:33AM

1
1.33
Jan 24 2022 11:37AM

8
1.95
Jan 24 2022 11:59AM

1
1.95
Jan 24 2022 12:00PM

2
1.95
Jan 24 2022 12:08PM

and need to be displayed like

qty
Info
dErr

8
1.97
Jan 24 2022  10:12AM

10
1.95
Jan 24 2022 10:32AM

11
1.33
Jan 24 2022 11:37AM

11
1.95
Jan 24 2022 12:08PM

Body:
A double row_number can be used to calculate a ranking.

Then the ranking can be used in the aggregation to solve this Gaps-And-Islands type of problem.

select sum(qty) as qty, Info, max(dFError) as dErr
from (
  select Info, dFError, qty
  , convert(date, dFError) as dErrorDate
  , Rnk = row_number() over (order by dFError)
  + row_number() over (partition by Info order by dFError desc)
  from TableData
) q
group by Info, Rnk
order by dErr;

qty
Info
dErr

2
1.97
2021-08-11 09:06:00.000

88
1.33
2021-12-21 14:04:00.000

10
1.95
2021-12-22 21:45:00.000

46
1.33
2021-12-27 19:11:00.000

23
1.95
2021-12-27 19:18:00.000

8
1.97
2022-01-24 10:12:00.000

10
1.95
2022-01-24 10:32:00.000

11
1.33
2022-01-24 11:37:00.000

11
1.95
2022-01-24 12:08:00.000

Demo on db<>fiddle here


问:
Dependency Walker for Java?
I am looking for a tool that lists the .class dependencies for a given Java class to run.  Kind of like what Dependency Walker does for Windows applications.

I am aware of some tools, but they are overly complicated or not quite a match, including

Class Dependency Analyzer

GenJar

Dependency Finder

One-JAR

Any suggestions?  TIA!!

答: Although you already accepted an answer, I'd like to contribute that you might want to take a look at CodePro AnalytiX - an Eclipse plugin allowing for code analysis including dependency analysis.</p>

Title: Dependency Walker for Java?