问:
AttributeError: type object 'GridOptionsBuilder' has no attribute 'from_dataframe'
I am trying to load gridoptionsbuilder but getting error.

Here is my code below:

```<code>import streamlit as st
import pandas as pd
from st_aggrid import AgGrid,GridOptionsBuilder

file_upload = st.file_uploader('Upload file','.xlsx')

if file_upload is not None:
    df = pd.read_excel(file_upload)

    st.write('### Initial data')
    st.dataframe(df)

    # Add format parameter based from excel data format.
    df['Integration'] = pd.to_datetime(df['Integration'], format="%d/%m/%Y")
    df['Actual '] = pd.to_datetime(df["Actual "], format="%d/%m/%Y")
    gb = GridOptionsBuilder.from_dataframe(df)
    gb.configure_column("date_tz_aware", type=["dateColumnFilter","customDateTimeFormat"], custom_format_string='yyyy-MM-dd HH:mm zzz', pivot=True)

    gb.configure_grid_options(domLayout='normal')
    gridOptions = gb.build()
    grid_response = AgGrid(
    df,
    gridOptions=gridOptions,
    width='100%',
    allow_unsafe_jscode=True, #Set it to True to allow jsfunction to be injected

    )

    st.write(gridOptions)
</code>```

Will needs some assistance here.
screenshot of error

Body:
I am trying to load gridoptionsbuilder but getting error.

Here is my code below:

import streamlit as st
import pandas as pd
from st_aggrid import AgGrid,GridOptionsBuilder

file_upload = st.file_uploader('Upload file','.xlsx')

if file_upload is not None:
    df = pd.read_excel(file_upload)

    st.write('### Initial data')
    st.dataframe(df)

    # Add format parameter based from excel data format.
    df['Integration'] = pd.to_datetime(df['Integration'], format="%d/%m/%Y")
    df['Actual '] = pd.to_datetime(df["Actual "], format="%d/%m/%Y")
    gb = GridOptionsBuilder.from_dataframe(df)
    gb.configure_column("date_tz_aware", type=["dateColumnFilter","customDateTimeFormat"], custom_format_string='yyyy-MM-dd HH:mm zzz', pivot=True)

    gb.configure_grid_options(domLayout='normal')
    gridOptions = gb.build()
    grid_response = AgGrid(
    df,
    gridOptions=gridOptions,
    width='100%',
    allow_unsafe_jscode=True, #Set it to True to allow jsfunction to be injected

    )

    st.write(gridOptions)

Will needs some assistance here.
screenshot of error


来源: stackexchange

问:
Issue while importing sparkdl into a spark app
this is my actual code that I'm trying to run, it a brain tumor classifier
`

```<code>import findspark
findspark.init()

from pyspark.conf import SparkConf
from pyspark import SparkContext
conf = SparkConf().set("spark.jars", "/opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar")
conf.setAppName("ML_provaaaa")
sc = SparkContext(conf=conf)
from pyspark.sql import SparkSession
sql = SparkSession(sc)
import sparkdl
from pyspark.ml.evaluation import MulticlassClassificationEvaluator
from pyspark.ml.classification import LogisticRegression
from pyspark.ml import Pipeline
from keras.applications import InceptionV3

path_no = "/opt/spark-data/no"
path_yes = "/opt/spark-data/yes"

no_brain = sql.read.format("image").load(path_no).withColumn("label",lit(0))
yes_brain = sql.read.format("image").load(path_yes).withColumn("label",lit(1))

dfs = [no_brain,yes_brain]

whole_ds = reduce(lambda no_brain, yes_brain: no_brain.union(yes_brain.select(no_brain.columns)), dfs)

train, test = whole_ds.randomSplit([0.8, 0.2], 127)

whole_ds.printSchema()

featurizer = DeepImageFeaturizer(inputCol="image",
                                 outputCol="features",
                                 modelName="InceptionV3")
lr = LogisticRegression(maxIter=5, regParam=0.03,
                        elasticNetParam=0.5, labelCol="label")
# define a pipeline model
sparkdn = Pipeline(stages=[featurizer, lr])
spark_model = sparkdn.fit(train) # start fitting or training

evaluator = MulticlassClassificationEvaluator()
tx_test = spark_model.transform(test)
print('F1-Score ', evaluator.evaluate(tx_test,
                                      {evaluator.metricName: 'f1'}))
print('Precision ', evaluator.evaluate(tx_test,
                                       {evaluator.metricName:                    'weightedPrecision'}))
print('Recall ', evaluator.evaluate(tx_test,
                                    {evaluator.metricName: 'weightedRecall'}))
print('Accuracy ', evaluator.evaluate(tx_test,

                                       {evaluator.metricName: 'accuracy'}))
</code>```

`

This is the actual console log that I get, as you can see** I don't get any type of output from the printSchema, show and so on** while in other spark app I get it:

`

```<code>/opt/spark# /opt/spark/bin/spark-submit --master spark://spark-master:7077 --jars /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar /opt/spark-apps/MLimage1.py
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.0.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
22/12/10 15:57:21 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
22/12/10 15:57:22 INFO SparkContext: Running Spark version 3.0.2
22/12/10 15:57:22 INFO ResourceUtils: ==============================================================
22/12/10 15:57:22 INFO ResourceUtils: Resources for spark.driver:

22/12/10 15:57:22 INFO ResourceUtils: ==============================================================
22/12/10 15:57:22 INFO SparkContext: Submitted application: ML_provaaaa
22/12/10 15:57:22 INFO SecurityManager: Changing view acls to: root
22/12/10 15:57:22 INFO SecurityManager: Changing modify acls to: root
22/12/10 15:57:22 INFO SecurityManager: Changing view acls groups to:
22/12/10 15:57:22 INFO SecurityManager: Changing modify acls groups to:
22/12/10 15:57:22 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(root); groups with view permissions: Set(); users  with modify permissions: Set(root); groups with modify permissions: Set()
22/12/10 15:57:23 INFO Utils: Successfully started service 'sparkDriver' on port 38207.
22/12/10 15:57:23 INFO SparkEnv: Registering MapOutputTracker
22/12/10 15:57:23 INFO SparkEnv: Registering BlockManagerMaster
22/12/10 15:57:23 INFO BlockManagerMasterEndpoint: Using org.apache.spark.storage.DefaultTopologyMapper for getting topology information
22/12/10 15:57:23 INFO BlockManagerMasterEndpoint: BlockManagerMasterEndpoint up
22/12/10 15:57:23 INFO SparkEnv: Registering BlockManagerMasterHeartbeat
22/12/10 15:57:24 INFO DiskBlockManager: Created local directory at /tmp/blockmgr-ed66c81d-408a-4a02-a2a8-5a10931e588d
22/12/10 15:57:24 INFO MemoryStore: MemoryStore started with capacity 434.4 MiB
22/12/10 15:57:24 INFO SparkEnv: Registering OutputCommitCoordinator
22/12/10 15:57:24 INFO Utils: Successfully started service 'SparkUI' on port 4040.
22/12/10 15:57:25 INFO SparkUI: Bound SparkUI to spark-master, and started at http://9a5412086ef7:4040
22/12/10 15:57:25 INFO SparkContext: Added JAR /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar at spark://9a5412086ef7:38207/jars/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar with timestamp 1670687842467
22/12/10 15:57:25 WARN SparkContext: Please ensure that the number of slots available on your executors is limited by the number of cores to task cpus and not another custom resource. If cores is not the limiting resource then dynamic allocation will not work properly!
22/12/10 15:57:25 INFO StandaloneAppClient$ClientEndpoint: Connecting to master spark://spark-master:7077...
22/12/10 15:57:26 INFO TransportClientFactory: Successfully created connection to spark-master/172.18.0.3:7077 after 104 ms (0 ms spent in bootstraps)
22/12/10 15:57:26 INFO StandaloneSchedulerBackend: Connected to Spark cluster with app ID app-20221210155726-0008
22/12/10 15:57:26 INFO Utils: Successfully started service 'org.apache.spark.network.netty.NettyBlockTransferService' on port 42969.
22/12/10 15:57:26 INFO NettyBlockTransferService: Server created on 9a5412086ef7:42969
22/12/10 15:57:26 INFO StandaloneAppClient$ClientEndpoint: Executor added: app-20221210155726-0008/0 on worker-20221210144935-172.18.0.7-7000 (172.18.0.7:7000) with 1 core(s)
22/12/10 15:57:26 INFO BlockManager: Using org.apache.spark.storage.RandomBlockReplicationPolicy for block replication policy
22/12/10 15:57:26 INFO StandaloneSchedulerBackend: Granted executor ID app-20221210155726-0008/0 on hostPort 172.18.0.7:7000 with 1 core(s), 1024.0 MiB RAM
22/12/10 15:57:26 INFO StandaloneAppClient$ClientEndpoint: Executor added: app-20221210155726-0008/1 on worker-20221210144935-172.18.0.8-7000 (172.18.0.8:7000) with 1 core(s)
22/12/10 15:57:26 INFO StandaloneSchedulerBackend: Granted executor ID app-20221210155726-0008/1 on hostPort 172.18.0.8:7000 with 1 core(s), 1024.0 MiB RAM
22/12/10 15:57:26 INFO BlockManagerMaster: Registering BlockManager BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:26 INFO BlockManagerMasterEndpoint: Registering block manager 9a5412086ef7:42969 with 434.4 MiB RAM, BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:26 INFO BlockManagerMaster: Registered BlockManager BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:26 INFO BlockManager: Initialized BlockManager: BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:27 INFO StandaloneSchedulerBackend: SchedulerBackend is ready for scheduling beginning after reached minRegisteredResourcesRatio: 0.0
22/12/10 15:57:27 INFO StandaloneAppClient$ClientEndpoint: Executor updated: app-20221210155726-0008/1 is now RUNNING
22/12/10 15:57:27 INFO StandaloneAppClient$ClientEndpoint: Executor updated: app-20221210155726-0008/0 is now RUNNING
22/12/10 15:57:32 INFO SparkContext: Invoking stop() from shutdown hook
22/12/10 15:57:32 INFO SparkUI: Stopped Spark web UI at http://9a5412086ef7:4040
22/12/10 15:57:32 INFO StandaloneSchedulerBackend: Shutting down all executors
22/12/10 15:57:32 INFO CoarseGrainedSchedulerBackend$DriverEndpoint: Asking each executor to shut down
22/12/10 15:57:32 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
22/12/10 15:57:32 INFO MemoryStore: MemoryStore cleared
22/12/10 15:57:32 INFO BlockManager: BlockManager stopped
22/12/10 15:57:32 INFO BlockManagerMaster: BlockManagerMaster stopped
22/12/10 15:57:32 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
22/12/10 15:57:32 INFO SparkContext: Successfully stopped SparkContext
22/12/10 15:57:32 INFO ShutdownHookManager: Shutdown hook called
22/12/10 15:57:32 INFO ShutdownHookManager: Deleting directory /tmp/spark-197b0a93-dcd6-4434-86a4-315d5e092015
22/12/10 15:57:32 INFO ShutdownHookManager: Deleting directory /tmp/spark-197b0a93-dcd6-4434-86a4-315d5e092015/pyspark-dd40c8b9-4e42-417d-8e1b-f78800915b65
22/12/10 15:57:32 INFO ShutdownHookManager: Deleting directory /tmp/spark-c4e37ec3-cff7-45a1-8209-0406cf138311
</code>```

`

When I look into the web GUI of the master node to see what's happening it reports that the app was successfully deployed and finished after 2seconds, other ML apps usually takes 1.2 min,the same into the slaves in which the task is "KILLED"

I'm submitting the spark app to a containered spark master node through a remote shell via the following command:

/opt/spark/bin/spark-submit --master spark://spark-master:7077 --jars /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar /opt/spark-apps/MLimage1.py

the jar file is inside a folder in which the master will check the presence of jars (opt/spark-apps) while it checks for data into (opt/spark-data)

The strange fact is that when I change my code and I don't use the findspark:
`

```<code>from pyspark.sql import SparkSession
def init_spark():
  sql = SparkSession.builder\
    .appName("analysisMIII-app")\
    .config("spark.jars", "/opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar")\
    .getOrCreate()
  sc = sql.sparkContext
  return sql,sc
</code>```

`

the program doesn't start with the following console logs :
`

```<code>WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.0.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
22/12/10 16:21:25 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
log4j:WARN No appenders could be found for logger (org.apache.spark.util.ShutdownHookManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
root@9a5412086ef7:/opt/spark# /opt/spark/bin/spark-submit --master spark://spark-master:7077 --jars /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar /opt/spark-apps/MLprova.py
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.0.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
22/12/10 16:26:37 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
log4j:WARN No appenders could be found for logger (org.apache.spark.util.ShutdownHookManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
</code>```

`

I'm looking for a solution.

ContentLicense: CC BY-SA 4.0

Body:
this is my actual code that I'm trying to run, it a brain tumor classifier
`

import findspark
findspark.init()

from pyspark.conf import SparkConf
from pyspark import SparkContext
conf = SparkConf().set("spark.jars", "/opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar")
conf.setAppName("ML_provaaaa")
sc = SparkContext(conf=conf)
from pyspark.sql import SparkSession
sql = SparkSession(sc)
import sparkdl
from pyspark.ml.evaluation import MulticlassClassificationEvaluator
from pyspark.ml.classification import LogisticRegression
from pyspark.ml import Pipeline
from keras.applications import InceptionV3

path_no = "/opt/spark-data/no"
path_yes = "/opt/spark-data/yes"

no_brain = sql.read.format("image").load(path_no).withColumn("label",lit(0))
yes_brain = sql.read.format("image").load(path_yes).withColumn("label",lit(1))

dfs = [no_brain,yes_brain]

whole_ds = reduce(lambda no_brain, yes_brain: no_brain.union(yes_brain.select(no_brain.columns)), dfs)

train, test = whole_ds.randomSplit([0.8, 0.2], 127)

whole_ds.printSchema()

featurizer = DeepImageFeaturizer(inputCol="image",
                                 outputCol="features",
                                 modelName="InceptionV3")
lr = LogisticRegression(maxIter=5, regParam=0.03,
                        elasticNetParam=0.5, labelCol="label")
# define a pipeline model
sparkdn = Pipeline(stages=[featurizer, lr])
spark_model = sparkdn.fit(train) # start fitting or training

evaluator = MulticlassClassificationEvaluator()
tx_test = spark_model.transform(test)
print('F1-Score ', evaluator.evaluate(tx_test,
                                      {evaluator.metricName: 'f1'}))
print('Precision ', evaluator.evaluate(tx_test,
                                       {evaluator.metricName:                    'weightedPrecision'}))
print('Recall ', evaluator.evaluate(tx_test,
                                    {evaluator.metricName: 'weightedRecall'}))
print('Accuracy ', evaluator.evaluate(tx_test,

                                       {evaluator.metricName: 'accuracy'}))

`

This is the actual console log that I get, as you can see** I don't get any type of output from the printSchema, show and so on** while in other spark app I get it:

`

/opt/spark# /opt/spark/bin/spark-submit --master spark://spark-master:7077 --jars /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar /opt/spark-apps/MLimage1.py
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.0.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
22/12/10 15:57:21 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
22/12/10 15:57:22 INFO SparkContext: Running Spark version 3.0.2
22/12/10 15:57:22 INFO ResourceUtils: ==============================================================
22/12/10 15:57:22 INFO ResourceUtils: Resources for spark.driver:

22/12/10 15:57:22 INFO ResourceUtils: ==============================================================
22/12/10 15:57:22 INFO SparkContext: Submitted application: ML_provaaaa
22/12/10 15:57:22 INFO SecurityManager: Changing view acls to: root
22/12/10 15:57:22 INFO SecurityManager: Changing modify acls to: root
22/12/10 15:57:22 INFO SecurityManager: Changing view acls groups to:
22/12/10 15:57:22 INFO SecurityManager: Changing modify acls groups to:
22/12/10 15:57:22 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(root); groups with view permissions: Set(); users  with modify permissions: Set(root); groups with modify permissions: Set()
22/12/10 15:57:23 INFO Utils: Successfully started service 'sparkDriver' on port 38207.
22/12/10 15:57:23 INFO SparkEnv: Registering MapOutputTracker
22/12/10 15:57:23 INFO SparkEnv: Registering BlockManagerMaster
22/12/10 15:57:23 INFO BlockManagerMasterEndpoint: Using org.apache.spark.storage.DefaultTopologyMapper for getting topology information
22/12/10 15:57:23 INFO BlockManagerMasterEndpoint: BlockManagerMasterEndpoint up
22/12/10 15:57:23 INFO SparkEnv: Registering BlockManagerMasterHeartbeat
22/12/10 15:57:24 INFO DiskBlockManager: Created local directory at /tmp/blockmgr-ed66c81d-408a-4a02-a2a8-5a10931e588d
22/12/10 15:57:24 INFO MemoryStore: MemoryStore started with capacity 434.4 MiB
22/12/10 15:57:24 INFO SparkEnv: Registering OutputCommitCoordinator
22/12/10 15:57:24 INFO Utils: Successfully started service 'SparkUI' on port 4040.
22/12/10 15:57:25 INFO SparkUI: Bound SparkUI to spark-master, and started at http://9a5412086ef7:4040
22/12/10 15:57:25 INFO SparkContext: Added JAR /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar at spark://9a5412086ef7:38207/jars/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar with timestamp 1670687842467
22/12/10 15:57:25 WARN SparkContext: Please ensure that the number of slots available on your executors is limited by the number of cores to task cpus and not another custom resource. If cores is not the limiting resource then dynamic allocation will not work properly!
22/12/10 15:57:25 INFO StandaloneAppClient$ClientEndpoint: Connecting to master spark://spark-master:7077...
22/12/10 15:57:26 INFO TransportClientFactory: Successfully created connection to spark-master/172.18.0.3:7077 after 104 ms (0 ms spent in bootstraps)
22/12/10 15:57:26 INFO StandaloneSchedulerBackend: Connected to Spark cluster with app ID app-20221210155726-0008
22/12/10 15:57:26 INFO Utils: Successfully started service 'org.apache.spark.network.netty.NettyBlockTransferService' on port 42969.
22/12/10 15:57:26 INFO NettyBlockTransferService: Server created on 9a5412086ef7:42969
22/12/10 15:57:26 INFO StandaloneAppClient$ClientEndpoint: Executor added: app-20221210155726-0008/0 on worker-20221210144935-172.18.0.7-7000 (172.18.0.7:7000) with 1 core(s)
22/12/10 15:57:26 INFO BlockManager: Using org.apache.spark.storage.RandomBlockReplicationPolicy for block replication policy
22/12/10 15:57:26 INFO StandaloneSchedulerBackend: Granted executor ID app-20221210155726-0008/0 on hostPort 172.18.0.7:7000 with 1 core(s), 1024.0 MiB RAM
22/12/10 15:57:26 INFO StandaloneAppClient$ClientEndpoint: Executor added: app-20221210155726-0008/1 on worker-20221210144935-172.18.0.8-7000 (172.18.0.8:7000) with 1 core(s)
22/12/10 15:57:26 INFO StandaloneSchedulerBackend: Granted executor ID app-20221210155726-0008/1 on hostPort 172.18.0.8:7000 with 1 core(s), 1024.0 MiB RAM
22/12/10 15:57:26 INFO BlockManagerMaster: Registering BlockManager BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:26 INFO BlockManagerMasterEndpoint: Registering block manager 9a5412086ef7:42969 with 434.4 MiB RAM, BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:26 INFO BlockManagerMaster: Registered BlockManager BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:26 INFO BlockManager: Initialized BlockManager: BlockManagerId(driver, 9a5412086ef7, 42969, None)
22/12/10 15:57:27 INFO StandaloneSchedulerBackend: SchedulerBackend is ready for scheduling beginning after reached minRegisteredResourcesRatio: 0.0
22/12/10 15:57:27 INFO StandaloneAppClient$ClientEndpoint: Executor updated: app-20221210155726-0008/1 is now RUNNING
22/12/10 15:57:27 INFO StandaloneAppClient$ClientEndpoint: Executor updated: app-20221210155726-0008/0 is now RUNNING
22/12/10 15:57:32 INFO SparkContext: Invoking stop() from shutdown hook
22/12/10 15:57:32 INFO SparkUI: Stopped Spark web UI at http://9a5412086ef7:4040
22/12/10 15:57:32 INFO StandaloneSchedulerBackend: Shutting down all executors
22/12/10 15:57:32 INFO CoarseGrainedSchedulerBackend$DriverEndpoint: Asking each executor to shut down
22/12/10 15:57:32 INFO MapOutputTrackerMasterEndpoint: MapOutputTrackerMasterEndpoint stopped!
22/12/10 15:57:32 INFO MemoryStore: MemoryStore cleared
22/12/10 15:57:32 INFO BlockManager: BlockManager stopped
22/12/10 15:57:32 INFO BlockManagerMaster: BlockManagerMaster stopped
22/12/10 15:57:32 INFO OutputCommitCoordinator$OutputCommitCoordinatorEndpoint: OutputCommitCoordinator stopped!
22/12/10 15:57:32 INFO SparkContext: Successfully stopped SparkContext
22/12/10 15:57:32 INFO ShutdownHookManager: Shutdown hook called
22/12/10 15:57:32 INFO ShutdownHookManager: Deleting directory /tmp/spark-197b0a93-dcd6-4434-86a4-315d5e092015
22/12/10 15:57:32 INFO ShutdownHookManager: Deleting directory /tmp/spark-197b0a93-dcd6-4434-86a4-315d5e092015/pyspark-dd40c8b9-4e42-417d-8e1b-f78800915b65
22/12/10 15:57:32 INFO ShutdownHookManager: Deleting directory /tmp/spark-c4e37ec3-cff7-45a1-8209-0406cf138311

`

When I look into the web GUI of the master node to see what's happening it reports that the app was successfully deployed and finished after 2seconds, other ML apps usually takes 1.2 min,the same into the slaves in which the task is "KILLED"

I'm submitting the spark app to a containered spark master node through a remote shell via the following command:

/opt/spark/bin/spark-submit --master spark://spark-master:7077 --jars /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar /opt/spark-apps/MLimage1.py

the jar file is inside a folder in which the master will check the presence of jars (opt/spark-apps) while it checks for data into (opt/spark-data)

The strange fact is that when I change my code and I don't use the findspark:
`

from pyspark.sql import SparkSession
def init_spark():
  sql = SparkSession.builder\
    .appName("analysisMIII-app")\
    .config("spark.jars", "/opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar")\
    .getOrCreate()
  sc = sql.sparkContext
  return sql,sc

`

the program doesn't start with the following console logs :
`

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.0.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
22/12/10 16:21:25 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
log4j:WARN No appenders could be found for logger (org.apache.spark.util.ShutdownHookManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
root@9a5412086ef7:/opt/spark# /opt/spark/bin/spark-submit --master spark://spark-master:7077 --jars /opt/spark-apps/spark-deep-learning-1.5.0-spark2.4-s_2.11.jar /opt/spark-apps/MLprova.py
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.spark.unsafe.Platform (file:/opt/spark/jars/spark-unsafe_2.12-3.0.2.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of org.apache.spark.unsafe.Platform
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
22/12/10 16:26:37 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
log4j:WARN No appenders could be found for logger (org.apache.spark.util.ShutdownHookManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

`

I'm looking for a solution.


问:
External function in react-native
How to create external function in react-native? example in C:

Function.C

```<code>int Function(char* variable1, int variable2)
{
  //Actions in function

  return answer;
}
</code>```

Function.h

```<code>int Function(char* variable1, int variable2);
</code>```

main.C

```<code>#include "Function.h"
...
char variableA;
int variableB=0;
//Some code

if(Function(variableA, variableB))
....
else
....
</code>```

I am trying to create my first app for my android

Title: External function in react-native

Body:
How to create external function in react-native? example in C:

Function.C

int Function(char* variable1, int variable2)
{
  //Actions in function

  return answer;
}

Function.h

int Function(char* variable1, int variable2);

main.C

#include "Function.h"
...
char variableA;
int variableB=0;
//Some code

if(Function(variableA, variableB))
....
else
....

I am trying to create my first app for my android


问:
TypeError: forward() got an unexpected keyword argument 'size'
```<code>
</code>```

with mss() as sct:
monitor = {"top": 220, "left": 640, "width": 640, "height":640}

```<code>while(True):
    size =640
    screenshot = np.array(sct.grab(monitor))
    results = model(screenshot,size=640)
    df= results.pandas().xyxy[0]
</code>```
```<code>
</code>```
```<code>I'm having a problem running a script...
together with yolov5

  File "D:\Users\Guto\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'size'
</code>```
```<code></code>```
```<code>with mss() as sct:
    monitor = {"top": 220, "left": 640, "width": 640, "height":640}

    while(True):
        size =640
        screenshot = np.array(sct.grab(monitor))
        results = model(screenshot,size=640)
        df= results.pandas().xyxy[0]
</code>```
```<code>

</code>```

I'm having a problem running a script...
together with yalov5

File "D:\Users\Guto\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'size'

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

Body:
with mss() as sct:
monitor = {"top": 220, "left": 640, "width": 640, "height":640}

while(True):
    size =640
    screenshot = np.array(sct.grab(monitor))
    results = model(screenshot,size=640)
    df= results.pandas().xyxy[0]

I'm having a problem running a script...
together with yolov5

  File "D:\Users\Guto\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
    return forward_call(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'size'

with mss() as sct:
    monitor = {"top": 220, "left": 640, "width": 640, "height":640}

    while(True):
        size =640
        screenshot = np.array(sct.grab(monitor))
        results = model(screenshot,size=640)
        df= results.pandas().xyxy[0]

I'm having a problem running a script...
together with yalov5

File "D:\Users\Guto\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1190, in _call_impl
return forward_call(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'size'


问:
How to create drop down Languages prestashop?
I have style good on my store for languages with flags, but I want to change my style languages to drop down with height.

I have shared the code below, but the code is simple and PHP can't delete or remove this code, PHP redirects any style to the languages store. I have 2 images: the first one is my style number, and the 2nd one is a style I want dropdown with like this height

Image Number 1 I have Style

Image Number 2 style I want

the code cant remove PHP code or delete any think in this I want edit HTML and CSS

```<code><style>
{literal}
#currencies_block_top3  ul {list-style:none }

#currencies_block_top3 li {box-shadow: 1px 1px 1pc black, 0 0 25px blue, 0 0 5px darkblue;
 margin-right: 3px; padding:1px; background:none ; text-shadow:0px 0px 10px gold; font-size:14px; font-weight:bold; float:left; display:inline-block; margin-left:1px;}
#currencies_block_top3 li a {color:white;}
#currencies_block_top3 li.selected {padding:1px; background:black; text-shadow:0px 0px 10px gold; }
#currencies_block_top3 li.selected a{ color:red;}
{/literal}
</style>

<div id="currencies_block_top3">
        <ul>
            {foreach from=$languages item=language}
                    <li {if $language.id_lang == $current_language.id_lang} class="current" {/if}>
                      <a href="{url entity='language' id=$language.id_lang}" class="dropdown-item">
                         <img src="{$urls.img_lang_url|escape:'html':'UTF-8'}{$language.id_lang|escape:'html':'UTF-8'}.jpg" alt="{$language.iso_code|escape:'html':'UTF-8'}" width="32" height="32" />
                         {$language.name_simple}
                        </a>
                    </li>
                  {/foreach}
        </ul>
</div>

</code>```

Body:
I have style good on my store for languages with flags, but I want to change my style languages to drop down with height.

I have shared the code below, but the code is simple and PHP can't delete or remove this code, PHP redirects any style to the languages store. I have 2 images: the first one is my style number, and the 2nd one is a style I want dropdown with like this height

Image Number 1 I have Style

Image Number 2 style I want

the code cant remove PHP code or delete any think in this I want edit HTML and CSS

            {foreach from=$languages item=language}

                         {$language.name_simple}

                  {/foreach}


问:
react-native Firestore query to search in an area
I need to query my collection to find the records in an area.

Currently, I've got my map view boundaries in a JSON object:

```<code>{
    "minLng": -123.12382489442824,
    "minLat": 49.27978719725107,
    "maxLng": -123.11826568096875,
    "maxLat": 49.28467300126758
}
</code>```

And I need to filter documents with locations that are inside this area.
Is it possible with Firestore in react-native?

In a simple statement, fetching records in an area.

Body:
I need to query my collection to find the records in an area.

Currently, I've got my map view boundaries in a JSON object:

{
    "minLng": -123.12382489442824,
    "minLat": 49.27978719725107,
    "maxLng": -123.11826568096875,
    "maxLat": 49.28467300126758
}

And I need to filter documents with locations that are inside this area.
Is it possible with Firestore in react-native?

In a simple statement, fetching records in an area.


问:
Sending tail log data to the react component Nodejs
I have a list of log files some of which are done updating and some are still updating. I'm using server side events to fetch the data to the react component but the res.write() is not sending anything to the front-end

Client Code

```<code>//This function is present in useEffect block
const getLogs = async () => {
    const path = props.file;
    await fetchEventSource(`${baseURL}/stream`, {
      method: "POST",
      headers: {
        Accept: "text/event-stream",
        fileName: path
      },
      onopen(res) {
        if (res.ok && res.status === 200) {
          console.log("Connection made ", res);
        } else if (
          res.status >= 400 &&
          res.status < 500 &&
          res.status !== 429
        ) {
          console.log("Client side error ", res);
        }
        else console.log(res)
      },
      onmessage(event) {
        event.data = event.data.toString().split("\n");
        console.log(event.data);
        if(event.data.length) setData((data) => [...data, event.data]);
      },
      onclose() {
        console.log("Connection closed by the server");
      },
      onerror(err) {
        console.log("There was an error from server", err);
      },
    });
  }
</code>```

Server code

```<code>app.post('/stream', async (req, res) => {
    const filename = req.headers.filename;
    res.writeHead(200, {
        Connection: "keep-alive",
        "Content-Type": "text/event-stream",
        "Cache-Control": "no-cache",
    });
    res.flushHeaders();
    const stream = TailingReadableStream.createReadStream(filename, { timeout: 0 });
    stream.on('data', buffer => {
        res.write(
            `data:${JSON.stringify(buffer)}`
        )
    });
    stream.on('close', () => {
        console.log("close");
    });
    res.on('close', () => {
        console.log('Client closed connection')
    })
})
</code>```

Body:
I have a list of log files some of which are done updating and some are still updating. I'm using server side events to fetch the data to the react component but the res.write() is not sending anything to the front-end

Client Code

//This function is present in useEffect block
const getLogs = async () => {
    const path = props.file;
    await fetchEventSource(`${baseURL}/stream`, {
      method: "POST",
      headers: {
        Accept: "text/event-stream",
        fileName: path
      },
      onopen(res) {
        if (res.ok && res.status === 200) {
          console.log("Connection made ", res);
        } else if (
          res.status >= 400 &&
          res.status < 500 &&
          res.status !== 429
        ) {
          console.log("Client side error ", res);
        }
        else console.log(res)
      },
      onmessage(event) {
        event.data = event.data.toString().split("\n");
        console.log(event.data);
        if(event.data.length) setData((data) => [...data, event.data]);
      },
      onclose() {
        console.log("Connection closed by the server");
      },
      onerror(err) {
        console.log("There was an error from server", err);
      },
    });
  }

Server code

app.post('/stream', async (req, res) => {
    const filename = req.headers.filename;
    res.writeHead(200, {
        Connection: "keep-alive",
        "Content-Type": "text/event-stream",
        "Cache-Control": "no-cache",
    });
    res.flushHeaders();
    const stream = TailingReadableStream.createReadStream(filename, { timeout: 0 });
    stream.on('data', buffer => {
        res.write(
            `data:${JSON.stringify(buffer)}`
        )
    });
    stream.on('close', () => {
        console.log("close");
    });
    res.on('close', () => {
        console.log('Client closed connection')
    })
})


问:
R raster::extract fails to create data.frame (again)
I am having the same issue as @J.Babt here. The only answer to the question is that it was a bug that was solved in a newer version of the package raster. However, even with the most updated version of the package, I'm getting the exact same error.

Error in do.call(rbind, sapply(1:length(res), function(x) if (!is.null(res[[x]])) cbind(x, :
second argument must be a list

This is the part of my code that retrieves the above error:

```<code>wall_auxiliar_population_41_42 <- raster::extract(population, wall_41_42_line, df = TRUE, cellnumbers = TRUE)
</code>```

This is what wall_41_42_line is:

```<code>class(wall_41_42_line)
</code>```

"sf"         "data.frame"

Here's the data to replicate the code above: raster and line.

Body:
I am having the same issue as @J.Babt here. The only answer to the question is that it was a bug that was solved in a newer version of the package raster. However, even with the most updated version of the package, I'm getting the exact same error.

Error in do.call(rbind, sapply(1:length(res), function(x) if (!is.null(res[[x]])) cbind(x, :
second argument must be a list

This is the part of my code that retrieves the above error:

wall_auxiliar_population_41_42 <- raster::extract(population, wall_41_42_line, df = TRUE, cellnumbers = TRUE)

This is what wall_41_42_line is:

class(wall_41_42_line)

"sf"         "data.frame"

Here's the data to replicate the code above: raster and line.


问:
Export shapefile to Postgres with geometry that is not given in the attribute table
I work with exporting shapefiles to PostgreSQL through Python scripting. When I open the .shp file in QGIS, I can visualize the layer as a map. I get info about the coordinates and geometry, even though the .shp file does not have any geometry field (see image).

Shapefile visualization and attribute table

I want to export the shapefiles to PostgreSQL with the geometry included, but I don't know where to retrieve it from. The connection to the database was successful, the export as well, but the Postgres table only contains the attribute table of the shapefile.

Each dataset has a .shp, .shx, .prj, .dbf and .cpg file. I saw projection information in the .prj file and I was wondering if I could somehow translate that information to a geometry column. Or if I could retrieve the geometry from one of these auxiliary files.

Or is there a better way? Maybe some GDAL/OGR function that also takes the .shx, .prj, .dbf and .cpg files into consideration when exporting the table to Postgres and does an elegant merge between them?

I tried using the algorithm given here - https://lists.osgeo.org/pipermail/gdal-dev/2011-July/029304.html. Using this script I encountered the main problem - the export being done only on the .shp file, not taking the auxiliary info into account.

Thank you!


问:
any method for broadcast streams does not unsubscribe
If a broadcast stream is used, then when using any and after finding the desired value, the subscription is not canceled. Is this a bug in the library or just a misapplication of it? If the stream is not broadcast, then the code works as expected.

```<code>import 'dart:async';

Stream<int> test() async* {
  for (int i = 1; i <= 10; i++) {
    print('current value:$i');
    yield i;
  }
}

void main() async {
  Stream _s = test();
  var s = _s.asBroadcastStream();

  print(await s.any((element) => element >= 5));
}
</code>```

When applying any to broadcast streams, I expected that after finding the desired value, the subscription would be canceled, but the experiment shows that this is not the case.

Body:
If a broadcast stream is used, then when using any and after finding the desired value, the subscription is not canceled. Is this a bug in the library or just a misapplication of it? If the stream is not broadcast, then the code works as expected.

import 'dart:async';

Stream<int> test() async* {
  for (int i = 1; i <= 10; i++) {
    print('current value:$i');
    yield i;
  }
}

void main() async {
  Stream _s = test();
  var s = _s.asBroadcastStream();

  print(await s.any((element) => element >= 5));
}

When applying any to broadcast streams, I expected that after finding the desired value, the subscription would be canceled, but the experiment shows that this is not the case.


问:
Best way to create two large objects with similar fields in Java
I have a Document Generator class that takes in the values that need to be written, writes them to the document using a third party document creation tool and returns the generated document.

The thing is, the class can load 1 of 2 templates, depending on if one of the values passed in is positive or negative.  Both templates write to mostly the same fields, but the negative template is missing a few of these, so they do not need to be written given the negative case.

What would be the best way to go about this?  My solution was to just use if statements to load the different template and set the appropriate values.  But this doesn't feel very extensible to me, adding additional templates would make the code messier.

One solution I had considered was using an Interface and creating separate classes for both templates, and have them set their own fields.  But both templates are nearly identical, so I feel like this would add too much code duplication.

Here's roughly what my code looks like:

Class that calls the document generator:

```<code>public class DocumentService {

private final DocumentGenerator documentGenerator;

public Document getDocument(DocumentValues documentValues) {
      return documentGenerator.createDocument(documentValues)
  }
}
</code>```

Document generator class:

```<code>public class DocumentGenerator {

public Document createDocument(DocumentValues documentValues) {
        ThirdPartyDocumentTool document;

        if (documentValues.invoiceAmount >= 0)
            document.setTemplate("Positive-Invoice.pdf")
        else
            document.setTemplate("Negative-Invoice.pdf")

        document.setField("key1", documentValues.value1)
        document.setField("key2", documentValues.value2)
        document.setField("key3", documentValues.value3)
        ...

        if (documentValues.invoiceAmount >= 0) {
           document.setField("key8", documentValues.value8)
           document.setField("key9", documentValues.value9)
        }

        return document.createDocument()
              }
            }
</code>```

Thank you for your time!

Body:
I have a Document Generator class that takes in the values that need to be written, writes them to the document using a third party document creation tool and returns the generated document.

The thing is, the class can load 1 of 2 templates, depending on if one of the values passed in is positive or negative.  Both templates write to mostly the same fields, but the negative template is missing a few of these, so they do not need to be written given the negative case.

What would be the best way to go about this?  My solution was to just use if statements to load the different template and set the appropriate values.  But this doesn't feel very extensible to me, adding additional templates would make the code messier.

One solution I had considered was using an Interface and creating separate classes for both templates, and have them set their own fields.  But both templates are nearly identical, so I feel like this would add too much code duplication.

Here's roughly what my code looks like:

Class that calls the document generator:

public class DocumentService {

private final DocumentGenerator documentGenerator;

public Document getDocument(DocumentValues documentValues) {
      return documentGenerator.createDocument(documentValues)
  }
}

Document generator class:

public class DocumentGenerator {

public Document createDocument(DocumentValues documentValues) {
        ThirdPartyDocumentTool document;

        if (documentValues.invoiceAmount >= 0)
            document.setTemplate("Positive-Invoice.pdf")
        else
            document.setTemplate("Negative-Invoice.pdf")

        document.setField("key1", documentValues.value1)
        document.setField("key2", documentValues.value2)
        document.setField("key3", documentValues.value3)
        ...

        if (documentValues.invoiceAmount >= 0) {
           document.setField("key8", documentValues.value8)
           document.setField("key9", documentValues.value9)
        }

        return document.createDocument()
              }
            }

Thank you for your time!


问:
Cant handle two interactive windows in matplotlib
A need to show two interactive windows and on each i got two sliders, but only on second window it works.
On first it just in static mode, and I cant use it to show what will be if I change the slider</p>
```<code>from matplotlib import pyplot as plt
import numpy as np
from matplotlib.axes import Axes
from matplotlib.widgets import Slider, RadioButtons

funcs = {
    'sin(x)': lambda x, amp, freq: amp * np.sin(2 * np.pi * freq * x),
    'cos(x)': lambda x, amp, freq: amp * np.cos(2 * np.pi * freq * x)
}
figs = [plt.figure(1), plt.figure(2)]
for i in range(2):
    fig = figs[i]
    fig.subplots_adjust(left=0.25, bottom=0.25)
    fig.suptitle(f"Волна {i + 1}")
    x = np.linspace(0, np.pi * 3, 500)
    ax: Axes = fig.add_subplot(111, xlim=(0, 3 * np.pi), ylim=(-5, 5), yticks=np.arange(-5, 5))
    ax.set_aspect('equal')
    ax.grid(True, which='both')
    line, = ax.plot(x, funcs['sin(x)'](x, 1, 1 / (2 * np.pi)), linewidth=2, color='red')
    amp_slider_ax = fig.add_axes([0.25, 0.15, 0.65, 0.03], facecolor="lightgoldenrodyellow")
    amp_slider = Slider(amp_slider_ax, 'Amp', -5, 5, valinit=1)
    freq_slider_ax = fig.add_axes([0.25, 0.1, 0.65, 0.03], facecolor="lightgoldenrodyellow")
    freq_slider = Slider(freq_slider_ax, 'Freq', 0, 2, valinit=1 / (2 * np.pi))
    func_radios_ax = fig.add_axes([0.025, 0.5, 0.15, 0.15], facecolor="lightgoldenrodyellow")
    func_radios = RadioButtons(func_radios_ax, funcs.keys(), active=0)

    def sliders_on_changed(val):
        line.set_ydata(funcs[func_radios.value_selected](x, amp_slider.val, freq_slider.val))
        fig.canvas.draw_idle()

    def func_radios_on_clicked(label):
        line.set_ydata(funcs[label](x, amp_slider.val, freq_slider.val))
        fig.canvas.draw_idle()

    amp_slider.on_changed(sliders_on_changed)
    freq_slider.on_changed(sliders_on_changed)
    func_radios.on_clicked(func_radios_on_clicked)
plt.show()
</code>```

Body:
A need to show two interactive windows and on each i got two sliders, but only on second window it works.
On first it just in static mode, and I cant use it to show what will be if I change the slider

from matplotlib import pyplot as plt
import numpy as np
from matplotlib.axes import Axes
from matplotlib.widgets import Slider, RadioButtons

funcs = {
    'sin(x)': lambda x, amp, freq: amp * np.sin(2 * np.pi * freq * x),
    'cos(x)': lambda x, amp, freq: amp * np.cos(2 * np.pi * freq * x)
}
figs = [plt.figure(1), plt.figure(2)]
for i in range(2):
    fig = figs[i]
    fig.subplots_adjust(left=0.25, bottom=0.25)
    fig.suptitle(f"Волна {i + 1}")
    x = np.linspace(0, np.pi * 3, 500)
    ax: Axes = fig.add_subplot(111, xlim=(0, 3 * np.pi), ylim=(-5, 5), yticks=np.arange(-5, 5))
    ax.set_aspect('equal')
    ax.grid(True, which='both')
    line, = ax.plot(x, funcs['sin(x)'](x, 1, 1 / (2 * np.pi)), linewidth=2, color='red')
    amp_slider_ax = fig.add_axes([0.25, 0.15, 0.65, 0.03], facecolor="lightgoldenrodyellow")
    amp_slider = Slider(amp_slider_ax, 'Amp', -5, 5, valinit=1)
    freq_slider_ax = fig.add_axes([0.25, 0.1, 0.65, 0.03], facecolor="lightgoldenrodyellow")
    freq_slider = Slider(freq_slider_ax, 'Freq', 0, 2, valinit=1 / (2 * np.pi))
    func_radios_ax = fig.add_axes([0.025, 0.5, 0.15, 0.15], facecolor="lightgoldenrodyellow")
    func_radios = RadioButtons(func_radios_ax, funcs.keys(), active=0)

    def sliders_on_changed(val):
        line.set_ydata(funcs[func_radios.value_selected](x, amp_slider.val, freq_slider.val))
        fig.canvas.draw_idle()

    def func_radios_on_clicked(label):
        line.set_ydata(funcs[label](x, amp_slider.val, freq_slider.val))
        fig.canvas.draw_idle()

    amp_slider.on_changed(sliders_on_changed)
    freq_slider.on_changed(sliders_on_changed)
    func_radios.on_clicked(func_radios_on_clicked)
plt.show()


问:
Problems with GKE log-based custom metric HPA
I'm working with a GKE cluster, my application has some 'special' logs that are used by a log-based metric as a simple 'counter' metric. I can see this metric in 'Metric Explorer' with name:

"logging.googleapis.com/user/custom_metric_name"

I'm trying to define an HPA for my application following:

https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics

using this metric. I tried running all commands listed in the guide and adding this piece of code:

```<code>apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: dployment-name
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: deployment-name
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Pods
    pods:
      metric:
        name: logging.googleapis.com|user|custom_metric_name
      target:
        type: AverageValue
        averageValue: 20
</code>```

but the metric still does not work, using kubectl get hpa the target has unknown
and using kubectl describe hpa I get the following error:
"the HPA was unable to compute the replica count: unable to get metric logging.googleapis.com|user|custom_metric_name: unable to fetch metrics from custom metrics API: googleapi: Error 400: The supplied filter does not specify a valid combination of metric monitored resource descriptors. The query will not return any timme series., badRequest"

Anyone has some ideas? Thank for the help.

Body:
I'm working with a GKE cluster, my application has some 'special' logs that are used by a log-based metric as a simple 'counter' metric. I can see this metric in 'Metric Explorer' with name:

"logging.googleapis.com/user/custom_metric_name"

I'm trying to define an HPA for my application following:

https://cloud.google.com/kubernetes-engine/docs/tutorials/autoscaling-metrics

using this metric. I tried running all commands listed in the guide and adding this piece of code:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: dployment-name
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: deployment-name
  minReplicas: 1
  maxReplicas: 5
  metrics:
  - type: Pods
    pods:
      metric:
        name: logging.googleapis.com|user|custom_metric_name
      target:
        type: AverageValue
        averageValue: 20

but the metric still does not work, using kubectl get hpa the target has unknown
and using kubectl describe hpa I get the following error:
"the HPA was unable to compute the replica count: unable to get metric logging.googleapis.com|user|custom_metric_name: unable to fetch metrics from custom metrics API: googleapi: Error 400: The supplied filter does not specify a valid combination of metric monitored resource descriptors. The query will not return any timme series., badRequest"

Anyone has some ideas? Thank for the help.


问:
How do I secure my Static website hosted by AWS S3 , Route53, CloudFront & ACM
I have followed this guide on  AWS documentation. I am trying to host a simple static website in the UK [eu-west-2]. I can see that a few people have asked this question but none of the solutions seem to change this status :/ The web content shows up ok but the address bar shows that the website is not secure.

From what I understand

To be able to use Cloudfront, the SSL certificate xxxxxx.co.uk (with both www.xxxxxx.co.uk & xxxxxx.co.uk) must be requested in N.Virginia region, which I created & linked from scratch incase the default was faulty :check

Configure root domain bucket for website hosting & Configure  subdomain bucket for website redirect

DNS validation for SSL certificate so that Cname records are automatically added to R53. Crossed checked to see that the correct cname is linked to the SSL certificate used by Cloudfront

At one stage, I added the Alias to CloudFront as an A record in my R53 for xxxxxx.co.uk. It didn't work, because there was nothing pointing to the root domain bucket anymore [Thought i'd mention this incase it helps with troubleshooting]

I've checked AWS ACM Troubleshooting advice too :

Certificate for the domain(/s) is new

Caches cleared when refreshing page / Tried a different browser

It's a simple www.xxxxxx.co.uk website and so the certificate is valid for the name of the server

Other resource used include

https://towardsdatascience.com/static-hosting-with-ssl-on-s3-a4b66fb7cd00

https://medium.com/@aidan.hallett/how-to-set-up-a-static-website-with-ssl-tls-and-a-custom-domain-using-aws-s3-and-cloudfront-145be108b431

But I still get the 'Not secure' error which is driving me batty atm. Thanks in advance


问:
Relationship with string field EF Core 7.0
how are you?

I have a need to relate 2 tables one to many with a string field that are not table keys

```<code> public class Schedule
 {
     public int Id { get; set}
     public string Comment { get; set;}
     public string Name { get; set;}
}
 public class Products
{
     public int Id { get; set;}
     public string Product { get; set;}
 }
</code>```

I need to relate Schedule.Name with Products.Product

How can I do this in a simple way

I'm using EF Core 7.0

I read several posts, but usually the tutorials are referring to standard relationships. Where an ID field relates to another ID from another table

Thanks

I tried using data annotation and api fluent, but I couldn't get a result

Body:
how are you?

I have a need to relate 2 tables one to many with a string field that are not table keys

 public class Schedule
 {
     public int Id { get; set}
     public string Comment { get; set;}
     public string Name { get; set;}
}
 public class Products
{
     public int Id { get; set;}
     public string Product { get; set;}
 }

I need to relate Schedule.Name with Products.Product

How can I do this in a simple way

I'm using EF Core 7.0

I read several posts, but usually the tutorials are referring to standard relationships. Where an ID field relates to another ID from another table

Thanks

I tried using data annotation and api fluent, but I couldn't get a result


问:
Exclude a specific class from Maven dependency at runtime
I am working with a Spring Boot application, where I have added one dependency in pom.xml, but I would like to remove one specific class from one of the dependencies as follows:

pom.xml

```<code><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.myapp</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.anotherapp</groupId>
            <artifactId>java-commons</artifactId>
            <version>0.0.10-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <useIncrementalCompilation>false</useIncrementalCompilation>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <additionalOptions>
                        <additionalOption>-Xdoclint:none</additionalOption>
                    </additionalOptions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>com.anotherapp:java-commons</artifact>
                            <excludes>
                                <exclude>src/main/java/com/anotherapp/exception/TcInternalExceptionAspect.*</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>
                                        com.myapp.MainClass
                                    </mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>target/classes/static/</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-info</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plug>
            </build>
        </profile>
    </profiles>
</project>
</code>```

Here, in this project, as you can see in the above pom, I would like to exclude the class: TcInternalExceptionAspect from the dependency java-commons. As recommended in a few posts here, I included the shade plugin.

But, after the build is complete, I am still able to see the TcInternalExceptionAspect class in the final jar file. I am not able to understand, what I am missing here.

In this context, I have gone through this: How to exclude specific class from a Maven dependency ( Jar dependency) at runtime, but it did not help.

Could anyone please help here? Thanks.

Body:
I am working with a Spring Boot application, where I have added one dependency in pom.xml, but I would like to remove one specific class from one of the dependencies as follows:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.myapp</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.anotherapp</groupId>
            <artifactId>java-commons</artifactId>
            <version>0.0.10-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <useIncrementalCompilation>false</useIncrementalCompilation>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <additionalOptions>
                        <additionalOption>-Xdoclint:none</additionalOption>
                    </additionalOptions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.14.1</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.4.1</version>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>META-INF/*.SF</exclude>
                                <exclude>META-INF/*.DSA</exclude>
                                <exclude>META-INF/*.RSA</exclude>
                            </excludes>
                        </filter>
                        <filter>
                            <artifact>com.anotherapp:java-commons</artifact>
                            <excludes>
                                <exclude>src/main/java/com/anotherapp/exception/TcInternalExceptionAspect.*</exclude>
                            </excludes>
                        </filter>
                    </filters>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>
                                        com.myapp.MainClass
                                    </mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <configuration>
                            <filesets>
                                <fileset>
                                    <directory>target/classes/static/</directory>
                                </fileset>
                            </filesets>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-info</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plug>
            </build>
        </profile>
    </profiles>
</project>

Here, in this project, as you can see in the above pom, I would like to exclude the class: TcInternalExceptionAspect from the dependency java-commons. As recommended in a few posts here, I included the shade plugin.

But, after the build is complete, I am still able to see the TcInternalExceptionAspect class in the final jar file. I am not able to understand, what I am missing here.

In this context, I have gone through this: How to exclude specific class from a Maven dependency ( Jar dependency) at runtime, but it did not help.

Could anyone please help here? Thanks.


问:
Pandas Boolean Row Selection with Mixed Types
I am trying to select rows in a data frame data based on two conditions. One is on a column called let's call it id is meant to be selected on membership in a list keep and another, call it toggle, is meant to be checked on an equality condition.

My code is:

```<code> new_data = data[(data['id'].isin(keep) & data['toggle']==2)]
</code>```

which returns a data frame with zero rows. However if I do

```<code>new_data = data[data['id'].isin(keep)]
new_data = new_data[new_data['toggle']==2]
</code>```

I get a data frame with several rows which is what SHOULD happen. What am I doing wrong here?

Body:
I am trying to select rows in a data frame data based on two conditions. One is on a column called let's call it id is meant to be selected on membership in a list keep and another, call it toggle, is meant to be checked on an equality condition.

My code is:

 new_data = data[(data['id'].isin(keep) & data['toggle']==2)]

which returns a data frame with zero rows. However if I do

new_data = data[data['id'].isin(keep)]
new_data = new_data[new_data['toggle']==2]

I get a data frame with several rows which is what SHOULD happen. What am I doing wrong here?


问:
Python: Trying to scan for active bluetooth devices
I found online multiple sources that said that discover_devices scans for active bluetooth devices, but for me it was printing all the bluetooth devices that remembered on my computer. Is there something wrong with my code/settings?

`

```<code>import bluetooth

nearby_devices = bluetooth.discover_devices(lookup_names=True)
print(nearby_devices)

for addr, name in nearby_devices:
    print('\nname = ', name, "\naddress = ", addr)

</code>```

`

Body:
I found online multiple sources that said that discover_devices scans for active bluetooth devices, but for me it was printing all the bluetooth devices that remembered on my computer. Is there something wrong with my code/settings?

`

import bluetooth

nearby_devices = bluetooth.discover_devices(lookup_names=True)
print(nearby_devices)

for addr, name in nearby_devices:
    print('\nname = ', name, "\naddress = ", addr)

`


问:
maven issue : Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central
A maven build showing me below error: any help to fix it ?
Below is version

```<code> mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 17.0.5, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.5.0.8-2.el8.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-326.el8.x86_64", arch: "amd64", family: "unix"

[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom: Unknown host repo.maven.apache.org: Name or service not known -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
</code>```

The pom stops below is where it stuck in DEBUG :

```<code>[INFO] --------------------------------[ pom ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
</code>```

and I tried creating settings.xml with correct proxy but never helped. wget works fine from bvelow location : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom

So I am sure its not proxy issue and other packages copied fine.
Any idea ?

Body:
A maven build showing me below error: any help to fix it ?
Below is version

 mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 17.0.5, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.5.0.8-2.el8.x86_64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-326.el8.x86_64", arch: "amd64", family: "unix"

[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom: Unknown host repo.maven.apache.org: Name or service not known -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

The pom stops below is where it stuck in DEBUG :

[INFO] --------------------------------[ pom ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom

and I tried creating settings.xml with correct proxy but never helped. wget works fine from bvelow location : https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom

So I am sure its not proxy issue and other packages copied fine.
Any idea ?


问:
ArrayList partially overwrites stored values (but not all of them) when adding new object to the list (object variables aren´t static)
First of all English is not my first language, so sorry in advance for the mistakes.

The thing is I need some help understanding why I´m overwriting some values inside my array list.

I know this question has been asked before but all solutions I found about this issue are related to variables declared static when they shouldn´t be, which I think is not my case.

The code is searching in two different .xml documents for pop songs contained in a especific album, and returning the array with the title and genres of each song.

First I have a Song defined as:

```<code>public class Song {
    private String title;
    private ArrayList<String> genre;
    public Song (String t, ArrayList<String> g) {
        title = t;
        genre = g;
    }
    public String getTitle () { return title; }
    public ArrayList<String> getGenre () { return genre; }
}
</code>```

Then I´m searching trough the .xml documents for the required album and country.
It correctly finds the songs and the genres, but I´m having trouble adding them into an array.
The code is the following:
In this example the required album is called "titulo5" and thecountry is "england".

```<code>import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

public class Main {
    private static ArrayList<Song> Songs = new ArrayList<Song>();
    static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    static DocumentBuilder db;
    static {
        try {
            db = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {

        String nextURL = run("tmvl_01.xml","england","titulo5");
        nextURL = run(nextURL,"england","titulo5");

    }
    private static String run(String filename, String country, String album)throws ParserConfigurationException, IOException, SAXException
    {
        String nextURL = null;
        ArrayList<String> auxArray = new ArrayList<String>();
        try
        {
            Document doc = db.parse(new File(filename));
            Boolean test = false;

            NodeList nl = doc.getElementsByTagName("Album");
            Element elem;

            for (int x=0; x < nl.getLength(); x++)
            {
                elem = (Element)nl.item(x);
                NodeList nlTitles = elem.getElementsByTagName("Titulo");
                NodeList nlSongs = elem.getElementsByTagName("Song");
                Element elemAlbumTitle = (Element)nlTitles.item(0);
                String albumName = elemAlbumTitle.getTextContent().trim();
                if (albumName.equals(album)){
                    for(int i= 0; i < nlSongs.getLength();i++)
                    {
                        Element elemSongs = (Element)nlSongs.item(i);
                        NodeList nlSongTitle = elem.getElementsByTagName("Title");
                        Element elemSongTItle = (Element) nlSongTitle.item(i);
                        String songTItle = elemSongTItle.getTextContent().trim();
                        NodeList nlGenre = elemSongs.getElementsByTagName("Genre");
                        auxArray.clear();
                        for (int e = 0; e< nlGenre.getLength(); e++)
                        {
                            Element elemGenre = (Element) nlGenre.item(e);
                            String genreName = elemGenre.getTextContent().trim();

                            auxArray.add(genreName);
                            if(genreName.equals("pop"))
                            {
                                test = true;
                            }
                        }

                        if(test == true)
                        {
                            System.out.println("Array: " + auxArray);
                            System.out.println("Titulo: " +songTItle);

                            Song check = new Song(songTItle,auxArray);

                            System.out.println("Check SOng: " + check.getGenre());
                            Songs.add(check); //Here is the issue
                            System.out.println("ArraySize: " + Songs.size());

                            for(int z = 0; z<Songs.size();z++) {
                                String songTitle = Songs.get(z).getTitle();
                                System.out.println("ArrayTitulo: " + songTitle);
                                String songGenres;
                                for (int p = 0  ; p < Songs.get(z).getGenre().size();p++)
                                {
                                    songGenres = Songs.get(z).getGenre().get(p);
                                    System.out.println("ArrayGenreP: "+p + "  ArrayGenreZ: " + z +  "  Item: "+songGenres);

                                }
                            }
                            System.out.println("Genres: " + Songs.get(0).getGenre());
                            if(Songs.size()>1){
                                System.out.println("Genres: " + Songs.get(1).getGenre());

                            }
                            auxArray.clear();
                            test = false;
                        }

                    }
                }
            }
            NodeList nl_TVMLs = doc.getElementsByTagName("TVML");
            Element elemnt;

            for (int x=0; x < nl_TVMLs.getLength(); x++)
            {
                elemnt = (Element)nl_TVMLs.item(x);
                nextURL = elemnt.getTextContent().trim();
                System.out.println("Siguiente URL: " + nextURL);
            }
        }
        catch(SAXException e)
        {
            System.out.println("Excepction no well formed");
        }
        return nextURL;
    }

}
</code>```

This, I think, it should add in the Songs array two songs, with two titles and, two genres the first one and three genres the second one, resulting in something like this:

Song Title: 8 Genres:[metal,pop,balad]

Song Title: 11 Genres:[funk,pop]

But the output I´m getting is:

Song Title: 8 Genres: [funk,pop]

Song Title: 11 Genres:[funk,pop]

Titles are correct, but genres are beeing overwrited by the last search in the loop.

My System.out.println() results are:

```<code>Array: [metal, pop, ballad]                 --> *First genre extracted array*

Title: 8
Check SOng: [metal, pop, ballad]            --> *Genres inside the Song object*

ArraySize: 1

ArrayTitulo: 8 --> Title is OK

ArrayGenreP: 0  ArrayGenreZ: 0  Item: metal  --> *P = genres index and Z = title index*

ArrayGenreP: 1  ArrayGenreZ: 0  Item: pop

ArrayGenreP: 2  ArrayGenreZ: 0  Item: ballad

Genres: [metal, pop, ballad]                 *--> Here is OK: Title 8 should have this 3 genres*

Array: [funk, pop]                           *--> This is the second array which is correct*

Title: 11                                    *--> This is the second title which is also ok*

Check SOng: [funk, pop]                      *--> This is the array stored in the new song object*

ArraySize: 2                                 *--> The new updated array size*

ArrayTitle: 8                                *--> The first title is correct*

ArrayGenreP: 0  ArrayGenreZ: 0  Item: funk   *--> Here is the problem, it overwrites the previous genres*

ArrayGenreP: 1  ArrayGenreZ: 0  Item: pop    * --> (but not the previous title)*

ArrayTitle: 11                                 --> Second title is also correct

ArrayGenreP: 0  ArrayGenreZ: 1  Item: funk  *-->These are the correct genres for song with title 11*

ArrayGenreP: 1  ArrayGenreZ: 1  Item: pop
Genres: [funk, pop]                         *--> Here should be [metal, pop, ballad] *

Genres: [funk, pop]                         *--> Here is OK*

</code>```

And I´m completely stuck, I don´t know what else I can try, so some help would be very appreciated.

Maybe is something that has already beeing answered, if is the case I´m sorry, not my intention to waste anyones time.

Just in case I´m showing next the 2 .xml documents I created. The first one is:

```<code><?xml version="1.0"?>
<Music>
   <Year>2001</Year>
   <Album>
      <Name>uno</Name>
      <Country>spain</Country>
      <Titulo>titulo1</Titulo>
      <Song>
         <Title>1</Title>
         <Genre>pop</Genre>
         <Genre>rock</Genre>
      </Song>
      <Song>
         <Title>2</Title>
         <Genre>metal</Genre>
      </Song>
   </Album>
   <Album>
      <Name>dos</Name>
      <Country>england</Country>
      <Titulo>titulo2</Titulo>
      <Song>
         <Title>3</Title>
         <Genre>pop</Genre>
         <Genre>metal</Genre>
         <Genre>soul</Genre>
      </Song>
   </Album>
   <TVML>tmvl_02.xml</TVML>
</Music>
</code>```

And the second one:

```<code><?xml version="1.0"?>
<Music>
   <Year>2003</Year>
   <Album>
      <Name>tres</Name>
      <Country>morocco</Country>
      <Titulo>titulo3</Titulo>
      <Song>
         <Title>4</Title>
         <Genre>pop</Genre>
         <Genre>soul</Genre>
      </Song>
      <Song>
         <Title>5</Title>
         <Genre>reggae</Genre>
      </Song>
      <Song>
         <Title>6</Title>
         <Genre>rock</Genre>
         <Genre>pop</Genre>
      </Song>
   </Album>
   <Album>
      <Name>cuatro</Name>
      <Country>france</Country>
      <Titulo>titulo4</Titulo>
      <Song>
         <Title>7</Title>
         <Genre>inide</Genre>
      </Song>
   </Album>
   <Album>
      <Name>cinco</Name>
      <Country>england</Country>
      <Titulo>titulo5</Titulo>
      <Song>
         <Title>10</Title>
         <Genre>rock</Genre>
      </Song>
      <Song>
         <Title>8</Title>
         <Genre>metal</Genre>
         <Genre>pop</Genre>
         <Genre>ballad</Genre>
      </Song>
      <Song>
         <Title>9</Title>
         <Genre>rock</Genre>
      </Song>
      <Song>
         <Title>11</Title>
         <Genre>funk</Genre>
         <Genre>pop</Genre>
      </Song>
   </Album>
</Music>
</code>```

Thx in advance for your help and merry christmas.

Body:
First of all English is not my first language, so sorry in advance for the mistakes.

The thing is I need some help understanding why I´m overwriting some values inside my array list.

I know this question has been asked before but all solutions I found about this issue are related to variables declared static when they shouldn´t be, which I think is not my case.

The code is searching in two different .xml documents for pop songs contained in a especific album, and returning the array with the title and genres of each song.

First I have a Song defined as:

public class Song {
    private String title;
    private ArrayList<String> genre;
    public Song (String t, ArrayList<String> g) {
        title = t;
        genre = g;
    }
    public String getTitle () { return title; }
    public ArrayList<String> getGenre () { return genre; }
}

Then I´m searching trough the .xml documents for the required album and country.
It correctly finds the songs and the genres, but I´m having trouble adding them into an array.
The code is the following:
In this example the required album is called "titulo5" and thecountry is "england".

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

public class Main {
    private static ArrayList<Song> Songs = new ArrayList<Song>();
    static DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    static DocumentBuilder db;
    static {
        try {
            db = dbf.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {

        String nextURL = run("tmvl_01.xml","england","titulo5");
        nextURL = run(nextURL,"england","titulo5");

    }
    private static String run(String filename, String country, String album)throws ParserConfigurationException, IOException, SAXException
    {
        String nextURL = null;
        ArrayList<String> auxArray = new ArrayList<String>();
        try
        {
            Document doc = db.parse(new File(filename));
            Boolean test = false;

            NodeList nl = doc.getElementsByTagName("Album");
            Element elem;

            for (int x=0; x < nl.getLength(); x++)
            {
                elem = (Element)nl.item(x);
                NodeList nlTitles = elem.getElementsByTagName("Titulo");
                NodeList nlSongs = elem.getElementsByTagName("Song");
                Element elemAlbumTitle = (Element)nlTitles.item(0);
                String albumName = elemAlbumTitle.getTextContent().trim();
                if (albumName.equals(album)){
                    for(int i= 0; i < nlSongs.getLength();i++)
                    {
                        Element elemSongs = (Element)nlSongs.item(i);
                        NodeList nlSongTitle = elem.getElementsByTagName("Title");
                        Element elemSongTItle = (Element) nlSongTitle.item(i);
                        String songTItle = elemSongTItle.getTextContent().trim();
                        NodeList nlGenre = elemSongs.getElementsByTagName("Genre");
                        auxArray.clear();
                        for (int e = 0; e< nlGenre.getLength(); e++)
                        {
                            Element elemGenre = (Element) nlGenre.item(e);
                            String genreName = elemGenre.getTextContent().trim();

                            auxArray.add(genreName);
                            if(genreName.equals("pop"))
                            {
                                test = true;
                            }
                        }

                        if(test == true)
                        {
                            System.out.println("Array: " + auxArray);
                            System.out.println("Titulo: " +songTItle);

                            Song check = new Song(songTItle,auxArray);

                            System.out.println("Check SOng: " + check.getGenre());
                            Songs.add(check); //Here is the issue
                            System.out.println("ArraySize: " + Songs.size());

                            for(int z = 0; z<Songs.size();z++) {
                                String songTitle = Songs.get(z).getTitle();
                                System.out.println("ArrayTitulo: " + songTitle);
                                String songGenres;
                                for (int p = 0  ; p < Songs.get(z).getGenre().size();p++)
                                {
                                    songGenres = Songs.get(z).getGenre().get(p);
                                    System.out.println("ArrayGenreP: "+p + "  ArrayGenreZ: " + z +  "  Item: "+songGenres);

                                }
                            }
                            System.out.println("Genres: " + Songs.get(0).getGenre());
                            if(Songs.size()>1){
                                System.out.println("Genres: " + Songs.get(1).getGenre());

                            }
                            auxArray.clear();
                            test = false;
                        }

                    }
                }
            }
            NodeList nl_TVMLs = doc.getElementsByTagName("TVML");
            Element elemnt;

            for (int x=0; x < nl_TVMLs.getLength(); x++)
            {
                elemnt = (Element)nl_TVMLs.item(x);
                nextURL = elemnt.getTextContent().trim();
                System.out.println("Siguiente URL: " + nextURL);
            }
        }
        catch(SAXException e)
        {
            System.out.println("Excepction no well formed");
        }
        return nextURL;
    }

}

This, I think, it should add in the Songs array two songs, with two titles and, two genres the first one and three genres the second one, resulting in something like this:

Song Title: 8 Genres:[metal,pop,balad]

Song Title: 11 Genres:[funk,pop]

But the output I´m getting is:

Song Title: 8 Genres: [funk,pop]

Song Title: 11 Genres:[funk,pop]

Titles are correct, but genres are beeing overwrited by the last search in the loop.

My System.out.println() results are:

Array: [metal, pop, ballad]                 --> *First genre extracted array*

Title: 8
Check SOng: [metal, pop, ballad]            --> *Genres inside the Song object*

ArraySize: 1

ArrayTitulo: 8 --> Title is OK

ArrayGenreP: 0  ArrayGenreZ: 0  Item: metal  --> *P = genres index and Z = title index*

ArrayGenreP: 1  ArrayGenreZ: 0  Item: pop

ArrayGenreP: 2  ArrayGenreZ: 0  Item: ballad

Genres: [metal, pop, ballad]                 *--> Here is OK: Title 8 should have this 3 genres*

Array: [funk, pop]                           *--> This is the second array which is correct*

Title: 11                                    *--> This is the second title which is also ok*

Check SOng: [funk, pop]                      *--> This is the array stored in the new song object*

ArraySize: 2                                 *--> The new updated array size*

ArrayTitle: 8                                *--> The first title is correct*

ArrayGenreP: 0  ArrayGenreZ: 0  Item: funk   *--> Here is the problem, it overwrites the previous genres*

ArrayGenreP: 1  ArrayGenreZ: 0  Item: pop    * --> (but not the previous title)*

ArrayTitle: 11                                 --> Second title is also correct

ArrayGenreP: 0  ArrayGenreZ: 1  Item: funk  *-->These are the correct genres for song with title 11*

ArrayGenreP: 1  ArrayGenreZ: 1  Item: pop
Genres: [funk, pop]                         *--> Here should be [metal, pop, ballad] *

Genres: [funk, pop]                         *--> Here is OK*

And I´m completely stuck, I don´t know what else I can try, so some help would be very appreciated.

Maybe is something that has already beeing answered, if is the case I´m sorry, not my intention to waste anyones time.

Just in case I´m showing next the 2 .xml documents I created. The first one is:

<?xml version="1.0"?>
<Music>
   <Year>2001</Year>
   <Album>
      <Name>uno</Name>
      <Country>spain</Country>
      <Titulo>titulo1</Titulo>
      <Song>
         <Title>1</Title>
         <Genre>pop</Genre>
         <Genre>rock</Genre>
      </Song>
      <Song>
         <Title>2</Title>
         <Genre>metal</Genre>
      </Song>
   </Album>
   <Album>
      <Name>dos</Name>
      <Country>england</Country>
      <Titulo>titulo2</Titulo>
      <Song>
         <Title>3</Title>
         <Genre>pop</Genre>
         <Genre>metal</Genre>
         <Genre>soul</Genre>
      </Song>
   </Album>
   <TVML>tmvl_02.xml</TVML>
</Music>

And the second one:

<?xml version="1.0"?>
<Music>
   <Year>2003</Year>
   <Album>
      <Name>tres</Name>
      <Country>morocco</Country>
      <Titulo>titulo3</Titulo>
      <Song>
         <Title>4</Title>
         <Genre>pop</Genre>
         <Genre>soul</Genre>
      </Song>
      <Song>
         <Title>5</Title>
         <Genre>reggae</Genre>
      </Song>
      <Song>
         <Title>6</Title>
         <Genre>rock</Genre>
         <Genre>pop</Genre>
      </Song>
   </Album>
   <Album>
      <Name>cuatro</Name>
      <Country>france</Country>
      <Titulo>titulo4</Titulo>
      <Song>
         <Title>7</Title>
         <Genre>inide</Genre>
      </Song>
   </Album>
   <Album>
      <Name>cinco</Name>
      <Country>england</Country>
      <Titulo>titulo5</Titulo>
      <Song>
         <Title>10</Title>
         <Genre>rock</Genre>
      </Song>
      <Song>
         <Title>8</Title>
         <Genre>metal</Genre>
         <Genre>pop</Genre>
         <Genre>ballad</Genre>
      </Song>
      <Song>
         <Title>9</Title>
         <Genre>rock</Genre>
      </Song>
      <Song>
         <Title>11</Title>
         <Genre>funk</Genre>
         <Genre>pop</Genre>
      </Song>
   </Album>
</Music>

Thx in advance for your help and merry christmas.


问:
Most effective way to get collection of Elements with data attribute
I have an approach to attach functionality to HTML code with custom data attributes like

```<code><div data-prefix-f1="..." data-prefix-f2="..."></div>
</code>```

Now I'd like to list all Elements having dataset, or better those having data-prefix-* attribute. My current approach is

```<code><div data-prefix data-prefix-f1="..." data-prefix-f2="..."></div>
<script>
    container.querySelectorAll('[data-prefix]').forEach(el => /* examine el.dataset */)
</script>
</code>```

But I'd like to have the HTML source as lean as possible and the empty data-prefix is kind of redundant and the code less readable. On the other hand, looping and examining ALL elements would be too expensive overhead. Any idea to effectively iterate Elements having data-prefix-* attributes?

Body:
I have an approach to attach functionality to HTML code with custom data attributes like

Now I'd like to list all Elements having dataset, or better those having data-prefix-* attribute. My current approach is

But I'd like to have the HTML source as lean as possible and the empty data-prefix is kind of redundant and the code less readable. On the other hand, looping and examining ALL elements would be too expensive overhead. Any idea to effectively iterate Elements having data-prefix-* attributes?


问:
Difference between Interface declared in Class and Interface declared as a file
I have an assignment to create a game in Java, so right now I'm making the stub implementations for classes. I want to make them as rigorously as possible, so that's why I'm asking:

What is the difference between an Interface declared in a class and an Interface declared as a file? Let's say, I have the following 2 pieces of code:

```<code>public class Test {

private int firstNumber;
private int secondNumber;

public void testMethod() {}

**public interface Interface1{
// some methods
}**
</code>```

and

```<code>public Interface Interface2 {
// some methods
}
</code>```

Can I do something more ( i.e. access ) with Interface1 that I cannot do with Interface2 or vice versa?

P.S.: Started OOP a couple of weeks ago, take me easy :-)!

I made a class  in which I declared an interface and an interface as a file and they seem to have the same functionalities, but maybe I'm missing something important here.

Body:
I have an assignment to create a game in Java, so right now I'm making the stub implementations for classes. I want to make them as rigorously as possible, so that's why I'm asking:

What is the difference between an Interface declared in a class and an Interface declared as a file? Let's say, I have the following 2 pieces of code:

public class Test {

private int firstNumber;
private int secondNumber;

public void testMethod() {}

**public interface Interface1{
// some methods
}**

and

public Interface Interface2 {
// some methods
}

Can I do something more ( i.e. access ) with Interface1 that I cannot do with Interface2 or vice versa?

P.S.: Started OOP a couple of weeks ago, take me easy :-)!

I made a class  in which I declared an interface and an interface as a file and they seem to have the same functionalities, but maybe I'm missing something important here.