问:
TableFilter library not working if there's toggle row with colspan
I have here a table with toggle row and it works fine with jquery and bootstrap 4

```<code><table class="table" id="myTable">
  <tr>
    <th>Toggle</th>
    <th>Name</th>
    <th>Company</th>
    <th>Country</th>
  </tr>
  <tr>
    <td><button data-toggle="collapse" data-target="#collapse1" aria-expanded="false" aria-controls="collapse1">Toggle</button></td>
    <td>Maria Anders</td>
    <td>Alfreds Futterkiste</td>
    <td>Germany</td>
  </tr>
  <tr class="collapse" id="collapse1">
    <td colspan="4"><strong>Maria Anders' Description</strong></td>
  </tr>
  <tr>
    <td><button data-toggle="collapse" data-target="#collapse2" aria-expanded="false" aria-controls="collapse2">Toggle</button></td>
    <td>Francisco Chang</td>
    <td>Centro comercial Moctezuma</td>
    <td>Mexico</td>
  </tr>
  <tr class="collapse" id="collapse2">
    <td colspan="4"><strong>Francisco Chang's Description</strong></td>
  </tr>
  <tr>
    <td><button data-toggle="collapse" data-target="#collapse3" aria-expanded="false" aria-controls="collapse3">Toggle</button></td>
    <td>Roland Mendel</td>
    <td>Ernst Handel</td>
    <td>Austria</td>
  </tr>
  <tr class="collapse" id="collapse3">
    <td colspan="4"><strong>Roland Mendel's Description</strong></td>
  </tr>
  <tr>
    <td><button data-toggle="collapse" data-target="#collapse4" aria-expanded="false" aria-controls="collapse4">Toggle</button></td>
    <td>Helen Bennett</td>
    <td>Island Trading</td>
    <td>UK</td>
  </tr>
  <tr class="collapse" id="collapse4">
    <td colspan="4"><strong>Helen Bennett's Description</strong></td>
  </tr>
  <tr>
    <td><button data-toggle="collapse" data-target="#collapse5" aria-expanded="false" aria-controls="collapse5">Toggle</button></td>
    <td>Yoshi Tannamuri</td>
    <td>Laughing Bacchus Winecellars</td>
    <td>Canada</td>
  </tr>
  <tr class="collapse" id="collapse5">
    <td colspan="4"><strong>Yoshi Tannamuri's Description</strong></td>
  </tr>
</table>
</code>```

Now, I added the TableFilter Library and here's the configuration

```<code>// Add configuration t the filters that shall be initialized
var filtersConfig = {
  base_path: "https://rawgit.com/koalyptus/TableFilter/master/dist/tablefilter/",
  popup_filters: true,
  col_0: 'none',
  col_1: 'checklist',
  col_2: 'none',
  col_3: 'checklist',
};
var tf = new TableFilter('myTable', filtersConfig);
tf.init();
</code>```

But, the TableFilter doesn't work and I think because of the colspan on the second row. Why does it happen? And, what's the best solution?

Here's the fiddle where the filter doesn't work: https://jsfiddle.net/f9uzxsqj/

Here's the fiddle where the filter works by adding hidden empty row as the first row: (I'm confused why this works) https://jsfiddle.net/f9uzxsqj/1/

Body:
I have here a table with toggle row and it works fine with jquery and bootstrap 4

    Toggle
    Name
    Company
    Country

    <button data-toggle="collapse" data-target="#collapse1" aria-expanded="false" aria-controls="collapse1">Toggle</button>
    Maria Anders
    Alfreds Futterkiste
    Germany

    Maria Anders' Description

    <button data-toggle="collapse" data-target="#collapse2" aria-expanded="false" aria-controls="collapse2">Toggle</button>
    Francisco Chang
    Centro comercial Moctezuma
    Mexico

    Francisco Chang's Description

    <button data-toggle="collapse" data-target="#collapse3" aria-expanded="false" aria-controls="collapse3">Toggle</button>
    Roland Mendel
    Ernst Handel
    Austria

    Roland Mendel's Description

    <button data-toggle="collapse" data-target="#collapse4" aria-expanded="false" aria-controls="collapse4">Toggle</button>
    Helen Bennett
    Island Trading
    UK

    Helen Bennett's Description

    <button data-toggle="collapse" data-target="#collapse5" aria-expanded="false" aria-controls="collapse5">Toggle</button>
    Yoshi Tannamuri
    Laughing Bacchus Winecellars
    Canada

    Yoshi Tannamuri's Description

Now, I added the TableFilter Library and here's the configuration

// Add configuration t the filters that shall be initialized
var filtersConfig = {
  base_path: "https://rawgit.com/koalyptus/TableFilter/master/dist/tablefilter/",
  popup_filters: true,
  col_0: 'none',
  col_1: 'checklist',
  col_2: 'none',
  col_3: 'checklist',
};
var tf = new TableFilter('myTable', filtersConfig);
tf.init();

But, the TableFilter doesn't work and I think because of the colspan on the second row. Why does it happen? And, what's the best solution?

Here's the fiddle where the filter doesn't work: https://jsfiddle.net/f9uzxsqj/

Here's the fiddle where the filter works by adding hidden empty row as the first row: (I'm confused why this works) https://jsfiddle.net/f9uzxsqj/1/


来源: stackexchange

问:
Tidymodels: Nested Dataset and Hyperparameter Tuning
I am working on a classification model to predict building age. I want to train my random forest models by groups (suburbs) within the larger dataset.

I've used this as the basis of the code below.

My question is - how should I write the code to train and record the hyperparameters for each suburb?

```<code>age.rf <- rand_forest(
  mtry = tune(),
  trees = tune(),
  min_n = tune()) %>%
  set_mode("classification") %>%
  set_engine("ranger")

age.workflow <- workflow() %>%
  add_model(age.rf)

### function for model fitting and predicting
age.predict <- function(df) {

  # split the dataset
  set.seed(1)
  split <- initial_split(df)
  train_df <- training(df)
  test_df <- testing(df)

  # create recipe
  age.recipe <- recipe(decade_built ~ .,
                       data = train_df) %>%
    update_role(bld_index, new_role = "ID") %>%
    step_dummy(all_nominal_predictors(), -has_role("ID")) %>%
    step_zv(all_predictors()) %>%
    step_normalize(all_numeric_predictors()) %>%
    prep()

  # hyperparameters
  age.randgrid_rf <- grid_random(mtry(c(1,20)),
                               trees(),
                               min_n(),
                               size = 10)

  ctrl <- control_grid(save_pred = T, extract = extract_model)
  age_folds <- vfold_cv(train_df, strata = "suburb", v = 10)

  age.tunerandom_rf <- age.workflow %>%
    tune_grid(resamples = age_folds,
              grid = age.randgrid_rf,
              control = ctrl)

  # best parameters
  age.params_rf <- select_best(age.tunerandom_rf)

  # finalise model
  age.final_rf <- finalize_model(age.spec_rf, age.params_rf)
  age.workflowfinal_rf <- workflow() %>%
    add_recipe(age.recipe) %>%
    add_model(age.final_rf)

  # predict on test data
  predict(age.workflowfinal_rf, test_df)
  }

age_nested <- final.df %>%
  group_by(suburb) %>%
  nest()

age.preds <- age_nested %>%
  mutate(prediction = map(data, possibly(age.predict, otherwise = NA)))
</code>```

I've mapped out the dataset using the nest() function, and followed the workflow based on Julia's post on another page.

Any help to identify how to get the hyperparameters, as well as apply them to the individual models for each group would be much appreciated.

At the moment, my output is NA.

ContentLicense: CC BY-SA 4.0

Body:
I am working on a classification model to predict building age. I want to train my random forest models by groups (suburbs) within the larger dataset.

I've used this as the basis of the code below.

My question is - how should I write the code to train and record the hyperparameters for each suburb?

age.rf <- rand_forest(
  mtry = tune(),
  trees = tune(),
  min_n = tune()) %>%
  set_mode("classification") %>%
  set_engine("ranger")

age.workflow <- workflow() %>%
  add_model(age.rf)

### function for model fitting and predicting
age.predict <- function(df) {

  # split the dataset
  set.seed(1)
  split <- initial_split(df)
  train_df <- training(df)
  test_df <- testing(df)

  # create recipe
  age.recipe <- recipe(decade_built ~ .,
                       data = train_df) %>%
    update_role(bld_index, new_role = "ID") %>%
    step_dummy(all_nominal_predictors(), -has_role("ID")) %>%
    step_zv(all_predictors()) %>%
    step_normalize(all_numeric_predictors()) %>%
    prep()

  # hyperparameters
  age.randgrid_rf <- grid_random(mtry(c(1,20)),
                               trees(),
                               min_n(),
                               size = 10)

  ctrl <- control_grid(save_pred = T, extract = extract_model)
  age_folds <- vfold_cv(train_df, strata = "suburb", v = 10)

  age.tunerandom_rf <- age.workflow %>%
    tune_grid(resamples = age_folds,
              grid = age.randgrid_rf,
              control = ctrl)

  # best parameters
  age.params_rf <- select_best(age.tunerandom_rf)

  # finalise model
  age.final_rf <- finalize_model(age.spec_rf, age.params_rf)
  age.workflowfinal_rf <- workflow() %>%
    add_recipe(age.recipe) %>%
    add_model(age.final_rf)

  # predict on test data
  predict(age.workflowfinal_rf, test_df)
  }

age_nested <- final.df %>%
  group_by(suburb) %>%
  nest()

age.preds <- age_nested %>%
  mutate(prediction = map(data, possibly(age.predict, otherwise = NA)))

I've mapped out the dataset using the nest() function, and followed the workflow based on Julia's post on another page.

Any help to identify how to get the hyperparameters, as well as apply them to the individual models for each group would be much appreciated.

At the moment, my output is NA.


问:
GridSearchCV() vs TrainTestSplit() in sklearn - different scores?
I have the following code I have a question about. I use GridSearchCV() to get the best  parameters. I use the parameters received from the GridSearchCV() and input it into GradientBoostingClassifer(). I get different scores for AUC however even though I have a random seed. Does anyone know why this is the case? Does it have to do with how things are split in GridSearch vs TrainTestSplit?</p>
```<code>gb = GradientBoostingClassifier(random_state = 0)
search3 = GridSearchCV(gb,
                       param_grid = param_grid,
                       cv =  3,
                       scoring = 'roc_auc',
                       verbose = True,
                       n_jobs = -1)
search3.fit(X_train, y_train)

print('Best score: {}'.format(search3.best_score_))
print('Best params: {}'.format(search3.best_params_))

clf = GradientBoostingClassifier(learning_rate = 1,
                                 max_depth = 5,
                                 n_estimators = 500,
                                 random_state = 0).fit(X_train, y_train)
print('AUC Score:', roc_auc_score(y_test, clf.predict_proba(X_test)[:,1]))

</code>```

Body:
I have the following code I have a question about. I use GridSearchCV() to get the best  parameters. I use the parameters received from the GridSearchCV() and input it into GradientBoostingClassifer(). I get different scores for AUC however even though I have a random seed. Does anyone know why this is the case? Does it have to do with how things are split in GridSearch vs TrainTestSplit?

gb = GradientBoostingClassifier(random_state = 0)
search3 = GridSearchCV(gb,
                       param_grid = param_grid,
                       cv =  3,
                       scoring = 'roc_auc',
                       verbose = True,
                       n_jobs = -1)
search3.fit(X_train, y_train)

print('Best score: {}'.format(search3.best_score_))
print('Best params: {}'.format(search3.best_params_))

clf = GradientBoostingClassifier(learning_rate = 1,
                                 max_depth = 5,
                                 n_estimators = 500,
                                 random_state = 0).fit(X_train, y_train)
print('AUC Score:', roc_auc_score(y_test, clf.predict_proba(X_test)[:,1]))


问:
Does anyone know the python code to do in the crud (windows) name eligible
I am making a crud with windows in tkinter, only that in my system they ask me that they are already default names since they will always be the same. What are the lines of code that are used to make that?

Currently I have no idea how to do that. [Here are eligible names that are already fixed]


问:
Validation issue on JSON schema #jsonschema
enter image description hereI am trying to create a JSON schema which is expecting inputs from 3 sources (file/Table/Kafka message), at a time any one of them will get the data from external source.

Issue :
I am using "anyOf" keyword in JSON but when I am applying "anyOf" and testing the negative scenario that is removing one of required field from the input properties, it's not giving any validation error, which ideally should have given that required field is missing.

**Expectation: **

Need to get input from any one of the source (file/table/message). If external party sends data in the file format, file portion from JSON schema should get executed, similarly if gets data from table or kafka message then relevant portion from JSON schema should get executed.

JSON SCHEMA CODE:

```{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "type": "object",
    "title": "Job",
    "properties": {
        "unique_name": {
            "type": "string",
            "format": "regex",
            "pattern": "[a-zA-Z0-9_]+"
        },
        "processing_instructions_file": {
            "type": "string",
            "examples": [
                "/path/to/some/file/processing123.yaml"
            ]
        },
        "variables": {
            "type": "array",
            "additionalItems": true,
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "examples": [
                            "environment_prefix"
                        ]
                    },
                    "value": {
                        "type": "string",
                        "examples": [
                            "DEV"
                        ]
                    }
                },
                "additionalProperties": true,
                "required": [
                    "name",
                    "value"
                ]
            }
        },
        "inputs": {
            "type": "array",
            "additionalItems": true,
            "items": {
                "type": "object",
                "properties": {
                    "is_stream": {
                        "type": "boolean",
                        "examples": [
                            true
                        ],
                        "default": false
                    }
                },
                "additionalProperties": true,
                "anyOf": [
                    {
                        "type": "object",
                        "properties": {
                            "file": {
                                "type": "object",
                                "properties": {
                                    "folder_structure": {
                                        "type": "string",
                                        "examples": [
                                            "$environment_prefix\\$$yyyy-MMM-dd"
                                        ]
                                    },
                                    "naming_convention": {
                                        "type": "string",
                                        "examples": [
                                            "STATIC_FILE_NAME:$$yyyy_MMM-dd"
                                        ]
                                    },
                                    "format type": {
                                        "type": "string",
                                        "enum": [
                                            "CSV",
                                            "EBCDIC"
                                        ],
                                        "examples": [
                                            "CSV"
                                        ]
                                    },
                                    "format_options": {
                                        "type": "array",
                                        "additionalItems": true,
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "option_name": {
                                                    "type": "string",
                                                    "examples": [
                                                        "generate_record_id"
                                                    ]
                                                },
                                                "option_value": {
                                                    "type": [
                                                        "string",
                                                        "boolean"
                                                    ],
                                                    "examples": [
                                                        true
                                                    ]
                                                }
                                            },
                                            "additionalProperties": true,
                                            "required": [
                                                "option_name",
                                                "option_value"
                                            ]
                                        }
                                    }
                                },
                                "additionalProperties": true,
                                "if": {
                                    "properties": {
                                        "format type": {
                                            "type": "string",
                                            "enum": [
                                                "CSV",
                                                "EBCDIC"
                                            ],
                                            "examples": [
                                                "CSV"
                                            ],
                                            "const": "EBCDIC"
                                        }
                                    },
                                    "required": [
                                        "format type"
                                    ]
                                },
                                "then": {
                                    "properties": {
                                        "schema_location": {
                                            "type": "string",
                                            "examples": [
                                                "some_path"
                                            ]
                                        }
                                    },
                                    "required": [
                                        "schema_location"
                                    ]
                                },
                                "else": {
                                    "properties": {
                                        "schema_location": {
                                            "type": "string",
                                            "examples": [
                                                "some_path"
                                            ]
                                        }
                                    }
                                },
                                "required": [
                                    "folder_structure",
                                    "naming_convention",
                                    "format type",
                                    "format_options"
                                ]
                            }
                        },
                        "additionalProperties": true
                    },
                    {
                        "type": "object",
                        "properties": {
                            "table": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "examples": [
                                            "tbl_employees"
                                        ]
                                    },
                                    "jdbc_url": {
                                        "type": "string",
                                        "examples": [
                                            "orcl@thinXXX"
                                        ]
                                    },
                                    "jdbc_library_jar": {
                                        "type": "string",
                                        "examples": [
                                            "orcl.jar"
                                        ]
                                    },
                                    "schema": {
                                        "type": "string",
                                        "examples": [
                                            "xxxxx"
                                        ]
                                    },
                                    "info_date_from_column_name": {
                                        "type": "string",
                                        "examples": [
                                            "ASOF_DATE"
                                        ]
                                    },
                                    "info_date_to_column_name": {
                                        "type": "string",
                                        "examples": [
                                            "END_DATE"
                                        ]
                                    },
                                    "primary_key_column_name": {
                                        "type": "array",
                                        "additionalItems": true,
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "additionalProperties": true,
                                "required": [
                                    "name",
                                    "jdbc_url",
                                    "schema"
                                ]
                            }
                        },
                        "additionalProperties": true
                    },
                    {
                        "type": "object",
                        "properties": {
                            "message": {
                                "type": "object",
                                "properties": {
                                    "topic_name": {
                                        "type": "string",
                                        "examples": [
                                            "XXXXXX"
                                        ]
                                    },
                                    "group_id": {
                                        "type": "string",
                                        "examples": [
                                            "XXXXX"
                                        ]
                                    },
                                    "port": {
                                        "type": "integer",
                                        "examples": [
                                            8081
                                        ]
                                    },
                                    "kafka_cluster_ip": {
                                        "type": "string",
                                        "examples": [
                                            "1.1.1.1"
                                        ]
                                    },
                                    "kafka_cluster_schema_registry": {
                                        "type": "string",
                                        "examples": [
                                            "1.1.1.1"
                                        ]
                                    }
                                },
                                "additionalProperties": true,
                                "required": [
                                    "topic_name",
                                    "group_id",
                                    "port",
                                    "kafka_cluster_ip",
                                    "kafka_cluster_schema_registry"
                                ]
                            }
                        },
                        "additionalProperties": true
                    }
                ]
            }
        },
        "outputs": {
            "type": "array",
            "additionalItems": true,
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "examples": [
                            "output_3"
                        ]
                    },
                    "is_stream": {
                        "type": "boolean",
                        "examples": [
                            true
                        ]
                    },
                    "spark_save_mode": {
                        "type": "string",
                        "examples": [
                            "append"
                        ]
                    },
                    "file": {
                        "type": "object",
                        "properties": {
                            "root_path": {
                                "type": "string",
                                "examples": [
                                    "some_path"
                                ]
                            },
                            "folder_structure": {
                                "type": "string",
                                "examples": [
                                    "$environment_prefix\\$$yyyy-MMM-dd"
                                ]
                            },
                            "naming_convention": {
                                "type": "string",
                                "examples": [
                                    "STATIC_FILE_NAME:$$yyyy_MMM-dd"
                                ]
                            },
                            "partition_by": {
                                "type": "array",
                                "additionalItems": true,
                                "items": {
                                    "type": "string"
                                }
                            },
                            "format": {
                                "type": "object",
                                "properties": {
                                    "format_type": {
                                        "type": "string",
                                        "examples": [
                                            "CSV"
                                        ]
                                    },
                                    "format_options": {
                                        "type": "array",
                                        "additionalItems": true,
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "option_name": {
                                                    "type": "string",
                                                    "examples": [
                                                        "include_header"
                                                    ]
                                                },
                                                "option_value": {
                                                    "type": [
                                                        "string",
                                                        "boolean"
                                                    ],
                                                    "examples": [
                                                        true
                                                    ]
                                                }
                                            },
                                            "additionalProperties": true,
                                            "required": [
                                                "option_name",
                                                "option_value"
                                            ]
                                        }
                                    }
                                },
                                "additionalProperties": true,
                                "required": [
                                    "format_type",
                                    "format_options"
                                ]
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "root_path",
                            "folder_structure",
                            "naming_convention",
                            "partition_by",
                            "format"
                        ]
                    },
                    "mongo": {
                        "type": "object",
                        "properties": {
                            "mongo_spark_connector_options": {
                                "type": "array",
                                "additionalItems": true,
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "option_name": {
                                            "type": "string",
                                            "examples": [
                                                "format"
                                            ]
                                        },
                                        "option_value": {
                                            "type": "string"
                                        }
                                    },
                                    "additionalProperties": true,
                                    "required": [
                                        "option_name",
                                        "option_value"
                                    ]
                                }
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "mongo_spark_connector_options"
                        ]
                    },
                    "table": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "examples": [
                                    "tbl_employees"
                                ]
                            },
                            "jdbc_url": {
                                "type": "string",
                                "examples": [
                                    "orcl@thin:XXX"
                                ]
                            },
                            "jdbc_library_jar": {
                                "type": "string",
                                "examples": [
                                    "orcl.jar"
                                ]
                            },
                            "schema": {
                                "type": "string",
                                "examples": [
                                    "xxxxx"
                                ]
                            },
                            "info_date_from_column_name": {
                                "type": "string",
                                "examples": [
                                    "ASOF_DATE"
                                ]
                            },
                            "info_date_to_column_name": {
                                "type": "string",
                                "examples": [
                                    "END_DATE"
                                ]
                            },
                            "primary_key_column_name": {
                                "type": "array",
                                "additionalItems": true,
                                "items": {
                                    "type": "string"
                                }
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "name",
                            "jdbc_url",
                            "jdbc_library_jar",
                            "schema",
                            "info_date_from_column_name",
                            "info_date_to_column_name",
                            "primary_key_column_name"
                        ]
                    },
                    "message": {
                        "type": "object",
                        "properties": {
                            "topic_name": {
                                "type": "string",
                                "examples": [
                                    "XXXXXX"
                                ]
                            },
                            "group_id": {
                                "type": "string",
                                "examples": [
                                    "XXXXX"
                                ]
                            },
                            "port": {
                                "type": "integer",
                                "examples": [
                                    8081
                                ]
                            },
                            "kafka_cluster_ip": {
                                "type": "string",
                                "examples": [
                                    "1.1.1.1"
                                ]
                            },
                            "kafka_cluster_schema_registry": {
                                "type": "string",
                                "examples": [
                                    "1.1.1.1"
                                ]
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "topic_name",
                            "group_id",
                            "port",
                            "kafka_cluster_ip",
                            "kafka_cluster_schema_registry"
                        ]
                    }
                },
                "additionalProperties": true,
                "required": [
                    "name",
                    "is_stream"
                ]
            }
        }
    },
    "additionalProperties": true,
    "required": [
        "unique_name",
        "processing_instructions_file",
        "inputs",
        "outputs"
    ]
}
```
<p>JSON DATA</p>
```{
    "unique_name": "aXeTGImcM6PrCalRpGjLigbj1puXXvK",
    "processing_instructions_file": "/path/to/some/file/processing123.yaml",
    "variables": [
        {
            "name": "environment_prefix",
            "value": "DEV"
        }
    ],
    "inputs": [
        {
            "is_stream": false,
            "file": {
                "folder_structure": "$environment_prefix\\$$yyyy-MMM-dd",
                "naming_convention": "STATIC_FILE_NAME:$$yyyy_MMM-dd",
                "format type": "CSV",
                "format_options": [
                    {
                        "option_name": "generate_record_id",
                        "option_value": "Lorem"
                    }
                ],
                "schema_location": "some_path"
            }
        }
    ],
    "outputs": [
        {
            "name": "output_3",
            "is_stream": true,
            "spark_save_mode": "append",
            "file": {
                "root_path": "some_path",
                "folder_structure": "$environment_prefix\\$$yyyy-MMM-dd",
                "naming_convention": "STATIC_FILE_NAME:$$yyyy_MMM-dd",
                "partition_by": [
                    "Lorem"
                ],
                "format": {
                    "format_type": "CSV",
                    "format_options": [
                        {
                            "option_name": "include_header",
                            "option_value": "Lorem"
                        }
                    ]
                }
            },
            "mongo": {
                "mongo_spark_connector_options": [
                    {
                        "option_name": "format",
                        "option_value": "Lorem"
                    }
                ]
            },
            "table": {
                "name": "tbl_employees",
                "jdbc_url": "orcl@thin:XXX",
                "jdbc_library_jar": "orcl.jar",
                "schema": "xxxxx",
                "info_date_from_column_name": "ASOF_DATE",
                "info_date_to_column_name": "END_DATE",
                "primary_key_column_name": [
                    "Lorem"
                ]
            },
            "message": {
                "topic_name": "XXXXXX",
                "group_id": "XXXXX",
                "port": 8081,
                "kafka_cluster_ip": "1.1.1.1",
                "kafka_cluster_schema_registry": "1.1.1.1"
            }
        }
    ]
}
```

Body:
enter image description hereI am trying to create a JSON schema which is expecting inputs from 3 sources (file/Table/Kafka message), at a time any one of them will get the data from external source.

Issue :
I am using "anyOf" keyword in JSON but when I am applying "anyOf" and testing the negative scenario that is removing one of required field from the input properties, it's not giving any validation error, which ideally should have given that required field is missing.

**Expectation: **

Need to get input from any one of the source (file/table/message). If external party sends data in the file format, file portion from JSON schema should get executed, similarly if gets data from table or kafka message then relevant portion from JSON schema should get executed.

JSON SCHEMA CODE:

{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "type": "object",
    "title": "Job",
    "properties": {
        "unique_name": {
            "type": "string",
            "format": "regex",
            "pattern": "[a-zA-Z0-9_]+"
        },
        "processing_instructions_file": {
            "type": "string",
            "examples": [
                "/path/to/some/file/processing123.yaml"
            ]
        },
        "variables": {
            "type": "array",
            "additionalItems": true,
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "examples": [
                            "environment_prefix"
                        ]
                    },
                    "value": {
                        "type": "string",
                        "examples": [
                            "DEV"
                        ]
                    }
                },
                "additionalProperties": true,
                "required": [
                    "name",
                    "value"
                ]
            }
        },
        "inputs": {
            "type": "array",
            "additionalItems": true,
            "items": {
                "type": "object",
                "properties": {
                    "is_stream": {
                        "type": "boolean",
                        "examples": [
                            true
                        ],
                        "default": false
                    }
                },
                "additionalProperties": true,
                "anyOf": [
                    {
                        "type": "object",
                        "properties": {
                            "file": {
                                "type": "object",
                                "properties": {
                                    "folder_structure": {
                                        "type": "string",
                                        "examples": [
                                            "$environment_prefix\\$$yyyy-MMM-dd"
                                        ]
                                    },
                                    "naming_convention": {
                                        "type": "string",
                                        "examples": [
                                            "STATIC_FILE_NAME:$$yyyy_MMM-dd"
                                        ]
                                    },
                                    "format type": {
                                        "type": "string",
                                        "enum": [
                                            "CSV",
                                            "EBCDIC"
                                        ],
                                        "examples": [
                                            "CSV"
                                        ]
                                    },
                                    "format_options": {
                                        "type": "array",
                                        "additionalItems": true,
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "option_name": {
                                                    "type": "string",
                                                    "examples": [
                                                        "generate_record_id"
                                                    ]
                                                },
                                                "option_value": {
                                                    "type": [
                                                        "string",
                                                        "boolean"
                                                    ],
                                                    "examples": [
                                                        true
                                                    ]
                                                }
                                            },
                                            "additionalProperties": true,
                                            "required": [
                                                "option_name",
                                                "option_value"
                                            ]
                                        }
                                    }
                                },
                                "additionalProperties": true,
                                "if": {
                                    "properties": {
                                        "format type": {
                                            "type": "string",
                                            "enum": [
                                                "CSV",
                                                "EBCDIC"
                                            ],
                                            "examples": [
                                                "CSV"
                                            ],
                                            "const": "EBCDIC"
                                        }
                                    },
                                    "required": [
                                        "format type"
                                    ]
                                },
                                "then": {
                                    "properties": {
                                        "schema_location": {
                                            "type": "string",
                                            "examples": [
                                                "some_path"
                                            ]
                                        }
                                    },
                                    "required": [
                                        "schema_location"
                                    ]
                                },
                                "else": {
                                    "properties": {
                                        "schema_location": {
                                            "type": "string",
                                            "examples": [
                                                "some_path"
                                            ]
                                        }
                                    }
                                },
                                "required": [
                                    "folder_structure",
                                    "naming_convention",
                                    "format type",
                                    "format_options"
                                ]
                            }
                        },
                        "additionalProperties": true
                    },
                    {
                        "type": "object",
                        "properties": {
                            "table": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "examples": [
                                            "tbl_employees"
                                        ]
                                    },
                                    "jdbc_url": {
                                        "type": "string",
                                        "examples": [
                                            "orcl@thinXXX"
                                        ]
                                    },
                                    "jdbc_library_jar": {
                                        "type": "string",
                                        "examples": [
                                            "orcl.jar"
                                        ]
                                    },
                                    "schema": {
                                        "type": "string",
                                        "examples": [
                                            "xxxxx"
                                        ]
                                    },
                                    "info_date_from_column_name": {
                                        "type": "string",
                                        "examples": [
                                            "ASOF_DATE"
                                        ]
                                    },
                                    "info_date_to_column_name": {
                                        "type": "string",
                                        "examples": [
                                            "END_DATE"
                                        ]
                                    },
                                    "primary_key_column_name": {
                                        "type": "array",
                                        "additionalItems": true,
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "additionalProperties": true,
                                "required": [
                                    "name",
                                    "jdbc_url",
                                    "schema"
                                ]
                            }
                        },
                        "additionalProperties": true
                    },
                    {
                        "type": "object",
                        "properties": {
                            "message": {
                                "type": "object",
                                "properties": {
                                    "topic_name": {
                                        "type": "string",
                                        "examples": [
                                            "XXXXXX"
                                        ]
                                    },
                                    "group_id": {
                                        "type": "string",
                                        "examples": [
                                            "XXXXX"
                                        ]
                                    },
                                    "port": {
                                        "type": "integer",
                                        "examples": [
                                            8081
                                        ]
                                    },
                                    "kafka_cluster_ip": {
                                        "type": "string",
                                        "examples": [
                                            "1.1.1.1"
                                        ]
                                    },
                                    "kafka_cluster_schema_registry": {
                                        "type": "string",
                                        "examples": [
                                            "1.1.1.1"
                                        ]
                                    }
                                },
                                "additionalProperties": true,
                                "required": [
                                    "topic_name",
                                    "group_id",
                                    "port",
                                    "kafka_cluster_ip",
                                    "kafka_cluster_schema_registry"
                                ]
                            }
                        },
                        "additionalProperties": true
                    }
                ]
            }
        },
        "outputs": {
            "type": "array",
            "additionalItems": true,
            "items": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string",
                        "examples": [
                            "output_3"
                        ]
                    },
                    "is_stream": {
                        "type": "boolean",
                        "examples": [
                            true
                        ]
                    },
                    "spark_save_mode": {
                        "type": "string",
                        "examples": [
                            "append"
                        ]
                    },
                    "file": {
                        "type": "object",
                        "properties": {
                            "root_path": {
                                "type": "string",
                                "examples": [
                                    "some_path"
                                ]
                            },
                            "folder_structure": {
                                "type": "string",
                                "examples": [
                                    "$environment_prefix\\$$yyyy-MMM-dd"
                                ]
                            },
                            "naming_convention": {
                                "type": "string",
                                "examples": [
                                    "STATIC_FILE_NAME:$$yyyy_MMM-dd"
                                ]
                            },
                            "partition_by": {
                                "type": "array",
                                "additionalItems": true,
                                "items": {
                                    "type": "string"
                                }
                            },
                            "format": {
                                "type": "object",
                                "properties": {
                                    "format_type": {
                                        "type": "string",
                                        "examples": [
                                            "CSV"
                                        ]
                                    },
                                    "format_options": {
                                        "type": "array",
                                        "additionalItems": true,
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "option_name": {
                                                    "type": "string",
                                                    "examples": [
                                                        "include_header"
                                                    ]
                                                },
                                                "option_value": {
                                                    "type": [
                                                        "string",
                                                        "boolean"
                                                    ],
                                                    "examples": [
                                                        true
                                                    ]
                                                }
                                            },
                                            "additionalProperties": true,
                                            "required": [
                                                "option_name",
                                                "option_value"
                                            ]
                                        }
                                    }
                                },
                                "additionalProperties": true,
                                "required": [
                                    "format_type",
                                    "format_options"
                                ]
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "root_path",
                            "folder_structure",
                            "naming_convention",
                            "partition_by",
                            "format"
                        ]
                    },
                    "mongo": {
                        "type": "object",
                        "properties": {
                            "mongo_spark_connector_options": {
                                "type": "array",
                                "additionalItems": true,
                                "items": {
                                    "type": "object",
                                    "properties": {
                                        "option_name": {
                                            "type": "string",
                                            "examples": [
                                                "format"
                                            ]
                                        },
                                        "option_value": {
                                            "type": "string"
                                        }
                                    },
                                    "additionalProperties": true,
                                    "required": [
                                        "option_name",
                                        "option_value"
                                    ]
                                }
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "mongo_spark_connector_options"
                        ]
                    },
                    "table": {
                        "type": "object",
                        "properties": {
                            "name": {
                                "type": "string",
                                "examples": [
                                    "tbl_employees"
                                ]
                            },
                            "jdbc_url": {
                                "type": "string",
                                "examples": [
                                    "orcl@thin:XXX"
                                ]
                            },
                            "jdbc_library_jar": {
                                "type": "string",
                                "examples": [
                                    "orcl.jar"
                                ]
                            },
                            "schema": {
                                "type": "string",
                                "examples": [
                                    "xxxxx"
                                ]
                            },
                            "info_date_from_column_name": {
                                "type": "string",
                                "examples": [
                                    "ASOF_DATE"
                                ]
                            },
                            "info_date_to_column_name": {
                                "type": "string",
                                "examples": [
                                    "END_DATE"
                                ]
                            },
                            "primary_key_column_name": {
                                "type": "array",
                                "additionalItems": true,
                                "items": {
                                    "type": "string"
                                }
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "name",
                            "jdbc_url",
                            "jdbc_library_jar",
                            "schema",
                            "info_date_from_column_name",
                            "info_date_to_column_name",
                            "primary_key_column_name"
                        ]
                    },
                    "message": {
                        "type": "object",
                        "properties": {
                            "topic_name": {
                                "type": "string",
                                "examples": [
                                    "XXXXXX"
                                ]
                            },
                            "group_id": {
                                "type": "string",
                                "examples": [
                                    "XXXXX"
                                ]
                            },
                            "port": {
                                "type": "integer",
                                "examples": [
                                    8081
                                ]
                            },
                            "kafka_cluster_ip": {
                                "type": "string",
                                "examples": [
                                    "1.1.1.1"
                                ]
                            },
                            "kafka_cluster_schema_registry": {
                                "type": "string",
                                "examples": [
                                    "1.1.1.1"
                                ]
                            }
                        },
                        "additionalProperties": true,
                        "required": [
                            "topic_name",
                            "group_id",
                            "port",
                            "kafka_cluster_ip",
                            "kafka_cluster_schema_registry"
                        ]
                    }
                },
                "additionalProperties": true,
                "required": [
                    "name",
                    "is_stream"
                ]
            }
        }
    },
    "additionalProperties": true,
    "required": [
        "unique_name",
        "processing_instructions_file",
        "inputs",
        "outputs"
    ]
}

JSON DATA

{
    "unique_name": "aXeTGImcM6PrCalRpGjLigbj1puXXvK",
    "processing_instructions_file": "/path/to/some/file/processing123.yaml",
    "variables": [
        {
            "name": "environment_prefix",
            "value": "DEV"
        }
    ],
    "inputs": [
        {
            "is_stream": false,
            "file": {
                "folder_structure": "$environment_prefix\\$$yyyy-MMM-dd",
                "naming_convention": "STATIC_FILE_NAME:$$yyyy_MMM-dd",
                "format type": "CSV",
                "format_options": [
                    {
                        "option_name": "generate_record_id",
                        "option_value": "Lorem"
                    }
                ],
                "schema_location": "some_path"
            }
        }
    ],
    "outputs": [
        {
            "name": "output_3",
            "is_stream": true,
            "spark_save_mode": "append",
            "file": {
                "root_path": "some_path",
                "folder_structure": "$environment_prefix\\$$yyyy-MMM-dd",
                "naming_convention": "STATIC_FILE_NAME:$$yyyy_MMM-dd",
                "partition_by": [
                    "Lorem"
                ],
                "format": {
                    "format_type": "CSV",
                    "format_options": [
                        {
                            "option_name": "include_header",
                            "option_value": "Lorem"
                        }
                    ]
                }
            },
            "mongo": {
                "mongo_spark_connector_options": [
                    {
                        "option_name": "format",
                        "option_value": "Lorem"
                    }
                ]
            },
            "table": {
                "name": "tbl_employees",
                "jdbc_url": "orcl@thin:XXX",
                "jdbc_library_jar": "orcl.jar",
                "schema": "xxxxx",
                "info_date_from_column_name": "ASOF_DATE",
                "info_date_to_column_name": "END_DATE",
                "primary_key_column_name": [
                    "Lorem"
                ]
            },
            "message": {
                "topic_name": "XXXXXX",
                "group_id": "XXXXX",
                "port": 8081,
                "kafka_cluster_ip": "1.1.1.1",
                "kafka_cluster_schema_registry": "1.1.1.1"
            }
        }
    ]
}


问:
Is it faster to get data from a wordpress database using a REST API or WP_Query
I have posts in a custom table on a WordPress setup. I am currently fetching the data using WP_Query but I was wondering if it would make sense to create different custom endpoints to fetch the data back as JSON? Which way is better for performance and also how is caching handled for each?


问:
I switched from CRA to Vite. Accessing via Browser from another computer on the same network is not working
I have two laptops. On laptop1 I run CRA or Vite. On laptop2 I have an open Browser

Before, when I used create-react-app...  I could use laptop2 to access the project via lap.top.1.ip:3000

But if I do the same with vite it throws a time-out error: lap.top.1.ip:5173

I think that the problem has to do with vite.config.js
https://vitejs.dev/config/server-options.html

But I just don't know enough to make vite to work: "Specify which IP addresses the server should listen on"

Can someone provide some help? Thank you

I haven't tried anything, I'm just starting with vite. First time using it


问:
How can I add this timer to my javascript game?
I found this timer code but I don't know how to implement it in my javascript game. I'm also trying to include everything in one file. This is the timer code below.

HTML:
You have: 0 seconds remaining!

<button id="playAgainButton" onclick="start()">Go!</button>

javascript:

```<code>var timer;
var timeLeft = 60; // seconds

// What to do when the timer runs out
function gameOver() {
  // This cancels the setInterval, so the updateTimer stops getting called
  cancelInterval(timer);

  // re-show the button, so they can start it again
  $('#playAgainButton').show();
}

function updateTimer() {
  timeLeft = timeLeft - 1;
  if(timeLeft >= 0)
    $('#timer').html(timeLeft);
  else {
    gameOver();
  }
}

// The button has an on-click event handler that calls this
function start() {
  // setInterval is a built-in function that will call the given function
  // every N milliseconds (1 second = 1000 ms)
  timer = setInterval(updateTimer, 1000);

  // It will be a whole second before the time changes, so we'll call the update
  // once ourselves
  updateTimer();

  // We don't want the to be able to restart the timer while it is running,
  // so hide the button.
   $('#playAgainButton').hide();
}
</code>```

This is the code I'm trying to implement the timer in. I Tried multiple ways but did not work out.

```<code>AB.clockTick       = 100;

    // Speed of run: Step every n milliseconds. Default 100.

AB.maxSteps        = 100000;

    // Length of run: Maximum length of run in steps. Default 1000.

AB.screenshotStep  = 100;

    // Take screenshot on this step. (All resources should have finished loading.) Default 50.

 const FILE_ARRAY = [
        "/uploads/starter/earth.1.jpg",  // array 0 to 4 are the earths
        "/uploads/starter/earth.2.jpg",
        "/uploads/starter/earth.3.jpg",
        "/uploads/starter/earth.4.jpg",
        "/uploads/starter/earth.5.jpg",
        "/uploads/starter/baby.1.png",  // array 5
        "/uploads/starter/ghost.3.png"  // array 6
        ];

const SKYCOLOR  = 0xccffcc;             // a number, not a string

const ARMYSIZE = 50;       // an "army" of objects

const objectsize = 500 ;

const WALKSTEP = 200;       // bounds of the random move per timestep
                            // try 50 (vibrating sheet) versus 1000 (cloud)

const MAXPOS                = 4000 ;            // start things within these bounds
const startRadiusConst      = MAXPOS * 1.5 ;    // distance from centre to start the camera at
const maxRadiusConst        = MAXPOS * 5 ;      // maximum distance from camera we will render things

ABHandler.MAXCAMERAPOS      = MAXPOS * 10 ;         // allow camera go far away

ABWorld.drawCameraControls  = false;

AB.drawRunControls          = false;

    var THEARMY     = new Array( ARMYSIZE );

    var textureArray = new Array ( FILE_ARRAY.length );

function loadResources()        // asynchronous file loads - call initScene() when all finished
{
    for ( var i = 0; i < FILE_ARRAY.length; i++ )
      startFileLoad ( i );                      // launch n asynchronous file loads
}

function startFileLoad ( n )                // asynchronous file load of texture n
{
    var loader = new THREE.TextureLoader();

    loader.load ( FILE_ARRAY[n], function ( thetexture )
    {
        thetexture.minFilter  = THREE.LinearFilter;
        textureArray[n] = thetexture;
        if ( asynchFinished() ) initArmy();
    });
}

function asynchFinished()       // all file loads returned
{
    for ( var i = 0; i < FILE_ARRAY.length; i++ )
        if ( ! textureArray[i] )
            return false;

      return true;
}

function initArmy()      // called when all textures ready
{
 var t = 0;

 for ( var c=1 ; c <= ARMYSIZE ; c++ )
 {
    //    var shape = new THREE.SphereGeometry ( objectsize, 30, 30 );
   var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );

    var theobject  = new THREE.Mesh( shape );

    theobject.position.x = AB.randomIntAtoB ( -MAXPOS, MAXPOS );
    theobject.position.z = AB.randomIntAtoB ( -MAXPOS, MAXPOS );
    theobject.position.y =  0;

//  var r = AB.randomIntAtoB ( 0, textureArray.length - 1 );    // random texture
    var r = AB.randomIntAtoB ( 0, 4 );                          // random one of the earths
    theobject.material =  new THREE.MeshBasicMaterial ( { map: textureArray[r] } );

    ABWorld.scene.add(theobject);
    THEARMY[t] = theobject;                 // save it for later
    t++;
 }

  // can start the run loop

    ABWorld.render();

    AB.removeLoading();

    AB.runReady = true;

    AB.msg ( ` <hr> <p> Multi-user game. Pick a side. Click buttons to change boxes on all users' machines. Drag the camera. <p>
            <button onclick='baby();'  class=ab-largenormbutton > Baby </button>
            <button onclick='skull();'  class=ab-largenormbutton > Skull </button> <p> ` );
}

function moveArmy()         // move all the objects
{
 for ( var i = 0; i < THEARMY.length; i++ )
 {
   if ( THEARMY[i] )        // in case initArmy() not called yet
   {
        THEARMY[i].position.x =  THEARMY[i].position.x + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
        THEARMY[i].position.z =  THEARMY[i].position.z + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
        THEARMY[i].position.y =  THEARMY[i].position.y + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
        ABWorld.scene.add( THEARMY[i] );
   }
 }
}

AB.world.newRun = function()
{
    AB.loadingScreen();

    AB.runReady = false;

    ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR  );

    loadResources();        // aynch file loads
                            // calls initArmy() when it returns
};

AB.world.nextStep = function()
{
    moveArmy();
};

//--- Socket functionality -----------------------------------------------------

// start socket

AB.socketStart();

// functions called by buttons
// baby and skull are textures 5 and 6 in the array:

function baby()  {    changeBox(5);    AB.socketOut (5); }
function skull() {    changeBox(6);    AB.socketOut (6); }

function changeBox(n)   // change a random box to texture n (5 or 6)
{
    var i = AB.randomIntAtoB ( 0, THEARMY.length - 1 );     // pick a random box to change
    THEARMY[i].material =  new THREE.MeshBasicMaterial ( { map: textureArray[n] } );
}

AB.socketIn = function(n)       // incoming data on socket, i.e. clicks of other player
{
    if ( ! AB.runReady ) return;
    changeBox(n);
};

</code>```

Body:
I found this timer code but I don't know how to implement it in my javascript game. I'm also trying to include everything in one file. This is the timer code below.

HTML:
You have: 0 seconds remaining!

<button id="playAgainButton" onclick="start()">Go!</button>

javascript:

var timer;
var timeLeft = 60; // seconds

// What to do when the timer runs out
function gameOver() {
  // This cancels the setInterval, so the updateTimer stops getting called
  cancelInterval(timer);

  // re-show the button, so they can start it again
  $('#playAgainButton').show();
}

function updateTimer() {
  timeLeft = timeLeft - 1;
  if(timeLeft >= 0)
    $('#timer').html(timeLeft);
  else {
    gameOver();
  }
}

// The button has an on-click event handler that calls this
function start() {
  // setInterval is a built-in function that will call the given function
  // every N milliseconds (1 second = 1000 ms)
  timer = setInterval(updateTimer, 1000);

  // It will be a whole second before the time changes, so we'll call the update
  // once ourselves
  updateTimer();

  // We don't want the to be able to restart the timer while it is running,
  // so hide the button.
   $('#playAgainButton').hide();
}

This is the code I'm trying to implement the timer in. I Tried multiple ways but did not work out.

AB.clockTick       = 100;

    // Speed of run: Step every n milliseconds. Default 100.

AB.maxSteps        = 100000;

    // Length of run: Maximum length of run in steps. Default 1000.

AB.screenshotStep  = 100;

    // Take screenshot on this step. (All resources should have finished loading.) Default 50.

 const FILE_ARRAY = [
        "/uploads/starter/earth.1.jpg",  // array 0 to 4 are the earths
        "/uploads/starter/earth.2.jpg",
        "/uploads/starter/earth.3.jpg",
        "/uploads/starter/earth.4.jpg",
        "/uploads/starter/earth.5.jpg",
        "/uploads/starter/baby.1.png",  // array 5
        "/uploads/starter/ghost.3.png"  // array 6
        ];

const SKYCOLOR  = 0xccffcc;             // a number, not a string

const ARMYSIZE = 50;       // an "army" of objects

const objectsize = 500 ;

const WALKSTEP = 200;       // bounds of the random move per timestep
                            // try 50 (vibrating sheet) versus 1000 (cloud)

const MAXPOS                = 4000 ;            // start things within these bounds
const startRadiusConst      = MAXPOS * 1.5 ;    // distance from centre to start the camera at
const maxRadiusConst        = MAXPOS * 5 ;      // maximum distance from camera we will render things

ABHandler.MAXCAMERAPOS      = MAXPOS * 10 ;         // allow camera go far away

ABWorld.drawCameraControls  = false;

AB.drawRunControls          = false;

    var THEARMY     = new Array( ARMYSIZE );

    var textureArray = new Array ( FILE_ARRAY.length );

function loadResources()        // asynchronous file loads - call initScene() when all finished
{
    for ( var i = 0; i < FILE_ARRAY.length; i++ )
      startFileLoad ( i );                      // launch n asynchronous file loads
}

function startFileLoad ( n )                // asynchronous file load of texture n
{
    var loader = new THREE.TextureLoader();

    loader.load ( FILE_ARRAY[n], function ( thetexture )
    {
        thetexture.minFilter  = THREE.LinearFilter;
        textureArray[n] = thetexture;
        if ( asynchFinished() ) initArmy();
    });
}

function asynchFinished()       // all file loads returned
{
    for ( var i = 0; i < FILE_ARRAY.length; i++ )
        if ( ! textureArray[i] )
            return false;

      return true;
}

function initArmy()      // called when all textures ready
{
 var t = 0;

 for ( var c=1 ; c <= ARMYSIZE ; c++ )
 {
    //    var shape = new THREE.SphereGeometry ( objectsize, 30, 30 );
   var shape = new THREE.BoxGeometry( objectsize, objectsize, objectsize );

    var theobject  = new THREE.Mesh( shape );

    theobject.position.x = AB.randomIntAtoB ( -MAXPOS, MAXPOS );
    theobject.position.z = AB.randomIntAtoB ( -MAXPOS, MAXPOS );
    theobject.position.y =  0;

//  var r = AB.randomIntAtoB ( 0, textureArray.length - 1 );    // random texture
    var r = AB.randomIntAtoB ( 0, 4 );                          // random one of the earths
    theobject.material =  new THREE.MeshBasicMaterial ( { map: textureArray[r] } );

    ABWorld.scene.add(theobject);
    THEARMY[t] = theobject;                 // save it for later
    t++;
 }

  // can start the run loop

    ABWorld.render();

    AB.removeLoading();

    AB.runReady = true;

    AB.msg ( `

 Multi-user game. Pick a side. Click buttons to change boxes on all users' machines. Drag the camera.

            <button onclick='baby();'  class=ab-largenormbutton > Baby </button>
            <button onclick='skull();'  class=ab-largenormbutton > Skull </button>
 ` );
}

function moveArmy()         // move all the objects
{
 for ( var i = 0; i < THEARMY.length; i++ )
 {
   if ( THEARMY[i] )        // in case initArmy() not called yet
   {
        THEARMY[i].position.x =  THEARMY[i].position.x + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
        THEARMY[i].position.z =  THEARMY[i].position.z + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
        THEARMY[i].position.y =  THEARMY[i].position.y + AB.randomIntAtoB(-WALKSTEP,WALKSTEP) ;
        ABWorld.scene.add( THEARMY[i] );
   }
 }
}

AB.world.newRun = function()
{
    AB.loadingScreen();

    AB.runReady = false;

    ABWorld.init3d ( startRadiusConst, maxRadiusConst, SKYCOLOR  );

    loadResources();        // aynch file loads
                            // calls initArmy() when it returns
};

AB.world.nextStep = function()
{
    moveArmy();
};

//--- Socket functionality -----------------------------------------------------

// start socket

AB.socketStart();

// functions called by buttons
// baby and skull are textures 5 and 6 in the array:

function baby()  {    changeBox(5);    AB.socketOut (5); }
function skull() {    changeBox(6);    AB.socketOut (6); }

function changeBox(n)   // change a random box to texture n (5 or 6)
{
    var i = AB.randomIntAtoB ( 0, THEARMY.length - 1 );     // pick a random box to change
    THEARMY[i].material =  new THREE.MeshBasicMaterial ( { map: textureArray[n] } );
}

AB.socketIn = function(n)       // incoming data on socket, i.e. clicks of other player
{
    if ( ! AB.runReady ) return;
    changeBox(n);
};


问:
I dont know how coursera inputs a list

I have the assignment detailed in the image. The course has a place where you put the formula and it runs it and checks if it's correct. The problem is that it inputs a list which I don't know how to reference. Here is my formula:

```<code>def stats():
  # Output the list that the global identifier
  # my_list is bound to and the mean and
  # the population standard deviation of the
  # numbers in the list, rounded to two decimal
  # places.

    print(list1)
    my_list=float(sum(list1) / len(list1))
    print("mean is " + str(my_list))
    variance = (sum((x-(sum(list1) / len(list1)))**2 for x in list1) / (len(list1)))**0.5
    print("population standard deviation is "+ str(round(variance,2)))
list1=input()
</code>```

I tried putting input() but it doesn't work. I also tried putting the input argument inside the def.

Title: I dont know how coursera inputs a list

Body:
I have the assignment detailed in the image. The course has a place where you put the formula and it runs it and checks if it's correct. The problem is that it inputs a list which I don't know how to reference. Here is my formula:

def stats():
  # Output the list that the global identifier
  # my_list is bound to and the mean and
  # the population standard deviation of the
  # numbers in the list, rounded to two decimal
  # places.

    print(list1)
    my_list=float(sum(list1) / len(list1))
    print("mean is " + str(my_list))
    variance = (sum((x-(sum(list1) / len(list1)))**2 for x in list1) / (len(list1)))**0.5
    print("population standard deviation is "+ str(round(variance,2)))
list1=input()

I tried putting input() but it doesn't work. I also tried putting the input argument inside the def.


问:
Warning: Accessing non-existent property 'response' of module exports inside circular dependency
```<code>(node:9796) Warning: Accessing non-existent property 'response' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
Application started and Listening on port 3000
</code>```

i tried typing node --trace warnings to show where the warning was created but it doesn't help much

Body:
(node:9796) Warning: Accessing non-existent property 'response' of module exports inside circular dependency
(Use `node --trace-warnings ...` to show where the warning was created)
Application started and Listening on port 3000

i tried typing node --trace warnings to show where the warning was created but it doesn't help much


问:
Got the `Error: RPC failed; curl 55 Send failure: Connection was aborted`
I faced a very simiilar problem as in error: RPC failed; curl 55 Send failure: Connection was aborted.

However, when I do

```<code>!git push origin main^10:main
</code>```

in google colab I got the error error: src refspec main^10 does not match any.

How can i solve this problem?

Problem:

```<code>Counting objects: 100% (18/18), done.
Delta compression using up to 4 threads
Compressing objects: 100% (15/15), done.
error: RPC failed; curl 55 Send failure: Connection was aborted
</code>```

Body:
I faced a very simiilar problem as in error: RPC failed; curl 55 Send failure: Connection was aborted.

However, when I do

!git push origin main^10:main

in google colab I got the error error: src refspec main^10 does not match any.

How can i solve this problem?

Problem:

Counting objects: 100% (18/18), done.
Delta compression using up to 4 threads
Compressing objects: 100% (15/15), done.
error: RPC failed; curl 55 Send failure: Connection was aborted


问:
Cannot find module 'C:\Program Files\nodejs\node_modules\corepack\dist\yarn.js'
I installed yarn globally using this command:

```<code>npm install --global yarn
</code>```

But i get an error when I run:

```<code>yarn --version
</code>```

error message

Everytime I run yarn commands I always get this error

Body:
I installed yarn globally using this command:

npm install --global yarn

But i get an error when I run:

yarn --version

error message

Everytime I run yarn commands I always get this error


问:
two CASE statements in a query SQL(or does it need another function?)
I have 2 conditions that I need to fulfill in the same query:

All products with similar root formula should be aggregated into their basic formula (exp.: xyz:dfr and xyz:dkf both should be aggregated to xyz product)

if sales <> 0 then ext-sales / sales, else 0 (which basically is first checks if the sales column doesnot equals 0 then we should get ext-sales / sales as a result

My first guess is that I have to use CASE WHEN but the problem is that we have two completely different columns


问:
spring mongo when point accumulating
i'd like to make point system

i have one user DB (with 'point' column) and one Point DB( all histories )

l used spring mongo with aggregation for accumulating

and i have 2 apis

searching all users

searching one users

but i am worried about DB Error later because of aggregate function.

is it ok that i use that query in two upper apis?

i am wondering how to make the code about point management system

```<code>@Override
public Long getCurrentPoint(String userId) {
    Criteria criteria = new Criteria();
    criteria.and("userId").is(userId);

    MatchOperation matchOperation = new MatchOperation(criteria);

    AggregationExpression conditionalOperators = ConditionalOperators.switchCases(
            ConditionalOperators.Switch.CaseOperator.when(ComparisonOperators.valueOf("division").equalToValue(PointDivision.ACCUMULATED)).then("$amount"),
            ConditionalOperators.Switch.CaseOperator.when(ComparisonOperators.valueOf("division").equalToValue(PointDivision.USED)).then(ArithmeticOperators.valueOf("$amount").multiplyBy(-1))
    );

    GroupOperation groupOperation = Aggregation.group("userId").sum(conditionalOperators).as("point");

    TypedAggregation<Point> aggregation = Aggregation.newAggregation(Point.class, matchOperation, groupOperation);
    AggregationResults<GetPointDto> output = mongoTemplate.aggregate(aggregation, GetPointDto.class);

    return output.getMappedResults().get(0).getPoint();
}

</code>```

Title: spring mongo when point accumulating

Body:
i'd like to make point system

i have one user DB (with 'point' column) and one Point DB( all histories )

l used spring mongo with aggregation for accumulating

and i have 2 apis

searching all users

searching one users

but i am worried about DB Error later because of aggregate function.

is it ok that i use that query in two upper apis?

i am wondering how to make the code about point management system

@Override
public Long getCurrentPoint(String userId) {
    Criteria criteria = new Criteria();
    criteria.and("userId").is(userId);

    MatchOperation matchOperation = new MatchOperation(criteria);

    AggregationExpression conditionalOperators = ConditionalOperators.switchCases(
            ConditionalOperators.Switch.CaseOperator.when(ComparisonOperators.valueOf("division").equalToValue(PointDivision.ACCUMULATED)).then("$amount"),
            ConditionalOperators.Switch.CaseOperator.when(ComparisonOperators.valueOf("division").equalToValue(PointDivision.USED)).then(ArithmeticOperators.valueOf("$amount").multiplyBy(-1))
    );

    GroupOperation groupOperation = Aggregation.group("userId").sum(conditionalOperators).as("point");

    TypedAggregation<Point> aggregation = Aggregation.newAggregation(Point.class, matchOperation, groupOperation);
    AggregationResults<GetPointDto> output = mongoTemplate.aggregate(aggregation, GetPointDto.class);

    return output.getMappedResults().get(0).getPoint();
}


问:
How do I solve "Exception thrown at...Access violation reading location" in C++?
I am doing a project for school, and I am not looking for answers, more so just an explanation on what this error is and how to correct it.

The scenario of the project does not matter for me to explain (unless you feel otherwise), but the code block the error is reading is this:

void CallProcedure(string pName)
{
    char* procname = new char[pName.length() + 1];
    std::strcpy(procname, pName.c_str());

    Py_Initialize();
    PyObject* my_module = PyImport_ImportModule("PythonCode");
    PyErr_Print();
    PyObject* my_function = PyObject_GetAttrString(my_module, procname);
    PyObject* my_result = PyObject_CallObject(my_function, NULL);
    Py_Finalize();

    delete[] procname;
}
```
<p>The error occurs on line</p>
<pre class="lang-cpp prettyprint-override"><code>PyObject* my_function = PyObject_GetAttrString(my_module, procname);
</code>```

The error message is

Exception thrown at 0x1E0CB9E7 (python36.dll) in SetUp.exe: 0xC0000005:

Acess violation reading location 0x00000004."
```

I am very novice and very much a beginner so if I am missing something in regards of information I apologize.

I have tried googling this error and have not found a direct answer. I am merely trying to just run the code before I change anything to see what the output is in regard to what I need to change and where I am with the code provided to us in the project.

Body:
I am doing a project for school, and I am not looking for answers, more so just an explanation on what this error is and how to correct it.

The scenario of the project does not matter for me to explain (unless you feel otherwise), but the code block the error is reading is this:

void CallProcedure(string pName)
{
    char* procname = new char[pName.length() + 1];
    std::strcpy(procname, pName.c_str());

    Py_Initialize();
    PyObject* my_module = PyImport_ImportModule("PythonCode");
    PyErr_Print();
    PyObject* my_function = PyObject_GetAttrString(my_module, procname);
    PyObject* my_result = PyObject_CallObject(my_function, NULL);
    Py_Finalize();

    delete[] procname;
}

The error occurs on line

PyObject* my_function = PyObject_GetAttrString(my_module, procname);

The error message is

Exception thrown at 0x1E0CB9E7 (python36.dll) in SetUp.exe: 0xC0000005:

Acess violation reading location 0x00000004."

I am very novice and very much a beginner so if I am missing something in regards of information I apologize.

I have tried googling this error and have not found a direct answer. I am merely trying to just run the code before I change anything to see what the output is in regard to what I need to change and where I am with the code provided to us in the project.


问:
How do I add a file to my apk files in order to allow it to execute on app start?
I have an apk of my business and I want to add an extra file to it in order for the code to run when the program starts (when I click the app to open). I’m not sure what type of file I should add because it’s kind of tricky to know.

I tried to add code to one of the files to open a file on start but it didn’t work. Can someone tell me what kind of file to add to the decompiled apk files in order for this to work?


问:
Why are Java LocalTime and OffsetTime values incorrect when viewed directly on database
Application server (JVM) running in time zone: Europe/Dublin - TimeZone.getDefault().getID()

Time zone for JDBC connections set for Spring / Hibernate using the configuration property:

```<code>spring.jpa.properties.hibernate.jdbc.time_zone=UTC
</code>```

Java Entity:

```<code>@Column(name = "local_time")
private LocalTime localTime;

@Column(name = "local_date_time")
private LocalDateTime localDateTime;

@Column(name = "offset_time")
private OffsetTime offsetTime;
</code>```

Java values debugged on application server (JVM) ..

LocalTime - time SQL type:

```<code>// LocalTime.ofInstant(now, Clock.systemDefaultZone().getZone())
01:32:13.283256
</code>```

LocalDateTime - timestamp SQL type:

```<code>// LocalDateTime.ofInstant(now, Clock.systemDefaultZone().getZone())
2022-12-06T01:32:13.283256
</code>```

OffsetTime - time with time zone SQL type:

```<code>// OffsetTime.ofInstant(now, Clock.systemDefaultZone().getZone())
01:32:13.283256Z
</code>```

Database configured to use UTC:

```<code>postgres=# select name, setting, source from pg_settings where name='TimeZone';
   name   | setting |       source
----------+---------+--------------------
 TimeZone | Etc/UTC | configuration file
</code>```

Query database (PostgreSQL) for values:

```<code>select * from item;

 id | local_time |      local_date_time       | offset_time
----+------------+----------------------------+-------------
  1 | 00:32:13   | 2022-12-06 01:32:13.283256 | 00:32:13+00
</code>```

Why are the column values for local_time and offset_time 1 hour behind UTC? Shouldn't they be the same as local_date_time i.e 01:32 rather than 00:32

local_date_time is the only column with correct value when directly querying the database. Why is that?

Body:
Application server (JVM) running in time zone: Europe/Dublin - TimeZone.getDefault().getID()

Time zone for JDBC connections set for Spring / Hibernate using the configuration property:

spring.jpa.properties.hibernate.jdbc.time_zone=UTC

Java Entity:

@Column(name = "local_time")
private LocalTime localTime;

@Column(name = "local_date_time")
private LocalDateTime localDateTime;

@Column(name = "offset_time")
private OffsetTime offsetTime;

Java values debugged on application server (JVM) ..

LocalTime - time SQL type:

// LocalTime.ofInstant(now, Clock.systemDefaultZone().getZone())
01:32:13.283256

LocalDateTime - timestamp SQL type:

// LocalDateTime.ofInstant(now, Clock.systemDefaultZone().getZone())
2022-12-06T01:32:13.283256

OffsetTime - time with time zone SQL type:

// OffsetTime.ofInstant(now, Clock.systemDefaultZone().getZone())
01:32:13.283256Z

Database configured to use UTC:

postgres=# select name, setting, source from pg_settings where name='TimeZone';
   name   | setting |       source
----------+---------+--------------------
 TimeZone | Etc/UTC | configuration file

Query database (PostgreSQL) for values:

select * from item;

 id | local_time |      local_date_time       | offset_time
----+------------+----------------------------+-------------
  1 | 00:32:13   | 2022-12-06 01:32:13.283256 | 00:32:13+00

Why are the column values for local_time and offset_time 1 hour behind UTC? Shouldn't they be the same as local_date_time i.e 01:32 rather than 00:32

local_date_time is the only column with correct value when directly querying the database. Why is that?


问:
Avoid timer task been delayed by system
I builded an Android foreground service that every 30 seconds runs a function thanks to a timer and a TimerTask.
In the emulator works all fine but when i run the service in my phone after a bit of time (like some hours, with unconstant use of phone) i see (thanks to logs sent to the server every 30 seconds) that tasks are delayed by the system but i need that they runs without delays.
`Java

```<code>private void startMonitoring(){
        try {
            boolean check_penalties_done = false;
            boolean create_new_race_done = false;
//            Runnable checker = () -> checkTime(check_penalties_done, create_new_race_done);
//            beeperHandle = scheduler.scheduleAtFixedRate(checker, 0, 30, SECONDS);
            File conf_path = getApplicationContext().getFilesDir();
            String conf_file = conf_path.toString() + "/serv_config.json";
            BufferedReader f_read = new BufferedReader(new FileReader(conf_file));
            JSONObject config = new JSONObject(f_read.readLine());
            mon_type = config.getString("update_type");

            if (mon_type.equals("one-shot") || mon_type.equals("cont")){

                mainTask task = new mainTask().setPath(path, check_penalties_done, create_new_race_done);

                timer.scheduleAtFixedRate(task, 0, 30000);

            } else {

                mainTask task = new mainTask().setPath(path, check_penalties_done, create_new_race_done);

                timer.schedule(task, 0);

                onDestroy();
            }

        } catch (Exception e) {
            registerLogs("start_monitoring", Arrays.toString(e.getStackTrace()));
        }
    }
</code>```

`

I tried with different methods of "timered tasks" like Threads, setting priority to Thread.MAX_PRIORITY and a ScheduledExecutorService but the problem still alive also using PowerManager.WakeLock.
I found here an old unanswered question similar to my problem but i think that mine is a bit different because the task are like queued and executed all at once (due to use of scheduleAtFixedRate i read, using schedule delayed task are deleted).
Is it possible to say to the Android system something like "don't delay this task"?

Title: Avoid timer task been delayed by system

Body:
I builded an Android foreground service that every 30 seconds runs a function thanks to a timer and a TimerTask.
In the emulator works all fine but when i run the service in my phone after a bit of time (like some hours, with unconstant use of phone) i see (thanks to logs sent to the server every 30 seconds) that tasks are delayed by the system but i need that they runs without delays.
`Java

private void startMonitoring(){
        try {
            boolean check_penalties_done = false;
            boolean create_new_race_done = false;
//            Runnable checker = () -> checkTime(check_penalties_done, create_new_race_done);
//            beeperHandle = scheduler.scheduleAtFixedRate(checker, 0, 30, SECONDS);
            File conf_path = getApplicationContext().getFilesDir();
            String conf_file = conf_path.toString() + "/serv_config.json";
            BufferedReader f_read = new BufferedReader(new FileReader(conf_file));
            JSONObject config = new JSONObject(f_read.readLine());
            mon_type = config.getString("update_type");

            if (mon_type.equals("one-shot") || mon_type.equals("cont")){

                mainTask task = new mainTask().setPath(path, check_penalties_done, create_new_race_done);

                timer.scheduleAtFixedRate(task, 0, 30000);

            } else {

                mainTask task = new mainTask().setPath(path, check_penalties_done, create_new_race_done);

                timer.schedule(task, 0);

                onDestroy();
            }

        } catch (Exception e) {
            registerLogs("start_monitoring", Arrays.toString(e.getStackTrace()));
        }
    }

`

I tried with different methods of "timered tasks" like Threads, setting priority to Thread.MAX_PRIORITY and a ScheduledExecutorService but the problem still alive also using PowerManager.WakeLock.
I found here an old unanswered question similar to my problem but i think that mine is a bit different because the task are like queued and executed all at once (due to use of scheduleAtFixedRate i read, using schedule delayed task are deleted).
Is it possible to say to the Android system something like "don't delay this task"?