问:
How to distinguish two shooting targets between each other using OpenCV
Let me start by saying that I'm a complete amateur in image recognition and I'm trying to complete my first assignment using OpenCV in Python. I'm currently really struggling and therefore I came here for some advice or any help in general that would put me on the right path.

What am I currently trying to do:

My goal here is to recognize a shooting target image that user uploads and compare it to one of two shooting target templates (images provided lower). My app is afterward going to calculate this shooting target based on the template it matches and give the user a really accurate score of his shot/shots (based on millimeters from the center of the target). This is just a long goal. For now, I'm just trying to figure out how to distinguish the uploaded target image from the templates I have.

Examples of shooting targets:

As I mentioned I have two shooting target templates: target 1 and target 2.

The user then uploads a target that must match one of the templates.

Example that matches target 1

Example that matches target 2

Whenever the uploaded shooting target doesn't match any of the templates, the app should tell the user and not continue with the calculation.

What have I done and tried so far:

For starters, I figured it would be beneficial to remove everything from the background and crop the image by the shooting target, and so I did. (I thought if I removed all of the background interference I could easily just compare the two images, but I later found out this actually wouldn't be accurate at all).

After that, I tried to calculate the percentage of the black color to the other color inside the target (without the background), but again found out this wouldn't be accurate since the shooter could shoot through a lot of the black color and then the percentage would fluctuate. Also, I wouldn't be able to tell if it's one of the templates since another completely different shooting target could have the same amount of black color in the middle.

As of comparison of the two images, I tried a lot of ways (histogram, feature matching with brute force, template matching) and neither of those seemed to be accurate nor usable (I could have been doing it wrong tho, that's a possibility).

What I have figured after all of those failures is that possibly the best solution would be to compare the circles inside the shooting target or the numbers inside the black middle circles, but I couldn't figure out how to do so properly.

Do you guys have any idea on how to go about this? I would really appreciate any help or any push towards the solution of my problem. Code examples are highly appreciated and would make my day.

Best regards.

答:
The targets seem to differ only in score bands (rings) 4, 5 and 6. So I would try and concentrate on those areas.

I took your sample images and resized them to exactly 500x500 pixels, then I measured the radius from the centre to the outside edge of band 4 (which was 167 px) and to the edge of band 6 (which was 95 px). So the outer limit of the area of interest is 167/500, or 0.33xW and the inner limit is 95/500, or 0.19xW where W is the width of the enclosing rectangle.

So, you can draw that mask like this:

```<code>#!/usr/bin/env python3

import numpy as np
import cv2

# Define width/height of target in pixels
W = 300

# Make mask, white for area of interest, black elsewhere
mask = np.zeros((W,W),dtype=np.uint8)
cv2.circle(mask, (W//2,W//2), int(0.33*W), 255, -1)  # White outer circle
cv2.circle(mask, (W//2,W//2), int(0.19*W), 0, -1)    # Black inner circle
</code>```

That gives you this mask:

You can now calculate, say, the mean of all pixels within that mask using:

```<code>maskedMean = cv2.mean(YourImage, mask)
</code>```

and only pixels that are white within the mask will contribute to the mean.

Here is the mask placed beside one of your targets:

Body:
The targets seem to differ only in score bands (rings) 4, 5 and 6. So I would try and concentrate on those areas.

I took your sample images and resized them to exactly 500x500 pixels, then I measured the radius from the centre to the outside edge of band 4 (which was 167 px) and to the edge of band 6 (which was 95 px). So the outer limit of the area of interest is 167/500, or 0.33xW and the inner limit is 95/500, or 0.19xW where W is the width of the enclosing rectangle.

So, you can draw that mask like this:

#!/usr/bin/env python3

import numpy as np
import cv2

# Define width/height of target in pixels
W = 300

# Make mask, white for area of interest, black elsewhere
mask = np.zeros((W,W),dtype=np.uint8)
cv2.circle(mask, (W//2,W//2), int(0.33*W), 255, -1)  # White outer circle
cv2.circle(mask, (W//2,W//2), int(0.19*W), 0, -1)    # Black inner circle

That gives you this mask:

You can now calculate, say, the mean of all pixels within that mask using:

maskedMean = cv2.mean(YourImage, mask)

and only pixels that are white within the mask will contribute to the mean.

Here is the mask placed beside one of your targets:


来源: stackexchange

问:
get_attribute problem with selenium python
I've been suing Selenium-Python for about 2 months. I want to get 'rel' attribute value. Every other values are working, but 'rel' value returns none
i.e

```<code><span class="isOdd" data-ratio="-1" data-outcome="1.85" data-percentage="23" data-market-id="1677954" data-outcomeno="1" data-id="undefined" rel="[{'fixedoddsweb':'1.62','ratiostatus':0},{'fixedoddsweb':'1.90','ratiostatus':-1},{'fixedoddsweb':'1.85','ratiostatus':-1}]" style="" xpath="1">1.85
</code>```

and if I try like;

```<code>link = browser.find_element_by_xpath("//*[@id='eventContentContainer']/div[2]/div[1]/span[4]/ul/li[1]/span")
print(str(link.get_attribute("class")))
</code>```

it returns, isOdd and its correct .
Or if I try to take data-id it returns undefined which is correct value again. Now,

If I try to take rel attribute it returns "None"

I searched on the internet, they always same thing again and again about get_attribute value. I am not good in HTML. Is there any special thing for rel attribute?

Edit 1:
I also used execute.script() for another element, and the output like;

```<code>{'class': 'isOdd', 'data-id': 'undefined', 'data-market-id': '1679546', 'data-outcome': '3.10', 'data-outcomeno': '1', 'data-percentage': '3', 'data-ratio': '-1'}
</code>```

every attribute was printed except 'rel'

Edit 2:
I found the REAL problem, if you wait on the element about 1-2 seconds, then some tags pops on the elenment then it has rel attribute. Do you know how to wait on the element about 1 sec then click? I guess it is about dynamic element

答:
This might be what you are after?

```<code>link=WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH,"//*[@id='eventContentContainer']/div[4]/div[4]/span[4]/ul/li[4]/span")))
print(link.get_attribute('rel'))
</code>```

Add these imports before trying the above:

```<code>from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I've been suing Selenium-Python for about 2 months. I want to get 'rel' attribute value. Every other values are working, but 'rel' value returns none
i.e

1.85

and if I try like;

link = browser.find_element_by_xpath("//*[@id='eventContentContainer']/div[2]/div[1]/span[4]/ul/li[1]/span")
print(str(link.get_attribute("class")))

it returns, isOdd and its correct .
Or if I try to take data-id it returns undefined which is correct value again. Now,

If I try to take rel attribute it returns "None"

I searched on the internet, they always same thing again and again about get_attribute value. I am not good in HTML. Is there any special thing for rel attribute?

Edit 1:
I also used execute.script() for another element, and the output like;

{'class': 'isOdd', 'data-id': 'undefined', 'data-market-id': '1679546', 'data-outcome': '3.10', 'data-outcomeno': '1', 'data-percentage': '3', 'data-ratio': '-1'}

every attribute was printed except 'rel'

Edit 2:
I found the REAL problem, if you wait on the element about 1-2 seconds, then some tags pops on the elenment then it has rel attribute. Do you know how to wait on the element about 1 sec then click? I guess it is about dynamic element

Body:
This might be what you are after?

link=WebDriverWait(browser, 10).until(EC.presence_of_element_located((By.XPATH,"//*[@id='eventContentContainer']/div[4]/div[4]/span[4]/ul/li[4]/span")))
print(link.get_attribute('rel'))

Add these imports before trying the above:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait


问:
On submitting the form in /reg.html, "Method Not Allowed The method is not allowed for the requested URL." is shown
I'm trying the following:

Open homepage.html first

If Register is selected, move to reg.html and enter the form. Submit the form and do some backend processing

If Show is selected, print the registered APIs

The issue I'm facing is when I'm trying to fill the form and clicking on submit, it shows error 405. The further actions are thus void.

homepage.html

```<code><!DOCTYPE html>
<html>
  <head>
    <title>API Management Platform</title>
  </head>
  <body>
    <h1>Welcome to API Management Platform</h1>
    <h2>You can register a new API and also see a list of already registered APIs</h2>
    Click on one of the following links!<br>
        1. <a href=reg>Register a new API</a><br>
        2. <a href=show>Display the list of APIs</a><br>
  </body>
</html>
</code>```

reg.html

```<code><!DOCTYPE html>
<html>
  <head>
    <title>Register API</title>
  </head>
  <body>
    <h1>Welcome to API Management Platform</h1>
    <h2>Please enter the API details</h2>
    <form action=. method="POST" enctype="multipart/form-data">
      <h3>API Data</h3>
      <p>Name: <input type = "text" name = "Name" /></p>
      <p>Description: <input type = "text" name = "Description" /></p>
      <p>Link: <input type = "url" name = "Link" /></p>
      <p>Developer: <input type = "text" name = "Developer" /></p>
      <input type="submit" name="my-form" value="Submit"><br>
    </form>
  </body>
</html>
</code>```

show.html

```<code><!DOCTYPE html>
<html>
   <head>
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>List of APIs</title>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
   </head>
   <body>
      <br />
      <div class="container" >
         <div class="table-responsive">
            <h1>Details</h1>
            <br />
            <table class="table table-bordered table-striped" id="employee_table">
               <tr>
                    <th>API ID</th>
                    <th>Name</th>
                    <th>Description</th>
                    <th>Link</th>
                    <th>Developed By</th>
               </tr>
            </table>
         </div>
      </div>
      <br />
   </body>
</html>
<script>
  $(document).ready(function(){
    $.getJSON("https://extendsclass.com/api/json-storage/bin/dabbbff", function(data){
      var employee_data = '';
      $.each(data, function(key, value){
        employee_data += '<tr>';
        employee_data += '<td>'+key+'</td>';
        employee_data += '<td>'+value.Name+'</td>';
        employee_data += '<td>'+value.Description+'</td>';
        employee_data += '<td>'+value.Link+'</td>';
        employee_data += '<td>'+value.Developer+'</td>';
        employee_data += '<tr>';
      });
      $('#employee_table').append(employee_data);
    });
  });
</script>
</code>```

UI_AMP.py

```<code>from flask import Flask, request, render_template, redirect, url_for
import sys,os
from CMD_AMP import *

app = Flask(__name__)

@app.route('/')
def home():
    return render_template("homepage.html")

@app.route('/reg')
def regAPI():
    return render_template("reg.html")

@app.route('/show')
def getAPI():
    return render_template("show.html")

@app.route('/reg', methods=['POST'])
def my_form_post():
        name = request.form['Name']
        print(name)
        desc = request.form['Description']
        print(desc)
        link = request.form['Link']
        print(link)
        devr = request.form['Developer']
        print(devr)
        apidev = {"Name": name, "Description": desc, "Link": link, "Developer": devr}
        insertAPI(apidev)
        return render_template("show.html")

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5555, debug=True, threaded=True)
</code>```

答:
The reason the error is occurring is:

Because you have "action = . " in your form.

On page render that translates to " action = '.' " .

Which routes to :

```<code>@app.route('/')
def home():
</code>```

Since the home function is not written to handle a POST method(default is GET). You get a "A 405 Method Not Allowed Error"

By default the if you do not assign a form action, when you submit the form it routes to the function/route of the page it is on.

In your reg.html, change this line

```<code><form action=. method="POST" enctype="multipart/form-data">
</code>```

to

```<code><form action="{{url_for('my_form_post')}}" method="POST" enctype="multipart/form-data">
</code>```

Body:
I'm trying the following:

Open homepage.html first

If Register is selected, move to reg.html and enter the form. Submit the form and do some backend processing

If Show is selected, print the registered APIs

The issue I'm facing is when I'm trying to fill the form and clicking on submit, it shows error 405. The further actions are thus void.

homepage.html

<!DOCTYPE html>

    <title>API Management Platform</title>

Welcome to API Management Platform

You can register a new API and also see a list of already registered APIs

    Click on one of the following links!

        1. Register a new API

        2. Display the list of APIs

reg.html

<!DOCTYPE html>

    <title>Register API</title>

Welcome to API Management Platform

Please enter the API details

    <form action=. method="POST" enctype="multipart/form-data">

API Data

Name: <input type = "text" name = "Name" />

Description: <input type = "text" name = "Description" />

Link: <input type = "url" name = "Link" />

Developer: <input type = "text" name = "Developer" />

      <input type="submit" name="my-form" value="Submit">

    </form>

show.html

<!DOCTYPE html>

      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>List of APIs</title>

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />

Details

                    API ID
                    Name
                    Description
                    Link
                    Developed By

UI_AMP.py

from flask import Flask, request, render_template, redirect, url_for
import sys,os
from CMD_AMP import *

app = Flask(__name__)

@app.route('/')
def home():
    return render_template("homepage.html")

@app.route('/reg')
def regAPI():
    return render_template("reg.html")

@app.route('/show')
def getAPI():
    return render_template("show.html")

@app.route('/reg', methods=['POST'])
def my_form_post():
        name = request.form['Name']
        print(name)
        desc = request.form['Description']
        print(desc)
        link = request.form['Link']
        print(link)
        devr = request.form['Developer']
        print(devr)
        apidev = {"Name": name, "Description": desc, "Link": link, "Developer": devr}
        insertAPI(apidev)
        return render_template("show.html")

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5555, debug=True, threaded=True)

Body:
The reason the error is occurring is:

Because you have "action = . " in your form.

On page render that translates to " action = '.' " .

Which routes to :

@app.route('/')
def home():

Since the home function is not written to handle a POST method(default is GET). You get a "A 405 Method Not Allowed Error"

By default the if you do not assign a form action, when you submit the form it routes to the function/route of the page it is on.

In your reg.html, change this line

<form action=. method="POST" enctype="multipart/form-data">

to

<form action="{{url_for('my_form_post')}}" method="POST" enctype="multipart/form-data">


问:
Error response from daemon: Get https://registry-1.docker.io/v2/: dial tcp: lookup registry-1.docker.io on 192.168.65.1:53: no such host
I am new to dockers. When I am running the docker pull sonarqube I am getting the following error.

Error response from daemon: Get https://registry-1.docker.io/v2/: dial TCP: lookup registry-1.docker.io on 192.168.65.1:53: no such host

Can you please let me know why I am getting the error and how can I rectify this.

答:
make sure that your server is not located in the following areas:

Docker is a US company, we must comply with US export control regulations. In an  effort to comply with these, we now block all IP addresses that are located in Cuba,  Iran, North Korea, Republic of Crimea, Sudan, and Syria.

ContentLicense: CC BY-SA 3.0


问:
Force www. and https in nginx.conf (SSL)
After purchasing a SSL certificate I have been trying to force all pages to secured https and to www.

https://www.exampl.com is working and secure but only if type it in exactly. www.example.com or example.com are still pointing to http.

We use nginx as a proxy and need to input the rewrite there. I have SSH / root access via Putty. I have accessed nginx.conf by inputting into putty.

Now what? Do I input the nginx commands on this page? Starting where the cursor is? Any command lines first?

HTTPS:

.htacess – Original code I was given before I found out I had to input into nginx

```<code>RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
</code>```

Nginx code converter – This is how it shows on the converter. Is everything on the correct lines?

```<code># nginx configuration location / {
if ($http_host ~* "^example.com"){
rewrite ^(.*)$ http://example.com/$1 redirect; } }
</code>```

and then

WWW

.htacess – Original code I was given before I found out I had to input into nginx

```<code>#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
</code>```

Nginx code converter – This is how it shows on the converter. Is everything on the correct line?

```<code># nginx configuration location / {
if ($http_host ~* "^example.com"){
rewrite ^(.*)$ http://www.example.com/$1 redirect; }
</code>```

}

Do I then save? Restart?

Any help would be greatly appreciated. I have been battling this for weeks. My Hosting company helped as far as they could, now I am learning on the fly…. Or should I just stop and hire a developer? $$$

Thanks

答:
I searched a lot , finally this is my right answer.
     also remember to add a www A record in your domain registar's dns control panel. </p>

```<code> # Force all users to https://www.example.com
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://www.example.com$request_uri;
}
server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate /etc/nginx/ssl/www.example.com.pem;
    ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
    return 301 https://www.example.com$request_uri;
}
server {
    listen 443 ssl;
    server_name www.example.com;
    root /var/www/html

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;
    ssl_certificate /etc/nginx/ssl/www.example.com.pem;
    ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
}
</code>```

Body:
After purchasing a SSL certificate I have been trying to force all pages to secured https and to www.

https://www.exampl.com is working and secure but only if type it in exactly. www.example.com or example.com are still pointing to http.

We use nginx as a proxy and need to input the rewrite there. I have SSH / root access via Putty. I have accessed nginx.conf by inputting into putty.

Now what? Do I input the nginx commands on this page? Starting where the cursor is? Any command lines first?

HTTPS:

.htacess – Original code I was given before I found out I had to input into nginx

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Nginx code converter – This is how it shows on the converter. Is everything on the correct lines?

# nginx configuration location / {
if ($http_host ~* "^example.com"){
rewrite ^(.*)$ http://example.com/$1 redirect; } }

and then

WWW

.htacess – Original code I was given before I found out I had to input into nginx

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Nginx code converter – This is how it shows on the converter. Is everything on the correct line?

# nginx configuration location / {
if ($http_host ~* "^example.com"){
rewrite ^(.*)$ http://www.example.com/$1 redirect; }

}

Do I then save? Restart?

Any help would be greatly appreciated. I have been battling this for weeks. My Hosting company helped as far as they could, now I am learning on the fly…. Or should I just stop and hire a developer? $$$

Thanks

Body:
I searched a lot , finally this is my right answer.
     also remember to add a www A record in your domain registar's dns control panel.

 # Force all users to https://www.example.com
server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://www.example.com$request_uri;
}
server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate /etc/nginx/ssl/www.example.com.pem;
    ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
    return 301 https://www.example.com$request_uri;
}
server {
    listen 443 ssl;
    server_name www.example.com;
    root /var/www/html

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;
    ssl_certificate /etc/nginx/ssl/www.example.com.pem;
    ssl_certificate_key /etc/nginx/ssl/www.example.com.key;
}


问:
Cannot run program CreateProcess error=206, The filename or extension is too long
I get the titled error when I use jvmarguments in the pom file. I'm using mvnw command with the below plugin to enable debugging. If I remove the jvm argument, it works. But I want to enable remote debugging with the mvnw command

Code Snippet:

```<code><plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>${start-class}</mainClass>
            <executable>true</executable>
            <fork>true</fork>
            <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
        </configuration>
</plugin>
</code>```

Error:

*[ERROR] Failed to execute goal
  org.springframework.boot:spring-boot-maven-plugin:2.0.7.RELEASE:run
  (default-cli) on project dxcgateway: Could not exec java: Cannot run
  program "C:\Program Files\Java\jdk1.8.0_202\jre\bin\java.exe":
  CreateProcess error=206, The filename or extension is too long ->
  [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException:
  Failed to execute goal
  org.springframework.boot:spring-boot-maven-plugin:2.0.7.RELEASE:run
  (default-cli) on project dxcg ateway: Could not exec java

Caused by: java.io.IOException: Cannot run program "C:\Program
  Files\Java\jdk1.8.0_202\jre\bin\java.exe": CreateProcess error=206,
  The filename or extension is too long
      at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
      at org.springframework.boot.loader.tools.RunProcess.run (RunProcess.java:77)

Caused by: java.io.IOException: Cannot run program "C:\Program
  Files\Java\jdk1.8.0_202\jre\bin\java.exe": CreateProcess error=206,
  The filename or extension is too long
      at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
      at org.springframework.boot.loader.tools.RunProcess.run (RunProcess.java:77)*

答:
change </p>

```<code><fork>true</fork>
</code>```

<p>to </p>

```<code><fork>false</fork>
</code>```

Body:
I get the titled error when I use jvmarguments in the pom file. I'm using mvnw command with the below plugin to enable debugging. If I remove the jvm argument, it works. But I want to enable remote debugging with the mvnw command

Code Snippet:

<plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
            <execution>
                <goals>
                    <goal>repackage</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <mainClass>${start-class}</mainClass>
            <executable>true</executable>
            <fork>true</fork>
            <jvmArguments>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmArguments>
        </configuration>
</plugin>

Error:

*[ERROR] Failed to execute goal
  org.springframework.boot:spring-boot-maven-plugin:2.0.7.RELEASE:run
  (default-cli) on project dxcgateway: Could not exec java: Cannot run
  program "C:\Program Files\Java\jdk1.8.0_202\jre\bin\java.exe":
  CreateProcess error=206, The filename or extension is too long ->
  [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException:
  Failed to execute goal
  org.springframework.boot:spring-boot-maven-plugin:2.0.7.RELEASE:run
  (default-cli) on project dxcg ateway: Could not exec java

Caused by: java.io.IOException: Cannot run program "C:\Program
  Files\Java\jdk1.8.0_202\jre\bin\java.exe": CreateProcess error=206,
  The filename or extension is too long
      at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
      at org.springframework.boot.loader.tools.RunProcess.run (RunProcess.java:77)

Caused by: java.io.IOException: Cannot run program "C:\Program
  Files\Java\jdk1.8.0_202\jre\bin\java.exe": CreateProcess error=206,
  The filename or extension is too long
      at java.lang.ProcessBuilder.start (ProcessBuilder.java:1048)
      at org.springframework.boot.loader.tools.RunProcess.run (RunProcess.java:77)*

Body:
change

<fork>true</fork>

to

<fork>false</fork>


问:
Split dataframe into many sub-dataframes based on timestamp
I have a large csv with the following format:

```<code>timestamp,name,age
2020-03-01 00:00:01,nick
2020-03-01 00:00:01,john
2020-03-01 00:00:02,nick
2020-03-01 00:00:02,john
2020-03-01 00:00:04,peter
2020-03-01 00:00:05,john
2020-03-01 00:00:10,nick
2020-03-01 00:00:12,john
2020-03-01 00:00:54,hank
2020-03-01 00:01:03,peter
</code>```

I load csv into a dataframe with:

```<code>df = pd.read_csv("/home/test.csv")
</code>```

and then I want to create multiple dataframes every 2 seconds. For example:

df1 contains:

```<code>2020-03-01 00:00:01,nick
2020-03-01 00:00:01,john
2020-03-01 00:00:02,nick
2020-03-01 00:00:02,john
</code>```

df2 contains :

```<code>2020-03-01 00:00:04,peter
2020-03-01 00:00:05,john
</code>```

and so on.

I achieve to split timestamps with command below:

```<code>full_idx = pd.date_range(start=df['timestamp'].min(), end = df['timestamp'].max(), freq ='0.2T')
</code>```

but how I can store these spitted dataframes? How can I split a dataset based on timestamps into multiple dataframes?

答:
How about .resample()?

```<code>#first loading your data
>>> import pandas as pd
>>>
>>> df = pd.read_csv('dates.csv', index_col='timestamp', parse_dates=True)
>>> df.head()
                      name  age
timestamp
2020-03-01 00:00:01   nick  NaN
2020-03-01 00:00:01   john  NaN
2020-03-01 00:00:02   nick  NaN
2020-03-01 00:00:02   john  NaN
2020-03-01 00:00:04  peter  NaN

#resampling it at a frequency of 2 seconds
>>> resampled = df.resample('2s')
>>> type(resampled)
<class 'pandas.core.resample.DatetimeIndexResampler'>

#iterating over the resampler object and storing the sliced dfs in a dictionary
>>> df_dict = {}
>>> for i, (timestamp,df) in enumerate(resampled):
>>>     df_dict[i] = df
>>> df_dict[0]
                     name  age
timestamp
2020-03-01 00:00:01  nick  NaN
2020-03-01 00:00:01  john  NaN
</code>```

Now for some explanation...

resample() is great for rebinning DataFrames based on time (I use it often for downsampling time series data), but it can be used simply to cut up the DataFrame, as you want to do.  Iterating over the resampler object produced by df.resample() returns a tuple of (name of the bin,df corresponding to that bin): e.g. the first tuple is (timestamp of the first second,data corresponding to the first 2 seconds).  So to get the DataFrames out, we can loop over this object and store them somewhere, like a dict.

Note that this will produce every 2-second interval from the start to the end of the data, so many will be empty given your data.  But you can add a step to filter those out if needed.

Additionally, you could manually assign each sliced DataFrame to a variable, but this would be cumbersome (you would probably need to write a line for each 2 second bin, rather than a single small loop).  Rather with a dictionary, you can still associate each DataFrame with a callable name.  You could also use an OrderedDict or list or whatever collection.

A couple points on your script:

setting freq to "0.2T" is 12 seconds (.2 *60); you can rather
do freq="2s"

The example df and df2 are "out of phase," by that I mean one is binned in 2 seconds starting on odd numbers (1-2 seconds), while one is starting on evens (4-5 seconds).  So the date_range you mentioned wouldn't create those bins, it would create dfs from either 0-1s, 2-3s, 4-5s... OR 1-2s,3-4s,5-6s,... depending on which timestamp it started on.

For the latter point, you can use the base argument of .resample() to set the "phase" of the resampling.  So in the case above, base=0 would start bins on even numbers, and base=1 would start bins on odds.

This is assuming you are okay with that type of binning - if you really want 1-2 seconds and 4-5 seconds to be in different bins, you would have to do something more complicated I believe.

Body:
I have a large csv with the following format:

timestamp,name,age
2020-03-01 00:00:01,nick
2020-03-01 00:00:01,john
2020-03-01 00:00:02,nick
2020-03-01 00:00:02,john
2020-03-01 00:00:04,peter
2020-03-01 00:00:05,john
2020-03-01 00:00:10,nick
2020-03-01 00:00:12,john
2020-03-01 00:00:54,hank
2020-03-01 00:01:03,peter

I load csv into a dataframe with:

df = pd.read_csv("/home/test.csv")

and then I want to create multiple dataframes every 2 seconds. For example:

df1 contains:

2020-03-01 00:00:01,nick
2020-03-01 00:00:01,john
2020-03-01 00:00:02,nick
2020-03-01 00:00:02,john

df2 contains :

2020-03-01 00:00:04,peter
2020-03-01 00:00:05,john

and so on.

I achieve to split timestamps with command below:

full_idx = pd.date_range(start=df['timestamp'].min(), end = df['timestamp'].max(), freq ='0.2T')

but how I can store these spitted dataframes? How can I split a dataset based on timestamps into multiple dataframes?

Body:
How about .resample()?

#first loading your data
>>> import pandas as pd
>>>
>>> df = pd.read_csv('dates.csv', index_col='timestamp', parse_dates=True)
>>> df.head()
                      name  age
timestamp
2020-03-01 00:00:01   nick  NaN
2020-03-01 00:00:01   john  NaN
2020-03-01 00:00:02   nick  NaN
2020-03-01 00:00:02   john  NaN
2020-03-01 00:00:04  peter  NaN

#resampling it at a frequency of 2 seconds
>>> resampled = df.resample('2s')
>>> type(resampled)
<class 'pandas.core.resample.DatetimeIndexResampler'>

#iterating over the resampler object and storing the sliced dfs in a dictionary
>>> df_dict = {}
>>> for i, (timestamp,df) in enumerate(resampled):
>>>     df_dict[i] = df
>>> df_dict[0]
                     name  age
timestamp
2020-03-01 00:00:01  nick  NaN
2020-03-01 00:00:01  john  NaN

Now for some explanation...

resample() is great for rebinning DataFrames based on time (I use it often for downsampling time series data), but it can be used simply to cut up the DataFrame, as you want to do.  Iterating over the resampler object produced by df.resample() returns a tuple of (name of the bin,df corresponding to that bin): e.g. the first tuple is (timestamp of the first second,data corresponding to the first 2 seconds).  So to get the DataFrames out, we can loop over this object and store them somewhere, like a dict.

Note that this will produce every 2-second interval from the start to the end of the data, so many will be empty given your data.  But you can add a step to filter those out if needed.

Additionally, you could manually assign each sliced DataFrame to a variable, but this would be cumbersome (you would probably need to write a line for each 2 second bin, rather than a single small loop).  Rather with a dictionary, you can still associate each DataFrame with a callable name.  You could also use an OrderedDict or list or whatever collection.

A couple points on your script:

setting freq to "0.2T" is 12 seconds (.2 *60); you can rather
do freq="2s"

The example df and df2 are "out of phase," by that I mean one is binned in 2 seconds starting on odd numbers (1-2 seconds), while one is starting on evens (4-5 seconds).  So the date_range you mentioned wouldn't create those bins, it would create dfs from either 0-1s, 2-3s, 4-5s... OR 1-2s,3-4s,5-6s,... depending on which timestamp it started on.

For the latter point, you can use the base argument of .resample() to set the "phase" of the resampling.  So in the case above, base=0 would start bins on even numbers, and base=1 would start bins on odds.

This is assuming you are okay with that type of binning - if you really want 1-2 seconds and 4-5 seconds to be in different bins, you would have to do something more complicated I believe.


问:
determine if an application is shutting down normally
is there a way to determing if a jvm is shutting down normally?  Shutdown hook can only spawn a thread, is there a way to determine if the JVM is existing normally or abnormally at that time?</p>

答: Check return sttaus using command $?</p>

Body: Check return sttaus using command $?


问:
css rule to apply if only one element sits next to other element
I'd like to ask a question to see IF this is possible in CSS. It may not be: I'm prepared to make some styling concessions.

The context: I'm working on re-styling and redesigning an existing blog. This has over 80 posts that (for the most part) use the same markup. So what I'm trying to do is apply styling that works with the existing html - adding classes and changing orders means going through all posts and will take hours.

Markup example of one post:

```<code><p>Block of text </p>

<img src="example">

<p>Block of text </p>
<img src="example">
<img src="example">

<p>Block of text </p>
<img src="example">
</code>```

This is an example: the order of the images and paragraphs will vary from post to post so this will be completely randomised.

What I'm trying to do is apply a 50% width styling to images that follow each other up, so they sit next to each other.

Like this: □ □

I'd like to style images that sit on their own to be at fullwidth - 100%

Is there a way to achieve this using CSS?

CSS rules like nth-of-type(3) will not work - the order of the images and p tags is completely randomised, so where in one post the 3rd img tag will be placed on its own, in another this will have to sit next to another image.

A rule like img + img would work for the second image, but I would need the first image to also apply the same styling. A rule like p + img will also cause the single images to shrink.

Any suggestions? An answer of 'this cannot be done' is also fine as I'll know to stop trying.

答:
Flexbox can do this. I applied flex to body but it should be the container in your code:

body {
  display:flex;
  flex-wrap:wrap;
}
p {
 width:100%;
}
img {
  width:50%;
  min-width:0;
  flex-grow:1; /* this will do the trick when the image is alone */
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>Block of text </p>

<img src="https://i.picsum.photos/id/107/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/106/800/400.jpg">
<img src="https://i.picsum.photos/id/17/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/108/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/104/800/400.jpg">
<img src="https://i.picsum.photos/id/108/800/400.jpg">
<img src="https://i.picsum.photos/id/175/800/400.jpg">
<img src="https://i.picsum.photos/id/125/800/400.jpg"></code>```

Or like below if you want to apply this to image when there is no image with it even if the number is odd.

body {
  display:flex;
  flex-wrap:wrap;
}
p {
 width:100%;
}
img {
  width:50%;
  min-width:0;
}
p + img {
  flex-grow:1; /* this will do the trick when the image is alone */
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><p>Block of text </p>

<img src="https://i.picsum.photos/id/107/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/106/800/400.jpg">
<img src="https://i.picsum.photos/id/17/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/108/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/104/800/400.jpg">
<img src="https://i.picsum.photos/id/108/800/400.jpg">
<img src="https://i.picsum.photos/id/175/800/400.jpg"></code>```

Body:
I'd like to ask a question to see IF this is possible in CSS. It may not be: I'm prepared to make some styling concessions.

The context: I'm working on re-styling and redesigning an existing blog. This has over 80 posts that (for the most part) use the same markup. So what I'm trying to do is apply styling that works with the existing html - adding classes and changing orders means going through all posts and will take hours.

Markup example of one post:

Block of text

Block of text

Block of text

This is an example: the order of the images and paragraphs will vary from post to post so this will be completely randomised.

What I'm trying to do is apply a 50% width styling to images that follow each other up, so they sit next to each other.

Like this: □ □

I'd like to style images that sit on their own to be at fullwidth - 100%

Is there a way to achieve this using CSS?

CSS rules like nth-of-type(3) will not work - the order of the images and p tags is completely randomised, so where in one post the 3rd img tag will be placed on its own, in another this will have to sit next to another image.

A rule like img + img would work for the second image, but I would need the first image to also apply the same styling. A rule like p + img will also cause the single images to shrink.

Any suggestions? An answer of 'this cannot be done' is also fine as I'll know to stop trying.

Body:
Flexbox can do this. I applied flex to body but it should be the container in your code:

body {
  display:flex;
  flex-wrap:wrap;
}
p {
 width:100%;
}
img {
  width:50%;
  min-width:0;
  flex-grow:1; /* this will do the trick when the image is alone */
}

<p>Block of text </p>

<img src="https://i.picsum.photos/id/107/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/106/800/400.jpg">
<img src="https://i.picsum.photos/id/17/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/108/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/104/800/400.jpg">
<img src="https://i.picsum.photos/id/108/800/400.jpg">
<img src="https://i.picsum.photos/id/175/800/400.jpg">
<img src="https://i.picsum.photos/id/125/800/400.jpg">

Or like below if you want to apply this to image when there is no image with it even if the number is odd.

body {
  display:flex;
  flex-wrap:wrap;
}
p {
 width:100%;
}
img {
  width:50%;
  min-width:0;
}
p + img {
  flex-grow:1; /* this will do the trick when the image is alone */
}

<p>Block of text </p>

<img src="https://i.picsum.photos/id/107/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/106/800/400.jpg">
<img src="https://i.picsum.photos/id/17/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/108/800/400.jpg">

<p>Block of text </p>
<img src="https://i.picsum.photos/id/104/800/400.jpg">
<img src="https://i.picsum.photos/id/108/800/400.jpg">
<img src="https://i.picsum.photos/id/175/800/400.jpg">


问:
ACF Google Map - Marker Clustering
I've been tearing my hair out (not that I have any...) trying to get my head round this, i'm using as close to the ACF Google Map example as I can, I have each location (post) plotting on the map fine but cannot for the life of me get clustering working properly, i'd really appreciate some help in the correct context of what i'm trying to do. None of the solutions i;ve found seem to resolve the issue.

```<code>InvalidValueError: setMap: not an instance of Map; and not an instance of StreetViewPanorama,

Uncaught TypeError: this.map_.getZoom is not a function
</code>```

My JS is as follows (sorry for the post formatting!!!):

```<code>(function($) {

/*
*  render_map
*
*  This function will render a Google Map onto the selected jQuery element
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   $el (jQuery element)
*  @return  n/a
*/

function render_map( $el ) {

    // var
    var $markers = $el.find('.marker');

    // vars
    var args = {
        zoom        : 16,
        center      : new google.maps.LatLng(0, 0),
        mapTypeId   : google.maps.MapTypeId.ROADMAP
    };

    // create map
    var map = new google.maps.Map( $el[0], args);

    // add a markers reference
    map.markers = [];

    // add markers
    $markers.each(function(){
        add_marker( $(this), map );
    });

    // center map
    center_map( map );

    // add marker cluster
    var markerCluster = new MarkerClusterer( map.markers, map );
}

// create info window outside of each - then tell that singular infowindow to swap content based on click
var infowindow = new google.maps.InfoWindow({
    content     : ''
});

/*
*  add_marker
*
*  This function will add a marker to the selected Google Map
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   $marker (jQuery element)
*  @param   map (Google Map object)
*  @return  n/a
*/

function add_marker( $marker, map ) {

    // var
    var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );

    // create marker
    var marker = new google.maps.Marker({
        position    : latlng,
        map         : map
    });

    // add to array
    map.markers.push( marker );

    // if marker contains HTML, add it to an infoWindow
    if( $marker.html() )

    {

        // show info window when marker is clicked & close other markers
        google.maps.event.addListener(marker, 'click', function() {
            //swap content of that singular infowindow
            infowindow.setContent($marker.html());
            infowindow.open(map, marker);
        });

        // close info window when map is clicked
        google.maps.event.addListener(map, 'click', function(event) {
        if (infowindow) {
            infowindow.close(); }
        });
    }
}

/*
*  center_map
*
*  This function will center the map, showing all markers attached to this map
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   map (Google Map object)
*  @return  n/a
*/

function center_map( map ) {

    // vars
    var bounds = new google.maps.LatLngBounds();

    // loop through all markers and create bounds
    $.each( map.markers, function( i, marker ){

        var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
        bounds.extend( latlng );

    });

    // only 1 marker?
    if( map.markers.length == 1 )
    {
        // set center of map
        map.setCenter( bounds.getCenter() );
        map.setZoom( 16 );
    }
    else
    {
        // fit to bounds
        map.fitBounds( bounds );
    }
}

/*
*  document ready
*
*  This function will render each map when the document is ready (page has loaded)
*
*  @type    function
*  @date    8/11/2013
*  @since   5.0.0
*
*  @param   n/a
*  @return  n/a
*/

$(document).ready(function(){

    $('.acf-map').each(function(){

        render_map( $(this) );
    });
});

})(jQuery);
</code>```

Any help would be awesome...

答:
I added it as follows under render_map(). As suggested above you also need to add MarkerClustererPlus library in combination with the Maps JavaScript API to your scripts

```<code>// add marker cluster
var markerCluster = new MarkerClusterer(map, map.markers, {
    imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
</code>```

Title: ACF Google Map - Marker Clustering

Body:
I've been tearing my hair out (not that I have any...) trying to get my head round this, i'm using as close to the ACF Google Map example as I can, I have each location (post) plotting on the map fine but cannot for the life of me get clustering working properly, i'd really appreciate some help in the correct context of what i'm trying to do. None of the solutions i;ve found seem to resolve the issue.

InvalidValueError: setMap: not an instance of Map; and not an instance of StreetViewPanorama,

Uncaught TypeError: this.map_.getZoom is not a function

My JS is as follows (sorry for the post formatting!!!):

(function($) {

/*
*  render_map
*
*  This function will render a Google Map onto the selected jQuery element
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   $el (jQuery element)
*  @return  n/a
*/

function render_map( $el ) {

    // var
    var $markers = $el.find('.marker');

    // vars
    var args = {
        zoom        : 16,
        center      : new google.maps.LatLng(0, 0),
        mapTypeId   : google.maps.MapTypeId.ROADMAP
    };

    // create map
    var map = new google.maps.Map( $el[0], args);

    // add a markers reference
    map.markers = [];

    // add markers
    $markers.each(function(){
        add_marker( $(this), map );
    });

    // center map
    center_map( map );

    // add marker cluster
    var markerCluster = new MarkerClusterer( map.markers, map );
}

// create info window outside of each - then tell that singular infowindow to swap content based on click
var infowindow = new google.maps.InfoWindow({
    content     : ''
});

/*
*  add_marker
*
*  This function will add a marker to the selected Google Map
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   $marker (jQuery element)
*  @param   map (Google Map object)
*  @return  n/a
*/

function add_marker( $marker, map ) {

    // var
    var latlng = new google.maps.LatLng( $marker.attr('data-lat'), $marker.attr('data-lng') );

    // create marker
    var marker = new google.maps.Marker({
        position    : latlng,
        map         : map
    });

    // add to array
    map.markers.push( marker );

    // if marker contains HTML, add it to an infoWindow
    if( $marker.html() )

    {

        // show info window when marker is clicked & close other markers
        google.maps.event.addListener(marker, 'click', function() {
            //swap content of that singular infowindow
            infowindow.setContent($marker.html());
            infowindow.open(map, marker);
        });

        // close info window when map is clicked
        google.maps.event.addListener(map, 'click', function(event) {
        if (infowindow) {
            infowindow.close(); }
        });
    }
}

/*
*  center_map
*
*  This function will center the map, showing all markers attached to this map
*
*  @type    function
*  @date    8/11/2013
*  @since   4.3.0
*
*  @param   map (Google Map object)
*  @return  n/a
*/

function center_map( map ) {

    // vars
    var bounds = new google.maps.LatLngBounds();

    // loop through all markers and create bounds
    $.each( map.markers, function( i, marker ){

        var latlng = new google.maps.LatLng( marker.position.lat(), marker.position.lng() );
        bounds.extend( latlng );

    });

    // only 1 marker?
    if( map.markers.length == 1 )
    {
        // set center of map
        map.setCenter( bounds.getCenter() );
        map.setZoom( 16 );
    }
    else
    {
        // fit to bounds
        map.fitBounds( bounds );
    }
}

/*
*  document ready
*
*  This function will render each map when the document is ready (page has loaded)
*
*  @type    function
*  @date    8/11/2013
*  @since   5.0.0
*
*  @param   n/a
*  @return  n/a
*/

$(document).ready(function(){

    $('.acf-map').each(function(){

        render_map( $(this) );
    });
});

})(jQuery);

Any help would be awesome...

Body:
I added it as follows under render_map(). As suggested above you also need to add MarkerClustererPlus library in combination with the Maps JavaScript API to your scripts

// add marker cluster
var markerCluster = new MarkerClusterer(map, map.markers, {
    imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});


问:
how to rename the object key in nested array of object in javascript dynamically
I need to rename the object key name dynamically in a nested array of object JavaScript, I had tried with this code. This also I got from Stack Overflow only but this is not working that means it checking first level only not doing deep replacing.

```<code>const node = {
  'id': 'de603a3e',
  'name': 'erewr',
  'subGroups': [
     {
        'id': '83d7c7e4',
        'name': 'dfds',
        'subGroups': [ ]
     },
     {
        'id': '050cde96',
        'name': 'tetwet',
        'subGroups': [ ]
     },
     {
        'id': 'd67cc4e8',
        'name': 'wewqe',
        'subGroups': [
           {
              'id': '553c301d',
              'name': 'ewqe',
              'subGroups': [

              ]
           }
        ]
     },
     {
        'id': '5d5ae5f2',
        'name': 'rwq',
        'subGroups': [
           {
              'id': 'ff29ad54',
              'name': 'wqe',
              'subGroups': [

              ]
           },
           {
              'id': '5d013943',
              'name': 'weqe',
              'subGroups': [

              ]
           }
        ]
     }
  ]
}

console.log(renameKey(node, { subGroups: 'subordinates' }))

renameKey(obj, keysMap) {
    return transform(obj, function(result, value, key) {
      const currentKey = keysMap[key] || key;
      result[currentKey] = isObject(value) ? this.renameKey(value, keysMap) : value;
    });
  }
</code>```

I am using this code in TypeScript.
note : transform and isObject are lodash

I am getting error ERROR TypeError: Cannot read property 'replaceKeysDeep' of undefined

答:
This should work</p>

```<code>function renameKeys(node, keysMaps) {
    if(!isObject(node)) return node
    if(Array.isArray(node)) return node.map(item => renameKeys(item, keysMaps))

    return Object.entries(node).reduce((result, [key, value]) => {
        const newKey = keysMaps[key] || key;
        return {
            ...result,
            [newKey]: renameKeys(value, keysMaps)

        };
    }, {});
}
</code>```

Body:
I need to rename the object key name dynamically in a nested array of object JavaScript, I had tried with this code. This also I got from Stack Overflow only but this is not working that means it checking first level only not doing deep replacing.

const node = {
  'id': 'de603a3e',
  'name': 'erewr',
  'subGroups': [
     {
        'id': '83d7c7e4',
        'name': 'dfds',
        'subGroups': [ ]
     },
     {
        'id': '050cde96',
        'name': 'tetwet',
        'subGroups': [ ]
     },
     {
        'id': 'd67cc4e8',
        'name': 'wewqe',
        'subGroups': [
           {
              'id': '553c301d',
              'name': 'ewqe',
              'subGroups': [

              ]
           }
        ]
     },
     {
        'id': '5d5ae5f2',
        'name': 'rwq',
        'subGroups': [
           {
              'id': 'ff29ad54',
              'name': 'wqe',
              'subGroups': [

              ]
           },
           {
              'id': '5d013943',
              'name': 'weqe',
              'subGroups': [

              ]
           }
        ]
     }
  ]
}

console.log(renameKey(node, { subGroups: 'subordinates' }))

renameKey(obj, keysMap) {
    return transform(obj, function(result, value, key) {
      const currentKey = keysMap[key] || key;
      result[currentKey] = isObject(value) ? this.renameKey(value, keysMap) : value;
    });
  }

I am using this code in TypeScript.
note : transform and isObject are lodash

I am getting error ERROR TypeError: Cannot read property 'replaceKeysDeep' of undefined

Body:
This should work

function renameKeys(node, keysMaps) {
    if(!isObject(node)) return node
    if(Array.isArray(node)) return node.map(item => renameKeys(item, keysMaps))

    return Object.entries(node).reduce((result, [key, value]) => {
        const newKey = keysMaps[key] || key;
        return {
            ...result,
            [newKey]: renameKeys(value, keysMaps)

        };
    }, {});
}


问:
Eclipse in Windows10 : write "hello world" in C, got error : error in final lauch sequence
I am using Exlipse in Win10-64bit to right a simple "Hello World" in C

Here is my steps :

Donwload Eclipse-inst-win64 then execute

In exlipse -> Help -> Eclipse Marketspace, update Eclipse C/C++ IDE CDT 9.11 and install all the package

Download mingw-get-setup and install with all the package in Basic Setup

Set the path of bin of Mingw for system

Run Eclipse, create C project "Hello World ANSI C Project" with Toolchain "Mingw GCC"

Click "Build", then "Debug"
And I got the error as the photo :

Could anyone help me?
Thank you very much!

答: If you Google this problem, you’ll find tutorials that can help you and possibly explain this error 5. Setting up and IDE is just a basic process if you got any problem with your program or code instead, we are always here to help you. By the way, refer here to resolve your problem.


问:
Having Trouble Executing While Loop
I am attempting to create a coronavirus temp scan compare program. I want to open an excel file and create a small database each day of scanned employees. When I execute I am just getting the first input prompt and my excel spreadsheet is not opening. My goal was to have each line of code under the while statement nested and would continue to loop until the program operator ended the loop. My code is below. Any help is appreciated.</p>

```<code>from datetime import date
from xlwt import Workbook

# Workbook is created
wb = Workbook()

# add sheet
sheet1 = wb.add_sheet('Temperature Scans')

sheet1.write(0, 0, 'First Name')
sheet1.write(0, 1, 'Last Name')
sheet1.write(0, 2, 'Date')
sheet1.write(0, 3, 'Temperature')

Normal = 98.6

Recording = input("Are you Recording Temperature Today? 1 if yes; 0 if no: ")

while Recording == 1:
    Employee_First = input("Enter First Name: ")
    Employee_Last = input("Enter Last Name: ")
    Temp = float(input("Input Scanned Temperature (Example if 99 degrees enter 99): "))
    if Temp > Normal:
            print("Elevated Temperature Detected! Entrance Not Permitted")
    else:
            print("Temperature Within Acceptable Limits. Entrance Permitted")
    Date = today.strftime("%m/%d/%y")
    for i in range(0, 15000):
            sheet1.write(i+1, 0, Employee_First)
            sheet1.write(i+1, 1, Employee_Last)
            sheet1.write(i+1, 2, Date)
            sheet1.write(i+1, 3, Temp)

            Day = today.strftime("%d")
            Month = today.strftime("%m")
            Year = today.strftime("%y")

            wb.save(Month, _ , Day, _ , Year, 'Temp Scans.xlsx')

    break

    continue
</code>```

答:
Change this of your code:

```<code>Recording = input("Are you Recording Temperature Today? 1 if yes; 0 if no: ")
</code>```

To:

```<code>try:
    Recording = int(input("Are you Recording Temperature Today? 1 if yes; 0 if no: "))
except:
    print("Please enter a valid number (either 1 or 0)")
</code>```

in order to make sure that you enter the while loop:

```<code>...
while Recording == 1:
    Employee_First = input("Enter First Name: ")
...
</code>```

Since the input() will always return a string variable and you are making the comparison on the while loop with an integer.

EDIT

Here is a mofification of the code you provided using the openpyxl library. The code below will interactively ask for the employee's first name, last name and temperature and finally overwrite the temperaturescans.xlsx file (or create it if it doesn't exist and you run the python script for the first time).

```<code>from openpyxl import Workbook
from datetime import datetime

#Create workbook
wb = Workbook()

# grab the active worksheet
ws = wb.active

# Fill up the headers on the first row
ws['A1'] = 'First Name'
ws['B1'] = 'Last Name'
ws['C1'] = 'Date'
ws['D1'] = 'Temperature'

#Define some constant values
normal_temperature = 98.6
date = datetime.today().strftime('%m/%d/%y')

try:
    recording = int(input("Are you Recording Temperature Today? 1 if yes; 0 if no: "))
except:
     print('Please enter a number: either 1 or 0')

while recording == 1:
    #Get employees First Name
    employee_first = input('Enter First Name:')
    #Get employees Last Name
    employee_last = input('Enter Last Name:')
    #Get temperature
    try:
        temperature = float(input('Input Scanned Temperature (example if 99 degrees enter 99):'))
    except:
        print('Please enter a valid value for the temperature (99.2, 98.6)')
    #Check if the employee has a fever
    if temperature > normal_temperature:
        print('Elevated Temperature Detected! Entrance Not Permitted')
    else:
        print("Temperature Within Acceptable Limits. Entrance Permitted")
    #Add the employees row to the sheet
    ws.append([employee_first,employee_last,date,temperature])

    try:
        recording = int(input("Are you Recording Temperature Today? 1 if yes; 0 if no: "))
    except:
        print('All recordings have been made. Saving the file.')

#Save the file
print('Check the temperaturescans.xlsx file for the results.')
wb.save("temperaturescans.xlsx")
</code>```

Title: Having Trouble Executing While Loop

Body:
I am attempting to create a coronavirus temp scan compare program. I want to open an excel file and create a small database each day of scanned employees. When I execute I am just getting the first input prompt and my excel spreadsheet is not opening. My goal was to have each line of code under the while statement nested and would continue to loop until the program operator ended the loop. My code is below. Any help is appreciated.

from datetime import date
from xlwt import Workbook

# Workbook is created
wb = Workbook()

# add sheet
sheet1 = wb.add_sheet('Temperature Scans')

sheet1.write(0, 0, 'First Name')
sheet1.write(0, 1, 'Last Name')
sheet1.write(0, 2, 'Date')
sheet1.write(0, 3, 'Temperature')

Normal = 98.6

Recording = input("Are you Recording Temperature Today? 1 if yes; 0 if no: ")

while Recording == 1:
    Employee_First = input("Enter First Name: ")
    Employee_Last = input("Enter Last Name: ")
    Temp = float(input("Input Scanned Temperature (Example if 99 degrees enter 99): "))
    if Temp > Normal:
            print("Elevated Temperature Detected! Entrance Not Permitted")
    else:
            print("Temperature Within Acceptable Limits. Entrance Permitted")
    Date = today.strftime("%m/%d/%y")
    for i in range(0, 15000):
            sheet1.write(i+1, 0, Employee_First)
            sheet1.write(i+1, 1, Employee_Last)
            sheet1.write(i+1, 2, Date)
            sheet1.write(i+1, 3, Temp)

            Day = today.strftime("%d")
            Month = today.strftime("%m")
            Year = today.strftime("%y")

            wb.save(Month, _ , Day, _ , Year, 'Temp Scans.xlsx')

    break

    continue

Body:
Change this of your code:

Recording = input("Are you Recording Temperature Today? 1 if yes; 0 if no: ")

To:

try:
    Recording = int(input("Are you Recording Temperature Today? 1 if yes; 0 if no: "))
except:
    print("Please enter a valid number (either 1 or 0)")

in order to make sure that you enter the while loop:

...
while Recording == 1:
    Employee_First = input("Enter First Name: ")
...

Since the input() will always return a string variable and you are making the comparison on the while loop with an integer.

EDIT

Here is a mofification of the code you provided using the openpyxl library. The code below will interactively ask for the employee's first name, last name and temperature and finally overwrite the temperaturescans.xlsx file (or create it if it doesn't exist and you run the python script for the first time).

from openpyxl import Workbook
from datetime import datetime

#Create workbook
wb = Workbook()

# grab the active worksheet
ws = wb.active

# Fill up the headers on the first row
ws['A1'] = 'First Name'
ws['B1'] = 'Last Name'
ws['C1'] = 'Date'
ws['D1'] = 'Temperature'

#Define some constant values
normal_temperature = 98.6
date = datetime.today().strftime('%m/%d/%y')

try:
    recording = int(input("Are you Recording Temperature Today? 1 if yes; 0 if no: "))
except:
     print('Please enter a number: either 1 or 0')

while recording == 1:
    #Get employees First Name
    employee_first = input('Enter First Name:')
    #Get employees Last Name
    employee_last = input('Enter Last Name:')
    #Get temperature
    try:
        temperature = float(input('Input Scanned Temperature (example if 99 degrees enter 99):'))
    except:
        print('Please enter a valid value for the temperature (99.2, 98.6)')
    #Check if the employee has a fever
    if temperature > normal_temperature:
        print('Elevated Temperature Detected! Entrance Not Permitted')
    else:
        print("Temperature Within Acceptable Limits. Entrance Permitted")
    #Add the employees row to the sheet
    ws.append([employee_first,employee_last,date,temperature])

    try:
        recording = int(input("Are you Recording Temperature Today? 1 if yes; 0 if no: "))
    except:
        print('All recordings have been made. Saving the file.')

#Save the file
print('Check the temperaturescans.xlsx file for the results.')
wb.save("temperaturescans.xlsx")


问:
How to plot an RGB image using the image() function from a 3D array?
I have an array with dimension (28,28,3) height, width, depth. Each depth is one of the RGB channels. The values are between 0 and 1.

I want to use the image() function to plot the image. The z argument is a matrix. How can I convert the array into a matrix in order to be able to plot?

My final goal is to have something like this but with color images.

答:
The problem with graphics::image is that it will not plot your 3D array as a colour image. It plots a matrix as a heatmap.

Let's take a colorful patterned image:

```<code>R <- matrix(rep(sin(seq(0, 2*pi, length.out = 31))^2, length.out = 900), nrow = 30)
G <- matrix(rep(cos(seq(0, 2*pi, length.out = 15))^2, length.out = 900), nrow = 30)
B <- matrix(rep(sin(seq(pi, 2*pi, length.out = 30))^2, length.out = 900), nrow = 30)

my_img <- c(R, G, B)
dim(my_img) <- c(30, 30, 3)
</code>```

Now if I plot this with raster as @IanCampbell suggests, I get my desired image:

```<code>plot(raster::as.raster(my_img))
</code>```

whereas if I plot one layer (here the red channel) using image, I get a heatmap:

```<code>image(R)
</code>```

If you really want to use image, then you would have to average all your layers, but then you lose colour information, and still get a heat map:

```<code>image((R + B + G)/3)
</code>```

So the bottom line is that if you want to plot a colour image, then image is not the function you are looking for. There are lots of ways to plot multiple colour images in a single R window, so saying that you have to use image because you need to plot a grid of images just isn't true.

For example:

```<code>grid.arrange(rasterGrob(my_img),   rasterGrob(1-my_img),
             rasterGrob(1-my_img), rasterGrob(my_img), ncol = 2)
</code>```

Body:
The problem with graphics::image is that it will not plot your 3D array as a colour image. It plots a matrix as a heatmap.

Let's take a colorful patterned image:

R <- matrix(rep(sin(seq(0, 2*pi, length.out = 31))^2, length.out = 900), nrow = 30)
G <- matrix(rep(cos(seq(0, 2*pi, length.out = 15))^2, length.out = 900), nrow = 30)
B <- matrix(rep(sin(seq(pi, 2*pi, length.out = 30))^2, length.out = 900), nrow = 30)

my_img <- c(R, G, B)
dim(my_img) <- c(30, 30, 3)

Now if I plot this with raster as @IanCampbell suggests, I get my desired image:

plot(raster::as.raster(my_img))

whereas if I plot one layer (here the red channel) using image, I get a heatmap:

image(R)

If you really want to use image, then you would have to average all your layers, but then you lose colour information, and still get a heat map:

image((R + B + G)/3)

So the bottom line is that if you want to plot a colour image, then image is not the function you are looking for. There are lots of ways to plot multiple colour images in a single R window, so saying that you have to use image because you need to plot a grid of images just isn't true.

For example:

grid.arrange(rasterGrob(my_img),   rasterGrob(1-my_img),
             rasterGrob(1-my_img), rasterGrob(my_img), ncol = 2)


问:
Feign client always throws a null pointer exception in a Spring boot/Crawler4j app
I am running a Crawler4j instance in a Spring boot application and my OpenFeign client is always null.

```<code>public class MyCrawler extends WebCrawler {

@Autowired
    HubClient hubClient;

    @Override
    public void visit(Page page) {
// Lots of crawler code...
        if (page.getParseData() instanceof HtmlParseData) {
            hubClient.send(webPage.toString()); // Throws null pointer exception
}
}

</code>```

My Hubclient

```<code>@FeignClient("hub-worker")
public interface HubClient {
    @RequestMapping(method = RequestMethod.POST, value = "/pages", consumes = "application/json")
    void send(String webPage);
    //void createPage(WebPage webPage);
}
</code>```

My MainApplication

```<code>@EnableEurekaClient
@EnableFeignClients
@SpringBootApplication
public class CrawlerApplication {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(CrawlerApplication.class, args);
    }
}
</code>```

The stacktrace

```<code>
ext length: 89106
Html length: 1048334
Number of outgoing links: 158
10:14:38.634 [Crawler 164] WARN  e.u.ics.crawler4j.crawler.WebCrawler - Unhandled exception while fetching https://www.cnn.com: null
10:14:38.634 [Crawler 164] INFO  e.u.ics.crawler4j.crawler.WebCrawler - Stacktrace:
java.lang.NullPointerException: null
    at com.phishspider.crawler.MyCrawler.visit(MyCrawler.java:79)
    at edu.uci.ics.crawler4j.crawler.WebCrawler.processPage(WebCrawler.java:523)
    at edu.uci.ics.crawler4j.crawler.WebCrawler.run(WebCrawler.java:306)
    at java.base/java.lang.Thread.run(Thread.java:834)

</code>```

Line 79 is the hubClient call. When I factor out the hubVlient into another class that I instantiate in the crawler class like hubclient hc = new hubclient() and then have some method hc.send(page) the hubClient in that factored out class will throw the null pointer.

答:
In order to inject Spring beans (your client) into your crawler4j Web crawler object, you need to instantiate the Web crawler object via Spring.

For this purpose, you need to write a custom implementation of a WebCrawlerFactory, which provides / creates Spring-managed Web crawler objects. To do so, your Web crawler implementation needs to be a Spring Bean, i.e. at least annotated with @Component.

Body:
I am running a Crawler4j instance in a Spring boot application and my OpenFeign client is always null.

public class MyCrawler extends WebCrawler {

@Autowired
    HubClient hubClient;

    @Override
    public void visit(Page page) {
// Lots of crawler code...
        if (page.getParseData() instanceof HtmlParseData) {
            hubClient.send(webPage.toString()); // Throws null pointer exception
}
}

My Hubclient

@FeignClient("hub-worker")
public interface HubClient {
    @RequestMapping(method = RequestMethod.POST, value = "/pages", consumes = "application/json")
    void send(String webPage);
    //void createPage(WebPage webPage);
}

My MainApplication

@EnableEurekaClient
@EnableFeignClients
@SpringBootApplication
public class CrawlerApplication {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(CrawlerApplication.class, args);
    }
}

The stacktrace

ext length: 89106
Html length: 1048334
Number of outgoing links: 158
10:14:38.634 [Crawler 164] WARN  e.u.ics.crawler4j.crawler.WebCrawler - Unhandled exception while fetching https://www.cnn.com: null
10:14:38.634 [Crawler 164] INFO  e.u.ics.crawler4j.crawler.WebCrawler - Stacktrace:
java.lang.NullPointerException: null
    at com.phishspider.crawler.MyCrawler.visit(MyCrawler.java:79)
    at edu.uci.ics.crawler4j.crawler.WebCrawler.processPage(WebCrawler.java:523)
    at edu.uci.ics.crawler4j.crawler.WebCrawler.run(WebCrawler.java:306)
    at java.base/java.lang.Thread.run(Thread.java:834)

Line 79 is the hubClient call. When I factor out the hubVlient into another class that I instantiate in the crawler class like hubclient hc = new hubclient() and then have some method hc.send(page) the hubClient in that factored out class will throw the null pointer.


问:
Is there any way to interact with open external application alert from a webpage using selenium?
I tried switching tab that had popup using driver.switch_to.window(driver.window_handles[1])
and
closing the first tab, but none of them worked
This is the code that I tried to accept the popup driver.switch_to_alert().accept()

答:
Have you tried disabling notifications through the chrome options?
This is what I had to use on my webscraping project:

```<code>chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-notifications')
prefs = {'profile.default_content_setting_values.notifications': 2}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Users\jeffg\Desktop\WebScraping\chromedriver.exe')
</code>```

Documentation can be found here:

https://peter.sh/experiments/chromium-command-line-switches/

https://chromedriver.chromium.org/capabilities

Body:
Have you tried disabling notifications through the chrome options?
This is what I had to use on my webscraping project:

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-notifications')
prefs = {'profile.default_content_setting_values.notifications': 2}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Users\jeffg\Desktop\WebScraping\chromedriver.exe')

Documentation can be found here:

https://peter.sh/experiments/chromium-command-line-switches/

https://chromedriver.chromium.org/capabilities


问:
"npm ERR! unexpected end of JSON input near" while creating a new react app
[enter image description here][1]npm

I am trying for so many times to create a app in react but every time the CMD showing an ERR!

here is code :
Microsoft Windows [Version 10.0.18363.476]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Sumit>E:
The system cannot find the drive specified.

C:\Users\Sumit>D:

D:>React js
'React' is not recognized as an internal or external command,
operable program or batch file.

D:>react js
'react' is not recognized as an internal or external command,
operable program or batch file.

D:>React js
'React' is not recognized as an internal or external command,
operable program or batch file.

D:>create-react-app my_react

Creating a new React app in D:\my_react.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! Response timeout while trying to fetch https://registry.npmjs.org/react (over 30000ms)

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_33_43_496Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting my_react / from D:\
Done.

D:>create-react-app my-react-app

Creating a new React app in D:\my-react-app.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! Unexpected end of JSON input while parsing near '...Y3hEcJW8se9P4K6+GYGu9'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_34_57_334Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting my-react-app / from D:\
Done.

D:>create-react-app new-react

Creating a new React app in D:\new-react.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! Unexpected end of JSON input while parsing near '...gAAwSQP/RpJCkm/rgw8jt'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_38_28_735Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting new-react / from D:\
Done.

D:>npm create-react-app my-react-aplication

Usage: npm

where  is one of:
    access, adduser, audit, bin, bugs, c, cache, ci, cit,
    clean-install, clean-install-test, completion, config,
    create, ddp, dedupe, deprecate, dist-tag, docs, doctor,
    edit, explore, fund, get, help, help-search, hook, i, init,
    install, install-ci-test, install-test, it, link, list, ln,
    login, logout, ls, org, outdated, owner, pack, ping, prefix,
    profile, prune, publish, rb, rebuild, repo, restart, root,
    run, run-script, s, se, search, set, shrinkwrap, star,
    stars, start, stop, t, team, test, token, tst, un,
    uninstall, unpublish, unstar, up, update, v, version, view,
    whoami

npm  -h  quick help on
npm -l            display full usage info
npm help    search for help on
npm help npm      involved overview

Specify configs in the ini-formatted file:
    C:\Users\Sumit.npmrc
or on the command line via: npm  --key value
Config info can be viewed via: npm help config

npm@6.14.4 C:\Program Files\nodejs\node_modules\npm

D:>npx create-react-app my-react

Creating a new React app in D:\my-react.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts...

npm ERR! Unexpected end of JSON input while parsing near '...gAAwSQP/RpJCkm/rgw8jt'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Sumit\AppData\Roaming\npm-cache_logs\2020-06-01T14_54_02_126Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts has failed.

Deleting generated file... package.json
Deleting my-react / from D:\
Done.

D:>

答:
There are two things that you can do that might possibily help you resolve the issue you are facing.

1.If you are on a slow internet connection you might have to increase the timeout from 30s to 60s by adding this to your .npmrc file:

```<code>timeout=6000
</code>```

You can find the .npmrc file at the path:

```<code>C:\Program Files\nodejs\node_modules\npm
</code>```

2. This issue might be due to npm version mismatch, you can try to install the latest npm version by typing the following command in cmd:

```<code>npm install -g npm
</code>```

Hope this helps!!

Body:
There are two things that you can do that might possibily help you resolve the issue you are facing.

1.If you are on a slow internet connection you might have to increase the timeout from 30s to 60s by adding this to your .npmrc file:

timeout=6000

You can find the .npmrc file at the path:

C:\Program Files\nodejs\node_modules\npm

2. This issue might be due to npm version mismatch, you can try to install the latest npm version by typing the following command in cmd:

npm install -g npm

Hope this helps!!


问:
AddThis Share : LinkedIn always open in new window
We're using AddThis Social Share functionality with our Sitecore/MVC application. The problem we're facing is that the LinkedIn share always opens in new window. On Inspect, we can see the ```target=_blank``` in code, which is not being added in our code.

Any help?

Thanks,
Chandana

答:
I suspect that this is a problem with the AddThis Social Share functionality.  To share on LinkedIn, all you need is the following URL format...

```<code>https://www.linkedin.com/sharing/share-offsite/?url={url}
</code>```

Then you can setup your  element however you like, with target="_blank" or not.

Source: href="https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/plugins/share-plugin" rel="nofollow noreferrer">Official LinkedIn Sharing Documentation.

Body:
We're using AddThis Social Share functionality with our Sitecore/MVC application. The problem we're facing is that the LinkedIn share always opens in new window. On Inspect, we can see the
target=_blank
 in code, which is not being added in our code.

Any help?

Thanks,
Chandana

Body:
I suspect that this is a problem with the AddThis Social Share functionality.  To share on LinkedIn, all you need is the following URL format...

https://www.linkedin.com/sharing/share-offsite/?url={url}

Then you can setup your <a href="..."> element however you like, with target="_blank" or not.

Source: Official LinkedIn Sharing Documentation.


问:
how to install Expect for windows using ActiveTCL 8.6 x86
I'm trying to install Expect for Windows using ActiveTCL and I'm having a helluva time. I understand I need to use teacup/teapot? Is there any documentation at all? I'm trying to run teacup and it says "can't create directory" on my network drive, it's trying to install in a random directory that I can't seem to change.. </p>

<p>I've spent a day trying to figure out how to install, what I thought would be, a simple program... </p>

答: Yes!  Thanks for this post @Sean Farley!  Adding Expect to ActiveTcl was a clear as mud.  I agree that it does not seem to be supported in Tcl 8.6 or 64-bit Tcl 8.5.  After installing & uninstalling both of those the 32-bit version worked (also I think it's "teacup install Expect" to install).

Body:
I'm trying to install Expect for Windows using ActiveTCL and I'm having a helluva time. I understand I need to use teacup/teapot? Is there any documentation at all? I'm trying to run teacup and it says "can't create directory" on my network drive, it's trying to install in a random directory that I can't seem to change..

I've spent a day trying to figure out how to install, what I thought would be, a simple program...


问:
Xamarin Forms event of after install
I'd like to trigger some code to happen after the user installs a version of our Xamarin Forms application.  But I need it for every version install, not just the first installation, so setting a property flag won't work.

I have a solution that tracks application version numbers and can trigger it off that, but I was hoping there was an framework event or something that was more elegant.

答:
You can use Xamarin Essentials' Version Tracking

From there you can check when either the first time the current build is run, or the first time the current version is run:

// First time launching current version
var firstLaunchCurrent = VersionTracking.IsFirstLaunchForCurrentVersion;

// First time launching current build
var firstLaunchBuild = VersionTracking.IsFirstLaunchForCurrentBuild;
```

Title: Xamarin Forms event of after install


问:
How to handle varchar(max) in t4 script?
I'm using .tt scripting in VS 2017(SSDT 2017) in the DB project. We create staging tables structures manually and then the T4 script generates final destination tables based on the staging table structure.

I have this code to get columns and their data types to create my final destination tables but it looks if one of the fields is defined as varchar(max) then generated field gets varchar data type and that is it.
Here is the sample of the script.

```<code>         foreach (var col in table.GetReferenced(Table.Columns))
        {

            string columnText;
            string columnName = col.Name.Parts[2];

            // this attempts to limit to only columns from the source. there's gotta be a cleaner way.
            if (!skipColumns.Contains(columnName))
            {

                int length = col.GetProperty<int>(Column.Length);
                int precision = col.GetProperty<int>(Column.Precision);
                int scale = col.GetProperty<int>(Column.Scale);

                string suffix;
                if (length != 0)
                {
                    suffix = String.Format("({0})", length);
                }
                else if (precision != 0)
                {
                    suffix = String.Format("({0},{1})", precision, scale);
                }
                else if (precision == 0 && scale != 0)
                {
                    suffix = String.Format("({0})", scale);
                }
                else
                {
                    suffix = "";
                }

                bool nullable = col.GetProperty<bool>(Column.Nullable);
                string nullText = nullable ? "NULL" : "NOT NULL";

                string dataType = col.GetReferenced(Column.DataType).FirstOrDefault().Name.ToString();

                columnText = String.Format("[{0}] {1}{2} {3}", columnName, dataType, suffix, nullText);

                WriteLine("         " + columnText + ",");
            }
        }
</code>```

How to handle varchar(max) in t4 script?

答:
Here the answer.
You would have to use the following and then compare it.</p>

```<code>    bool isMax = col.GetProperty<bool>(Column.IsMax);
...
  if (isMax)
                    {
                        suffix = String.Format("({0})", "max");
                    }
</code>```

Body:
I'm using .tt scripting in VS 2017(SSDT 2017) in the DB project. We create staging tables structures manually and then the T4 script generates final destination tables based on the staging table structure.

I have this code to get columns and their data types to create my final destination tables but it looks if one of the fields is defined as varchar(max) then generated field gets varchar data type and that is it.
Here is the sample of the script.

         foreach (var col in table.GetReferenced(Table.Columns))
        {

            string columnText;
            string columnName = col.Name.Parts[2];

            // this attempts to limit to only columns from the source. there's gotta be a cleaner way.
            if (!skipColumns.Contains(columnName))
            {

                int length = col.GetProperty<int>(Column.Length);
                int precision = col.GetProperty<int>(Column.Precision);
                int scale = col.GetProperty<int>(Column.Scale);

                string suffix;
                if (length != 0)
                {
                    suffix = String.Format("({0})", length);
                }
                else if (precision != 0)
                {
                    suffix = String.Format("({0},{1})", precision, scale);
                }
                else if (precision == 0 && scale != 0)
                {
                    suffix = String.Format("({0})", scale);
                }
                else
                {
                    suffix = "";
                }

                bool nullable = col.GetProperty<bool>(Column.Nullable);
                string nullText = nullable ? "NULL" : "NOT NULL";

                string dataType = col.GetReferenced(Column.DataType).FirstOrDefault().Name.ToString();

                columnText = String.Format("[{0}] {1}{2} {3}", columnName, dataType, suffix, nullText);

                WriteLine("         " + columnText + ",");
            }
        }

How to handle varchar(max) in t4 script?

Body:
Here the answer.
You would have to use the following and then compare it.

    bool isMax = col.GetProperty<bool>(Column.IsMax);
...
  if (isMax)
                    {
                        suffix = String.Format("({0})", "max");
                    }


问:
How to filter rows where key is not present in a large dataframe
Suppose I have a streaming dataframe A and a large static dataframe B. Assume that typically A is of size < 10000 records. However, B is a much larger dataframe with size in the range of millions.

Lets assume both A and B have a 'key' column. I want to filter rows in A where A.key is not present in B. What is the best way to achieve this.

Right now, I have tried A.join(B, Seq("key"), "left_anti"). However, the performance is not upto the mark. Is there anyway I can fasten up the process

Physical plan:

```<code>== Physical Plan ==
SortMergeJoin [domainName#461], [domain#147], LeftAnti
:- *(5) Sort [domainName#461 ASC NULLS FIRST], false, 0
:  +- StreamingDeduplicate [domainName#461], state info [ checkpoint = hdfs://MTPrime-CO4-fed/MTPrime-CO4-0/projects/BingAdsAdQuality/Test/WhoIs/WhoIsStream/checkPoint/state, runId = 9d09398b-efda-41cb-ab77-1b5550cd5da9, opId = 0, ver = 63, numPartitions = 400], 0
:     +- Exchange hashpartitioning(domainName#461, 400)
:        +- Union
:           :- *(2) Project [value#460 AS domainName#461]
:           :  +- *(2) Filter isnotnull(value#460)
:           :     +- *(2) SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, java.lang.String, true], true, false) AS value#460]
:           :        +- MapPartitions <function1>, obj#459: java.lang.String
:           :           +- MapPartitions <function1>, obj#436: MTInterfaces.Fraud.RiskEntity
:           :              +- DeserializeToObject newInstance(class scala.Tuple3), obj#435: scala.Tuple3
:           :                 +- Exchange RoundRobinPartitioning(600)
:           :                    +- *(1) SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, assertnotnull(input[0, scala.Tuple3, true])._1, true, false) AS _1#142, staticinvoke(class org.apache.spark.sql.catalyst.util.DateTimeUtils$, TimestampType, fromJavaTimestamp, assertnotnull(input[0, scala.Tuple3, true])._2, true, false) AS _2#143, staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, assertnotnull(input[0, scala.Tuple3, true])._3, true, false) AS _3#144]
:           :                       +- *(1) MapElements <function1>, obj#141: scala.Tuple3
:           :                          +- *(1) MapElements <function1>, obj#132: scala.Tuple3
:           :                             +- *(1) DeserializeToObject createexternalrow(Body#60.toString, staticinvoke(class org.apache.spark.sql.catalyst.util.DateTimeUtils$, ObjectType(class java.sql.Timestamp), toJavaTimestamp, EventTime#37, true, false), Timestamp#48L, Offset#27L, Partition#72.toString, PartitionKey#84.toString, Publisher#96.toString, SequenceNumber#108L, StructField(Body,StringType,true), StructField(EventTime,TimestampType,true), StructField(Timestamp,LongType,true), StructField(Offset,LongType,true), StructField(Partition,StringType,true), StructField(PartitionKey,StringType,true), StructField(Publisher,StringType,true), StructField(SequenceNumber,LongType,true)), obj#131: org.apache.spark.sql.Row
:           :                                +- *(1) Project [cast(body#608 as string) AS Body#60, enqueuedTime#612 AS EventTime#37, cast(enqueuedTime#612 as bigint) AS Timestamp#48L, cast(offset#610 as bigint) AS Offset#27L, partition#609 AS Partition#72, partitionKey#614 AS PartitionKey#84, publisher#613 AS Publisher#96, sequenceNumber#611L AS SequenceNumber#108L]
:           :                                   +- Scan ExistingRDD[body#608,partition#609,offset#610,sequenceNumber#611L,enqueuedTime#612,publisher#613,partitionKey#614,properties#615,systemProperties#616]
:           +- *(4) Project [value#453 AS domainName#455]
:              +- *(4) Filter isnotnull(value#453)
:                 +- *(4) SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, java.lang.String, true], true, false) AS value#453]
:                    +- *(4) MapElements <function1>, obj#452: java.lang.String
:                       +- MapPartitions <function1>, obj#436: MTInterfaces.Fraud.RiskEntity
:                          +- DeserializeToObject newInstance(class scala.Tuple3), obj#435: scala.Tuple3
:                             +- ReusedExchange [_1#142, _2#143, _3#144], Exchange RoundRobinPartitioning(600)
+- *(8) Project [domain#147]
   +- *(8) Filter (isnotnull(rank#284) && (rank#284 = 1))
      +- Window [row_number() windowspecdefinition(domain#147, timestamp#151 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank#284], [domain#147], [timestamp#151 DESC NULLS LAST]
         +- *(7) Sort [domain#147 ASC NULLS FIRST, timestamp#151 DESC NULLS LAST], false, 0
            +- Exchange hashpartitioning(domain#147, 400)
               +- *(6) Project [domain#147, timestamp#151]
                  +- *(6) Filter isnotnull(domain#147)
                     +- *(6) FileScan csv [domain#147,timestamp#151] Batched: false, Format: CSV, Location: InMemoryFileIndex[hdfs://MTPrime-CO4-fed/MTPrime-CO4-0/projects/BingAdsAdQuality/Test/WhoIs], PartitionFilters: [], PushedFilters: [IsNotNull(domain)], ReadSchema: struct<domain:string,timestamp:string>
</code>```

Snapshots of query graph:

EDIT

 Right now I have moved the lookup data to a Cosmos DB store and created a TempView on top of it (say lookupdata). Now, I need to filter the ones that are not present in the store. I am exploring the following options:

1. create tempview on top of the streaming data as well and query

spark.sql(SELECT * FROM streamingdata s LEFT ANTI JOIN lookupdata l ON s.key = l.key")

Same as 1 but do inner sub-query instead of left anti join. i.e  spark.sql("SELECT s.* FROM streamingdata s WHERE s.key NOT IN (SELECT key FROM lookupdata l)")

Retain the streaming df as it is and do a filter op:

```<code>df.filter(x => { val key = x.getAs[String])("key")
  spark.sql("SELECT * FROM lookupdata l WHERE l.key = '"+key+"'").isEmpty
})
</code>```

which one would work better?

答:
It is not the recommended approach to do this with (Structured) Streaming. Imagine you are a Chinese company with 100M customers. How do you see that working on B with a 100M rows?

From my last assignment: If large dataset for reference data evident, use Hbase, or some other other key value store like Cassandra, with mapPartitions if volitatile or non-volatile. This is more difficult though. It was no easy task the data engineer, designer told me. Indeed, it is not that easy. But the way to go.

Body:
Suppose I have a streaming dataframe A and a large static dataframe B. Assume that typically A is of size < 10000 records. However, B is a much larger dataframe with size in the range of millions.

Lets assume both A and B have a 'key' column. I want to filter rows in A where A.key is not present in B. What is the best way to achieve this.

Right now, I have tried A.join(B, Seq("key"), "left_anti"). However, the performance is not upto the mark. Is there anyway I can fasten up the process

Physical plan:

== Physical Plan ==
SortMergeJoin [domainName#461], [domain#147], LeftAnti
:- *(5) Sort [domainName#461 ASC NULLS FIRST], false, 0
:  +- StreamingDeduplicate [domainName#461], state info [ checkpoint = hdfs://MTPrime-CO4-fed/MTPrime-CO4-0/projects/BingAdsAdQuality/Test/WhoIs/WhoIsStream/checkPoint/state, runId = 9d09398b-efda-41cb-ab77-1b5550cd5da9, opId = 0, ver = 63, numPartitions = 400], 0
:     +- Exchange hashpartitioning(domainName#461, 400)
:        +- Union
:           :- *(2) Project [value#460 AS domainName#461]
:           :  +- *(2) Filter isnotnull(value#460)
:           :     +- *(2) SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, java.lang.String, true], true, false) AS value#460]
:           :        +- MapPartitions <function1>, obj#459: java.lang.String
:           :           +- MapPartitions <function1>, obj#436: MTInterfaces.Fraud.RiskEntity
:           :              +- DeserializeToObject newInstance(class scala.Tuple3), obj#435: scala.Tuple3
:           :                 +- Exchange RoundRobinPartitioning(600)
:           :                    +- *(1) SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, assertnotnull(input[0, scala.Tuple3, true])._1, true, false) AS _1#142, staticinvoke(class org.apache.spark.sql.catalyst.util.DateTimeUtils$, TimestampType, fromJavaTimestamp, assertnotnull(input[0, scala.Tuple3, true])._2, true, false) AS _2#143, staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, assertnotnull(input[0, scala.Tuple3, true])._3, true, false) AS _3#144]
:           :                       +- *(1) MapElements <function1>, obj#141: scala.Tuple3
:           :                          +- *(1) MapElements <function1>, obj#132: scala.Tuple3
:           :                             +- *(1) DeserializeToObject createexternalrow(Body#60.toString, staticinvoke(class org.apache.spark.sql.catalyst.util.DateTimeUtils$, ObjectType(class java.sql.Timestamp), toJavaTimestamp, EventTime#37, true, false), Timestamp#48L, Offset#27L, Partition#72.toString, PartitionKey#84.toString, Publisher#96.toString, SequenceNumber#108L, StructField(Body,StringType,true), StructField(EventTime,TimestampType,true), StructField(Timestamp,LongType,true), StructField(Offset,LongType,true), StructField(Partition,StringType,true), StructField(PartitionKey,StringType,true), StructField(Publisher,StringType,true), StructField(SequenceNumber,LongType,true)), obj#131: org.apache.spark.sql.Row
:           :                                +- *(1) Project [cast(body#608 as string) AS Body#60, enqueuedTime#612 AS EventTime#37, cast(enqueuedTime#612 as bigint) AS Timestamp#48L, cast(offset#610 as bigint) AS Offset#27L, partition#609 AS Partition#72, partitionKey#614 AS PartitionKey#84, publisher#613 AS Publisher#96, sequenceNumber#611L AS SequenceNumber#108L]
:           :                                   +- Scan ExistingRDD[body#608,partition#609,offset#610,sequenceNumber#611L,enqueuedTime#612,publisher#613,partitionKey#614,properties#615,systemProperties#616]
:           +- *(4) Project [value#453 AS domainName#455]
:              +- *(4) Filter isnotnull(value#453)
:                 +- *(4) SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, java.lang.String, true], true, false) AS value#453]
:                    +- *(4) MapElements <function1>, obj#452: java.lang.String
:                       +- MapPartitions <function1>, obj#436: MTInterfaces.Fraud.RiskEntity
:                          +- DeserializeToObject newInstance(class scala.Tuple3), obj#435: scala.Tuple3
:                             +- ReusedExchange [_1#142, _2#143, _3#144], Exchange RoundRobinPartitioning(600)
+- *(8) Project [domain#147]
   +- *(8) Filter (isnotnull(rank#284) && (rank#284 = 1))
      +- Window [row_number() windowspecdefinition(domain#147, timestamp#151 DESC NULLS LAST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS rank#284], [domain#147], [timestamp#151 DESC NULLS LAST]
         +- *(7) Sort [domain#147 ASC NULLS FIRST, timestamp#151 DESC NULLS LAST], false, 0
            +- Exchange hashpartitioning(domain#147, 400)
               +- *(6) Project [domain#147, timestamp#151]
                  +- *(6) Filter isnotnull(domain#147)
                     +- *(6) FileScan csv [domain#147,timestamp#151] Batched: false, Format: CSV, Location: InMemoryFileIndex[hdfs://MTPrime-CO4-fed/MTPrime-CO4-0/projects/BingAdsAdQuality/Test/WhoIs], PartitionFilters: [], PushedFilters: [IsNotNull(domain)], ReadSchema: struct<domain:string,timestamp:string>

Snapshots of query graph:

EDIT

 Right now I have moved the lookup data to a Cosmos DB store and created a TempView on top of it (say lookupdata). Now, I need to filter the ones that are not present in the store. I am exploring the following options:

1. create tempview on top of the streaming data as well and query

spark.sql(SELECT * FROM streamingdata s LEFT ANTI JOIN lookupdata l ON s.key = l.key")

Same as 1 but do inner sub-query instead of left anti join. i.e  spark.sql("SELECT s.* FROM streamingdata s WHERE s.key NOT IN (SELECT key FROM lookupdata l)")

Retain the streaming df as it is and do a filter op:

df.filter(x => { val key = x.getAs[String])("key")
  spark.sql("SELECT * FROM lookupdata l WHERE l.key = '"+key+"'").isEmpty
})

which one would work better?