问:
Printing two values of one variable under different conditions
Please consider the statements below:

sum_value = fixed_value - current_value,

where fixed_value  is a constant, and current_value is a function of thresholds;

thresholds has two threshold_level values: thresholds = [10, 20];

I need to find a rato of sim_value corresponding to threshold_level = 10 to sim_value corresponding to threshold_level = 20, that is final_sim_value = sim_value_at_10/sim_value_at_20.

The code part is

```<code>thresholds = [10, 20]
fixed_value = 100

for threshold_level in thresholds:
    current_value = 5 - threshold_level
    sim_value = fixed_value - current_value

    def sim_value_multi(threshold_level):
        if threshold_level == 10:
            sim_value_at_10 = sim_value
            return sim_value_at_10
        if threshold_level == 20:
            sim_value_at_20 = sim_value
            return sim_value_at_20

    final_sim_value = sim_value_multi(10)/sim_value_multi(20)

    print('sim_value_multi(10) is ', sim_value_multi(10))
    print('sim_value_multi(20) is ', sim_value_multi(20))
    print('final_sim_value is ', final_sim_value)

print('--------------------')
final_sim_value = sim_value_multi(10)/sim_value_multi(20)

print('sim_value_multi(10) is ', sim_value_multi(10))
print('sim_value_multi(20) is ', sim_value_multi(20))
print('final_sim_value is ', final_sim_value)
</code>```

which gives this output:

```<code>sim_value_multi(10) is  105
sim_value_multi(20) is  105
final_sim_value is  1.0
sim_value_multi(10) is  115
sim_value_multi(20) is  115
final_sim_value is  1.0
--------------------
sim_value_multi(10) is  115
sim_value_multi(20) is  115
final_sim_value is  1.0
</code>```

Could you please correct me or suggest a proper solution?

答:
Are you trying to obtain this result ?

```<code>thresholds = [10, 20]
fixed_value = 100
current_values = []
for threshold_value in thresholds:
    current_values.append(fixed_value + threshold_value - 5)

print('sim_value_multi(10) is ', current_values[0])
print('sim_value_multi(20) is ', current_values[1])
print('final_sim_value is ', current_values[0]/current_values[1])
</code>```

Output

```<code>sim_value_multi(10) is  105
sim_value_multi(20) is  115
final_sim_value is  0.9130434782608695
</code>```

Body:
Please consider the statements below:

sum_value = fixed_value - current_value,

where fixed_value  is a constant, and current_value is a function of thresholds;

thresholds has two threshold_level values: thresholds = [10, 20];

I need to find a rato of sim_value corresponding to threshold_level = 10 to sim_value corresponding to threshold_level = 20, that is final_sim_value = sim_value_at_10/sim_value_at_20.

The code part is

thresholds = [10, 20]
fixed_value = 100

for threshold_level in thresholds:
    current_value = 5 - threshold_level
    sim_value = fixed_value - current_value

    def sim_value_multi(threshold_level):
        if threshold_level == 10:
            sim_value_at_10 = sim_value
            return sim_value_at_10
        if threshold_level == 20:
            sim_value_at_20 = sim_value
            return sim_value_at_20

    final_sim_value = sim_value_multi(10)/sim_value_multi(20)

    print('sim_value_multi(10) is ', sim_value_multi(10))
    print('sim_value_multi(20) is ', sim_value_multi(20))
    print('final_sim_value is ', final_sim_value)

print('--------------------')
final_sim_value = sim_value_multi(10)/sim_value_multi(20)

print('sim_value_multi(10) is ', sim_value_multi(10))
print('sim_value_multi(20) is ', sim_value_multi(20))
print('final_sim_value is ', final_sim_value)

which gives this output:

sim_value_multi(10) is  105
sim_value_multi(20) is  105
final_sim_value is  1.0
sim_value_multi(10) is  115
sim_value_multi(20) is  115
final_sim_value is  1.0
--------------------
sim_value_multi(10) is  115
sim_value_multi(20) is  115
final_sim_value is  1.0

Could you please correct me or suggest a proper solution?

Body:
Are you trying to obtain this result ?

thresholds = [10, 20]
fixed_value = 100
current_values = []
for threshold_value in thresholds:
    current_values.append(fixed_value + threshold_value - 5)

print('sim_value_multi(10) is ', current_values[0])
print('sim_value_multi(20) is ', current_values[1])
print('final_sim_value is ', current_values[0]/current_values[1])

Output

sim_value_multi(10) is  105
sim_value_multi(20) is  115
final_sim_value is  0.9130434782608695


来源: stackexchange

问:
Customer and Contact columns in PXCustomSelectorAttribute
I have created a custom selector attribute, that filters what customers will appear in the popup box based on the user's ID.

But I have run into the problem that I can't seem to customize it like a normal selector
ie:

```<code> [PXSelector(typeof(Search2<InventoryItem.inventoryID, LeftJoin<INItemQtyCost, On<InventoryItem.inventoryID, Equal<INItemQtyCost.inventoryID>>>>),
        typeof(InventoryItem.inventoryCD), typeof(InventoryItem.descr), typeof(INItemQtyCost.qtyAvail)
        SubstituteKey = typeof(InventoryItem.inventoryCD),
        Filterable = true)]
</code>```

And can only use my custom selector attribute like this:

```<code> [SalesRepCustomer]
</code>```

The constructor for the PXCustomSelectorAttribute is as follows:

```<code>public SalesRepCustomer() : base(typeof(Customer.bAccountID))
    {
        this.DescriptionField = typeof(Customer.acctName);
        this.SubstituteKey = typeof(Customer.acctCD);
    }
</code>```

Is there a way to use the search2<> and so on in a PXCustomSelectorAttribute?

答:
Utilization of the PXSelectorAttribute

```<code>public class SalesRepCustomer : PXSelectorAttribute
{
    public SalesRepCustomer() : base(typeof(Search<Customer.bAccountID>))
    {
    }
}
</code>```

Usage would be as follows :

```<code>public class BatchExtension : PXCacheExtension<Batch>
{
    public abstract class usrSalesRepCustomerID : BqlInt.Field<usrSalesRepCustomerID>
    {
    }
    [SalesRepCustomer(SubstituteKey = typeof(Customer.acctName), DescriptionField = typeof(Customer.legalName))]
    public int? UsrSalesRepCustomerID
    {
        get; set;
    }
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have created a custom selector attribute, that filters what customers will appear in the popup box based on the user's ID.

But I have run into the problem that I can't seem to customize it like a normal selector
ie:

 [PXSelector(typeof(Search2<InventoryItem.inventoryID, LeftJoin<INItemQtyCost, On<InventoryItem.inventoryID, Equal<INItemQtyCost.inventoryID>>>>),
        typeof(InventoryItem.inventoryCD), typeof(InventoryItem.descr), typeof(INItemQtyCost.qtyAvail)
        SubstituteKey = typeof(InventoryItem.inventoryCD),
        Filterable = true)]

And can only use my custom selector attribute like this:

 [SalesRepCustomer]

The constructor for the PXCustomSelectorAttribute is as follows:

public SalesRepCustomer() : base(typeof(Customer.bAccountID))
    {
        this.DescriptionField = typeof(Customer.acctName);
        this.SubstituteKey = typeof(Customer.acctCD);
    }

Is there a way to use the search2<> and so on in a PXCustomSelectorAttribute?

Body:
Utilization of the PXSelectorAttribute

public class SalesRepCustomer : PXSelectorAttribute
{
    public SalesRepCustomer() : base(typeof(Search<Customer.bAccountID>))
    {
    }
}

Usage would be as follows :

public class BatchExtension : PXCacheExtension<Batch>
{
    public abstract class usrSalesRepCustomerID : BqlInt.Field<usrSalesRepCustomerID>
    {
    }
    [SalesRepCustomer(SubstituteKey = typeof(Customer.acctName), DescriptionField = typeof(Customer.legalName))]
    public int? UsrSalesRepCustomerID
    {
        get; set;
    }
}


问:
MTKView in Cocoa doesn't draw in Retina
I have a MTKView in Cocoa.

I'm displaying a texture with drawable.texture - but the texture only shows over a quarter of the screen - Non-Retina.

Do I need to do any additional setup to get this to work?

```<code>class MyView : MTKView
</code>```

The following code has no-affect:

```<code>let scale = NSScreen.mainScreen()!.backingScaleFactor
var s = frame.size
s.width *= scale
s.height *= scale

metalLayer.contentsScale = scale
metalLayer.framebufferOnly = false
metalLayer.drawableSize = s
</code>```

Update:

Here's the method I have to load the texture from the image:

```<code>func textureFromImage(image: NSImage, inout tex:MTLTexture?) {

    let textureLoader = MTKTextureLoader(device: self.device!)
    do {
        tex = try textureLoader.newTextureWithCGImage(image.CGImage, options: nil)
    }
    catch {
        fatalError("Can't load texture")
    }
}
</code>```

and the code to present:

```<code>let commandBuffer = commandQueue.commandBuffer()
    let commandEncoder = commandBuffer.computeCommandEncoder()
    commandEncoder.setComputePipelineState(pipelineState)
    commandEncoder.setTexture(originalTexture, atIndex: 0)
    commandEncoder.setTexture(drawable.texture, atIndex: 1)
    commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
    commandEncoder.endEncoding()
    commandBuffer.presentDrawable(drawable)
    commandBuffer.commit();
</code>```

All of the sizes for the original input image and texture are the same size as the view.

答:
5 years late to the party, but I just had this problem because I called

renderEncoder.setViewport(MTLViewport(originX: 0, originY: 0, width: Double(viewport.x), height: Double(viewport.y), znear: -1.0, zfar: 1.0)) with viewport.x/y being in points instead of pixels.

To render properly I multiplied x/y by screen scale (x2 for retina).

ContentLicense: CC BY-SA 3.0

Title: MTKView in Cocoa doesn't draw in Retina

Body:
I have a MTKView in Cocoa.

I'm displaying a texture with drawable.texture - but the texture only shows over a quarter of the screen - Non-Retina.

Do I need to do any additional setup to get this to work?

class MyView : MTKView

The following code has no-affect:

let scale = NSScreen.mainScreen()!.backingScaleFactor
var s = frame.size
s.width *= scale
s.height *= scale

metalLayer.contentsScale = scale
metalLayer.framebufferOnly = false
metalLayer.drawableSize = s

Update:

Here's the method I have to load the texture from the image:

func textureFromImage(image: NSImage, inout tex:MTLTexture?) {

    let textureLoader = MTKTextureLoader(device: self.device!)
    do {
        tex = try textureLoader.newTextureWithCGImage(image.CGImage, options: nil)
    }
    catch {
        fatalError("Can't load texture")
    }
}

and the code to present:

let commandBuffer = commandQueue.commandBuffer()
    let commandEncoder = commandBuffer.computeCommandEncoder()
    commandEncoder.setComputePipelineState(pipelineState)
    commandEncoder.setTexture(originalTexture, atIndex: 0)
    commandEncoder.setTexture(drawable.texture, atIndex: 1)
    commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
    commandEncoder.endEncoding()
    commandBuffer.presentDrawable(drawable)
    commandBuffer.commit();

All of the sizes for the original input image and texture are the same size as the view.


问:
Normalize the number of rows based on min and max of that rows in dataframe
I have a data frame and I want to normalize each number based on the minimum of that row and the maximum of that row based on this formulation.

```<code>  x_normalized = (x_unnormalized-x_min)/(x_max-x_min).
</code>```

I've check the scikit-learn package and I could not find any function for that. Could you help me with this? I also provide a sample as follows and what I want.

```<code>import pandas as pd
import numpy as np

df = pd.DataFrame()
df['id'] = [a, b, c]
df['c1'] = [2, 5, 3]
df['c2'] = [0, 5, 6]
df['c3'] = [8, 7, 9]

print(df)
#here is the dataframe which i want
df = pd.DataFrame()
df['id'] = [a, b, c]
df['c1'] = [1/4, 0, 0]
df['c2'] = [0, 0, 0.5]
df['c3'] = [1, 1, 1]
df
</code>```

答:
It looks like there is a typo in your output.

You can use simple vectorial operations:

```<code>def norm(df):
    MIN = df.min(1)
    MAX = df.max(1)
    return df.sub(MIN, 0).div(MAX-MIN, 0)

df2 = norm(df)
</code>```

output:

```<code>     c1   c2   c3
0  0.25  0.0  1.0
1  0.00  0.0  1.0
2  0.00  0.5  1.0
</code>```

axis-aware version:

```<code>def norm(df, axis=1):
    MIN = df.min(axis)
    MAX = df.max(axis)
    return df.sub(MIN, 1-axis).div(MAX-MIN, 1-axis)

norm(df, axis=0)
</code>```

output:

```<code>         c1        c2   c3
0  0.000000  0.000000  0.5
1  1.000000  0.833333  0.0
2  0.333333  1.000000  1.0
</code>```

Body:
I have a data frame and I want to normalize each number based on the minimum of that row and the maximum of that row based on this formulation.

  x_normalized = (x_unnormalized-x_min)/(x_max-x_min).

I've check the scikit-learn package and I could not find any function for that. Could you help me with this? I also provide a sample as follows and what I want.

import pandas as pd
import numpy as np

df = pd.DataFrame()
df['id'] = [a, b, c]
df['c1'] = [2, 5, 3]
df['c2'] = [0, 5, 6]
df['c3'] = [8, 7, 9]

print(df)
#here is the dataframe which i want
df = pd.DataFrame()
df['id'] = [a, b, c]
df['c1'] = [1/4, 0, 0]
df['c2'] = [0, 0, 0.5]
df['c3'] = [1, 1, 1]
df

Body:
It looks like there is a typo in your output.

You can use simple vectorial operations:

def norm(df):
    MIN = df.min(1)
    MAX = df.max(1)
    return df.sub(MIN, 0).div(MAX-MIN, 0)

df2 = norm(df)

output:

     c1   c2   c3
0  0.25  0.0  1.0
1  0.00  0.0  1.0
2  0.00  0.5  1.0

axis-aware version:

def norm(df, axis=1):
    MIN = df.min(axis)
    MAX = df.max(axis)
    return df.sub(MIN, 1-axis).div(MAX-MIN, 1-axis)

norm(df, axis=0)

output:

         c1        c2   c3
0  0.000000  0.000000  0.5
1  1.000000  0.833333  0.0
2  0.333333  1.000000  1.0


问:
Rename elements of list based on condition
I have a huge list samplelist containing various tibbles (in the simplified sample called Alpha, Beta and Gamma). Each tibble contains various elements (in the sample called sample_0 and sample_1). However, not each tibble contains each element (Gamma contains only sample_0, but not sample_1). What I would like to do is to rename the elements based on a condition: if there is an element sample_1 in a tibble, rename it to sampling. However, if the tibble does not contain sample_1, rename sample_0 to sampling (so that the list now contains an element called sampling for each tibble).

```<code>samplelist <- list(Alpha = structure(list(sample_0 = c(3, NA, 7, 9, 2),
                                     sample_1 = c(NA, 8, 5, 4, NA)),
                                row.names = c(NA, -5L),
                                class = c("tbl_df", "tbl", "data.frame")),
              Beta = structure (list(sample_0 = c(2, 9, NA, 3, 7),
                                     sample_1 = c(3, 7, 9, 3, NA)),
                                row.names = c(NA, -5L),
                                class = c("tbl_df", "tbl", "data.frame")),
              Gamma = structure(list(sample_0 = c(NA, NA, 4, 6, 3)),
                                row.names = c(NA, -5L),
                                class = c("tbl_df", "tbl", "data.frame")))
</code>```

Does anybody know how to get the following desired output?

```<code>samplelist
$Alpha
# A tibble: 5 x 2
  sample_0 sampling
     <dbl>    <dbl>
1        3       NA
2       NA        8
3        7        5
4        9        4
5        2       NA

$Beta
# A tibble: 5 x 2
  sample_0 sampling
     <dbl>    <dbl>
1        2        3
2        9        7
3       NA        9
4        3        3
5        7       NA

$Gamma
# A tibble: 5 x 1
       sampling
          <dbl>
  1          NA
  2          NA
  3           4
  4           6
  5           3
</code>```

EDIT
With the code provided by @akrun:

```<code>map(errorlist,  ~  if(ncol(.x) == 1 && names(.x) == 'sample_0')
      setNames(.x, 'sampling') else
      rename_with(.x, ~ 'sampling', matches('sample_1')))
</code>```

I got the disired output for my samplelist. However, if there's more than one group in Gamma, the (adjusted) code only works for Alpha and Beta, yet leaves Gamma unchanged (Delta added from before editing):

```<code>errorlist <- list(Alpha = structure(list(sample_0 = c(3, NA, 7, 9, 2),
                                         sample_1 = c(NA, 8, 5, 4, NA),
                                         sample_2 = c(7, 3, 5, NA, NA)),
                                    row.names = c(NA, -5L),
                                    class = c("tbl_df", "tbl", "data.frame")),
                  Beta = structure (list(sample_0 = c(2, 9, NA, 3, 7),
                                         sample_1 = c(3, 7, 9, 3, NA),
                                         sample_2 = c(4, 2, 6, 4, 6)),
                                    row.names = c(NA, -5L),
                                    class = c("tbl_df", "tbl", "data.frame")),
                  Gamma = structure(list(sample_0 = c(NA, NA, 4, 6, 3),
                                         sample_1 = c(3, 7, 3, NA, 8)),
                                    row.names = c(NA, -5L),
                                    class = c("tbl_df", "tbl", "data.frame")),
                  Delta = structure (list(error = c(3, 7, 9, 3, NA)),
                                     row.names = c(NA, -5L),
                                     class = c("tbl_df", "tbl", "data.frame")))

map(errorlist,  ~  if(ncol(.x) == 1 && names(.x) == 'sample_1')
  setNames(.x, 'sampling') else
    rename_with(.x, ~ 'sampling', matches('sample_2')))
</code>```

Output:

```<code>$Alpha
# A tibble: 5 x 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        3       NA        7
2       NA        8        3
3        7        5        5
4        9        4       NA
5        2       NA       NA

$Beta
# A tibble: 5 x 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        2        3        4
2        9        7        2
3       NA        9        6
4        3        3        4
5        7       NA        6

$Gamma
# A tibble: 5 x 2
  sample_0 sample_1
     <dbl>    <dbl>
1       NA        3
2       NA        7
3        4        3
4        6       NA
5        3        8

$Delta
# A tibble: 5 x 1
  error
  <dbl>
1     3
2     7
3     9
4     3
5    NA
</code>```

答:
Here is an option - loop over the list with map and do the changes with a condition (if/else) (Here, we are using errorlist as it is more general.  It also works with samplelist)

```<code>library(dplyr)
library(purrr)
map(errorlist,  ~  if(ncol(.x) == 1 && names(.x) == 'sample_0')
      setNames(.x, 'sampling') else
      rename_with(.x, ~ 'sampling', matches('sample_1')))
</code>```

-output

```<code>$Alpha
# A tibble: 5 × 2
  sample_0 sampling
     <dbl>    <dbl>
1        3       NA
2       NA        8
3        7        5
4        9        4
5        2       NA

$Beta
# A tibble: 5 × 2
  sample_0 sampling
     <dbl>    <dbl>
1        2        3
2        9        7
3       NA        9
4        3        3
5        7       NA

$Gamma
# A tibble: 5 × 1
  sampling
     <dbl>
1       NA
2       NA
3        4
4        6
5        3

$Delta
# A tibble: 5 × 1
  error
  <dbl>
1     3
2     7
3     9
4     3
5    NA
</code>```

Update

Based on the OP's comments

```<code>lapply(errorlist, \(x) {
  nm1 <- stringr::str_subset(names(x), "^sample_\\d+$")
  i1 <- which.max(as.numeric(stringr::str_extract(nm1,
       "(?<=sample_)\\d+")))
   if(length(i1) > 0) names(x)[names(x) == nm1[i1]] <- "sampling"
   x})
</code>```

-output

```<code>$Alpha
# A tibble: 5 × 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        3       NA        7
2       NA        8        3
3        7        5        5
4        9        4       NA
5        2       NA       NA

$Beta
# A tibble: 5 × 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        2        3        4
2        9        7        2
3       NA        9        6
4        3        3        4
5        7       NA        6

$Gamma
# A tibble: 5 × 2
  sample_0 sampling
     <dbl>    <dbl>
1       NA        3
2       NA        7
3        4        3
4        6       NA
5        3        8

$Delta
# A tibble: 5 × 1
  error
  <dbl>
1     3
2     7
3     9
4     3
5    NA
</code>```

Body:
I have a huge list samplelist containing various tibbles (in the simplified sample called Alpha, Beta and Gamma). Each tibble contains various elements (in the sample called sample_0 and sample_1). However, not each tibble contains each element (Gamma contains only sample_0, but not sample_1). What I would like to do is to rename the elements based on a condition: if there is an element sample_1 in a tibble, rename it to sampling. However, if the tibble does not contain sample_1, rename sample_0 to sampling (so that the list now contains an element called sampling for each tibble).

samplelist <- list(Alpha = structure(list(sample_0 = c(3, NA, 7, 9, 2),
                                     sample_1 = c(NA, 8, 5, 4, NA)),
                                row.names = c(NA, -5L),
                                class = c("tbl_df", "tbl", "data.frame")),
              Beta = structure (list(sample_0 = c(2, 9, NA, 3, 7),
                                     sample_1 = c(3, 7, 9, 3, NA)),
                                row.names = c(NA, -5L),
                                class = c("tbl_df", "tbl", "data.frame")),
              Gamma = structure(list(sample_0 = c(NA, NA, 4, 6, 3)),
                                row.names = c(NA, -5L),
                                class = c("tbl_df", "tbl", "data.frame")))

Does anybody know how to get the following desired output?

samplelist
$Alpha
# A tibble: 5 x 2
  sample_0 sampling
     <dbl>    <dbl>
1        3       NA
2       NA        8
3        7        5
4        9        4
5        2       NA

$Beta
# A tibble: 5 x 2
  sample_0 sampling
     <dbl>    <dbl>
1        2        3
2        9        7
3       NA        9
4        3        3
5        7       NA

$Gamma
# A tibble: 5 x 1
       sampling
          <dbl>
  1          NA
  2          NA
  3           4
  4           6
  5           3

EDIT
With the code provided by @akrun:

map(errorlist,  ~  if(ncol(.x) == 1 && names(.x) == 'sample_0')
      setNames(.x, 'sampling') else
      rename_with(.x, ~ 'sampling', matches('sample_1')))

I got the disired output for my samplelist. However, if there's more than one group in Gamma, the (adjusted) code only works for Alpha and Beta, yet leaves Gamma unchanged (Delta added from before editing):

errorlist <- list(Alpha = structure(list(sample_0 = c(3, NA, 7, 9, 2),
                                         sample_1 = c(NA, 8, 5, 4, NA),
                                         sample_2 = c(7, 3, 5, NA, NA)),
                                    row.names = c(NA, -5L),
                                    class = c("tbl_df", "tbl", "data.frame")),
                  Beta = structure (list(sample_0 = c(2, 9, NA, 3, 7),
                                         sample_1 = c(3, 7, 9, 3, NA),
                                         sample_2 = c(4, 2, 6, 4, 6)),
                                    row.names = c(NA, -5L),
                                    class = c("tbl_df", "tbl", "data.frame")),
                  Gamma = structure(list(sample_0 = c(NA, NA, 4, 6, 3),
                                         sample_1 = c(3, 7, 3, NA, 8)),
                                    row.names = c(NA, -5L),
                                    class = c("tbl_df", "tbl", "data.frame")),
                  Delta = structure (list(error = c(3, 7, 9, 3, NA)),
                                     row.names = c(NA, -5L),
                                     class = c("tbl_df", "tbl", "data.frame")))

map(errorlist,  ~  if(ncol(.x) == 1 && names(.x) == 'sample_1')
  setNames(.x, 'sampling') else
    rename_with(.x, ~ 'sampling', matches('sample_2')))

Output:

$Alpha
# A tibble: 5 x 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        3       NA        7
2       NA        8        3
3        7        5        5
4        9        4       NA
5        2       NA       NA

$Beta
# A tibble: 5 x 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        2        3        4
2        9        7        2
3       NA        9        6
4        3        3        4
5        7       NA        6

$Gamma
# A tibble: 5 x 2
  sample_0 sample_1
     <dbl>    <dbl>
1       NA        3
2       NA        7
3        4        3
4        6       NA
5        3        8

$Delta
# A tibble: 5 x 1
  error
  <dbl>
1     3
2     7
3     9
4     3
5    NA

Body:
Here is an option - loop over the list with map and do the changes with a condition (if/else) (Here, we are using errorlist as it is more general.  It also works with samplelist)

library(dplyr)
library(purrr)
map(errorlist,  ~  if(ncol(.x) == 1 && names(.x) == 'sample_0')
      setNames(.x, 'sampling') else
      rename_with(.x, ~ 'sampling', matches('sample_1')))

-output

$Alpha
# A tibble: 5 × 2
  sample_0 sampling
     <dbl>    <dbl>
1        3       NA
2       NA        8
3        7        5
4        9        4
5        2       NA

$Beta
# A tibble: 5 × 2
  sample_0 sampling
     <dbl>    <dbl>
1        2        3
2        9        7
3       NA        9
4        3        3
5        7       NA

$Gamma
# A tibble: 5 × 1
  sampling
     <dbl>
1       NA
2       NA
3        4
4        6
5        3

$Delta
# A tibble: 5 × 1
  error
  <dbl>
1     3
2     7
3     9
4     3
5    NA

Update

Based on the OP's comments

lapply(errorlist, \(x) {
  nm1 <- stringr::str_subset(names(x), "^sample_\\d+$")
  i1 <- which.max(as.numeric(stringr::str_extract(nm1,
       "(?<=sample_)\\d+")))
   if(length(i1) > 0) names(x)[names(x) == nm1[i1]] <- "sampling"
   x})

-output

$Alpha
# A tibble: 5 × 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        3       NA        7
2       NA        8        3
3        7        5        5
4        9        4       NA
5        2       NA       NA

$Beta
# A tibble: 5 × 3
  sample_0 sample_1 sampling
     <dbl>    <dbl>    <dbl>
1        2        3        4
2        9        7        2
3       NA        9        6
4        3        3        4
5        7       NA        6

$Gamma
# A tibble: 5 × 2
  sample_0 sampling
     <dbl>    <dbl>
1       NA        3
2       NA        7
3        4        3
4        6       NA
5        3        8

$Delta
# A tibble: 5 × 1
  error
  <dbl>
1     3
2     7
3     9
4     3
5    NA


问:
Access union all into new table
I have a saved query (MyUnion) for a union, appending monthly files (linked views):

```<code>select * from RawTrade1801
union all
select * from RawTrade1802
</code>```

Trying to write this to a new table is proving problematic:

```<code>SELECT MyUnion.* into RawTrade2
FROM MyUnion
WHERE Field8 = 'ZAR';
</code>```

I get an error: Cannot open database "

My aim is to once a month create a master table by appending every monthly file.

答:
Create the Union query, save it with the name like 'qUnion'.
From menu open:

Create-->Query--> Make Table.

In Add Table Menu chose "Queries" and

Add your union query ('qUnion').

Select the fields that you need.

Open query.

Anew table will be created.

Title: Access union all into new table

Body:
I have a saved query (MyUnion) for a union, appending monthly files (linked views):

select * from RawTrade1801
union all
select * from RawTrade1802

Trying to write this to a new table is proving problematic:

SELECT MyUnion.* into RawTrade2
FROM MyUnion
WHERE Field8 = 'ZAR';

I get an error: Cannot open database "

My aim is to once a month create a master table by appending every monthly file.


问:
ImportError: cannot import name 'text_encoding' from 'io' (unknown location)
I've been trying to open up a virtual environment. I can open scrapy from anaconda powershell prompt, but I can't use it in the virtual environment. I have created the environment by using the command:

```<code>C:\Python310\Scripts\virtualenv.exe C:\ProgramData\Anaconda3
</code>```

I have also started the virtual environment using the command:

```<code>C:\ProgramData\Anaconda3\Scripts\activate.bat
</code>```

But I when I try using this command,

```<code>scrapy shell
</code>```

it gives this error:

```<code>Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
  File "C:\Python310\lib\io.py", line 54, in <module>
ImportError: cannot import name 'text_encoding' from 'io' (unknown location)
</code>```

I installed the virtual environment module with this command:

```<code>pip install virtualenv
</code>```

But there are nothing like "activate.bat" in my scripts folder (C:\Python310\Scripts) instead there is the file "virtualenv.exe". However there is a scripts folder in my virtual environment (C:\ProgramData\Anaconda3\Scripts) which has the file "activate.bat".

How can I fix the error?
Am I doing something wrong?
Thank you.

答:
I had same error but not on windows and I solved it by rebuilding Python, so I suggest you re-install Python. Also, I suggest not mixing pure Python with Anaconda. Did this work with another version of Python?
Finally, I cant tell which 3.10 you are using but I would use the latest 3.10.2.
if you need more help then you need to add more info.
You may like to check the scrapy docs.</p>

Body:
I've been trying to open up a virtual environment. I can open scrapy from anaconda powershell prompt, but I can't use it in the virtual environment. I have created the environment by using the command:

C:\Python310\Scripts\virtualenv.exe C:\ProgramData\Anaconda3

I have also started the virtual environment using the command:

C:\ProgramData\Anaconda3\Scripts\activate.bat

But I when I try using this command,

scrapy shell

it gives this error:

Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
  File "C:\Python310\lib\io.py", line 54, in <module>
ImportError: cannot import name 'text_encoding' from 'io' (unknown location)

I installed the virtual environment module with this command:

pip install virtualenv

But there are nothing like "activate.bat" in my scripts folder (C:\Python310\Scripts) instead there is the file "virtualenv.exe". However there is a scripts folder in my virtual environment (C:\ProgramData\Anaconda3\Scripts) which has the file "activate.bat".

How can I fix the error?
Am I doing something wrong?
Thank you.


问:
Frame ancestor is set to none even though it's not
I'm running a matrix synapse instance with OpenID Keycloak and as web-client, I use Riot.
I receive has refused to connect with : "Refused to frame 'https://matrix.domain.com/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'none'".

However I have no problem connecting to it through Riot, I get the error when I display Riot in an iframe and try login, all the websites are of same domain wildcard.

My nginx config on matrix.instance.com is

server {                                                                                server_name matrix.domain.com;                                                                                root /var/www/matrix.domain.com;                                                                                index index.html;                                                                                #add_header 'Access-Control-Allow-Origin' '*';                                                                          add_header Content-Security-Policy "frame-ancestors https://website1.domain.com https://website2.domain.com>                                                                                location / {                                                                                proxy_set_header X-Forwarded-For $remote_addr;                                                                          proxy_set_header X-Forwarded-Proto $scheme;                                                                             proxy_set_header Host $host;                                                                                proxy_pass http://localhost:8008;                                                                              }

答:
I have found the solution, matrix-synapse throws the flag from this directory
/opt/venvs/matrix-synapse/lib/python3.8/site-packages/synapse/http/server.py</p>


问:
C++ Initializer lists
I have to fill a std::vector with elements of type struct MHD_OptionItem.
This struct have this implementation:

```<code>struct MHD_OptionItem
{
    enum MHD_OPTION option;
    intptr_t value;
    void *ptr_value;
 };
</code>```

I have tried this way:

```<code> vector<struct MHD_OptionItem> iov;
 if(...)
     iov.push_back({ MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL });
 if(...)
     iov.push_back({ MHD_OPTION_CONNECTION_TIMEOUT, connectionTimeout });
 [....]
</code>```

but the g++ compiler, as expected, says to me:

warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x

I know that I can initialize a temporary struct and then pass it to the vector, but this method seems to me to be inefficient and not so elegant.

I can't change the struct inserting a constructor because this is not my code but a library included.

There is an elegant way to do this without using c++0x syntax?

答:
How about having a constructor and copy constructor introduced,

```<code>struct MHD_OptionItem
{
  //...
  MHD_OptionItem(MHD_OPTION, intptr_t, void*);  // makes struct a non-POD
  MHD_OptionItem(const MHD_OptionItem&) // copy constructor
};
</code>```

And using it for initialization,

```<code>iov.push_back(MHD_OptionItem(MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL));
</code>```

Yes, you are introducing a temporary. But still the syntax remains elegant

Title: C++ Initializer lists

Body:
I have to fill a std::vector with elements of type struct MHD_OptionItem.
This struct have this implementation:

struct MHD_OptionItem
{
    enum MHD_OPTION option;
    intptr_t value;
    void *ptr_value;
 };

I have tried this way:

 vector<struct MHD_OptionItem> iov;
 if(...)
     iov.push_back({ MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL });
 if(...)
     iov.push_back({ MHD_OPTION_CONNECTION_TIMEOUT, connectionTimeout });
 [....]

but the g++ compiler, as expected, says to me:

warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x

I know that I can initialize a temporary struct and then pass it to the vector, but this method seems to me to be inefficient and not so elegant.

I can't change the struct inserting a constructor because this is not my code but a library included.

There is an elegant way to do this without using c++0x syntax?

Body:
How about having a constructor and copy constructor introduced,

struct MHD_OptionItem
{
  //...
  MHD_OptionItem(MHD_OPTION, intptr_t, void*);  // makes struct a non-POD
  MHD_OptionItem(const MHD_OptionItem&) // copy constructor
};

And using it for initialization,

iov.push_back(MHD_OptionItem(MHD_OPTION_NOTIFY_COMPLETED, requestCompleted, NULL));

Yes, you are introducing a temporary. But still the syntax remains elegant


问:
Snowflake - How to create summary table containing unique records
I'm looking for some Snowflake syntax assistance in how to generate a summary table or view from an existing table. My summary table should have 1 row per unique id from the existing table along with boolean values indicating if the various milestones (as per the summary column names) have been hit. Any help is appreciated as I am a Snowflake novice. Thanks.

Existing Table

Desired Summary Table/View

答:
try this and see if this helps to get what you want.</p>
```<code>SELECT ID, decode(HIT_PIPELINE_A, NULL,FALSE,TRUE) ,
           decode(HIT_PIPELINE_B, NULL,FALSE,TRUE),
           decode(HIT_PIPELINE_C, NULL,FALSE,TRUE),
           decode(HIT_STAGE_4, NULL,FALSE,TRUE),
           decode(HIT_STAGE_5, NULL,FALSE,TRUE),
           decode(HIT_STAGE_6, NULL,FALSE,TRUE) FROM
(
SELECT * from tab1
PIVOT(MAx(PIPELINE_ID) FOR stage_id IN ('1','2','3','4','5','6'))
 AS P(ID,DT,HIT_PIPELINE_A,HIT_PIPELINE_B,HIT_PIPELINE_C,HIT_STAGE_4,HIT_STAGE_5,HIT_STAGE_6)
) order by ID;

create or replace table Tab1  (ID varchar2(100), updated date, pipeline_id varchar2(100), stage_id varchar2(10));
insert into tab1 values(1111, to_date('02/01/2022 09:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '1' );
insert into tab1 values(1111, to_date('02/01/2022 10:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '2' );
insert into tab1 values(1111, to_date('02/01/2022 11:01:00','mm/dd/yyyy hh:mm:ss'), 'B', '5' );

insert into tab1 values(2222, to_date('02/02/2022 13:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '1' );
insert into tab1 values(2222, to_date('02/03/2022 18:01:00','mm/dd/yyyy hh:mm:ss'), 'B', '5' );
insert into tab1 values(2222, to_date('02/04/2022 07:01:00','mm/dd/yyyy hh:mm:ss'), 'B', '6' );

insert into tab1 values(3333, to_date('02/02/2022 14:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '1' );
insert into tab1 values(3333, to_date('02/03/2022 18:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '2' );
insert into tab1 values(3333, to_date('02/03/2022 07:01:00','mm/dd/yyyy hh:mm:ss'), 'C', '7' );
insert into tab1 values(3333, to_date('02/03/2022 21:01:00','mm/dd/yyyy hh:mm:ss'), 'C', '8' );
insert into tab1 values(3333, to_date('02/05/2022 17:01:00','mm/dd/yyyy hh:mm:ss'), 'C', '9' );
</code>```

Body:
try this and see if this helps to get what you want.

SELECT ID, decode(HIT_PIPELINE_A, NULL,FALSE,TRUE) ,
           decode(HIT_PIPELINE_B, NULL,FALSE,TRUE),
           decode(HIT_PIPELINE_C, NULL,FALSE,TRUE),
           decode(HIT_STAGE_4, NULL,FALSE,TRUE),
           decode(HIT_STAGE_5, NULL,FALSE,TRUE),
           decode(HIT_STAGE_6, NULL,FALSE,TRUE) FROM
(
SELECT * from tab1
PIVOT(MAx(PIPELINE_ID) FOR stage_id IN ('1','2','3','4','5','6'))
 AS P(ID,DT,HIT_PIPELINE_A,HIT_PIPELINE_B,HIT_PIPELINE_C,HIT_STAGE_4,HIT_STAGE_5,HIT_STAGE_6)
) order by ID;

create or replace table Tab1  (ID varchar2(100), updated date, pipeline_id varchar2(100), stage_id varchar2(10));
insert into tab1 values(1111, to_date('02/01/2022 09:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '1' );
insert into tab1 values(1111, to_date('02/01/2022 10:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '2' );
insert into tab1 values(1111, to_date('02/01/2022 11:01:00','mm/dd/yyyy hh:mm:ss'), 'B', '5' );

insert into tab1 values(2222, to_date('02/02/2022 13:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '1' );
insert into tab1 values(2222, to_date('02/03/2022 18:01:00','mm/dd/yyyy hh:mm:ss'), 'B', '5' );
insert into tab1 values(2222, to_date('02/04/2022 07:01:00','mm/dd/yyyy hh:mm:ss'), 'B', '6' );

insert into tab1 values(3333, to_date('02/02/2022 14:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '1' );
insert into tab1 values(3333, to_date('02/03/2022 18:01:00','mm/dd/yyyy hh:mm:ss'), 'A', '2' );
insert into tab1 values(3333, to_date('02/03/2022 07:01:00','mm/dd/yyyy hh:mm:ss'), 'C', '7' );
insert into tab1 values(3333, to_date('02/03/2022 21:01:00','mm/dd/yyyy hh:mm:ss'), 'C', '8' );
insert into tab1 values(3333, to_date('02/05/2022 17:01:00','mm/dd/yyyy hh:mm:ss'), 'C', '9' );


问:
What is the difference between pip list and pip freeze?
What is the difference between pip list and pip freeze? Seems them both doing about the same, but formatting is different, what is the use case of each of them? which one is more preferable?

答: pip list shows all installed packages, whereas pip freeze shows the ones installed by the user.


问:
npm run scripts not working, bur running scripts separately works
I have been trying to run scripts using NPM run scripts. However, it ends up in error.

Package.json

```<code>"scripts": {
    "ng": "ng",
    "start": "ng serve --open",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

**Error while running in console**
> ng serve --open

'T\project-name\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'E:\Projects\@angular\cli\bin\ng'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project-name@0.0.0 start: `ng serve --open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project-name@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Noel\AppData\Roaming\npm-cache\_logs\2020-09-17T08_36_36_725Z-debug.log

E:\Projects\project-folder\project-name>npm run start

> project-name@0.0.0 start E:\Projects\project-folder\project-name
> ng serve --open

'T\project-name\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'E:\Projects\@angular\cli\bin\ng'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project-name@0.0.0 start: `ng serve --open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project-name@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user name\AppData\Roaming\npm-cache\_logs\2020-09-17T08_36_39_450Z-debug.log
</code>```

Error Log

```<code>0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.6
3 info using node@v12.18.4
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle project-name@0.0.0~prestart: project-name@0.0.0
6 info lifecycle project-name@0.0.0~start: project-name@0.0.0
7 verbose lifecycle project-name@0.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle project-name@0.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;E:\Projects\AT&T\at-t_parallon_fe\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\nodejs\;C:\Users\Noel\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Noel\AppData\Roaming\Composer\vendor\bin;C:\Users\Noel\AppData\Roaming\npm
9 verbose lifecycle project-name@0.0.0~start: CWD: E:\Projects\AT&T\at-t_parallon_fe
10 silly lifecycle project-name@0.0.0~start: Args: [ '/d /s /c', 'ng serve --open' ]
11 silly lifecycle project-name@0.0.0~start: Returned: code: 1  signal: null
12 info lifecycle project-name@0.0.0~start: Failed to exec start script
13 verbose stack Error: project-name@0.0.0 start: `ng serve --open`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid project-name@0.0.0
15 verbose cwd E:\Projects\project-folder\project-name
16 verbose Windows_NT 10.0.10240
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start"
18 verbose node v12.18.4
19 verbose npm  v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error project-name@0.0.0 start: `ng serve --open`
22 error Exit status 1
23 error Failed at the project-name@0.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
</code>```

Resolutions tried

I tried reinstalling the node

I tried adding the system32 path to the PATH variable in the system variables.

But still, I am facing the issue. Any help with the issue will be greatly appreciated.

答:
Whenever you get the error of missing scripts, it means that the scripts do not exist in the folder from which you are trying to access them.

Try this instead.

Ensure that you are in the exact folder from which you are trying to run the scripts from. It could be that you have two similarly named folders and that you are trying to run the scripts from the one without the node modules or that you are just trying to run the scripts from a totally different folder that doesn't include the node modules.

Body:
I have been trying to run scripts using NPM run scripts. However, it ends up in error.

Package.json

"scripts": {
    "ng": "ng",
    "start": "ng serve --open",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

**Error while running in console**
> ng serve --open

'T\project-name\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'E:\Projects\@angular\cli\bin\ng'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project-name@0.0.0 start: `ng serve --open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project-name@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Noel\AppData\Roaming\npm-cache\_logs\2020-09-17T08_36_36_725Z-debug.log

E:\Projects\project-folder\project-name>npm run start

> project-name@0.0.0 start E:\Projects\project-folder\project-name
> ng serve --open

'T\project-name\node_modules\.bin\' is not recognized as an internal or external command,
operable program or batch file.
internal/modules/cjs/loader.js:968
  throw err;
  ^

Error: Cannot find module 'E:\Projects\@angular\cli\bin\ng'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! project-name@0.0.0 start: `ng serve --open`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the project-name@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user name\AppData\Roaming\npm-cache\_logs\2020-09-17T08_36_39_450Z-debug.log

Error Log

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'start'
1 verbose cli ]
2 info using npm@6.14.6
3 info using node@v12.18.4
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle project-name@0.0.0~prestart: project-name@0.0.0
6 info lifecycle project-name@0.0.0~start: project-name@0.0.0
7 verbose lifecycle project-name@0.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle project-name@0.0.0~start: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;E:\Projects\AT&T\at-t_parallon_fe\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Program Files\nodejs\;C:\Users\Noel\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\Noel\AppData\Roaming\Composer\vendor\bin;C:\Users\Noel\AppData\Roaming\npm
9 verbose lifecycle project-name@0.0.0~start: CWD: E:\Projects\AT&T\at-t_parallon_fe
10 silly lifecycle project-name@0.0.0~start: Args: [ '/d /s /c', 'ng serve --open' ]
11 silly lifecycle project-name@0.0.0~start: Returned: code: 1  signal: null
12 info lifecycle project-name@0.0.0~start: Failed to exec start script
13 verbose stack Error: project-name@0.0.0 start: `ng serve --open`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1021:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
14 verbose pkgid project-name@0.0.0
15 verbose cwd E:\Projects\project-folder\project-name
16 verbose Windows_NT 10.0.10240
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start"
18 verbose node v12.18.4
19 verbose npm  v6.14.6
20 error code ELIFECYCLE
21 error errno 1
22 error project-name@0.0.0 start: `ng serve --open`
22 error Exit status 1
23 error Failed at the project-name@0.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Resolutions tried

I tried reinstalling the node

I tried adding the system32 path to the PATH variable in the system variables.

But still, I am facing the issue. Any help with the issue will be greatly appreciated.


问:
How to get the all the values in multiple columns and store them in one variable
I'm trying to get the values of 4 columns (N, P, R, T) and store them in one column.
Also, I thought of doing the same thing but for rows ( So like concatenate 4 cells in 4 columns and store them in a variable via a for loop). I think I would start doung that when I figure the columns first.

for example:-

so here i want to store the values of each column and store them in one variable and then sum all 4 values to get the value of all four columns which is (14+12+11+7) which is 44.

I wrote this code but it doesn't seem to me like its storing the values.

```<code>function percentage(){

  const thisSheet = SpreadsheetApp.openByUrl(THIS).getSheetByName('WP_Data');
 var range=thisSheet.getRangeList(['N3:N', 'P3:P', 'R3:R', 'T3:T']);
 var rangeN= thisSheet.getRange("N3:N");
 var valueN=rangeN.getValues();
 var rangeP= thisSheet.getRange("P3:P");
 var valueP=rangeP.getValues();
 var rangeR= thisSheet.getRange("R3:R");
 var valueR=rangeR.getValues();
 var rangeT= thisSheet.getRange("T3:T");
 var valueT=rangeT.getValues();
 console.log()
 var val =valueN + valueP + valueR + valueT;

}
</code>```

would really appreciate the help.

If you need more info please let me know

答:
Something like this?</p>
```<code>function percentage(){

  const thisSheet = SpreadsheetApp.openByUrl(THIS).getSheetByName('WP_Data');
  var values = thisSheet.getRange(3,14,thisSheet.getLastRow()-2,7).getValues(); // N3:T??
  var results = [];
  var i = 0;
  for( i=0; i<values.length; i++ ) {
    results.push([values[i][0]+values[i][2]+values[i][4]+values[i][6]]); // index 0 = column N, etc.
  }
  // don't know what you want to do with it but you could use setValues(results)
  thisSheet.getRange(??,??,results.length,1).setValues(results);
}
</code>```

Body:
I'm trying to get the values of 4 columns (N, P, R, T) and store them in one column.
Also, I thought of doing the same thing but for rows ( So like concatenate 4 cells in 4 columns and store them in a variable via a for loop). I think I would start doung that when I figure the columns first.

for example:-

so here i want to store the values of each column and store them in one variable and then sum all 4 values to get the value of all four columns which is (14+12+11+7) which is 44.

I wrote this code but it doesn't seem to me like its storing the values.

function percentage(){

  const thisSheet = SpreadsheetApp.openByUrl(THIS).getSheetByName('WP_Data');
 var range=thisSheet.getRangeList(['N3:N', 'P3:P', 'R3:R', 'T3:T']);
 var rangeN= thisSheet.getRange("N3:N");
 var valueN=rangeN.getValues();
 var rangeP= thisSheet.getRange("P3:P");
 var valueP=rangeP.getValues();
 var rangeR= thisSheet.getRange("R3:R");
 var valueR=rangeR.getValues();
 var rangeT= thisSheet.getRange("T3:T");
 var valueT=rangeT.getValues();
 console.log()
 var val =valueN + valueP + valueR + valueT;

}

would really appreciate the help.

If you need more info please let me know

Body:
Something like this?

function percentage(){

  const thisSheet = SpreadsheetApp.openByUrl(THIS).getSheetByName('WP_Data');
  var values = thisSheet.getRange(3,14,thisSheet.getLastRow()-2,7).getValues(); // N3:T??
  var results = [];
  var i = 0;
  for( i=0; i<values.length; i++ ) {
    results.push([values[i][0]+values[i][2]+values[i][4]+values[i][6]]); // index 0 = column N, etc.
  }
  // don't know what you want to do with it but you could use setValues(results)
  thisSheet.getRange(??,??,results.length,1).setValues(results);
}


问:
Parse Json with Python where a single object contains 200 objects, and I want to operate on each object individually
So I have an object I imported into a dict.

```<code>{"results":[
{"Name":"fed-sv01","NodeID":118,"XID":"37be","RowID":"2","Vendor":"Wnet","Status":"0"},
{"Name":"Joe-sv02","NodeID":119,"XID":"ab39","RowID":"2","Vendor":"Wnet","Status":"92"},
...
{"Name":"May-sv01","NodeID":703,"XID":"zc93","RowID":"2","Vendor":"Wnet","Status":"4"}]}
</code>```

I show 3 lines, but there are around 200 similar lines.

So "results":[] is a top level container that simply encapsulated the set of objects.

What I want to do is iterate through the nested objects:

```<code>{"Name":"fed-sv01","NodeID":118,"XID":"37be","RowID":"2","Vendor":"Wnet","Status":"0"}
</code>```

And build a different json object:

```<code>{"Name":"fred-sv01","Status":"0"}
</code>```

That I will then push out to another system set up to catch these objects.  I have the code for that, what I'm trying to do is peel the json objects from inside results[] one at a time, and I'm not finding any examples of how to do that.  I could just run a command on the json to remove the results[] wrapper, but that seems silly if all I have to do is deal with results[] inside the scripts that do the iteration.

I want to read a line, create a new object, ship the object off. Rinse & repeat until iterated through all 200 objects.  We could pop them off as we iterate if that makes it easier, but I'm not sure it does.  The original object is ephemeral, so it can be destroyed.

Does anyone have some example code showing how to parse json in a results[] object with python?

The comments are helping, this is what I have now:

```<code>import json

with open('json.results') as json_file:
    data = json.load(json_file)

    for row in data['results']:
            print(row)  #good so far

            node = {row('Name'), row('Status')}
            for item in node():
                print(item) #blows up with "TypeError: 'dict' object is not callable"
</code>```

答:
Making Barmar`s comment and mine into an answer:

for item in container['results']: will iterate over the list of objects, and with newDict = { 'name': item['Name'], 'status': item['Status']} you can build a new object capturing the keys of the first and then do the rest of the work using this new object.

Body:
So I have an object I imported into a dict.

{"results":[
{"Name":"fed-sv01","NodeID":118,"XID":"37be","RowID":"2","Vendor":"Wnet","Status":"0"},
{"Name":"Joe-sv02","NodeID":119,"XID":"ab39","RowID":"2","Vendor":"Wnet","Status":"92"},
...
{"Name":"May-sv01","NodeID":703,"XID":"zc93","RowID":"2","Vendor":"Wnet","Status":"4"}]}

I show 3 lines, but there are around 200 similar lines.

So "results":[] is a top level container that simply encapsulated the set of objects.

What I want to do is iterate through the nested objects:

{"Name":"fed-sv01","NodeID":118,"XID":"37be","RowID":"2","Vendor":"Wnet","Status":"0"}

And build a different json object:

{"Name":"fred-sv01","Status":"0"}

That I will then push out to another system set up to catch these objects.  I have the code for that, what I'm trying to do is peel the json objects from inside results[] one at a time, and I'm not finding any examples of how to do that.  I could just run a command on the json to remove the results[] wrapper, but that seems silly if all I have to do is deal with results[] inside the scripts that do the iteration.

I want to read a line, create a new object, ship the object off. Rinse & repeat until iterated through all 200 objects.  We could pop them off as we iterate if that makes it easier, but I'm not sure it does.  The original object is ephemeral, so it can be destroyed.

Does anyone have some example code showing how to parse json in a results[] object with python?

The comments are helping, this is what I have now:

import json

with open('json.results') as json_file:
    data = json.load(json_file)

    for row in data['results']:
            print(row)  #good so far

            node = {row('Name'), row('Status')}
            for item in node():
                print(item) #blows up with "TypeError: 'dict' object is not callable"


问:
How to call business object class from main method?
I have separated my code into business object, access layer as shown below:

```<code>void Main()
{

}

//====================================================================
// Business object
public class ExpenseBO
{
    public void MakeExpense(ExpensePayload payload)
    {
        var trA = new TrAccess();
        var acA = new AcAccess();

        var account = acA.MakeAccount(payload.Account);

        payload.Transaction.Account = account;
        trA.MakeTransaction(payload.Transaction);
    }
}

//----------------------------------------------------------------------------
public class TrAccess
{
    private const string connString = "Host=localhost;Username=postgres;Password=1234;Database=ExpenseManagerDB";

    public void MakeTransaction(T t)
    {
            using (var connection = new NpgsqlConnection(connString))
            {
                connection.Execute(@"INSERT INTO transaction (account_id, amount, date, note)
                                         SELECT a.account_id,@amount, @date, @note
                                         FROM account AS a
                                         WHERE a.account_name = @account_name", new { t.Amount, t.Date, t.Note, a.Account_Name });
            }
    }
}

public class AcAccess
{
    private const string connString = "Host=localhost;Username=postgres;Password=1234;Database=ExpenseManagerDB";

    public void MakeAccount(A a)
    {
        using (var connection = new NpgsqlConnection(connString))
        {
            connection.Execute(@"INSERT INTO account(account_name, type)
                             VALUES(@account_name, @type)", new { account.Account_Name, account.Type });
        }
    }
}

public class T
{
    public int Transaction_Id { get; set; }
    public int Account_Id { get; set; }
    public decimal Amount { get; set; }
    public string Note { get; set; }
    public DateTime Date { get; set; }
}

public class A
{
    public int Account_Id { get; set; }
    public string Account_Name { get; set; }
    public string Type { get; set; }
}

//--------------------------------------------
public class ExpensePayload
{
    public T Transaction { get; set; }
    public A Account { get; set; }
}
</code>```

Now I wanted to call the ExpenseBO class method MakeExpense from the main methods which will create two objects and with them calls TrAccess, AcAccess.

But there is an ExpensePayload class. If I wanted to call ExpenseBO class MakeExpense method in main method, how should I do that? How should I create a ExpensePayload class object and call it in main method?

答:
```<code>  public void AccessToExpenseBO()
{
    var request = new ExpensePayload
    {
        Account = new A
        {
            Account_Id = 1,
            Account_Name = "Account 1",
            Type = "Type 1"
        },
        Transaction = new T
        {
            Account_Id = 1,
            Amount = 25,
            Date = DateTime.Now,
            Note = "Note 1",
            Transaction_Id = 25

        }
    };
    var expenseBO = new ExpenseBO();
    expenseBO.MakeExpense(request);
}
</code>```

Basically, you can access how I show it but, I am gonna add some comments base on your code.

MakeAccount method does not return a value so, you cannot assign it to a variable. You should return a value in this case an Account to do what you want inside MakeExpense method.

```<code>public void MakeExpense(ExpensePayload payload)
{
    var trA = new TrAccess();
    var acA = new AcAccess();

    var account = acA.MakeAccount(payload.Account); //void method

    payload.Account = account; // so, there is no an account
    trA.MakeTransaction(payload.Transaction);
}
</code>```

Body:
I have separated my code into business object, access layer as shown below:

void Main()
{

}

//====================================================================
// Business object
public class ExpenseBO
{
    public void MakeExpense(ExpensePayload payload)
    {
        var trA = new TrAccess();
        var acA = new AcAccess();

        var account = acA.MakeAccount(payload.Account);

        payload.Transaction.Account = account;
        trA.MakeTransaction(payload.Transaction);
    }
}

//----------------------------------------------------------------------------
public class TrAccess
{
    private const string connString = "Host=localhost;Username=postgres;Password=1234;Database=ExpenseManagerDB";

    public void MakeTransaction(T t)
    {
            using (var connection = new NpgsqlConnection(connString))
            {
                connection.Execute(@"INSERT INTO transaction (account_id, amount, date, note)
                                         SELECT a.account_id,@amount, @date, @note
                                         FROM account AS a
                                         WHERE a.account_name = @account_name", new { t.Amount, t.Date, t.Note, a.Account_Name });
            }
    }
}

public class AcAccess
{
    private const string connString = "Host=localhost;Username=postgres;Password=1234;Database=ExpenseManagerDB";

    public void MakeAccount(A a)
    {
        using (var connection = new NpgsqlConnection(connString))
        {
            connection.Execute(@"INSERT INTO account(account_name, type)
                             VALUES(@account_name, @type)", new { account.Account_Name, account.Type });
        }
    }
}

public class T
{
    public int Transaction_Id { get; set; }
    public int Account_Id { get; set; }
    public decimal Amount { get; set; }
    public string Note { get; set; }
    public DateTime Date { get; set; }
}

public class A
{
    public int Account_Id { get; set; }
    public string Account_Name { get; set; }
    public string Type { get; set; }
}

//--------------------------------------------
public class ExpensePayload
{
    public T Transaction { get; set; }
    public A Account { get; set; }
}

Now I wanted to call the ExpenseBO class method MakeExpense from the main methods which will create two objects and with them calls TrAccess, AcAccess.

But there is an ExpensePayload class. If I wanted to call ExpenseBO class MakeExpense method in main method, how should I do that? How should I create a ExpensePayload class object and call it in main method?

Body:
  public void AccessToExpenseBO()
{
    var request = new ExpensePayload
    {
        Account = new A
        {
            Account_Id = 1,
            Account_Name = "Account 1",
            Type = "Type 1"
        },
        Transaction = new T
        {
            Account_Id = 1,
            Amount = 25,
            Date = DateTime.Now,
            Note = "Note 1",
            Transaction_Id = 25

        }
    };
    var expenseBO = new ExpenseBO();
    expenseBO.MakeExpense(request);
}

Basically, you can access how I show it but, I am gonna add some comments base on your code.

MakeAccount method does not return a value so, you cannot assign it to a variable. You should return a value in this case an Account to do what you want inside MakeExpense method.

public void MakeExpense(ExpensePayload payload)
{
    var trA = new TrAccess();
    var acA = new AcAccess();

    var account = acA.MakeAccount(payload.Account); //void method

    payload.Account = account; // so, there is no an account
    trA.MakeTransaction(payload.Transaction);
}


问:
MSMQ Receive() method timeout
My original question from a while ago is MSMQ Slow Queue Reading, however I have advanced from that and now think I know the problem a bit more clearer.

My code (well actually part of an open source library I am using) looks like this:

```<code>queue.Receive(TimeSpan.FromSeconds(10), MessageQueueTransactionType.Automatic);
</code>```

Which is using the Messaging.MessageQueue.Receive function and queue is a MessageQueue.  The problem is as follows.

The above line of code will be called with the specified timeout (10 seconds).  The Receive(...) function is a blocking function, and is supposed to block until a message arrives in the queue at which time it will return.  If no message is received before the timeout is hit, it will return at the timeout.  If a message is in the queue when the function is called, it will return that message immediately.

However, what is happening is the Receive(...) function is being called, seeing that there is no message in the queue, and hence waiting for a new message to come in.  When a new message comes in (before the timeout), it isn't detecting this new message and continues waiting.  The timeout is eventually hit, at which point the code continues and calls Receive(...) again, where it picks up the message and processes it.

Now, this problem only occurs after a number of days/weeks.  I can make it work normally again by deleting & recreating the queue.  It happens on different computers, and different queues.  So it seems like something is building up, until some point when it breaks the triggering/notification ability that the Receive(...) function uses.

I've checked a lot of different things, and everything seems normal & isn't different from a queue that is working normally.  There is plenty of disk space (13gig free) and RAM (about 350MB free out of 1GB from what I can tell).  I have checked registry entries which all appear the same as other queues, and the performance monitor doesn't show anything out of the normal.  I have also run the TMQ tool and can't see anything noticably wrong from that.

I am using Windows XP on all the machines and they all have service pack 3 installed.  I am not sending a large amount of messages to the queues, at most it would be 1 every 2 seconds but generally a lot less frequent than that.  The messages are only small too and nowhere near the 4MB limit.

The only thing I have just noticed is the p0000001.mq and r0000067.mq files in C:\WINDOWS\system32\msmq\storage are both 4,096KB however they are that size on other computers also which are not currently experiencing the problem.  The problem does not happen to every queue on the computer at once, as I can recreate 1 problem queue on the computer and the other queues still experience the problem.

I am not very experienced with MSMQ so if you post possible things to check can you please explain how to check them or where I can find more details on what you are talking about.

Currently the situation is:

ComputerA - 4 queues normal

ComputerB - 2 queues experiencing problem, 1 queue normal

ComputerC - 2 queues experiencing problem

ComputerD - 1 queue normal

ComputerE - 2 queues normal

So I have a large number of computers/queues to compare and test against.

答:
Try this

public Message Receive(   TimeSpan timeout,   Cursor cursor )

overloaded function.

To get a cursor for a MessageQueue, call the CreateCursor method for that queue.

A Cursor is used with such methods as Peek(TimeSpan, Cursor, PeekAction) and Receive(TimeSpan, Cursor) when you need to read messages that are not at the front of the queue. This includes reading messages synchronously or asynchronously. Cursors do not need to be used to read only the first message in a queue.

When reading messages within a transaction, Message Queuing does not roll back cursor movement if the transaction is aborted. For example, suppose there is a queue with two messages, A1 and A2. If you remove message A1 while in a transaction, Message Queuing moves the cursor to message A2. However, if the transaction is aborted for any reason, message A1 is inserted back into the queue but the cursor remains pointing at message A2.

To close the cursor, call Close.

Title: MSMQ Receive() method timeout

Body:
My original question from a while ago is MSMQ Slow Queue Reading, however I have advanced from that and now think I know the problem a bit more clearer.

My code (well actually part of an open source library I am using) looks like this:

queue.Receive(TimeSpan.FromSeconds(10), MessageQueueTransactionType.Automatic);

Which is using the Messaging.MessageQueue.Receive function and queue is a MessageQueue.  The problem is as follows.

The above line of code will be called with the specified timeout (10 seconds).  The Receive(...) function is a blocking function, and is supposed to block until a message arrives in the queue at which time it will return.  If no message is received before the timeout is hit, it will return at the timeout.  If a message is in the queue when the function is called, it will return that message immediately.

However, what is happening is the Receive(...) function is being called, seeing that there is no message in the queue, and hence waiting for a new message to come in.  When a new message comes in (before the timeout), it isn't detecting this new message and continues waiting.  The timeout is eventually hit, at which point the code continues and calls Receive(...) again, where it picks up the message and processes it.

Now, this problem only occurs after a number of days/weeks.  I can make it work normally again by deleting & recreating the queue.  It happens on different computers, and different queues.  So it seems like something is building up, until some point when it breaks the triggering/notification ability that the Receive(...) function uses.

I've checked a lot of different things, and everything seems normal & isn't different from a queue that is working normally.  There is plenty of disk space (13gig free) and RAM (about 350MB free out of 1GB from what I can tell).  I have checked registry entries which all appear the same as other queues, and the performance monitor doesn't show anything out of the normal.  I have also run the TMQ tool and can't see anything noticably wrong from that.

I am using Windows XP on all the machines and they all have service pack 3 installed.  I am not sending a large amount of messages to the queues, at most it would be 1 every 2 seconds but generally a lot less frequent than that.  The messages are only small too and nowhere near the 4MB limit.

The only thing I have just noticed is the p0000001.mq and r0000067.mq files in C:\WINDOWS\system32\msmq\storage are both 4,096KB however they are that size on other computers also which are not currently experiencing the problem.  The problem does not happen to every queue on the computer at once, as I can recreate 1 problem queue on the computer and the other queues still experience the problem.

I am not very experienced with MSMQ so if you post possible things to check can you please explain how to check them or where I can find more details on what you are talking about.

Currently the situation is:

ComputerA - 4 queues normal

ComputerB - 2 queues experiencing problem, 1 queue normal

ComputerC - 2 queues experiencing problem

ComputerD - 1 queue normal

ComputerE - 2 queues normal

So I have a large number of computers/queues to compare and test against.


问:
Issues while running with BigQueryIO.Write.Method.STORAGE_WRITE_API
We are testing with STORAGE_WRITE_API to insert data into BigQuery. We've seen several errors/warnings in our Dataflow pipeline(written in Java). It might work well in the beginning, but eventually the system lag would be increasing, it would stop processing any data from PubSub and the unacked messages piled up.

One common warning is:

```<code>Operation ongoing in step insertTableRowsToBigQuery/StorageApiLoads/StorageApiWriteSharded/Write Records for at least 03h35m00s without outputting or completing in state process
  at java.base@11.0.9/jdk.internal.misc.Unsafe.park(Native Method)
  at java.base@11.0.9/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
  at java.base@11.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:885)
  at java.base@11.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1039)
  at java.base@11.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1345)
  at java.base@11.0.9/java.util.concurrent.CountDownLatch.await(CountDownLatch.java:232)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager$Callback.await(RetryManager.java:153)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager$Operation.await(RetryManager.java:136)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager.await(RetryManager.java:256)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager.run(RetryManager.java:248)
  at app//org.apache.beam.sdk.io.gcp.bigquery.StorageApiWritesShardedRecords$WriteRecordsDoFn.process(StorageApiWritesShardedRecords.java:453)
  at app//org.apache.beam.sdk.io.gcp.bigquery.StorageApiWritesShardedRecords$WriteRecordsDoFn$DoFnInvoker.invokeProcessElement(Unknown Source)
</code>```

Other exceptions we've seen:

Got error io.grpc.StatusRuntimeException: FAILED_PRECONDITION: Stream is closed

Got error io.grpc.StatusRuntimeException: ALREADY_EXIST

```<code>PodSandboxStatus of sandbox "..." for pod "df-...-pipeline-...-harness-qw4j_default(...)" error: rpc error: code = Unknown desc = Error: No such container
</code>```

Code sample:

```<code>        toBq.apply("insertTableRowsToBigQuery",
                BigQueryIO
                        .writeTableRows()
                        .to(String.format("%s:%s.%s", PROJECT_ID, DATASET, table))
                        .withTriggeringFrequency(Duration.standardSeconds(options.getTriggeringFrequency()))
                        .withNumStorageWriteApiStreams(options.getNumStorageWriteApiStreams())
                        .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER)
                        .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND));

</code>```

答: There was a production issue related to connection being stuck after streaming 10MB which has been fixed. If you try again, it should work.</p>

Body:
We are testing with STORAGE_WRITE_API to insert data into BigQuery. We've seen several errors/warnings in our Dataflow pipeline(written in Java). It might work well in the beginning, but eventually the system lag would be increasing, it would stop processing any data from PubSub and the unacked messages piled up.

One common warning is:

Operation ongoing in step insertTableRowsToBigQuery/StorageApiLoads/StorageApiWriteSharded/Write Records for at least 03h35m00s without outputting or completing in state process
  at java.base@11.0.9/jdk.internal.misc.Unsafe.park(Native Method)
  at java.base@11.0.9/java.util.concurrent.locks.LockSupport.park(LockSupport.java:194)
  at java.base@11.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:885)
  at java.base@11.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1039)
  at java.base@11.0.9/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1345)
  at java.base@11.0.9/java.util.concurrent.CountDownLatch.await(CountDownLatch.java:232)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager$Callback.await(RetryManager.java:153)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager$Operation.await(RetryManager.java:136)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager.await(RetryManager.java:256)
  at app//org.apache.beam.sdk.io.gcp.bigquery.RetryManager.run(RetryManager.java:248)
  at app//org.apache.beam.sdk.io.gcp.bigquery.StorageApiWritesShardedRecords$WriteRecordsDoFn.process(StorageApiWritesShardedRecords.java:453)
  at app//org.apache.beam.sdk.io.gcp.bigquery.StorageApiWritesShardedRecords$WriteRecordsDoFn$DoFnInvoker.invokeProcessElement(Unknown Source)

Other exceptions we've seen:

Got error io.grpc.StatusRuntimeException: FAILED_PRECONDITION: Stream is closed

Got error io.grpc.StatusRuntimeException: ALREADY_EXIST

PodSandboxStatus of sandbox "..." for pod "df-...-pipeline-...-harness-qw4j_default(...)" error: rpc error: code = Unknown desc = Error: No such container

Code sample:

        toBq.apply("insertTableRowsToBigQuery",
                BigQueryIO
                        .writeTableRows()
                        .to(String.format("%s:%s.%s", PROJECT_ID, DATASET, table))
                        .withTriggeringFrequency(Duration.standardSeconds(options.getTriggeringFrequency()))
                        .withNumStorageWriteApiStreams(options.getNumStorageWriteApiStreams())
                        .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_NEVER)
                        .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND));


问:
How to fix Command PhaseScriptExecution failed with a nonzero exit code on flutter run in macOS?
I am working on a flutter app. I recently shifted to macOS and since then haven't been able to run the app. Other apps are running fine so I think the error is in within the code of this app. And maybe because of this same reason I am unable to make a build.

Here is the output of flutter doctor:

```<code>[✓] Flutter (Channel stable, 1.20.1, on Mac OS X 10.15.6 19G73, locale en-US)
    • Flutter version 1.20.1 at /Users/bhawna/dev/flutter
    • Framework revision 2ae34518b8 (4 days ago), 2020-08-05 19:53:19 -0700
    • Engine revision c8e3b94853
    • Dart version 2.9.0

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] VS Code (version 1.47.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.13.2

[✓] Connected device (1 available)
    • iPhone 8 (mobile) • 3D03BDE4-F1A6-45AB-B095-01107CDDC2CD • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)
</code>```

Output of flutter run:

```<code>Running "flutter pub get" in delivero...                            1.6s
Launching lib/main.dart on iPhone 8 in debug mode...

Running pod install...                                             38.2s
Running Xcode build...

Xcode build done.                                           449.0s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode's output:
↳
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inapp_purchase-2.2.0/ios/Classes/FlutterInappPurchasePlugin.
    m:45:52: warning: assigning to 'id<IAPPromotionObserverDelegate>' from incompatible type 'FlutterInappPurchasePlugin *__strong'
        [IAPPromotionObserver sharedObserver].delegate = self;
                                                       ^ ~~~~
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inapp_purchase-2.2.0/ios/Classes/FlutterInappPurchasePlugin.
    m:200:79: warning: implicit conversion loses integer precision: 'SKPaymentTransactionState' (aka 'enum
    SKPaymentTransactionState') to 'int' [-Wshorten-64-to-32]
                                                         [NSNumber numberWithInt: item.transactionState], @"transactionStateIOS",
                                                         ~                        ^~~~~~~~~~~~~~~~~~~~~
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inapp_purchase-2.2.0/ios/Classes/FlutterInappPurchasePlugin.
    m:586:71: warning: implicit conversion loses integer precision: 'SKPaymentTransactionState' (aka 'enum
    SKPaymentTransactionState') to 'int' [-Wshorten-64-to-32]
                                                 [NSNumber numberWithInt: transaction.transactionState], @"transactionStateIOS",
                                                 ~                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 warnings generated.
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/contacts_service-0.3.10/ios/Classes/ContactsServicePlugin.m:6:4:
    warning: 'SwiftContactsServicePlugin' is only available on iOS 9.0 or newer [-Wunguarded-availability]
      [SwiftContactsServicePlugin registerWithRegistrar:registrar];
       ^~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/contacts_service-0.3.10/ios/Classes/ContactsServicePlugin.m:2:
    /Users/bhawna/delivero/delivero/build/ios/Debug-iphonesimulator/contacts_service/contacts_service.framework/Headers/contacts_serv
    ice-Swift.h:213:12: note: 'SwiftContactsServicePlugin' has been marked as being introduced in iOS 9.0 here, but the deployment
    target is iOS 8.0.0
    @interface SwiftContactsServicePlugin : NSObject <FlutterPlugin>
               ^
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/contacts_service-0.3.10/ios/Classes/ContactsServicePlugin.m:6:4:
    note: enclose 'SwiftContactsServicePlugin' in an @available check to silence this warning
      [SwiftContactsServicePlugin registerWithRegistrar:registrar];
       ^~~~~~~~~~~~~~~~~~~~~~~~~~
    1 warning generated.
    /Users/bhawna/dev/flutter/packages/flutter_tools/bin/xcode_backend.sh: line 13: pushd: /Users/hrvoje/Documents/Delivero
    Files/contactsFeature: No such file or directory
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone 8.
</code>```

Any help would be great. Thanks for your time.

答: For me this error occurred because of low disc space. as I cleaned some of files and it worked</p>

Body:
I am working on a flutter app. I recently shifted to macOS and since then haven't been able to run the app. Other apps are running fine so I think the error is in within the code of this app. And maybe because of this same reason I am unable to make a build.

Here is the output of flutter doctor:

[✓] Flutter (Channel stable, 1.20.1, on Mac OS X 10.15.6 19G73, locale en-US)
    • Flutter version 1.20.1 at /Users/bhawna/dev/flutter
    • Framework revision 2ae34518b8 (4 days ago), 2020-08-05 19:53:19 -0700
    • Engine revision c8e3b94853
    • Dart version 2.9.0

[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, set ANDROID_SDK_ROOT to that location.
      You may also want to add it to your PATH environment variable.

[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.6, Build version 11E708
    • CocoaPods version 1.9.3

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).

[✓] VS Code (version 1.47.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.13.2

[✓] Connected device (1 available)
    • iPhone 8 (mobile) • 3D03BDE4-F1A6-45AB-B095-01107CDDC2CD • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-6 (simulator)

Output of flutter run:

Running "flutter pub get" in delivero...                            1.6s
Launching lib/main.dart on iPhone 8 in debug mode...

Running pod install...                                             38.2s
Running Xcode build...

Xcode build done.                                           449.0s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **

Xcode's output:
↳
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inapp_purchase-2.2.0/ios/Classes/FlutterInappPurchasePlugin.
    m:45:52: warning: assigning to 'id<IAPPromotionObserverDelegate>' from incompatible type 'FlutterInappPurchasePlugin *__strong'
        [IAPPromotionObserver sharedObserver].delegate = self;
                                                       ^ ~~~~
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inapp_purchase-2.2.0/ios/Classes/FlutterInappPurchasePlugin.
    m:200:79: warning: implicit conversion loses integer precision: 'SKPaymentTransactionState' (aka 'enum
    SKPaymentTransactionState') to 'int' [-Wshorten-64-to-32]
                                                         [NSNumber numberWithInt: item.transactionState], @"transactionStateIOS",
                                                         ~                        ^~~~~~~~~~~~~~~~~~~~~
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inapp_purchase-2.2.0/ios/Classes/FlutterInappPurchasePlugin.
    m:586:71: warning: implicit conversion loses integer precision: 'SKPaymentTransactionState' (aka 'enum
    SKPaymentTransactionState') to 'int' [-Wshorten-64-to-32]
                                                 [NSNumber numberWithInt: transaction.transactionState], @"transactionStateIOS",
                                                 ~                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 warnings generated.
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/contacts_service-0.3.10/ios/Classes/ContactsServicePlugin.m:6:4:
    warning: 'SwiftContactsServicePlugin' is only available on iOS 9.0 or newer [-Wunguarded-availability]
      [SwiftContactsServicePlugin registerWithRegistrar:registrar];
       ^~~~~~~~~~~~~~~~~~~~~~~~~~
    In file included from
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/contacts_service-0.3.10/ios/Classes/ContactsServicePlugin.m:2:
    /Users/bhawna/delivero/delivero/build/ios/Debug-iphonesimulator/contacts_service/contacts_service.framework/Headers/contacts_serv
    ice-Swift.h:213:12: note: 'SwiftContactsServicePlugin' has been marked as being introduced in iOS 9.0 here, but the deployment
    target is iOS 8.0.0
    @interface SwiftContactsServicePlugin : NSObject <FlutterPlugin>
               ^
    /Users/bhawna/dev/flutter/.pub-cache/hosted/pub.dartlang.org/contacts_service-0.3.10/ios/Classes/ContactsServicePlugin.m:6:4:
    note: enclose 'SwiftContactsServicePlugin' in an @available check to silence this warning
      [SwiftContactsServicePlugin registerWithRegistrar:registrar];
       ^~~~~~~~~~~~~~~~~~~~~~~~~~
    1 warning generated.
    /Users/bhawna/dev/flutter/packages/flutter_tools/bin/xcode_backend.sh: line 13: pushd: /Users/hrvoje/Documents/Delivero
    Files/contactsFeature: No such file or directory
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build system
    note: Building targets in parallel
    note: Planning build
    note: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone 8.

Any help would be great. Thanks for your time.


问:
how to split a JSON column into multiple as I showed here in Postgres
One of the column of my table is JSON like this:

timestamp
values

xxxx
[{"d_st":1601,"d_val":2.731},{"d_st":1602,"d_val":0.465},{"d_st":1603,"d_val":0.422},{"d_st":1604,"d_val":2.803},{"d_st":1605,"d_val":2.771},{"d_st":1606,"d_val":260.352}]

How could I split it into d_st and d_val like this:

timestamp
dst
dval

xxxx
1601
2.731

xxxx
1602
0.465

and so on

I used this:

```<code>SELECT values ->> "d_st" AS dst, values ->> 'd_val' AS val
FROM ss;
</code>```

but can't get any value, just two empty column, why is that?

答:
for this purpose, you can use json_to_recordset or jsonb_to_recordset function depending on the data type of values column as follows:

```<code>Select ss.timestamp, x.d_st, x.d_val
From ss Cross Join Lateral json_to_recordset(ss.values) As x(d_st int, d_val numeric)
</code>```

Result:

timestamp
d_st
d_val

xxxx
1601
2.731

xxxx
1602
0.465

xxxx
1603
0.422

xxxx
1604
2.803

xxxx
1605
2.771

xxxx
1606
260.352

db<>fiddle

Body:
One of the column of my table is JSON like this:

timestamp
values

xxxx
[{"d_st":1601,"d_val":2.731},{"d_st":1602,"d_val":0.465},{"d_st":1603,"d_val":0.422},{"d_st":1604,"d_val":2.803},{"d_st":1605,"d_val":2.771},{"d_st":1606,"d_val":260.352}]

How could I split it into d_st and d_val like this:

timestamp
dst
dval

xxxx
1601
2.731

xxxx
1602
0.465

and so on

I used this:

SELECT values ->> "d_st" AS dst, values ->> 'd_val' AS val
FROM ss;

but can't get any value, just two empty column, why is that?

Body:
for this purpose, you can use json_to_recordset or jsonb_to_recordset function depending on the data type of values column as follows:

Select ss.timestamp, x.d_st, x.d_val
From ss Cross Join Lateral json_to_recordset(ss.values) As x(d_st int, d_val numeric)

Result:

timestamp
d_st
d_val

xxxx
1601
2.731

xxxx
1602
0.465

xxxx
1603
0.422

xxxx
1604
2.803

xxxx
1605
2.771

xxxx
1606
260.352

db<>fiddle


问:
.split() returns list of individual charachters instead of splitting it as the spaces
```<code>n = input("input n: ")
n.split()
print(n, len(n))
</code>```

Say the input is: 100 400, seperated by a space, .split() returns a list of all the individual digits, as well as the space between them, instead of the two numbers such that len(n) = 7, and n[0] = 1 instead of 100.

答:
If you want to split a string by spaces use</p>
```<code>n.split(' ')
</code>```

Body:
n = input("input n: ")
n.split()
print(n, len(n))

Say the input is: 100 400, seperated by a space, .split() returns a list of all the individual digits, as well as the space between them, instead of the two numbers such that len(n) = 7, and n[0] = 1 instead of 100.

Body:
If you want to split a string by spaces use

n.split(' ')