问:
Solidity importing problem on VSCode (WSL2) and Brownie
I'm working with a Solidity using Brownie Framework running on WSL2 Ubuntu 20.04 on Windows 10 host machine.

And I have to import chainlink dependecies to my project, so I have the following importors

```<code>import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";
</code>```

To get them work properly I added the folling code to brownie-config.yaml

```<code>dependencies:
  # - <organization/repo>@<version>
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
compiler:
  solc:
    remappings:
      - "@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1"
</code>```

So running brownie compile, the compiler works just fine, however visual studio code complains about the imports

Vscode error

Additional Info: I'm using the romote compiler version, and if I change it to "localNodeModule" Vscode stops complaining about the import but it starts to complain about solidity version:

Solidity error

And I not able to compile the project anymore.

I read some other post like this one: VScode Solidity extension - not finding openzepplin imports with similar problems, but unfornatelly the problems still unresolve.

答:
I solved it by doing: npm install @chainlink/contracts --save

and in the yaml file doing:

Body:
I'm working with a Solidity using Brownie Framework running on WSL2 Ubuntu 20.04 on Windows 10 host machine.

And I have to import chainlink dependecies to my project, so I have the following importors

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@chainlink/contracts/src/v0.6/vendor/SafeMathChainlink.sol";

To get them work properly I added the folling code to brownie-config.yaml

dependencies:
  # - <organization/repo>@<version>
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
compiler:
  solc:
    remappings:
      - "@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1"

So running brownie compile, the compiler works just fine, however visual studio code complains about the imports

Vscode error

Additional Info: I'm using the romote compiler version, and if I change it to "localNodeModule" Vscode stops complaining about the import but it starts to complain about solidity version:

Solidity error

And I not able to compile the project anymore.

I read some other post like this one: VScode Solidity extension - not finding openzepplin imports with similar problems, but unfornatelly the problems still unresolve.


来源: stackexchange

问:
I need the url in the ajax script to be a variable from a php file but I don't know how to do this
The top section has the variables and forms.  The program calls an html page depending on who logs in.  I need to be able to pull the page based on login information.

I pull the page number from the url when the page is called.  I need to use that page number in the ajax part of the program at the bottom to pull the data off the right page and put it in the chatbox.

Right now I can't pull the right page.  I am having a problem setting a variable in the ajax url:

I tried using "" but it will load the chatbox inside the chatbox as an image.

```<code>    <?php
    if(isset($_POST['enter'])){
    if($_POST['name'] != ""){
    $_SESSION['name'] =
    stripslashes(htmlspecialchars($_POST['name']));
    }
    else{
    echo '<span class="error">Please type in a name</span>';
    }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Chat - Customer Module</title>
    <link type="text/css" rel="stylesheet" href="style1.css" />
    </head>
    <body>

    <?php
    if(!isset($_SESSION['name'])){
    loginForm();
    }
    else{
    ?>
    <div id="wrapper">
    <div id="menu">
    <p class="welcome">Welcome, <b><?php echo $_SESSION['name']; ?>
    </b></p>
    <p class="logout"><a id="exit" href="#">Exit Chat</a></p>
    <div style="clear:both"></div>
    </div>
    <div id="chatbox"><?php
    if(file_exists($log) && filesize($log) > 0){
        $handle = fopen($log, "r");
        $contents = fread($handle, filesize($log));
        fclose($handle);
        echo $contents;
    }
     else{
        if(!isset($log));
        $contents = 'Welcome!';
        file_put_contents($log, $contents);
        echo $contents;
    }
    ?>
    </div>

    <form name="message" action="">
    <input name="usermsg" type="text" id="usermsg" size="63" />
    <input name="submitmsg" type="submit"  id="submitmsg"
    value="Send" />
    </form>
    <br />
    <form action="upload.php" method="post" enctype="multipart/form-
     data">
    Select image to upload:
    <input type="file" name="fileToUpload" />
    <input type="submit" value="Upload Image" name="submit" />
    </form>
    </div>
    <script type="text/javascript"
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js">
    </script>
    <script type="text/javascript">
    // jQuery Document
    $(document).ready(function(){
        //If user submits the form
    $("#submitmsg").click(function(){
    var clientmsg = $("#usermsg").val();
    $.post("post.php", {text: clientmsg});
    $("#usermsg").attr("value", "");
    return false;
    });

    //Load the file containing the chat log
    function loadLog(){
       var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;

    $.ajax({
    url: "chat/9999.html",

    cache: false,
    success: function(html){
    $("#chatbox").html(html); //Insert chat log into the #chatbox div
    var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
    if(newscrollHeight > oldscrollHeight){
    $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal');
        //Autoscroll to bottom of div
                }
            },
        });
    }
    setInterval (loadLog, 2500);    //Reload file every 2.5 seconds

     //If user wants to end session
    $("#exit").click(function(){
        var exit = confirm("Are you sure you want to end the
            session?");
    if(exit==true){window.location = 'index.php?logout=true';}
    });
    });
    </script>
</code>```

I have updated to give you more code.  I tried using the "" but the form isn't acting right.  It keeps loading the form inside the form again.

I need the "chat/9999.html" to be a variable so it can bring up one of a few pages.

答:
Without the PHP part of your code it's hard to know how it looks but based on my experience something like this will work if you mix php and html/javascript/jquery/ajax code:</p>
```<code><?php
//this is where you list your urls (array, user input, db, etc.)
$url = 'chat/9999.html';
?>

$.ajax({
    url: "<?=$url?>",

    cache: false,
    success: function(html){
    $("#chatbox").html(html); //Insert chat log into the #chatbox div
    var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
    if(newscrollHeight > oldscrollHeight){
    $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal');
   //Autoscroll to bottom of div
            }
        },
});
</code>```

ContentLicense: CC BY-SA 4.0

Body:
The top section has the variables and forms.  The program calls an html page depending on who logs in.  I need to be able to pull the page based on login information.

I pull the page number from the url when the page is called.  I need to use that page number in the ajax part of the program at the bottom to pull the data off the right page and put it in the chatbox.

Right now I can't pull the right page.  I am having a problem setting a variable in the ajax url:

I tried using "" but it will load the chatbox inside the chatbox as an image.

    <?php
    if(isset($_POST['enter'])){
    if($_POST['name'] != ""){
    $_SESSION['name'] =
    stripslashes(htmlspecialchars($_POST['name']));
    }
    else{
    echo 'Please type in a name';
    }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <title>Chat - Customer Module</title>
    <link type="text/css" rel="stylesheet" href="style1.css" />

    <?php
    if(!isset($_SESSION['name'])){
    loginForm();
    }
    else{
    ?>

Welcome, <?php echo $_SESSION['name']; ?>

Exit Chat

<?php
    if(file_exists($log) && filesize($log) > 0){
        $handle = fopen($log, "r");
        $contents = fread($handle, filesize($log));
        fclose($handle);
        echo $contents;
    }
     else{
        if(!isset($log));
        $contents = 'Welcome!';
        file_put_contents($log, $contents);
        echo $contents;
    }
    ?>

    <form name="message" action="">
    <input name="usermsg" type="text" id="usermsg" size="63" />
    <input name="submitmsg" type="submit"  id="submitmsg"
    value="Send" />
    </form>

    <form action="upload.php" method="post" enctype="multipart/form-
     data">
    Select image to upload:
    <input type="file" name="fileToUpload" />
    <input type="submit" value="Upload Image" name="submit" />
    </form>

I have updated to give you more code.  I tried using the "" but the form isn't acting right.  It keeps loading the form inside the form again.

I need the "chat/9999.html" to be a variable so it can bring up one of a few pages.

Body:
Without the PHP part of your code it's hard to know how it looks but based on my experience something like this will work if you mix php and html/javascript/jquery/ajax code:

<?php
//this is where you list your urls (array, user input, db, etc.)
$url = 'chat/9999.html';
?>

$.ajax({
    url: "<?=$url?>",

    cache: false,
    success: function(html){
    $("#chatbox").html(html); //Insert chat log into the #chatbox div
    var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
    if(newscrollHeight > oldscrollHeight){
    $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal');
   //Autoscroll to bottom of div
            }
        },
});


问:
How to ensure my regular expression does not match too much
A file has few words with numbers in the begining of them. i want to extract a particular no line.when given 1, it extracts line 1 also with 11, 21

FILE.txt has contents:

```
1.sample
lines of
2.sentences
present in
...
...
10.the
11.file
```

when Executed pro 1 file.txt
gives results from line 1,10 and also from line 11
as these three results have 1 in their string. i.e

Output of the script:

```
1.sample
10.the
11.file
```

Expected output: the output which i am expecting
is only line 1 contents and not the line 10 or line 11 contents.
i.e

Expected output:

```1.sample```

My current code:

```<code>proc pro { pattern args} {

   set file [open $args r]
   set lnum 0
   set occ 0
   while {[gets $file line] >=0} {
      incr lnum
      if {[regexp $pattern $line]} {
          incr occ
          puts "The pattern is present in line: $lnum"
          puts "$line"
      } else {
         puts "not found"
      }
   }
   puts "total number of occurencese : $occ"
   close $file
}
</code>```

the program is working fine but the thing is i am retrieving lines that i dont want to along with the expected line. As the number (1) which i want to retrieve is present in the other strings such as 11, 21, 14 etc these lines are also getting printed.

kindly tolerate my unclear way of explaining the question.

答:
You have to ensure your pattern matches only between word boundaries:

```<code>if {[regexp "\\m$pattern\\M" $line]} { ...
</code>```

See the documentation for regular expression syntax.

ContentLicense: CC BY-SA 3.0

Body:
A file has few words with numbers in the begining of them. i want to extract a particular no line.when given 1, it extracts line 1 also with 11, 21

FILE.txt has contents:

1.sample
lines of
2.sentences
present in
...
...
10.the
11.file

when Executed pro 1 file.txt
gives results from line 1,10 and also from line 11
as these three results have 1 in their string. i.e

Output of the script:

1.sample
10.the
11.file

Expected output: the output which i am expecting
is only line 1 contents and not the line 10 or line 11 contents.
i.e

Expected output:

1.sample

My current code:

proc pro { pattern args} {

   set file [open $args r]
   set lnum 0
   set occ 0
   while {[gets $file line] >=0} {
      incr lnum
      if {[regexp $pattern $line]} {
          incr occ
          puts "The pattern is present in line: $lnum"
          puts "$line"
      } else {
         puts "not found"
      }
   }
   puts "total number of occurencese : $occ"
   close $file
}

the program is working fine but the thing is i am retrieving lines that i dont want to along with the expected line. As the number (1) which i want to retrieve is present in the other strings such as 11, 21, 14 etc these lines are also getting printed.

kindly tolerate my unclear way of explaining the question.

Body:
You have to ensure your pattern matches only between word boundaries:

if {[regexp "\\m$pattern\\M" $line]} { ...

See the documentation for regular expression syntax.


问:
Semantic ui React css file not compiling/working with webpack 5
I am making a basic CRA app and wanted to use semantic-ui i followed the steps to the same but as soon as I import the CSS file in the index.js the app starts compiling and finishes it with two errors i dont know what I am doing wrong.

Here are the errors being shown

```<code>Cannot read properties of undefined (reading 'get')
during rendering of asset asset/inline|data:application/x-font-ttf;charset=utf-8
</code>```

https://i.stack.imgur.com/YHqyU.png

https://i.stack.imgur.com/iR1z0.png

答:
The main reason for this is an extra ";" at line 19990 of semantic.css
If removed, everything goes fine. In the 'semantic-ui-css/semantic.min.css' remove the extra ';'.</p>
```<code>@font-face {
    font-family: 'Step';
    src: url(data:application/x-font-ttf;charset=utf-8;;base64,AAEAAAAOAIAAAw...
}
</code>```

Body:
I am making a basic CRA app and wanted to use semantic-ui i followed the steps to the same but as soon as I import the CSS file in the index.js the app starts compiling and finishes it with two errors i dont know what I am doing wrong.

Here are the errors being shown

Cannot read properties of undefined (reading 'get')
during rendering of asset asset/inline|data:application/x-font-ttf;charset=utf-8

https://i.stack.imgur.com/YHqyU.png

https://i.stack.imgur.com/iR1z0.png

Body:
The main reason for this is an extra ";" at line 19990 of semantic.css
If removed, everything goes fine. In the 'semantic-ui-css/semantic.min.css' remove the extra ';'.

@font-face {
    font-family: 'Step';
    src: url(data:application/x-font-ttf;charset=utf-8;;base64,AAEAAAAOAIAAAw...
}


问:
How do I make my custom data type an instance of Functor?
I have this data type:

```<code>data F a b = F (a -> b)
</code>```

My task is to make this type an instance of the Functor class.
I understand how to do this with the usual examples. i.e. Maybe.

Usually, the given function is applied to the value which is extracted from the wrapper. Then the result is replaced in the same wrapper type. The wrapper in the case of the Maybe type being Just.

However, my data type represents a function of type a -> b. I don't understand how to transfer this concept to use a wrapped function. The reason to create this data type as well as the way to implement this idea are both lost on me.

I'm assuming I'm not fully understanding the concept behind functors or just missing the intention behind the given task where I must specifically define and use the custom data type above...

Please help me to correct the following...

instance Functor (F a) where

答:
A function is already an instance of Functor. So you can make use of the DeriveFunctor extension:

```<code>{-# LANGUAGE <strong>DeriveFunctor</strong> #-}

data F a b = F (a -> b) <strong>deriving Functor</strong></code>```

if you want to manually implement an instance of functor, you can look at the types. If you are implementing this for a function, then the signature of fmap should be:

```<code>fmap :: Functor f => (b -> c) -> f b -> f c
</code>```

and thus for f ~ (->) a, this means:

```<code>fmap :: (b -> c) -> ((->) a b) -> ((->) a c)  -- fmap for (->) a
</code>```

or more compact:

```<code>fmap :: (b -> c) -> (a -> b) -> (a -> c)  -- fmap for (->) a
</code>```

there is only one straightforward implementation for such fmap. If you are then implementing this for instance Functor (F a), the only difference is to unwrap the function from the F data constructor and wrap the result back in an F data constructor.

Body:
I have this data type:

data F a b = F (a -> b)

My task is to make this type an instance of the Functor class.
I understand how to do this with the usual examples. i.e. Maybe.

Usually, the given function is applied to the value which is extracted from the wrapper. Then the result is replaced in the same wrapper type. The wrapper in the case of the Maybe type being Just.

However, my data type represents a function of type a -> b. I don't understand how to transfer this concept to use a wrapped function. The reason to create this data type as well as the way to implement this idea are both lost on me.

I'm assuming I'm not fully understanding the concept behind functors or just missing the intention behind the given task where I must specifically define and use the custom data type above...

Please help me to correct the following...

instance Functor (F a) where

Body:
A function is already an instance of Functor. So you can make use of the DeriveFunctor extension:

{-# LANGUAGE DeriveFunctor #-}

data F a b = F (a -> b) deriving Functor

if you want to manually implement an instance of functor, you can look at the types. If you are implementing this for a function, then the signature of fmap should be:

fmap :: Functor f => (b -> c) -> f b -> f c

and thus for f ~ (->) a, this means:

fmap :: (b -> c) -> ((->) a b) -> ((->) a c)  -- fmap for (->) a

or more compact:

fmap :: (b -> c) -> (a -> b) -> (a -> c)  -- fmap for (->) a

there is only one straightforward implementation for such fmap. If you are then implementing this for instance Functor (F a), the only difference is to unwrap the function from the F data constructor and wrap the result back in an F data constructor.


问:
POST request receive large data in plain/text format in spring boot
I'm currently receiving POST requests which contain large data in plain/text format in spring boot.

We are receiving 5MB of data in each request and it takes approximately 2-3seconds to convert InputStream to String. I wanted to know a faster method to convert InputStream to String for a large dataset.

Sample Code:

```<code>@PostMapping(value = "receivingRequest", consumes = "plain/text")
public String receivingRequest(HttpServletRequest request) {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    byte[] buffer = new byte[1024];
    for (int length; (length = request.getInputStream().read(buffer)) != -1; ) {
        result.write(buffer, 0, length);
    }

    String requiredData = result.toString();
    ... rest of the code uses requiredData
}
</code>```

答:
A BufferedInputStream should improve the network transfer speed.

```<code>new BufferedInputStream(request.getInputStream()).read(buffer)
</code>```

Default BIS buffer size is 8192. You could experiment with the constructor that takes a custom buffered size to see if that helps further, though I think that probably is as large as needed to handle the underlying TCP block size.

Body:
I'm currently receiving POST requests which contain large data in plain/text format in spring boot.

We are receiving 5MB of data in each request and it takes approximately 2-3seconds to convert InputStream to String. I wanted to know a faster method to convert InputStream to String for a large dataset.

Sample Code:

@PostMapping(value = "receivingRequest", consumes = "plain/text")
public String receivingRequest(HttpServletRequest request) {
    ByteArrayOutputStream result = new ByteArrayOutputStream();

    byte[] buffer = new byte[1024];
    for (int length; (length = request.getInputStream().read(buffer)) != -1; ) {
        result.write(buffer, 0, length);
    }

    String requiredData = result.toString();
    ... rest of the code uses requiredData
}

Body:
A BufferedInputStream should improve the network transfer speed.

new BufferedInputStream(request.getInputStream()).read(buffer)

Default BIS buffer size is 8192. You could experiment with the constructor that takes a custom buffered size to see if that helps further, though I think that probably is as large as needed to handle the underlying TCP block size.


问:
How do I distinguish between left and right keys (CTRL and ALT)?
I started making use of Win32's raw input features to detect all keys on the keyboard. So far, everything is working great! I can distinguish between numbers on the top row and numbers in the keypad on the right. I can even detect between the left and right shift keys. However, the control and alt keys do not return unique scan codes. The control key returns 29, and the alt key returns 56.

The popular method for checking key states on these keys is GetAsyncKeyState. I have tested that function using VK_LCONTROL and VK_RCONTROL, and it works, but that only helps me for capturing key down events. I would really like to be able to capture key up events as well. It is obvious that the API is somehow aware of which key is being pressed; how do I get ahold of that information?

I am currently extracting the scan code from the RAWKEYBOARD structure's MakeCode field. That gives me information about every key (and its left/right alignment) except CTRL and ALT. How would I go about capturing the key up events (and knowing whether it is left/right)? Is it possible using just the RAWKEYBOARD structure? Or do I have to concoct some kind of workaround?

答:
To check extended key flag for "right" key in lParam also can do this way.

If true - it's right Ctrl or Alt, based on wParam == VK_CONTROL or VK_MENU

otherwise its's left Ctrl or Alt >

```<code>(HIWORD(lParam) & KF_EXTENDED) == KF_EXTENDED
</code>```

To get scan code also can do this >

```<code>BYTE scan_code = LOBYTE(HIWORD(lParam));
</code>```

for use

```<code>MapVirtualKey(scan_code, MAPVK_VSC_TO_VK_EX);
</code>```

for detect VK_LSHIFT or VK_RSHIFT based on wParam == VK_SHIFT

Body:
To check extended key flag for "right" key in lParam also can do this way.

If true - it's right Ctrl or Alt, based on wParam == VK_CONTROL or VK_MENU

otherwise its's left Ctrl or Alt >

(HIWORD(lParam) & KF_EXTENDED) == KF_EXTENDED

To get scan code also can do this >

BYTE scan_code = LOBYTE(HIWORD(lParam));

for use

MapVirtualKey(scan_code, MAPVK_VSC_TO_VK_EX);

for detect VK_LSHIFT or VK_RSHIFT based on wParam == VK_SHIFT


问:
If else statements in numpy arange
Basicaly I want to compare a variable between two np.arange()

```<code>x = 22.03
first = np.arange(18.5, 24.99, 0.01)
second = np.arange(25.0, 29.99, 0.01)

if x in first:
    print("x is in first")
elif x in second:
    print("x is in second")
</code>```

I expect to see "x isin first" but rather I get nothing printed on the terminal.
If I add another else: statement it will execute whatever is in that.

I am using numpy because I want to have a range of floats. The native range() function doesn't support floats

There happens no comparison between the two, why is that?

答:
```<code>x = 22.03
first = np.arange(18.5, 24.99, 0.01)
second = np.arange(25.0, 29.99, 0.01)

type(first)
Out[13]: numpy.ndarray

# cast to list and proper value rounding for boolean comparison
first = [round(n, 2) for n in first]

x in first
Out[16]: True
</code>```

Title: If else statements in numpy arange

Body:
Basicaly I want to compare a variable between two np.arange()

x = 22.03
first = np.arange(18.5, 24.99, 0.01)
second = np.arange(25.0, 29.99, 0.01)

if x in first:
    print("x is in first")
elif x in second:
    print("x is in second")

I expect to see "x isin first" but rather I get nothing printed on the terminal.
If I add another else: statement it will execute whatever is in that.

I am using numpy because I want to have a range of floats. The native range() function doesn't support floats

There happens no comparison between the two, why is that?


问:
command to execute docker rm <none> image on Windows
I need to remove some docker TAG having 'none' values on Windows.

Do you know the relative windows command to remove 'none' TAG on Docker?
I tried this one but it doesn't work:

echo docker rmi -f &&  (docker images -f "dangling=true" -q)

Thanks in advance

答: You can remove them by using their image ids. Or you can do docker image prune.


问:
How to mark data points that are >X from the data point before it or after it
I have a date/time dataframe with values at every 15 minutes (there are hundreds of data points). I want to mark down values that are > or < 1.5 from the value before or after it.

This is my dataframe:

```<code>df = structure(list(Timestamp =
                      structure(c(1622552400, 1622553300, 1622554200,
                                  1622555100, 1622556000, 1622556900),
                                class = c("POSIXct", "POSIXt"), tzone = "EST"),
                    Temp = c(13.173, 13.269, 13.269, 13.269, 15.269, 13.269)),
               row.names = c(NA, 6L), class = "data.frame")
</code>```

I imagine I will need some sort of looping but I don't really know where to start with that.

Ideally, the result would look like a dataframe with a date/time column, the column of values, and a new column filled with 0's and 1's (where 0 signifies the value was not > or < 1.5 and 1 signifies the value was < or > 1.5). So something like this table here (which has all 0's because none of the values are > or < 1.5 from the value before it):

```<code> Timestamp            Temp Difference_1.5
  <dttm>              <dbl>          <dbl>
1 2021-06-01 08:00:00  13.2              0
2 2021-06-01 08:15:00  13.3              0
3 2021-06-01 08:30:00  13.3              0
4 2021-06-01 08:45:00  13.3              0
5 2021-06-01 09:00:00  13.3              0
6 2021-06-01 09:15:00  13.3              0
>
</code>```

Any ideas out there?

Body:
I have a date/time dataframe with values at every 15 minutes (there are hundreds of data points). I want to mark down values that are > or < 1.5 from the value before or after it.

This is my dataframe:

df = structure(list(Timestamp =
                      structure(c(1622552400, 1622553300, 1622554200,
                                  1622555100, 1622556000, 1622556900),
                                class = c("POSIXct", "POSIXt"), tzone = "EST"),
                    Temp = c(13.173, 13.269, 13.269, 13.269, 15.269, 13.269)),
               row.names = c(NA, 6L), class = "data.frame")

I imagine I will need some sort of looping but I don't really know where to start with that.

Ideally, the result would look like a dataframe with a date/time column, the column of values, and a new column filled with 0's and 1's (where 0 signifies the value was not > or < 1.5 and 1 signifies the value was < or > 1.5). So something like this table here (which has all 0's because none of the values are > or < 1.5 from the value before it):

 Timestamp            Temp Difference_1.5
  <dttm>              <dbl>          <dbl>
1 2021-06-01 08:00:00  13.2              0
2 2021-06-01 08:15:00  13.3              0
3 2021-06-01 08:30:00  13.3              0
4 2021-06-01 08:45:00  13.3              0
5 2021-06-01 09:00:00  13.3              0
6 2021-06-01 09:15:00  13.3              0
>

Any ideas out there?

Body:
You can use diff() to calculate the difference between all consecutive elements.

df$dif <- as.integer(c(FALSE, abs(diff(df$Temp)) > 1.5))
df
#             Timestamp   Temp dif
# 1 2021-06-01 08:00:00 13.173   0
# 2 2021-06-01 08:15:00 13.269   0
# 3 2021-06-01 08:30:00 13.269   0
# 4 2021-06-01 08:45:00 13.269   0
# 5 2021-06-01 09:00:00 15.269   1
# 6 2021-06-01 09:15:00 13.269   1


问:
Is a (unit) test that mocks the result of a method call really valid?
I created a test method for a controller, but I am not sure if the test is really valid.

Inside the controller there's a method call that returns an object which one of the properties is a XML string.
I want to test if that XML contains a specific tag and so I created a text file with that xml and mocked the method call setting as result the xml read from the text file then I assert that the wanted tag is there.

So my question is, if the real method call changes and stop returning the correct XML with the tags I want, will my test fail or keep passing?

答:
Your test will keep passing of course. But the point of unit tests is testing one UNIT of code. In your case you are testing the controller action. Particularly you are testing that:

```<code>//Prepare
When my inner method returns some valid XML that I expect and the correct tag is present there.
//Act
Call the method
//Assert
Assert that my controller action will return status 200 OK (or similar)
</code>```

You are not testing the logic inside the method you are calling. Such test is called integration test. In those test you are testing how 2 components integrate with each other.

Body:
Your test will keep passing of course. But the point of unit tests is testing one UNIT of code. In your case you are testing the controller action. Particularly you are testing that:

//Prepare
When my inner method returns some valid XML that I expect and the correct tag is present there.
//Act
Call the method
//Assert
Assert that my controller action will return status 200 OK (or similar)

You are not testing the logic inside the method you are calling. Such test is called integration test. In those test you are testing how 2 components integrate with each other.


问:
Sharing data in local thread python in different threads
I have stored request_id in local thread python, this thread creates three more threads which won't have access to request_id. How can I share or send request_id info from one thread local to another.</p>

答:
Python methods of data sharing between threads and processes:

Multithreading and data sharing in python

Handling and Sharing Data Between Threads


问:
Get route path '/blog/{slug}' of current request in Symfony
For some logging/monitoring i would like to get the current route path including placeholders.

If my route is /blog/{slug} and the request is to http://localhost/blog/foobar what i need is "/blog/{slug}"

In request listeners this value seem to not be inside the request object. I only find the resolved path which i am not interested in.

In Compiler passes I have the issue that any Router related service I try to get from the ContainerBuilder returns an exception. If i had the

What is a clean way to obtain this?

答:
For routes with one param:

```<code>$routeWithoutParam = substr($request->getRequestUri(),0,strrpos($request->getRequestUri(),'/'));
$routeParams = $request->attributes->get('_route_params');

$routeDefinition = $routeWithoutParam.'/{' . array_key_first($paramsArray) . '}';

echo $routeDefinition;
</code>```

For routes with multiple params:

```<code>$routeParams = $request->attributes->get('_route_params');
$routeWithoutParam = '';
for ($i = 0; $i < count($routeParams); $i++) {
   $routeWithoutParam = $i === 0
      ? substr($request->getRequestUri(), 0, strrpos($request->getRequestUri(), '/'))
      : substr($routeWithoutParam, 0, strrpos($routeWithoutParam, '/'))
   ;
}

$routeDefinition = $routeWithoutParam.'/';
foreach (array_keys($routeParams) as $key => $param) {
  $routeDefinition.= '{' . $param . '}' . ($key < count($routeParams)-1 ? '/' : '');
}

echo $routeDefinition;
</code>```

Body:
For routes with one param:

$routeWithoutParam = substr($request->getRequestUri(),0,strrpos($request->getRequestUri(),'/'));
$routeParams = $request->attributes->get('_route_params');

$routeDefinition = $routeWithoutParam.'/{' . array_key_first($paramsArray) . '}';

echo $routeDefinition;

For routes with multiple params:

$routeParams = $request->attributes->get('_route_params');
$routeWithoutParam = '';
for ($i = 0; $i < count($routeParams); $i++) {
   $routeWithoutParam = $i === 0
      ? substr($request->getRequestUri(), 0, strrpos($request->getRequestUri(), '/'))
      : substr($routeWithoutParam, 0, strrpos($routeWithoutParam, '/'))
   ;
}

$routeDefinition = $routeWithoutParam.'/';
foreach (array_keys($routeParams) as $key => $param) {
  $routeDefinition.= '{' . $param . '}' . ($key < count($routeParams)-1 ? '/' : '');
}

echo $routeDefinition;


问:
How to change Android Studio default gradle JDK to 11
Getting this message when I click run:

```<code>> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.
</code>```

The answers from Error message "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8" to change the Gradle JDK in settings work. but only for that one project. When I create a new project, Android Studio automatically uses default 1.8 again.

I have 11 available, AS just doesn't automatically use it.
Things I tried: changed the JAVA_HOME env to the location for JDK 11 here, but still get the same error.

Invalid cache /restart a bunch of time does nothing

How to set it once and apply it to all future new projects?

Attaching app/build.gradle

```<code>plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.grid"
        minSdk 22
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
</code>```

top level build.gradle

```<code>// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
</code>```

答:
Multiple Android Studio Installed?

Short Answer:

Just delete the other version and it should fix the problem.

Long answer:

I had two versions of Android Studio installed Android 4.2 and Android Arctic Fox. Both Android Studio had different Gradle JDK version installed.

This is what I was seeing in Arctic Fox Gradle Settings. (Default selection was 1.8)

My theory:

If you notice Gradle JDK is installed under Applications/Android Studio/Content/

It's my assumption that Gradle Settings page pulls up all the installed Gradle JDK versions. And there is no option to set the default version in Settings page. So the first Gradle version becomes the default.

I don't know if it is alphabetically sorted or based on Download timestamp.

But I believe it is based on the timestamp. The oldest installed version gets to the top in the list.

Here is a supporting observation. When I deleted Android Studio 4.2 and ctrl+z (Undo) it the list order changed.

Disclaimer:

I could be completely wrong as I don't have any official doc, link that support this claim. It is just a theory.

And I also understand that it is not an ideal solution. As deleting old Android Studio may not be the option for everyone.

Body:
Getting this message when I click run:

> Failed to apply plugin 'com.android.internal.application'.
   > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
     You can try some of the following options:
       - changing the IDE settings.
       - changing the JAVA_HOME environment variable.
       - changing `org.gradle.java.home` in `gradle.properties`.

The answers from Error message "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8" to change the Gradle JDK in settings work. but only for that one project. When I create a new project, Android Studio automatically uses default 1.8 again.

I have 11 available, AS just doesn't automatically use it.
Things I tried: changed the JAVA_HOME env to the location for JDK 11 here, but still get the same error.

Invalid cache /restart a bunch of time does nothing

How to set it once and apply it to all future new projects?

Attaching app/build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdk 31

    defaultConfig {
        applicationId "com.example.grid"
        minSdk 22
        targetSdk 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.github.bumptech.glide:glide:4.12.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}

top level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


问:
Why my Reactstrap's Media object is not aligned properly?
I have recently started learning to react and reactstrap and I wanted to use Reactstrap's Media Object but my results are not what I want. As shown in documentation, the image heading and description should come right next to the image, but after applying the same, the image heading and description are aligned below the image.
Screenshot of my code's outcome.

Code:-

```<code>import React, {Component} from "react";
import {Media} from "reactstrap";

class Menu extends Component {
constructor(props) {
super(props);
this.state = {
  dishes: [
    {
      id: 0,
      name: "Uthappizza",
      image: "assets/images/uthappizza.png",
      category: "mains",
      label: "Hot",
      price: "4.99",
      description:
        "A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer."
    },
    {
      id: 1,
      name: "Zucchipakoda",
      image: "assets/images/zucchipakoda.png",
      category: "appetizer",
      label: "",
      price: "1.99",
      description:
        "Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce"
    },
    {
      id: 2,
      name: "Vadonut",
      image: "assets/images/vadonut.png",
      category: "appetizer",
      label: "New",
      price: "1.99",
      description:
        "A quintessential ConFusion experience, is it a vada or is it a donut?"
    },
    {
      id: 3,
      name: "ElaiCheese Cake",
      image: "assets/images/elaicheesecake.png",
      category: "dessert",
      label: "",
      price: "2.99",
      description:
        "A delectable, semi-sweet New York Style Cheese Cake, with Graham cracker crust and spiced with Indian cardamoms"
    }
  ],
};
}

render() {
const menu = this.state.dishes.map((dish) => {
  return (
    <div key={dish.id} className="col-12 mt-5">
      <Media>
        <Media left middle>
          <Media object src={dish.image} alt={dish.name} />
        </Media>
        <Media body className="ml-5">
          <Media heading>
          {dish.name}
          </Media>
          {dish.description}
        </Media>
      </Media>
    </div>
  );
});

return (
  <div className="container">
    <div className="row">
      <Media list>{menu}</Media>
    </div>
  </div>
);
}
}

export default Menu;
</code>```

Why my image heading and description are not aligned right to the image? Where I'm doing wrong?

答:
You probably are using bootstrap 5, which does not include the object Media anymore. See the bootstrap 5 documentation. I had the same problem. Try install the bootstrap 4 instead.

Anyway, I just did the downgrade of the bootstrap package to version 4.6.0 and everything is working properly here.

Body:
I have recently started learning to react and reactstrap and I wanted to use Reactstrap's Media Object but my results are not what I want. As shown in documentation, the image heading and description should come right next to the image, but after applying the same, the image heading and description are aligned below the image.
Screenshot of my code's outcome.

Code:-

import React, {Component} from "react";
import {Media} from "reactstrap";

class Menu extends Component {
constructor(props) {
super(props);
this.state = {
  dishes: [
    {
      id: 0,
      name: "Uthappizza",
      image: "assets/images/uthappizza.png",
      category: "mains",
      label: "Hot",
      price: "4.99",
      description:
        "A unique combination of Indian Uthappam (pancake) and Italian pizza, topped with Cerignola olives, ripe vine cherry tomatoes, Vidalia onion, Guntur chillies and Buffalo Paneer."
    },
    {
      id: 1,
      name: "Zucchipakoda",
      image: "assets/images/zucchipakoda.png",
      category: "appetizer",
      label: "",
      price: "1.99",
      description:
        "Deep fried Zucchini coated with mildly spiced Chickpea flour batter accompanied with a sweet-tangy tamarind sauce"
    },
    {
      id: 2,
      name: "Vadonut",
      image: "assets/images/vadonut.png",
      category: "appetizer",
      label: "New",
      price: "1.99",
      description:
        "A quintessential ConFusion experience, is it a vada or is it a donut?"
    },
    {
      id: 3,
      name: "ElaiCheese Cake",
      image: "assets/images/elaicheesecake.png",
      category: "dessert",
      label: "",
      price: "2.99",
      description:
        "A delectable, semi-sweet New York Style Cheese Cake, with Graham cracker crust and spiced with Indian cardamoms"
    }
  ],
};
}

render() {
const menu = this.state.dishes.map((dish) => {
  return (

      <Media>
        <Media left middle>
          <Media object src={dish.image} alt={dish.name} />
        </Media>
        <Media body className="ml-5">
          <Media heading>
          {dish.name}
          </Media>
          {dish.description}
        </Media>
      </Media>

  );
});

return (

      <Media list>{menu}</Media>

);
}
}

export default Menu;

Why my image heading and description are not aligned right to the image? Where I'm doing wrong?


问:
Search all .htaccess files in a Linux server webroot for a word and return file paths to a text file
I have a Linux server and want to search all the .htaccess files in all the folders (public_html webroot and subfolders) that have a certain word (eg ldap) in it. I also want the file paths returned to these .htaccess files with the word in it and saved to a text file.
Can I do this with grep or find and what syntax is optimal.
I tried find . -type f -printf '"%p"\n' | xargs grep ldap > /tmp/results.txt but want to only search .htaccess files exclusively.
Thanks

答:
Following your example, try using:

```<code>find . \( -type f -name .htaccess \) -print0 | xargs -0 grep -H ldap > /tmp/results.txt
</code>```

this find will list null-terminated files .htaccess in . directory, and xargs -0 pass them to the grep. grep -H ldap  will list files containing ldap string with filenames.

Body:
Following your example, try using:

find . \( -type f -name .htaccess \) -print0 | xargs -0 grep -H ldap > /tmp/results.txt

this find will list null-terminated files .htaccess in . directory, and xargs -0 pass them to the grep. grep -H ldap  will list files containing ldap string with filenames.


问:
UPDATED - How do I get an avg in a range of year
I have 2 tables attendance and people.

I need to get the AVG of attendance by range of year.

To do that I need get the column people.DT_NASCIMENTO_FUNDACAO (DATE) and attendance.DT_SOLICITACAO_ATENDIMENTO (DATE).

The result this query should be something like:

```<code>-------------------------
| 0 - 18 | 19 - 23| ... |
-------------------------
|  0.2   |  0.8   | ... |
-------------------------
</code>```

where 0.2 and 0.8 is a decimal representation of fraction of attendance by range of year.

people have CD_PESSOA PK and attendance have NU_USUARIO LIKE FK.

```<code> ______                           ____________
|PEOPLE| 1 ------------------> N | ATTENDANCE |
 -------                           ------------
</code>```

I created a code that count the numbers of time that a range of year happen:

```<code>SELECT
    SUM(CASE
        WHEN EXTRACT(YEAR FROM TO_DATE(P.DT_NASCIMENTO_FUNDACAO))
        BETWEEN EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) - 18
        AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO))
        THEN 1 ELSE 0 END) AS "0 - 18",

    SUM(CASE
        WHEN EXTRACT(YEAR FROM TO_DATE(P.DT_NASCIMENTO_FUNDACAO))
        BETWEEN EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) - 23
        AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) - 19
        THEN 1 ELSE 0 END) AS "19 - 23"
FROM ATTENDANCE G JOIN PEOPLE P
ON (G.NU_USUARIO = P.CD_PESSOA)
WHERE EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) >= EXTRACT(YEAR FROM SYSDATE) - 1
AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) <= EXTRACT(YEAR FROM SYSDATE);
</code>```

As result I have:

Now, I need change this result to show me the percentual representation. How can I do that?

Here in this link I crate the sql file to create the tables and insert sample data(50 people and 2000 attendances).

Here we have some 50 sample data about born and 1000 attendance date.

```<code>people.DT_NASCIMENTO_FUNDACAO

01-07-2010
15-09-2014
10-07-1970
26-01-1989
02-05-1982
09-05-2009
25-08-2006
02-12-2013
08-04-2008
11-01-1962
01-05-1980
11-11-1993
15-07-2013
03-03-1990
09-10-2013
31-12-2008
25-07-2015
16-06-1972
03-11-1985
03-11-2006
19-03-1955
03-01-1974
08-01-2015
13-11-2003
07-01-1989
22-01-2007
30-11-1999
04-12-1970
24-05-1983
25-04-2012
11-11-1988
16-09-1980
21-05-1989
01-06-2011
14-09-1973
16-10-2015
10-02-2000
30-10-2004
27-02-1965
30-01-2015
23-05-1993
07-01-1987
04-03-1998
22-10-2011
17-12-1999
19-02-1955
21-07-1961

attendance.DT_SOLICITACAO_ATENDIMENTO

18-09-2020
21-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
30-09-2020
30-09-2020
30-09-2020
14-09-2020
23-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
18-09-2020
21-09-2020
21-09-2020
04-09-2020
04-09-2020
04-09-2020
04-09-2020
04-09-2020
08-09-2020
08-09-2020
08-09-2020
09-09-2020
25-08-2020
25-08-2020
25-08-2020
25-08-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
08-09-2020
17-09-2020
08-09-2020
08-09-2020
08-09-2020
17-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
21-09-2020
13-10-2020
04-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
21-09-2020
21-09-2020
21-09-2020
18-09-2020
23-09-2020
18-09-2020
23-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
21-09-2020
21-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
29-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
25-09-2020
25-09-2020
25-09-2020
25-09-2020
28-09-2020
24-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
18-09-2020
03-08-2019
03-08-2019
03-08-2019
03-08-2019
02-08-2019
02-08-2019
02-08-2019
02-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
09-08-2019
06-08-2019
17-07-2019
17-10-2020
17-10-2020
18-10-2020
19-10-2020
19-10-2020
19-10-2020
19-10-2020
19-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
29-10-2020
29-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
28-10-2020
28-10-2020
10-10-2020
10-10-2020
10-10-2020
10-10-2020
08-10-2020
08-10-2020
08-10-2020
08-10-2020
11-10-2020
11-10-2020
13-10-2020
13-10-2020
14-10-2020
14-10-2020
17-10-2020
17-10-2020
17-10-2020
16-10-2020
18-10-2020
18-10-2020
04-10-2020
04-10-2020
13-10-2020
13-10-2020
13-10-2020
09-10-2020
13-10-2020
09-10-2020
14-10-2020
14-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
26-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
07-10-2020
12-10-2020
10-10-2020
16-10-2020
16-10-2020
15-10-2020
10-09-2020
10-09-2020
10-09-2020
09-03-2020
09-03-2020
11-09-2020
11-09-2020
11-09-2020
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
20-06-2019
20-06-2019
20-06-2019
20-06-2019
20-06-2019
20-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
03-06-2019
03-06-2019
26-06-2019
26-06-2019
26-06-2019
26-06-2019
26-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
14-06-2019
14-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
12-08-2021
12-08-2021
12-08-2021
12-08-2021
12-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
18-08-2021
18-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
19-08-2021
19-08-2021
19-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
30-11-2019
30-11-2019
30-11-2019
30-11-2019
30-11-2019
30-11-2019
11-11-2019
30-11-2019
27-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
11-11-2019
11-11-2019
12-11-2019
12-11-2019
12-11-2019
12-11-2019
30-10-2019
07-11-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
04-11-2019
04-11-2019
04-11-2019
04-11-2019
04-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
26-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
28-11-2019
03-12-2019
06-11-2019
07-11-2019
07-11-2019
12-11-2019
26-11-2019
28-11-2019
11-11-2019
12-11-2019
12-11-2019
25-11-2019
02-12-2019
13-11-2019
28-11-2019
07-11-2019
07-11-2019
07-11-2019
01-11-2019
01-11-2019
01-11-2019
01-11-2019
01-11-2019
01-11-2019
04-11-2019
04-11-2019
07-11-2019
07-11-2019
25-11-2019
14-03-2019
14-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
18-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
18-03-2019
18-03-2019
18-03-2019
18-03-2019
14-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
18-03-2019
01-03-2019
01-03-2019
01-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
18-03-2019
18-03-2019
18-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
19-03-2019
15-01-2019
05-02-2019
20-03-2019
27-12-2018
13-02-2019
13-02-2019
13-02-2019
13-02-2019
29-01-2019
13-11-2018
22-03-2019
12-03-2019
13-02-2019
13-02-2019
17-01-2019
25-03-2019
21-03-2019
21-02-2019
26-03-2019
22-02-2019
22-02-2019
22-02-2019
22-02-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
25-03-2019
07-02-2019
07-02-2019
28-02-2019
28-02-2019
28-02-2019
28-02-2019
28-02-2019
28-02-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
05-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
11-07-2019
11-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
11-07-2019
11-07-2019
11-07-2019
09-07-2019
11-07-2019
11-07-2019
11-07-2019
11-07-2019
</code>```

How can I do that?

答:
To solve my problem was necessary a group operation on database, incluse to create 2 temporary tables.

The solution to my case was:

```<code>WITH TABLE_X AS (
    SELECT P.CD_PESSOA, P.DT_NASCIMENTO_FUNDACAO, TO_DATE(SYSDATE) AS DATA_ATUAL, TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO),
    EXTRACT(YEAR FROM SYSDATE) - EXTRACT(YEAR FROM TO_DATE(P.DT_NASCIMENTO_FUNDACAO)) AS IDADE
    FROM ATTENDANCE G JOIN PEOPLE P
    ON (G.NU_USUARIO = P.CD_PESSOA)
    WHERE EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) >= EXTRACT(YEAR FROM SYSDATE) - 1
    AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) <= EXTRACT(YEAR FROM SYSDATE)
    ORDER BY IDADE DESC
),
TABLE_Y AS (SELECT
    SUM(CASE WHEN IDADE BETWEEN 0 AND 18 THEN 1 ELSE 0 END) AS "0-18",
    SUM(CASE WHEN IDADE BETWEEN 19 AND 23 THEN 1 ELSE 0 END) AS "19-23",
    SUM(CASE WHEN IDADE BETWEEN 24 AND 28 THEN 1 ELSE 0 END) AS "24-28",
    SUM(CASE WHEN IDADE BETWEEN 29 AND 33 THEN 1 ELSE 0 END) AS "29-33",
    SUM(CASE WHEN IDADE BETWEEN 34 AND 38 THEN 1 ELSE 0 END) AS "34-38",
    SUM(CASE WHEN IDADE BETWEEN 39 AND 43 THEN 1 ELSE 0 END) AS "39-43",
    SUM(CASE WHEN IDADE BETWEEN 44 AND 48 THEN 1 ELSE 0 END) AS "44-48",
    SUM(CASE WHEN IDADE BETWEEN 49 AND 53 THEN 1 ELSE 0 END) AS "49-53",
    SUM(CASE WHEN IDADE BETWEEN 54 AND 58 THEN 1 ELSE 0 END) AS "54-58",
    SUM(CASE WHEN IDADE >= 59 THEN 1 ELSE 0 END) AS "59+",
    SUM(CASE WHEN IDADE IS NULL THEN 1 ELSE 0 END) AS "VALORES_NULL",
    COUNT(IDADE) AS TOTAL_IDADE
FROM TABLE_X
)
SELECT
    ROUND(("0-18" / TOTAL_IDADE) * 100, 2) ||'%' AS "0-18",
    ROUND(("19-23" / TOTAL_IDADE) * 100, 2) ||'%' AS "19-23",
    ROUND(("24-28" / TOTAL_IDADE) * 100, 2) ||'%' AS "24-28",
    ROUND(("29-33" / TOTAL_IDADE) * 100, 2) ||'%' AS "29-33",
    ROUND(("34-38" / TOTAL_IDADE) * 100, 2) ||'%' AS "29-33",
    ROUND(("39-43" / TOTAL_IDADE) * 100, 2) ||'%' AS "34-38",
    ROUND(("44-48" / TOTAL_IDADE) * 100, 2) ||'%' AS "44-48",
    ROUND(("49-53" / TOTAL_IDADE) * 100, 2) ||'%' AS "49-53",
    ROUND(("54-58" / TOTAL_IDADE) * 100, 2) ||'%' AS "54-58",
    ROUND(("59+" / TOTAL_IDADE) * 100, 2) ||'%' AS "59+"
FROM TABLE_Y
</code>```

As result I had:

Body:
I have 2 tables attendance and people.

I need to get the AVG of attendance by range of year.

To do that I need get the column people.DT_NASCIMENTO_FUNDACAO (DATE) and attendance.DT_SOLICITACAO_ATENDIMENTO (DATE).

The result this query should be something like:

-------------------------
| 0 - 18 | 19 - 23| ... |
-------------------------
|  0.2   |  0.8   | ... |
-------------------------

where 0.2 and 0.8 is a decimal representation of fraction of attendance by range of year.

people have CD_PESSOA PK and attendance have NU_USUARIO LIKE FK.

 ______                           ____________
|PEOPLE| 1 ------------------> N | ATTENDANCE |
 -------                           ------------

I created a code that count the numbers of time that a range of year happen:

SELECT
    SUM(CASE
        WHEN EXTRACT(YEAR FROM TO_DATE(P.DT_NASCIMENTO_FUNDACAO))
        BETWEEN EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) - 18
        AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO))
        THEN 1 ELSE 0 END) AS "0 - 18",

    SUM(CASE
        WHEN EXTRACT(YEAR FROM TO_DATE(P.DT_NASCIMENTO_FUNDACAO))
        BETWEEN EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) - 23
        AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) - 19
        THEN 1 ELSE 0 END) AS "19 - 23"
FROM ATTENDANCE G JOIN PEOPLE P
ON (G.NU_USUARIO = P.CD_PESSOA)
WHERE EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) >= EXTRACT(YEAR FROM SYSDATE) - 1
AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) <= EXTRACT(YEAR FROM SYSDATE);

As result I have:

Now, I need change this result to show me the percentual representation. How can I do that?

Here in this link I crate the sql file to create the tables and insert sample data(50 people and 2000 attendances).

Here we have some 50 sample data about born and 1000 attendance date.

people.DT_NASCIMENTO_FUNDACAO

01-07-2010
15-09-2014
10-07-1970
26-01-1989
02-05-1982
09-05-2009
25-08-2006
02-12-2013
08-04-2008
11-01-1962
01-05-1980
11-11-1993
15-07-2013
03-03-1990
09-10-2013
31-12-2008
25-07-2015
16-06-1972
03-11-1985
03-11-2006
19-03-1955
03-01-1974
08-01-2015
13-11-2003
07-01-1989
22-01-2007
30-11-1999
04-12-1970
24-05-1983
25-04-2012
11-11-1988
16-09-1980
21-05-1989
01-06-2011
14-09-1973
16-10-2015
10-02-2000
30-10-2004
27-02-1965
30-01-2015
23-05-1993
07-01-1987
04-03-1998
22-10-2011
17-12-1999
19-02-1955
21-07-1961

attendance.DT_SOLICITACAO_ATENDIMENTO

18-09-2020
21-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
30-09-2020
30-09-2020
30-09-2020
14-09-2020
23-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
18-09-2020
21-09-2020
21-09-2020
04-09-2020
04-09-2020
04-09-2020
04-09-2020
04-09-2020
08-09-2020
08-09-2020
08-09-2020
09-09-2020
25-08-2020
25-08-2020
25-08-2020
25-08-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
01-09-2020
08-09-2020
17-09-2020
08-09-2020
08-09-2020
08-09-2020
17-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
08-09-2020
21-09-2020
13-10-2020
04-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
21-09-2020
21-09-2020
21-09-2020
18-09-2020
23-09-2020
18-09-2020
23-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
18-09-2020
21-09-2020
21-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
29-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
28-09-2020
25-09-2020
25-09-2020
25-09-2020
25-09-2020
28-09-2020
24-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
16-09-2020
18-09-2020
03-08-2019
03-08-2019
03-08-2019
03-08-2019
02-08-2019
02-08-2019
02-08-2019
02-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
09-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
22-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
23-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
30-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
27-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
21-08-2019
09-08-2019
06-08-2019
17-07-2019
17-10-2020
17-10-2020
18-10-2020
19-10-2020
19-10-2020
19-10-2020
19-10-2020
19-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
31-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
24-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
29-10-2020
29-10-2020
26-10-2020
26-10-2020
26-10-2020
26-10-2020
28-10-2020
28-10-2020
10-10-2020
10-10-2020
10-10-2020
10-10-2020
08-10-2020
08-10-2020
08-10-2020
08-10-2020
11-10-2020
11-10-2020
13-10-2020
13-10-2020
14-10-2020
14-10-2020
17-10-2020
17-10-2020
17-10-2020
16-10-2020
18-10-2020
18-10-2020
04-10-2020
04-10-2020
13-10-2020
13-10-2020
13-10-2020
09-10-2020
13-10-2020
09-10-2020
14-10-2020
14-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
01-10-2020
26-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
27-10-2020
07-10-2020
12-10-2020
10-10-2020
16-10-2020
16-10-2020
15-10-2020
10-09-2020
10-09-2020
10-09-2020
09-03-2020
09-03-2020
11-09-2020
11-09-2020
11-09-2020
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
19-06-2019
20-06-2019
20-06-2019
20-06-2019
20-06-2019
20-06-2019
20-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
28-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
03-06-2019
03-06-2019
26-06-2019
26-06-2019
26-06-2019
26-06-2019
26-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
27-06-2019
14-06-2019
14-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
29-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
30-06-2019
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
21-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
11-08-2021
12-08-2021
12-08-2021
12-08-2021
12-08-2021
12-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
18-08-2021
18-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
20-08-2021
19-08-2021
19-08-2021
19-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
18-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
19-08-2021
30-11-2019
30-11-2019
30-11-2019
30-11-2019
30-11-2019
30-11-2019
11-11-2019
30-11-2019
27-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
06-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
07-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
08-11-2019
11-11-2019
11-11-2019
12-11-2019
12-11-2019
12-11-2019
12-11-2019
30-10-2019
07-11-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
10-12-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
28-11-2019
04-11-2019
04-11-2019
04-11-2019
04-11-2019
04-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
25-11-2019
26-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
27-11-2019
28-11-2019
03-12-2019
06-11-2019
07-11-2019
07-11-2019
12-11-2019
26-11-2019
28-11-2019
11-11-2019
12-11-2019
12-11-2019
25-11-2019
02-12-2019
13-11-2019
28-11-2019
07-11-2019
07-11-2019
07-11-2019
01-11-2019
01-11-2019
01-11-2019
01-11-2019
01-11-2019
01-11-2019
04-11-2019
04-11-2019
07-11-2019
07-11-2019
25-11-2019
14-03-2019
14-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
20-03-2019
18-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
18-03-2019
18-03-2019
18-03-2019
18-03-2019
14-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
15-03-2019
18-03-2019
01-03-2019
01-03-2019
01-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
18-03-2019
18-03-2019
18-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
22-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
14-03-2019
19-03-2019
15-01-2019
05-02-2019
20-03-2019
27-12-2018
13-02-2019
13-02-2019
13-02-2019
13-02-2019
29-01-2019
13-11-2018
22-03-2019
12-03-2019
13-02-2019
13-02-2019
17-01-2019
25-03-2019
21-03-2019
21-02-2019
26-03-2019
22-02-2019
22-02-2019
22-02-2019
22-02-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
07-03-2019
25-03-2019
07-02-2019
07-02-2019
28-02-2019
28-02-2019
28-02-2019
28-02-2019
28-02-2019
28-02-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
13-03-2019
05-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
08-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
05-07-2019
11-07-2019
11-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
12-07-2019
11-07-2019
11-07-2019
11-07-2019
09-07-2019
11-07-2019
11-07-2019
11-07-2019
11-07-2019

How can I do that?

Body:
To solve my problem was necessary a group operation on database, incluse to create 2 temporary tables.

The solution to my case was:

WITH TABLE_X AS (
    SELECT P.CD_PESSOA, P.DT_NASCIMENTO_FUNDACAO, TO_DATE(SYSDATE) AS DATA_ATUAL, TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO),
    EXTRACT(YEAR FROM SYSDATE) - EXTRACT(YEAR FROM TO_DATE(P.DT_NASCIMENTO_FUNDACAO)) AS IDADE
    FROM ATTENDANCE G JOIN PEOPLE P
    ON (G.NU_USUARIO = P.CD_PESSOA)
    WHERE EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) >= EXTRACT(YEAR FROM SYSDATE) - 1
    AND EXTRACT(YEAR FROM TO_DATE(G.DT_SOLICITACAO_ATENDIMENTO)) <= EXTRACT(YEAR FROM SYSDATE)
    ORDER BY IDADE DESC
),
TABLE_Y AS (SELECT
    SUM(CASE WHEN IDADE BETWEEN 0 AND 18 THEN 1 ELSE 0 END) AS "0-18",
    SUM(CASE WHEN IDADE BETWEEN 19 AND 23 THEN 1 ELSE 0 END) AS "19-23",
    SUM(CASE WHEN IDADE BETWEEN 24 AND 28 THEN 1 ELSE 0 END) AS "24-28",
    SUM(CASE WHEN IDADE BETWEEN 29 AND 33 THEN 1 ELSE 0 END) AS "29-33",
    SUM(CASE WHEN IDADE BETWEEN 34 AND 38 THEN 1 ELSE 0 END) AS "34-38",
    SUM(CASE WHEN IDADE BETWEEN 39 AND 43 THEN 1 ELSE 0 END) AS "39-43",
    SUM(CASE WHEN IDADE BETWEEN 44 AND 48 THEN 1 ELSE 0 END) AS "44-48",
    SUM(CASE WHEN IDADE BETWEEN 49 AND 53 THEN 1 ELSE 0 END) AS "49-53",
    SUM(CASE WHEN IDADE BETWEEN 54 AND 58 THEN 1 ELSE 0 END) AS "54-58",
    SUM(CASE WHEN IDADE >= 59 THEN 1 ELSE 0 END) AS "59+",
    SUM(CASE WHEN IDADE IS NULL THEN 1 ELSE 0 END) AS "VALORES_NULL",
    COUNT(IDADE) AS TOTAL_IDADE
FROM TABLE_X
)
SELECT
    ROUND(("0-18" / TOTAL_IDADE) * 100, 2) ||'%' AS "0-18",
    ROUND(("19-23" / TOTAL_IDADE) * 100, 2) ||'%' AS "19-23",
    ROUND(("24-28" / TOTAL_IDADE) * 100, 2) ||'%' AS "24-28",
    ROUND(("29-33" / TOTAL_IDADE) * 100, 2) ||'%' AS "29-33",
    ROUND(("34-38" / TOTAL_IDADE) * 100, 2) ||'%' AS "29-33",
    ROUND(("39-43" / TOTAL_IDADE) * 100, 2) ||'%' AS "34-38",
    ROUND(("44-48" / TOTAL_IDADE) * 100, 2) ||'%' AS "44-48",
    ROUND(("49-53" / TOTAL_IDADE) * 100, 2) ||'%' AS "49-53",
    ROUND(("54-58" / TOTAL_IDADE) * 100, 2) ||'%' AS "54-58",
    ROUND(("59+" / TOTAL_IDADE) * 100, 2) ||'%' AS "59+"
FROM TABLE_Y

As result I had:


问:
How to get the name of person by passing city property from array of JS object
I have this array of objects

```<code>const arrofobj = [
{city:"paris", name: "chris"},
{city:"berlin", name: "john"},
{city:"moscow", name: "jev"}
];
</code>```

I want to write a function when I pass paris, I want to get back chris, how to achieve this?

Here is what I have tried

```<code>const arrofobj = [
{city:"paris", name: "chris"},
{city:"berlin", name: "john"},
{city:"moscow", name: "jev"}
];

function fetchname(cityname) {
  arrofobj.forEach((val)=>{if(Object.keys(val) == "city") {if (val.city == cityname) console.log(val.name)}})//nothing is printed
}

fetchname("paris");
</code>```

答:
I think it will help you
Hvae you any question in this code. Comment below</p>
```<code>    const arrofobj = [
  {city:"paris", name: "chris"},
  {city:"berlin", name: "john"},
  {city:"moscow", name: "jev"}
 ];

function fetchname(cityname) {
  const findValue = arrofobj.find((value)=>value.city==cityname)
    console.log(findValue)
    return findValue.name ?? ""
}

 fetchname("paris");
</code>```

Body:
I have this array of objects

const arrofobj = [
{city:"paris", name: "chris"},
{city:"berlin", name: "john"},
{city:"moscow", name: "jev"}
];

I want to write a function when I pass paris, I want to get back chris, how to achieve this?

Here is what I have tried

const arrofobj = [
{city:"paris", name: "chris"},
{city:"berlin", name: "john"},
{city:"moscow", name: "jev"}
];

function fetchname(cityname) {
  arrofobj.forEach((val)=>{if(Object.keys(val) == "city") {if (val.city == cityname) console.log(val.name)}})//nothing is printed
}

fetchname("paris");

Body:
I think it will help you
Hvae you any question in this code. Comment below

    const arrofobj = [
  {city:"paris", name: "chris"},
  {city:"berlin", name: "john"},
  {city:"moscow", name: "jev"}
 ];

function fetchname(cityname) {
  const findValue = arrofobj.find((value)=>value.city==cityname)
    console.log(findValue)
    return findValue.name ?? ""
}

 fetchname("paris");


问:
How to make a launcher
I have been developing for quite a time and I am now trying to make an app that will replace the original home (e.g. HTC sense).

I need the app to open when the the user hits the home button on their phone.

So basically it is a home replacement.

Does any one know how to go about this?

答:
Well, firstly you need to listen to the android.intent.category.HOME intent. Here are some links with full source code which you can have a look at:

Old launcher source code

New launcher source code

Or take a look at launcher plus.

Title: How to make a launcher


问:
How to pass variables between modules
I tired to print the winner with lower number of guesses, how to use count and counter variable from other modules in main.py. I tried using import, but it did not work, help!

main.py

```<code>from random import randint

from player_1 import player_1
from player_2 import player_2

def turn():
    global valid
    global val
    rand = randint(1, 2)
    player_turn = int(input("enter number 1 or 2"))
    if rand == player_turn:
        print("player 1 won the toss")
        valid = True

    else:
        print("player 2 won the toss")
        val = True
</code>```

def play_game():

```<code>valid = True
val = True
while valid:

    player_1()
    break
while val:
    player_2()
    break

if counter > count:
    print("player 1 won")
else:
    print("player 2 won")
</code>```

turn()
play_game()

```<code>
</code>```

player_1.py (how to use counter from here to main)

```<code>from random import randint
def player_1():

    rand_num = randint(1,100) # we generating a random int 1, 100

    counter = 0
    while True:
        guess_num = int(input('Guess a number b/w 1 to 100'))
        counter += 1
        if rand_num > guess_num:
            print('Guess something bigger!')
        elif rand_num < guess_num :
            print('Guess something smaller')

        else:
            print(f'the game is over , and it took you {counter} time to guess it')
            break

</code>```

player_2.py (how to use count from here to main)

```<code>from random import randint
def player_2():

    rand_num = randint(1,100) # we generating a random int 1, 100

    count= 0
    while True:
        guess_num = int(input('Guess a number b/w 1 to 100'))
        count += 1
        if rand_num > guess_num:
            print('Guess something bigger!')
        elif rand_num < guess_num :
            print('Guess something smaller')
        else:
            print(f'the game is over , and it took you {count} time to guess it')
            break # is a keyword to break out of anyloop when you needed

</code>```

答:
OK, here's a suggested replacement.  Your player_1 and player_2 functions are identical.  There's no reason to have them be two functions.  Just have that function return the number of guesses.

Similarly, turn can just return the answer it gets.  No need for globals.  Globals are evil, because you can't control who is messing with them.  A single variable should only be visible to the minimum amount of code necessary to do its job.

This code eliminates the globals and handles things in a more general way.

main.py:

```<code>from random import randint
from player_1 import player_1

def turn():
    rand = randint(1, 2)
    player_turn = int(input("enter number 1 or 2: "))
    if rand == player_turn:
        print("player 1 won the toss")
        return 1
    else:
        print("player 2 won the toss")
        return 2

def play_game( starter ):
    first = starter
    second = 3-starter
    print( f"Player {first}" )
    tries1 = player_1()
    print( f"Player {second}" )
    tries2 = player_1()

    if tries1 < tries2:
        print(f"player {first} won")
    else:
        print(f"player {second} won")

player = turn()
play_game( player )
</code>```

player_1.py

```<code>from random import randint
def player_1():
    rand_num = randint(1,100) # we generating a random int 1, 100

    counter = 0
    while True:
        guess_num = int(input('Guess a number b/w 1 to 100: '))
        counter += 1
        if rand_num > guess_num:
            print('Guess something bigger!')
        elif rand_num < guess_num :
            print('Guess something smaller')

        else:
            print(f'Your game is over, and it took you {counter} times to guess it')
            return counter
</code>```

Title: How to pass variables between modules

Body:
I tired to print the winner with lower number of guesses, how to use count and counter variable from other modules in main.py. I tried using import, but it did not work, help!

main.py

from random import randint

from player_1 import player_1
from player_2 import player_2

def turn():
    global valid
    global val
    rand = randint(1, 2)
    player_turn = int(input("enter number 1 or 2"))
    if rand == player_turn:
        print("player 1 won the toss")
        valid = True

    else:
        print("player 2 won the toss")
        val = True

def play_game():

valid = True
val = True
while valid:

    player_1()
    break
while val:
    player_2()
    break

if counter > count:
    print("player 1 won")
else:
    print("player 2 won")

turn()
play_game()

player_1.py (how to use counter from here to main)

from random import randint
def player_1():

    rand_num = randint(1,100) # we generating a random int 1, 100

    counter = 0
    while True:
        guess_num = int(input('Guess a number b/w 1 to 100'))
        counter += 1
        if rand_num > guess_num:
            print('Guess something bigger!')
        elif rand_num < guess_num :
            print('Guess something smaller')

        else:
            print(f'the game is over , and it took you {counter} time to guess it')
            break

player_2.py (how to use count from here to main)

from random import randint
def player_2():

    rand_num = randint(1,100) # we generating a random int 1, 100

    count= 0
    while True:
        guess_num = int(input('Guess a number b/w 1 to 100'))
        count += 1
        if rand_num > guess_num:
            print('Guess something bigger!')
        elif rand_num < guess_num :
            print('Guess something smaller')
        else:
            print(f'the game is over , and it took you {count} time to guess it')
            break # is a keyword to break out of anyloop when you needed

Body:
OK, here's a suggested replacement.  Your player_1 and player_2 functions are identical.  There's no reason to have them be two functions.  Just have that function return the number of guesses.

Similarly, turn can just return the answer it gets.  No need for globals.  Globals are evil, because you can't control who is messing with them.  A single variable should only be visible to the minimum amount of code necessary to do its job.

This code eliminates the globals and handles things in a more general way.

main.py:

from random import randint
from player_1 import player_1

def turn():
    rand = randint(1, 2)
    player_turn = int(input("enter number 1 or 2: "))
    if rand == player_turn:
        print("player 1 won the toss")
        return 1
    else:
        print("player 2 won the toss")
        return 2

def play_game( starter ):
    first = starter
    second = 3-starter
    print( f"Player {first}" )
    tries1 = player_1()
    print( f"Player {second}" )
    tries2 = player_1()

    if tries1 < tries2:
        print(f"player {first} won")
    else:
        print(f"player {second} won")

player = turn()
play_game( player )

player_1.py

from random import randint
def player_1():
    rand_num = randint(1,100) # we generating a random int 1, 100

    counter = 0
    while True:
        guess_num = int(input('Guess a number b/w 1 to 100: '))
        counter += 1
        if rand_num > guess_num:
            print('Guess something bigger!')
        elif rand_num < guess_num :
            print('Guess something smaller')

        else:
            print(f'Your game is over, and it took you {counter} times to guess it')
            return counter


问:
Spring Boot JPA with Hibernate Spatial self-reference leading to cycle
I am currently writing a service where I can store a geospatial point with some data. I have a "dataPoint" class that looks like this:

```<code>@Entity
@Table(name = "datapoint")
public class DataPoint {
    @Id
    int dataPoint_id;

    @Column(name = "body")
    String body;

    @Column(name = "location", columnDefinition = "Geometry")
    PGgeometry location;

    @Column(name = "deleted")
    boolean deleted;

    //Getters and Setters...
</code>```

I am trying to use Spring Boot to simply add a point with some information to a PostGIS database via an API path. I have built a controller that looks like this:

```<code>@RestController
@RequestMapping(value = "/dataPoint")
public class DataPointController {

    @Autowired
    private DataPointService myPointService;

    @RequestMapping(value = "/add/{body}/{latitude}/{longitude}/")
    public DataPoint addDataPoint(@PathVariable String body, @PathVariable double latitude, @PathVariable double longitude){
        DataPoint myPoint = new DataPoint();
        myPoint.setBody(body);
        PGgeometry geometry = new PGgeometry();
        try {
            geometry.setValue("POINT("+longitude +" " + latitude+")");
            geometry.setType("POINT");
            // Debugging Stuff
            System.out.println("GEOMETRY VALUE LOOK: {{{{ " + geometry.getValue() + "   " + geometry.getType());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        myPoint.setLocation(geometry);
        myPointService.saveDataPoint(myPoint);
        return myPoint;
    }
</code>```

Which is in turn linked to a DataPointService which just acts as a middle man between the controller where saveDataPoint() looks like this:

```<code>public void saveDataPoint(DataPoint myPoint) {
    dataPointRepository.save(myPoint);
}
</code>```

and the DataPointRepository, which looks like this:

```<code>@Repository
public interface DataPointRepository extends JpaRepository<DataPoint, Integer> {
}
</code>```

However, when I visit my add link, I get this error:

```<code>Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Direct self-reference leading to cycle (through reference chain: com.testing.model.DataPoint["location"]->org.postgis.PGgeometry["geometry"]->org.postgis.Point["firstPoint"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.testing.model.DataPoint["location"]->org.postgis.PGgeometry["geometry"]->org.postgis.Point["firstPoint"])
</code>```

I have seen the @JsonBackReference and its dual used in some examples, however, that has been used in situations where entities are being linked back and forth, which I do not see happening here, in fact, the error does not even seem to be cyclic, so what is happening here?

答:
I ran into the same issue. It's cyclic because Point has a field firstPoint that reference to Point again.
I was able to resolve the problem by installing this postgis-geojson: https://jitpack.io/p/stephenbrough/postgis-geojson</p>

Body:
I am currently writing a service where I can store a geospatial point with some data. I have a "dataPoint" class that looks like this:

@Entity
@Table(name = "datapoint")
public class DataPoint {
    @Id
    int dataPoint_id;

    @Column(name = "body")
    String body;

    @Column(name = "location", columnDefinition = "Geometry")
    PGgeometry location;

    @Column(name = "deleted")
    boolean deleted;

    //Getters and Setters...

I am trying to use Spring Boot to simply add a point with some information to a PostGIS database via an API path. I have built a controller that looks like this:

@RestController
@RequestMapping(value = "/dataPoint")
public class DataPointController {

    @Autowired
    private DataPointService myPointService;

    @RequestMapping(value = "/add/{body}/{latitude}/{longitude}/")
    public DataPoint addDataPoint(@PathVariable String body, @PathVariable double latitude, @PathVariable double longitude){
        DataPoint myPoint = new DataPoint();
        myPoint.setBody(body);
        PGgeometry geometry = new PGgeometry();
        try {
            geometry.setValue("POINT("+longitude +" " + latitude+")");
            geometry.setType("POINT");
            // Debugging Stuff
            System.out.println("GEOMETRY VALUE LOOK: {{{{ " + geometry.getValue() + "   " + geometry.getType());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        myPoint.setLocation(geometry);
        myPointService.saveDataPoint(myPoint);
        return myPoint;
    }

Which is in turn linked to a DataPointService which just acts as a middle man between the controller where saveDataPoint() looks like this:

public void saveDataPoint(DataPoint myPoint) {
    dataPointRepository.save(myPoint);
}

and the DataPointRepository, which looks like this:

@Repository
public interface DataPointRepository extends JpaRepository<DataPoint, Integer> {
}

However, when I visit my add link, I get this error:

Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Direct self-reference leading to cycle (through reference chain: com.testing.model.DataPoint["location"]->org.postgis.PGgeometry["geometry"]->org.postgis.Point["firstPoint"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Direct self-reference leading to cycle (through reference chain: com.testing.model.DataPoint["location"]->org.postgis.PGgeometry["geometry"]->org.postgis.Point["firstPoint"])

I have seen the @JsonBackReference and its dual used in some examples, however, that has been used in situations where entities are being linked back and forth, which I do not see happening here, in fact, the error does not even seem to be cyclic, so what is happening here?


问:
Does QuestDB have EXPLAIN
Postgres has syntax to show the query plan for a SQL statement:

https://www.postgresql.org/docs/9.4/using-explain.html

Does QuestDB have something equivalent so that I can see the query plan that would result from my SQL before actually executing it?

答:
The QuestDB docs show an explain option for the /exec HTTP endpoint. However, I can't get it to work on my instance running v6.2.

It should work like this:

curl -G \
    --data-urlencode "query=select * from t limit 2;" \
    --data-urlencode "explain=true" \
    http://localhost:9000/exec
```

Title: Does QuestDB have EXPLAIN