问:
Handle Windows Auth popup is not working in chrome
Not able to handle the chrome popup and its not working if i run from Jenkins(works fine only if the browser is active and have used robot Concept). please help
Thanks in advance.

Have tried with many solutions like Autoit,sendkeys,robot class etc


来源: stackexchange

问:
Sync player names in unity multi-player
I'm trying to sync all the player names on server and client side, I'm following this tutorial, but I've made some changes to the code.

InitiateMultiplayer.cs

```<code>using Unity.Netcode;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Text;

namespace Multiplayer
{
    public class InitiateMultiplayer : MonoBehaviour
    {
        [Serializable]
        public class ConnectionPayload
        {
            public string password;
            public string playerName;
        }

        public struct PlayerData
        {
            public string PlayerName { get; private set; }

            public PlayerData(string playerName)
            {
                PlayerName = playerName;
            }
        }

        private static Dictionary<ulong, PlayerData> clientData;

        // Start is called before the first frame update
        void Start()
        {
            NetworkManager.Singleton.NetworkConfig.ConnectionApproval = true;

            switch (Buttons.GameMode)
            {
                case "Host":
                    clientData = new Dictionary<ulong, PlayerData>();
                    clientData[NetworkManager.Singleton.LocalClientId] = new PlayerData(Buttons.PlayerName);
                    NetworkManager.Singleton.ConnectionApprovalCallback += ApprovalCheck;
                    NetworkManager.Singleton.StartHost();
                    break;

                case "Client":
                    Debug.Log("Client Started");
                    var payload = JsonUtility.ToJson(new ConnectionPayload()
                    {
                        password = "",
                        playerName = Buttons.PlayerName,
                    });

                    byte[] payloadBytes = Encoding.ASCII.GetBytes(payload);

                    // Set password ready to send to the server to validate
                    NetworkManager.Singleton.NetworkConfig.ConnectionData = payloadBytes;
                    NetworkManager.Singleton.StartClient();
                    break;

                default:
                    break;
            }
        }

        public static PlayerData? GetPlayerData(ulong clientId)
        {
            if (clientData.TryGetValue(clientId, out PlayerData playerData))
            {
                return playerData;
            }

            return null;
        }

        private void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
        {
            Debug.Log("approving");
            string payload = Encoding.ASCII.GetString(request.Payload);
            var connectionPayload = JsonUtility.FromJson<ConnectionPayload>(payload);

            response.Approved = true;

            response.Position = Vector3.zero;
            response.Rotation = Quaternion.identity;

            if (response.Approved)
            {
                response.CreatePlayerObject = true;
                Debug.Log("approved");
                response.PlayerPrefabHash = null;

                response.Pending = false;
                if (!clientData.TryGetValue(request.ClientNetworkId, out PlayerData playerData)) {
                    Debug.Log("we dont got data");
                    clientData[request.ClientNetworkId] = new PlayerData(connectionPayload.playerName);
                }
            }
        }
    }
}

</code>```

Player.cs

```<code>using Unity.Netcode;
using UnityEngine;
using TMPro;
using Unity.Collections;

namespace Multiplayer
{
    public class Player : NetworkBehaviour
    {
        [SerializeField] private TMP_Text displayNameText;
        [SerializeField] private Renderer playerBody3D;
        private NetworkVariable<FixedString32Bytes> displayName = new NetworkVariable<FixedString32Bytes>();

        public override void OnNetworkSpawn()
        {
            if (!IsServer) { return; }

            Debug.Log("Sapwned");

            InitiateMultiplayer.PlayerData? playerData = InitiateMultiplayer.GetPlayerData(OwnerClientId);

            if (playerData.HasValue)
            {
                Debug.Log("data -"+playerData.Value.PlayerName);
                displayName.Value = playerData.Value.PlayerName;
            }
        }

        private void OnEnable()
        {
            displayName.OnValueChanged += HandleDisplayNameChanged;
        }

        private void OnDisable()
        {
            displayName.OnValueChanged -= HandleDisplayNameChanged;
        }

        private void HandleDisplayNameChanged(FixedString32Bytes oldDisplayName, FixedString32Bytes newDisplayName)
        {
            if (IsClient) Debug.Log("client");
            Debug.Log("Change in value"+newDisplayName.ToString());
            displayNameText.text = newDisplayName.ToString();
        }

    }
}

</code>```

The issue I'm facing is that the names are getting synced only on the server side, on the client side the palyer names are the default text.

ContentLicense: CC BY-SA 4.0

Title: Sync player names in unity multi-player

Body:
I'm trying to sync all the player names on server and client side, I'm following this tutorial, but I've made some changes to the code.

InitiateMultiplayer.cs

using Unity.Netcode;
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Text;

namespace Multiplayer
{
    public class InitiateMultiplayer : MonoBehaviour
    {
        [Serializable]
        public class ConnectionPayload
        {
            public string password;
            public string playerName;
        }

        public struct PlayerData
        {
            public string PlayerName { get; private set; }

            public PlayerData(string playerName)
            {
                PlayerName = playerName;
            }
        }

        private static Dictionary<ulong, PlayerData> clientData;

        // Start is called before the first frame update
        void Start()
        {
            NetworkManager.Singleton.NetworkConfig.ConnectionApproval = true;

            switch (Buttons.GameMode)
            {
                case "Host":
                    clientData = new Dictionary<ulong, PlayerData>();
                    clientData[NetworkManager.Singleton.LocalClientId] = new PlayerData(Buttons.PlayerName);
                    NetworkManager.Singleton.ConnectionApprovalCallback += ApprovalCheck;
                    NetworkManager.Singleton.StartHost();
                    break;

                case "Client":
                    Debug.Log("Client Started");
                    var payload = JsonUtility.ToJson(new ConnectionPayload()
                    {
                        password = "",
                        playerName = Buttons.PlayerName,
                    });

                    byte[] payloadBytes = Encoding.ASCII.GetBytes(payload);

                    // Set password ready to send to the server to validate
                    NetworkManager.Singleton.NetworkConfig.ConnectionData = payloadBytes;
                    NetworkManager.Singleton.StartClient();
                    break;

                default:
                    break;
            }
        }

        public static PlayerData? GetPlayerData(ulong clientId)
        {
            if (clientData.TryGetValue(clientId, out PlayerData playerData))
            {
                return playerData;
            }

            return null;
        }

        private void ApprovalCheck(NetworkManager.ConnectionApprovalRequest request, NetworkManager.ConnectionApprovalResponse response)
        {
            Debug.Log("approving");
            string payload = Encoding.ASCII.GetString(request.Payload);
            var connectionPayload = JsonUtility.FromJson<ConnectionPayload>(payload);

            response.Approved = true;

            response.Position = Vector3.zero;
            response.Rotation = Quaternion.identity;

            if (response.Approved)
            {
                response.CreatePlayerObject = true;
                Debug.Log("approved");
                response.PlayerPrefabHash = null;

                response.Pending = false;
                if (!clientData.TryGetValue(request.ClientNetworkId, out PlayerData playerData)) {
                    Debug.Log("we dont got data");
                    clientData[request.ClientNetworkId] = new PlayerData(connectionPayload.playerName);
                }
            }
        }
    }
}

Player.cs

using Unity.Netcode;
using UnityEngine;
using TMPro;
using Unity.Collections;

namespace Multiplayer
{
    public class Player : NetworkBehaviour
    {
        [SerializeField] private TMP_Text displayNameText;
        [SerializeField] private Renderer playerBody3D;
        private NetworkVariable<FixedString32Bytes> displayName = new NetworkVariable<FixedString32Bytes>();

        public override void OnNetworkSpawn()
        {
            if (!IsServer) { return; }

            Debug.Log("Sapwned");

            InitiateMultiplayer.PlayerData? playerData = InitiateMultiplayer.GetPlayerData(OwnerClientId);

            if (playerData.HasValue)
            {
                Debug.Log("data -"+playerData.Value.PlayerName);
                displayName.Value = playerData.Value.PlayerName;
            }
        }

        private void OnEnable()
        {
            displayName.OnValueChanged += HandleDisplayNameChanged;
        }

        private void OnDisable()
        {
            displayName.OnValueChanged -= HandleDisplayNameChanged;
        }

        private void HandleDisplayNameChanged(FixedString32Bytes oldDisplayName, FixedString32Bytes newDisplayName)
        {
            if (IsClient) Debug.Log("client");
            Debug.Log("Change in value"+newDisplayName.ToString());
            displayNameText.text = newDisplayName.ToString();
        }

    }
}

The issue I'm facing is that the names are getting synced only on the server side, on the client side the palyer names are the default text.


问:
Vue router failure
I use a Vue router in a web application in identification page, when I enter first time login and password.
Web page loads a second time with changing the path
form 'http://localhost:8080/#/login' to 'http://localhost:8080/?#/login', when I try it again, the second time the router work well and i can enter the site

vue router

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';

Vue.use(VueRouter);

// configure router
const router = new VueRouter({
  routes, // short for routes: routes
  linkActiveClass: 'active',
  scrollBehavior: (to, from ,savedPosition) => {
    if (savedPosition) {
      return savedPosition;
    }
    if (to.hash) {
      return { selector: to.hash };
    }
    return { x: 0, y: 0 };
  }
});

export default router;
```
<p>I use a navigation guard which work well.</p>
<pre class="lang-js prettyprint-override"><code>async function guardMyroute(to, from, next)
{
  if(store.state.token) {
    const payload = {
      access_token: store.state.token,
      Nom: store.state.Nom
    }
    let Data = await axios.post('/token', payload).then((res => res.data))
    if (Data === true) {
      next(); // allow to enter route
    }
    if (Data === false) {
      next({path: '/Home'});
    }
  }
  else{next({path:'/Home'});}
}
</code>```

Title: Vue router failure

Body:
I use a Vue router in a web application in identification page, when I enter first time login and password.
Web page loads a second time with changing the path
form 'http://localhost:8080/#/login' to 'http://localhost:8080/?#/login', when I try it again, the second time the router work well and i can enter the site

vue router

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';

Vue.use(VueRouter);

// configure router
const router = new VueRouter({
  routes, // short for routes: routes
  linkActiveClass: 'active',
  scrollBehavior: (to, from ,savedPosition) => {
    if (savedPosition) {
      return savedPosition;
    }
    if (to.hash) {
      return { selector: to.hash };
    }
    return { x: 0, y: 0 };
  }
});

export default router;

I use a navigation guard which work well.

async function guardMyroute(to, from, next)
{
  if(store.state.token) {
    const payload = {
      access_token: store.state.token,
      Nom: store.state.Nom
    }
    let Data = await axios.post('/token', payload).then((res => res.data))
    if (Data === true) {
      next(); // allow to enter route
    }
    if (Data === false) {
      next({path: '/Home'});
    }
  }
  else{next({path:'/Home'});}
}


问:
Environment variable is showing blank after user logout
I have been trying to set below environment variable for a user, but once I set this variable, source the file and logout the user session the environment variable is showing blank

```<code>dbs_hdb_connect=ENCRYPT=TRUE,sslCryptoProvider=commoncrypto,sslKeyStore=/usr/sap/<SID>/HDBxx/<hostname>/sec/SAPSSLC.pse,sslTrustStore=/usr/sap/<SID>/HDBxx/<hostname>/sec/SAPSSLC.pse
</code>```

After logging out and log back into the user session the env variable is showing blank, is it something to do with the character length?

```<code>admin1> env | grep dbs_hdb_connect_property=
</code>```

I tried below scenario to confirm the issue, I adjusted the env variable name length and got below results. only "dbs_hdb_connect_property" is showing blank all other are working fine.

Content of .sapenv.sh file as follows:-

```<code>export dbs_hdb_connect_p="test"
export dbs_hdb_connect_proper="test"
export dbs_hdb_connect_propert="test"
export dbs_hdb_connect_pro="test"
export dbs_hdb_connect_prop="test"
export dbs_hdb_connect_pr="test"
export dbs_hdb_connect="test"
export dbs_hdb_connect_prope="test"
export dbs_hdb_connect_property="test"

source .sapenv.sh
</code>```

And after this I logged out of the user, logged back in and fired below command to check if the env variables populated. But as you can see "dbs_hdb_connect_property" is empty and others are populated.

```<code>admin1> env | grep dbs
</code>```
```<code>dbs_hdb_connect_p=test
dbs_hdb_connect_proper=test
dbs_hdb_connect_propert=test
dbs_hdb_connect_pro=test
dbs_hdb_connect_prop=test
dbs_hdb_connect_pr=test
dbs_hdb_connect=test
dbs_hdb_connect_prope=test
dbs_hdb_connect_property=
</code>```

I was setting the env variable permanently by mentioning the variable in .sapenv.sh file (This is similar to bashrc but for SAP application). The shell being used here is /bin/sh. And I am setting the variable for only one user.  My point is even if I mention this variable in bashrc or profile it's not loading. When I export it manually from command line it will load but as soon as I logout of that session it goes blank from next login. So, I am wondering is there any limit here for setting the variable name too long?

Body:
I have been trying to set below environment variable for a user, but once I set this variable, source the file and logout the user session the environment variable is showing blank

dbs_hdb_connect=ENCRYPT=TRUE,sslCryptoProvider=commoncrypto,sslKeyStore=/usr/sap/<SID>/HDBxx/<hostname>/sec/SAPSSLC.pse,sslTrustStore=/usr/sap/<SID>/HDBxx/<hostname>/sec/SAPSSLC.pse

After logging out and log back into the user session the env variable is showing blank, is it something to do with the character length?

admin1> env | grep dbs_hdb_connect_property=

I tried below scenario to confirm the issue, I adjusted the env variable name length and got below results. only "dbs_hdb_connect_property" is showing blank all other are working fine.

Content of .sapenv.sh file as follows:-

export dbs_hdb_connect_p="test"
export dbs_hdb_connect_proper="test"
export dbs_hdb_connect_propert="test"
export dbs_hdb_connect_pro="test"
export dbs_hdb_connect_prop="test"
export dbs_hdb_connect_pr="test"
export dbs_hdb_connect="test"
export dbs_hdb_connect_prope="test"
export dbs_hdb_connect_property="test"

source .sapenv.sh

And after this I logged out of the user, logged back in and fired below command to check if the env variables populated. But as you can see "dbs_hdb_connect_property" is empty and others are populated.

admin1> env | grep dbs

dbs_hdb_connect_p=test
dbs_hdb_connect_proper=test
dbs_hdb_connect_propert=test
dbs_hdb_connect_pro=test
dbs_hdb_connect_prop=test
dbs_hdb_connect_pr=test
dbs_hdb_connect=test
dbs_hdb_connect_prope=test
dbs_hdb_connect_property=

I was setting the env variable permanently by mentioning the variable in .sapenv.sh file (This is similar to bashrc but for SAP application). The shell being used here is /bin/sh. And I am setting the variable for only one user.  My point is even if I mention this variable in bashrc or profile it's not loading. When I export it manually from command line it will load but as soon as I logout of that session it goes blank from next login. So, I am wondering is there any limit here for setting the variable name too long?


问:
How I connect gorm with postgres?
I need your help, because my app can´t connect with postgresql (docker),
this is the error:

2022/12/13 11:04:29 C:/Users/Jose Gomez/Desktop/GoPrj/go-gorm-postgresql/db/connection.go:15

[error] failed to initialize database, got error failed to connect to host=localhost user=jose database=gorm: failed SASL auth (FATAL: la autentificaci�n password fall� para el usuario �jose� (SQLSTATE 28P01))
2022/12/13 11:04:29 failed to connect to host=localhost user=jose database=gorm: failed SASL auth
(FATAL: la autentificaci�n password fall� para el usuario �jose� (SQLSTATE 28P01))
exit status 1

and my dbconnection is:

```<code>package db

import (
    "log"

    "gorm.io/driver/postgres"
    "gorm.io/gorm"
)

var DNS = "host=localhost user=jose password=mysecretpassword dbname=gorm port=5432"
var DB *gorm.DB

func DBConnection() {
    var error error
    DB, error = gorm.Open(postgres.Open(DNS), &gorm.Config{})
    if error != nil {
        log.Fatal(error)
    } else {
        log.Println("DB Conectada!!!")
    }
}
</code>```

I need connect this dbconnection

Title: How I connect gorm with postgres?

Body:
I need your help, because my app can´t connect with postgresql (docker),
this is the error:

2022/12/13 11:04:29 C:/Users/Jose Gomez/Desktop/GoPrj/go-gorm-postgresql/db/connection.go:15

[error] failed to initialize database, got error failed to connect to host=localhost user=jose database=gorm: failed SASL auth (FATAL: la autentificaci�n password fall� para el usuario �jose� (SQLSTATE 28P01))
2022/12/13 11:04:29 failed to connect to host=localhost user=jose database=gorm: failed SASL auth
(FATAL: la autentificaci�n password fall� para el usuario �jose� (SQLSTATE 28P01))
exit status 1

and my dbconnection is:

package db

import (
    "log"

    "gorm.io/driver/postgres"
    "gorm.io/gorm"
)

var DNS = "host=localhost user=jose password=mysecretpassword dbname=gorm port=5432"
var DB *gorm.DB

func DBConnection() {
    var error error
    DB, error = gorm.Open(postgres.Open(DNS), &gorm.Config{})
    if error != nil {
        log.Fatal(error)
    } else {
        log.Println("DB Conectada!!!")
    }
}

I need connect this dbconnection


问:
How to simulate a Field storing only hours and minutes in Django
I would like to store for a model "House", in django, a field stocking an hour and a minute, and to be able to edit it easily by only editing hour and minute.

I am aware that TimeField exists in django, but its editing in Django admin is not so great : You have to set your value like this : 10:59:00 (for 10:59am)
I would like to be able to get a line with : Hour   [...]   Minute [...]  to be able to input two numbers (with validators so that the hour has to be between 0-23 and minutes between 0-59).

My best idea at this point was to make a OnetoOneField in the "House" model to an "Hour" Model which get two IntegerField (And using validators).
It works great, but the downside is that while editing an instance of House in admin, i can see the Hour instances linked to other instances of House.

For exemple if i have two "House" instances, House1 and House2, when i edit House2, i can see the Hour instance linked to House1 in the scrolling menu. (Problem that i would not get if i had directly two IntegerField in "House" for exemple).

Is there a better way to do this ? (Using TimeField with a custom admin form for example ?)

Thanks ! :)


问:
Spark always bradcasts tables greater than spark.sql.autoBroadcastJoinThreshold when performing streaming merge on DeltaTable sink
I am trying to do a streaming merge between delta tables using this guide - https://docs.delta.io/latest/delta-update.html#upsert-from-streaming-queries-using-foreachbatch

Our Code Sample (Java):

Dataset<Row> sourceDf = sparkSession
    .readStream()
    .format("delta")
    .option("inferSchema", "true")
    .load(sourcePath);

DeltaTable deltaTable = DeltaTable.forPath(sparkSession, targetPath);

sourceDf.createOrReplaceTempView("vTempView");

StreamingQuery sq = sparkSession.sql("select * from vTempView").writeStream()
    .format("delta")
    .foreachBatch((microDf, id) -> {
        deltaTable.alias("e").merge(microDf.alias("d"), "e.SALE_ID = d.SALE_ID")
            .whenMatched().updateAll()
            .whenNotMatched().insertAll()
            .execute();
    })
    .outputMode("update")
    .option("checkpointLocation", util.getFullS3Path(target)+"/_checkpoint")
    .trigger(Trigger.Once())
    .start();
```
<p><strong>Problem:</strong>
Here Source path and Target path is already in sync using the checkpoint folder. Which has around 8 million rows of data amounting to around 450mb of parquet files.</p>
<p>When new data comes in Source Path (let's say 987 rows), then above code will pick that up and perform a merge with target table. During this operation spark is trying to perform a BroadCastHashJoin, and broadcasts the target table which has 8M rows.</p>
<p>Here's a DAG snippet for merge operation (with table with 1M rows),
<img src="https://i.stack.imgur.com/uBZQr.png" alt="enter image description here" /></p>
<p><strong>Expectation:</strong>
I am expecting smaller dataset (i.e: 987 rows) to be broadcasted. If not then atleast spark should not broadcast target table, as it is larger than provided spark.sql.autoBroadcastJoinThreshold setting and neither are we providing any broadcast hint anywhere.</p>
<p><strong>Things I have tried:</strong>
I searched around and got this article - https://learn.microsoft.com/en-us/azure/databricks/kb/sql/bchashjoin-exceeds-bcjointhreshold-oom.
It provides 2 solutions,</p>
<ol>
<li>Run "ANALYZE TABLE ..." (but since we are reading target table from path and not from a table this is not possible)</li>
<li>Cache the table you are broadcasting, DeltaTable does not have any provision to cache table, so can't do this.</li>
</ol>
<p>I thought this was because we are using DeltaTable.forPath() method for reading target table and spark is unable to calculate target table metrics. So I also tried a different approach,</p>
<pre class="lang-java prettyprint-override"><code>Dataset<Row> sourceDf = sparkSession
    .readStream()
    .format("delta")
    .option("inferSchema", "true")
    .load(sourcePath);

Dataset<Row> targetDf = sparkSession
    .read()
    .format("delta")
    .option("inferSchema", "true")
    .load(targetPath);

sourceDf.createOrReplaceTempView("vtempview");
targetDf.createOrReplaceTempView("vtemptarget");
targetDf.cache();

StreamingQuery sq = sparkSession.sql("select * from vtempview").writeStream()
    .format("delta")
    .foreachBatch((microDf, id) -> {
        microDf.createOrReplaceTempView("vtempmicrodf");
        microDf.sparkSession().sql(
            "MERGE INTO vtemptarget as t USING vtempmicrodf as s ON t.SALE_ID = s.SALE_ID WHEN MATCHED THEN UPDATE SET * WHEN NOT MATCHED THEN INSERT * "
        );
    })
    .outputMode("update")
    .option("checkpointLocation", util.getFullS3Path(target)+"/_checkpoint")
    .trigger(Trigger.Once())
    .start();
</code>```

In above snippet I am also caching the targetDf so that Spark can calculate metrics and not broadcast target table. But it didn't help and spark still broadcasts it.

Now I am out of options. Can anyone give me some guidance on this?

Body:
I am trying to do a streaming merge between delta tables using this guide - https://docs.delta.io/latest/delta-update.html#upsert-from-streaming-queries-using-foreachbatch

Our Code Sample (Java):

Dataset<Row> sourceDf = sparkSession
    .readStream()
    .format("delta")
    .option("inferSchema", "true")
    .load(sourcePath);

DeltaTable deltaTable = DeltaTable.forPath(sparkSession, targetPath);

sourceDf.createOrReplaceTempView("vTempView");

StreamingQuery sq = sparkSession.sql("select * from vTempView").writeStream()
    .format("delta")
    .foreachBatch((microDf, id) -> {
        deltaTable.alias("e").merge(microDf.alias("d"), "e.SALE_ID = d.SALE_ID")
            .whenMatched().updateAll()
            .whenNotMatched().insertAll()
            .execute();
    })
    .outputMode("update")
    .option("checkpointLocation", util.getFullS3Path(target)+"/_checkpoint")
    .trigger(Trigger.Once())
    .start();

Problem:
Here Source path and Target path is already in sync using the checkpoint folder. Which has around 8 million rows of data amounting to around 450mb of parquet files.

When new data comes in Source Path (let's say 987 rows), then above code will pick that up and perform a merge with target table. During this operation spark is trying to perform a BroadCastHashJoin, and broadcasts the target table which has 8M rows.

Here's a DAG snippet for merge operation (with table with 1M rows),

Expectation:
I am expecting smaller dataset (i.e: 987 rows) to be broadcasted. If not then atleast spark should not broadcast target table, as it is larger than provided spark.sql.autoBroadcastJoinThreshold setting and neither are we providing any broadcast hint anywhere.

Things I have tried:
I searched around and got this article - https://learn.microsoft.com/en-us/azure/databricks/kb/sql/bchashjoin-exceeds-bcjointhreshold-oom.
It provides 2 solutions,

Run "ANALYZE TABLE ..." (but since we are reading target table from path and not from a table this is not possible)

Cache the table you are broadcasting, DeltaTable does not have any provision to cache table, so can't do this.

I thought this was because we are using DeltaTable.forPath() method for reading target table and spark is unable to calculate target table metrics. So I also tried a different approach,

Dataset<Row> sourceDf = sparkSession
    .readStream()
    .format("delta")
    .option("inferSchema", "true")
    .load(sourcePath);

Dataset<Row> targetDf = sparkSession
    .read()
    .format("delta")
    .option("inferSchema", "true")
    .load(targetPath);

sourceDf.createOrReplaceTempView("vtempview");
targetDf.createOrReplaceTempView("vtemptarget");
targetDf.cache();

StreamingQuery sq = sparkSession.sql("select * from vtempview").writeStream()
    .format("delta")
    .foreachBatch((microDf, id) -> {
        microDf.createOrReplaceTempView("vtempmicrodf");
        microDf.sparkSession().sql(
            "MERGE INTO vtemptarget as t USING vtempmicrodf as s ON t.SALE_ID = s.SALE_ID WHEN MATCHED THEN UPDATE SET * WHEN NOT MATCHED THEN INSERT * "
        );
    })
    .outputMode("update")
    .option("checkpointLocation", util.getFullS3Path(target)+"/_checkpoint")
    .trigger(Trigger.Once())
    .start();

In above snippet I am also caching the targetDf so that Spark can calculate metrics and not broadcast target table. But it didn't help and spark still broadcasts it.

Now I am out of options. Can anyone give me some guidance on this?


问:
Can't fetch or push anything to GitHub via GitHub Desktop
.netrc parser error

Suddenly today, i can't fetch or push anything to GitHub via GitHub Desktop. how can i solve this problem?

I tried this commands, but nothing is changed.

$ git config --global --unset credential.helper
$ git config --global credential.helper cache


问:
Syncing mongodb with multiple APIs
I have a project that has 2 Rest APIs to get a) stock and b) item price & status. Now, I am trying to sync that data with mongodb using cron jobs on node with incremental updates using timestamps (every 5 minutes). I am then taking this data and updating it on the master data in my database. This is again done using a cron job that sifts through all the data looking for changes. The data is not static with activation status, pricing and stock that keep changing.

I have heard of mongodb database triggers, but it is not supported by serverless instances of Atlas. Is there a better way of doing this? I do not have access to the sql database of the APIs themselves so hence I have to schedule crons to get the data synced. This process is also causing a huge increase in reads and writes.

Title: Syncing mongodb with multiple APIs


问:
Is there a concept/term for permutation simulations and compare to goal
Is there a concept in the AI, DS space where in I have a number I'm trying to optimize/maximize. The way this number would be optimize/maximize would be to add value to my input run my calculation and see how that compares to my goal, but I want to see how different permuations/combinations of adding/remove values optimizes my goal. For example:

Agent A,Agent B,Agent C,Agent D ..... N

I want to add their respective inputs into my calculation and see if adding all, none , some combinations, etc of them effects my goal result. If I just A how does that affect my goal results or A and B how does that affect my goal results  or A,B,C  how does that affect my goal results  or B,C or just B, etc. I believe this is a monte carlo excercise but its unclear to me how to do these different permutation test to arrive at check them again my goal result.

For reference I'm trying to do all of this in python. Thanks!

I've looked around to see concepts of scipy optimize but its unclear how to simulate different permautions to arrive at checking them again my goal result.


问:
concat prefix for every value in yaml array
Is there a way to concat a prefix for every value in an array? I want to avoid duplication in my configuration.

in service.yaml

```<code>cities:
- amsterdam
- brussels
- chicago
</code>```

wanted output in packages/city-package.yaml

```<code>city_map:
- city_amsterdam
- city_brussels
- city_chicago

city_map: %cities% << concat 'city_'$value <----- something like this
</code>```

Body:
Is there a way to concat a prefix for every value in an array? I want to avoid duplication in my configuration.

in service.yaml

cities:
- amsterdam
- brussels
- chicago

wanted output in packages/city-package.yaml

city_map:
- city_amsterdam
- city_brussels
- city_chicago

city_map: %cities% << concat 'city_'$value <----- something like this


问:
Automated clicking on a pop up using selenium
I have been trying to automate clicking on a pop up as soon as the site opens up but the error "selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found" is shown. and the pop up doesn't close.

I tried to execute following statements:

```<code>**driver.find_element(By.NAME,"bBPb-close").click()**
</code>```

on the following html code:

The pop up didn't close and an error occurred.

Body:
I have been trying to automate clicking on a pop up as soon as the site opens up but the error "selenium.common.exceptions.NoSuchWindowException: Message: no such window: target window already closed
from unknown error: web view not found" is shown. and the pop up doesn't close.

I tried to execute following statements:

**driver.find_element(By.NAME,"bBPb-close").click()**

on the following html code:

The pop up didn't close and an error occurred.


问:
Would a lack of sticky sessions cause a session to be terminated and user authentication to be reset?
If we had multiple pods but no sticky sessions, would an additional request cause the request to shift pod and thus reset the authentication for a user?

My understanding of sessions in kubernetes is that without sticky sessions, requests are handled in a 'round robin' way whereby a setup with 2 pods would handle requests pod 1 pod 2 1 2 etc. Could this potentially cause authentication to be reset?

Thanks


问:
How to change value of child of the same parent that entered other child value in forgot password feature in firebase realtime database
I'm working on a Firebase ecommerce app, I have been trying to update the password when passing the email of the user in "forgot password" feature but i can't get it right.

Here is my Firebase structure:

I want the method to get the user with the entered email, then update his password to a new one.

Here is my code:

```<code>set_new_pass.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        DatabaseReference reference = FirebaseDatabase.getInstance().getReference("users");
        Query checkUserDatabase = reference.orderByChild("email").equalTo(user_email);
        String user_newpass=new_password.getText().toString();
        HashMap hashMap = new HashMap();
        hashMap.put("password",user_newpass);
       // hashMap.put("email",user_email);
        checkUserDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if (snapshot.exists()){
                    //String username_ofuser =hashMap.get("username").toString();
                    reference.child(user_username).updateChildren(hashMap).addOnSuccessListener(new OnSuccessListener() {
                    @Override
                    public void onSuccess(Object o) {
                        Toast.makeText(SetNewPassword.this, "your password is successfully changed!", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
</code>```

How can I achieve my results?

this code should change the password of the user that has his email entered but it doesn't change anything actually so what can i do to make it work correctly??

Body:
I'm working on a Firebase ecommerce app, I have been trying to update the password when passing the email of the user in "forgot password" feature but i can't get it right.

Here is my Firebase structure:

I want the method to get the user with the entered email, then update his password to a new one.

Here is my code:

set_new_pass.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        DatabaseReference reference = FirebaseDatabase.getInstance().getReference("users");
        Query checkUserDatabase = reference.orderByChild("email").equalTo(user_email);
        String user_newpass=new_password.getText().toString();
        HashMap hashMap = new HashMap();
        hashMap.put("password",user_newpass);
       // hashMap.put("email",user_email);
        checkUserDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot snapshot) {
                if (snapshot.exists()){
                    //String username_ofuser =hashMap.get("username").toString();
                    reference.child(user_username).updateChildren(hashMap).addOnSuccessListener(new OnSuccessListener() {
                    @Override
                    public void onSuccess(Object o) {
                        Toast.makeText(SetNewPassword.this, "your password is successfully changed!", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }

How can I achieve my results?

this code should change the password of the user that has his email entered but it doesn't change anything actually so what can i do to make it work correctly??


问:
how convert code composable activity to empty activity?
this project observation internet connectivity ,how i convert code from composablle activity to empty activity what instant of collectAsState for empty activity

get code form video youtube observation internet connectivity video

interface observeconnectivity

```<code>package com.plcoding.observeconnectivity

import kotlinx.coroutines.flow.Flow

interface ConnectivityObserver {

fun observe(): Flow<Status>

enum class Status {
    Available, Unavailable, Losing, Lost
 }
}
</code>```

observeconnectivity class

```<code>package com.plcoding.observeconnectivity

import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.launch

@OptIn(ExperimentalCoroutinesApi::class)
class NetworkConnectivityObserver(
private val context: Context
): ConnectivityObserver {

private val connectivityManager =
    context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

override fun observe(): Flow<ConnectivityObserver.Status> {
    return callbackFlow {
        val callback = object : ConnectivityManager.NetworkCallback() {
            override fun onAvailable(network: Network) {
                super.onAvailable(network)
                launch { send(ConnectivityObserver.Status.Available) }
            }

            override fun onLosing(network: Network, maxMsToLive: Int) {
                super.onLosing(network, maxMsToLive)
                launch { send(ConnectivityObserver.Status.Losing) }
            }

            override fun onLost(network: Network) {
                super.onLost(network)
                launch { send(ConnectivityObserver.Status.Lost) }
            }

            override fun onUnavailable() {
                super.onUnavailable()
                launch { send(ConnectivityObserver.Status.Unavailable) }
            }
        }

        connectivityManager.registerDefaultNetworkCallback(callback)
        awaitClose {
            connectivityManager.unregisterNetworkCallback(callback)
        }
    }.distinctUntilChanged()
}
</code>```

}

how convert MainActivity  composble activity  to empty activity?

```<code>package com.plcoding.observeconnectivity

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.lifecycleScope
import com.plcoding.observeconnectivity.ui.theme.ObserveConnectivityTheme
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class MainActivity : ComponentActivity() {

private lateinit var connectivityObserver: ConnectivityObserver

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    connectivityObserver = NetworkConnectivityObserver(applicationContext)
    setContent {
        ObserveConnectivityTheme {
            val status by connectivityObserver.observe().collectAsState(
                initial = ConnectivityObserver.Status.Unavailable
            )
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Text(text = "Network status: $status")
            }
        }
    }
}
}
</code>```

theme.kt

```<code>package com.plcoding.observeconnectivity.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable

private val DarkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
)

private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200

/* Other default colors to override
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black,
*/
 )

 @Composable
 fun ObserveConnectivityTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) {
    DarkColorPalette
} else {
    LightColorPalette
}

MaterialTheme(
    colors = colors,
    typography = Typography,
    shapes = Shapes,
    content = content
)
</code>```

}

Body:
this project observation internet connectivity ,how i convert code from composablle activity to empty activity what instant of collectAsState for empty activity

get code form video youtube observation internet connectivity video

interface observeconnectivity

package com.plcoding.observeconnectivity

import kotlinx.coroutines.flow.Flow

interface ConnectivityObserver {

fun observe(): Flow<Status>

enum class Status {
    Available, Unavailable, Losing, Lost
 }
}

observeconnectivity class

package com.plcoding.observeconnectivity

import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.launch

@OptIn(ExperimentalCoroutinesApi::class)
class NetworkConnectivityObserver(
private val context: Context
): ConnectivityObserver {

private val connectivityManager =
    context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

override fun observe(): Flow<ConnectivityObserver.Status> {
    return callbackFlow {
        val callback = object : ConnectivityManager.NetworkCallback() {
            override fun onAvailable(network: Network) {
                super.onAvailable(network)
                launch { send(ConnectivityObserver.Status.Available) }
            }

            override fun onLosing(network: Network, maxMsToLive: Int) {
                super.onLosing(network, maxMsToLive)
                launch { send(ConnectivityObserver.Status.Losing) }
            }

            override fun onLost(network: Network) {
                super.onLost(network)
                launch { send(ConnectivityObserver.Status.Lost) }
            }

            override fun onUnavailable() {
                super.onUnavailable()
                launch { send(ConnectivityObserver.Status.Unavailable) }
            }
        }

        connectivityManager.registerDefaultNetworkCallback(callback)
        awaitClose {
            connectivityManager.unregisterNetworkCallback(callback)
        }
    }.distinctUntilChanged()
}

}

how convert MainActivity  composble activity  to empty activity?

package com.plcoding.observeconnectivity

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.lifecycleScope
import com.plcoding.observeconnectivity.ui.theme.ObserveConnectivityTheme
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class MainActivity : ComponentActivity() {

private lateinit var connectivityObserver: ConnectivityObserver

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    connectivityObserver = NetworkConnectivityObserver(applicationContext)
    setContent {
        ObserveConnectivityTheme {
            val status by connectivityObserver.observe().collectAsState(
                initial = ConnectivityObserver.Status.Unavailable
            )
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center
            ) {
                Text(text = "Network status: $status")
            }
        }
    }
}
}

theme.kt

package com.plcoding.observeconnectivity.ui.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable

private val DarkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
)

private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200

/* Other default colors to override
background = Color.White,
surface = Color.White,
onPrimary = Color.White,
onSecondary = Color.Black,
onBackground = Color.Black,
onSurface = Color.Black,
*/
 )

 @Composable
 fun ObserveConnectivityTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit
) {
val colors = if (darkTheme) {
    DarkColorPalette
} else {
    LightColorPalette
}

MaterialTheme(
    colors = colors,
    typography = Typography,
    shapes = Shapes,
    content = content
)

}


问:
After angular version upgrade from 8 to 13 then "close" icon in the popup not working
```<code><ng-template #userInfo>
    <div id="auth-users-roleinfo-popup" class="authorization-user-info asg-custom-background-color">
      <div class="authorization-user-info-header asg-custom-label-color">
        <div class="authorization-user-info-header-label-container">
          <span class="authorization-user-info-header-label" [ngbTooltip]="selectedOptionInfo.name" tooltipClass="general-tooltip" container="body">{{selectedOptionInfo.name}}</span>
          <span id="auth-users-editrole-label" class="authorization-user-info-edit-role mx-3 my-1" (click)="editRole(selectedOptionInfo)">Edit Role</span>
        </div>
        <i id="auth-users-selroleabout-icon" class="fa fa-close info-close authorization-user-role-info-close-icon" (click)="onAboutClick(selectedOptionInfo, null)"></i>
      </div>
      <div class="authorization-user-info-header-underline"></div>
      <div class="m-3">
        <div class="authorization-user-info-modal-content" *ngIf="selectedOptionInfo.description != ''">
          <p class="authorization-user-info-sub-header asg-custom-label-color" i18n="@@AuthorizationUser_UserInfo_Description">Description</p>
          <p class="authorization-user-info-sub-header-desc asg-custom-label-color">{{selectedOptionInfo.description}}</p>
          <div class="authorization-user-info-subheader-underline"></div>
        </div>

        <div class="authorization-user-info-modal-content" *ngIf="applications.length">
          <p class="authorization-user-info-sub-header asg-custom-label-color" i18n="@@AuthorizationUser_UserInfo_Scope">Scope</p>
          <p class="authorization-user-info-sub-header-desc asg-custom-label-color">{{getSelectedApplication(selectedOptionInfo)}}</p>
          <div class="authorization-user-info-subheader-underline"></div>
        </div>
        <div class="authorization-user-info-modal-content">
          <p class="authorization-user-info-sub-header asg-custom-label-color" i18n="@@AuthorizationUser_UserInfo_Permissions">Permissions</p>
          <p class="authorization-user-info-sub-header-desc asg-custom-label-color">{{getSelectedPermissions(selectedOptionInfo)}}</p>
          <div class="authorization-user-info-subheader-underline"></div>
        </div>
        <div class="authorization-user-info-modal-content">
          <p class="authorization-user-info-sub-header asg-custom-label-color" i18n="@@AuthorizationUser_UserInfo_Assignments">Is Assigned to User/Group</p>
          <p class="authorization-user-info-sub-header-desc asg-custom-label-color">{{selectedOptionInfo?.assignments?.join(', ')}}</p>
        </div>
      </div>
    </div>
  </ng-template>
</code>```

The "close" button in the Role info popup is not working. This issue might have occurred after the angular 13 upgrade.
Note : Clicking anywhere on the Role-info pop-up body except the "close" icon closes the popup. But clicking on the "close" icon doesn't close the popup.

```<code>id="auth-users-selroleabout-icon"
class="fa fa-close info-close authorization-user-role-info-close-icon"
</code>```

What should I add in the CSS file for working the close icon?

Body:
<ng-template #userInfo>

          {{selectedOptionInfo.name}}
          Edit Role

Description

{{selectedOptionInfo.description}}

Scope

{{getSelectedApplication(selectedOptionInfo)}}

Permissions

{{getSelectedPermissions(selectedOptionInfo)}}

Is Assigned to User/Group

{{selectedOptionInfo?.assignments?.join(', ')}}

  </ng-template>

The "close" button in the Role info popup is not working. This issue might have occurred after the angular 13 upgrade.
Note : Clicking anywhere on the Role-info pop-up body except the "close" icon closes the popup. But clicking on the "close" icon doesn't close the popup.

id="auth-users-selroleabout-icon"
class="fa fa-close info-close authorization-user-role-info-close-icon"

What should I add in the CSS file for working the close icon?


问:
Filter out 0 outbound value transaction from etherscan
I'm working on a small project - A plot of historical tokens amount in ETH address. I'm using Python and etherscan API https://docs.etherscan.io/api-endpoints/accounts

My test subject is a random address -
I got all the transactions of all the tokens, But the end balance does not match the balance the address currently has. There is a post about it - https://ethereum.stackexchange.com/questions/26521/why-is-my-balance-not-equal-to-the-sum-of-inbound-minus-the-sum-of-outbound-and but it not answering my question because it is without an API request.

The main problem is that in the response, I don't see any data indicating contract transactions or outbound value.

I will show you an example:
enter image description here

As we can see, there are eight transactions, and the sum of all of them is 39285968212.878494 (column value2). But the actual balance in the address 0x4c8CFE078a5B989CeA4B330197246ceD82764c63 is 29129061769, which is exactly the one transaction I colored in yellow. So from my understanding, I need to find a way to filter the other seven transactions from the data. But I don't know how, I would appreciate any help.

I tried to look for some information about it online but didn't find any thing useful.


问:
Why Python dataframe to sql does not work
I have a pandas dataframe and am trying to add it to a SQL table on a SQL server. I made the connection to the SQL server with sqlalchemy. I try it with df.to_sql(). But I get an error message that I don't have permission to create a table. But the table already exists and no new one should be created. I have if_exists='append'. But I get the same error message. Why does it want to create a table?

engine = create_engine(f'mssql+pyodbc://{user}:{pw}@{server_name}/{database_name}?driver=SQL+Server')

df.to_sql('TableName', conn, if_exists='append', index=False)


问:
embed additional second dataframe into plot
I want my plot to retrieve data from one dataframe, but hovering over the data i want it to incorperate data from both data frames.

example:

which results from

```<code>fig = px.scatter(X_reduced_df, x='EXTRACTION_DATE_SAMPLE', y='score_IF', color= 'anomaly_class_IF', hover_data=['score_IF','delta',
                                                                                'omicron',
                                                                                'NH4-N (titr.)(W)_Zusatzparameter-ESRI',
                                                                                'P ges. filtr. (photom.)(W) mA_Zusatzparameter-ESRI',
                                                                                'BSB5 (mit Verd) DIN 1899_Zusatzparameter-ESRI',
                                                                                'N org. (Ber. TKN)(W)_Zusatzparameter-ESRI'
                                                                                ], #range_x=['2015-12-01', '2016-01-15'],
                 title="Default Display with Gaps")
fig.show()
</code>```

Here i want the value "delta" to be associated with additional info on "delta" from another dataframe, i.e. i want "delta= 0, add info" where add info is a list or a dataframecolumn, or similar.(its a list of names associated with a double, like as:
column name: delta
column entries
gamma: 1.2

alpha: 1.3

.

.

.

)
basically its a correlation matrix. and i want the correlations associated with each entry to be displayed.
The second dataframe, the correlation matrix is regrettably not the same columns as the original dataframe, hence not joinable. i want column names to be associated with the add info. i thought about categories, but i cannot see how that could help for a compact add info.
also i do not want to meddle with the column names(like in forcing a rename with the add info).
the plotly library only allows for one dataframe as input, right? how can i add my add info, the i way i described?

Body:
I want my plot to retrieve data from one dataframe, but hovering over the data i want it to incorperate data from both data frames.

example:

which results from

fig = px.scatter(X_reduced_df, x='EXTRACTION_DATE_SAMPLE', y='score_IF', color= 'anomaly_class_IF', hover_data=['score_IF','delta',
                                                                                'omicron',
                                                                                'NH4-N (titr.)(W)_Zusatzparameter-ESRI',
                                                                                'P ges. filtr. (photom.)(W) mA_Zusatzparameter-ESRI',
                                                                                'BSB5 (mit Verd) DIN 1899_Zusatzparameter-ESRI',
                                                                                'N org. (Ber. TKN)(W)_Zusatzparameter-ESRI'
                                                                                ], #range_x=['2015-12-01', '2016-01-15'],
                 title="Default Display with Gaps")
fig.show()

Here i want the value "delta" to be associated with additional info on "delta" from another dataframe, i.e. i want "delta= 0, add info" where add info is a list or a dataframecolumn, or similar.(its a list of names associated with a double, like as:
column name: delta
column entries
gamma: 1.2

alpha: 1.3

.

.

.

)
basically its a correlation matrix. and i want the correlations associated with each entry to be displayed.
The second dataframe, the correlation matrix is regrettably not the same columns as the original dataframe, hence not joinable. i want column names to be associated with the add info. i thought about categories, but i cannot see how that could help for a compact add info.
also i do not want to meddle with the column names(like in forcing a rename with the add info).
the plotly library only allows for one dataframe as input, right? how can i add my add info, the i way i described?


问:
Can we connect Soil NPK sesnor to raspberry pi 3b+ by using RS485 module ? Has anyone ever tried it?
Hello all i want to connect soil npk sensor to my raspberry pi 3b+ so..can you help mi for connections or what module should i use to connect soil npk sensor to raspberry pi....
I also want sample program to how to test that

I want to get NPK values


问:
How can I use gradle installed in WSL alongside Android Studio installed on Windows
I've recently had to start developing a Micronaut project in Android Studio instead of IntelliJ IDEA Ultimate. I'd assumed that because they share the same base this would be fine but when I load up my project I get this (the project is held in the wsl filesystem and all development has been using WSL with IDEA):

```<code>14:07   Project [name] is using the following JDK location when running Gradle:
            //wsl$/Ubuntu-22.04/usr/lib/jvm/java-11-openjdk-amd64
            Using different JDK locations on different processes might cause Gradle to
            spawn multiple daemons, for example, by executing Gradle tasks from a terminal
            while using Android Studio.

            More info...
            Select a JDK
            Do not show this warning again
</code>```

It's unclear why this is happening, when I click 'Select a JDK', what is selected is the JDK installed on WSL that IntelliJ is using, likewise it is pointed at the same directory where my gradle properties is kept.

I'm not sure where to go with this, my guess would be maybe Android Studio is trying to run a gradle or java instance that's not the WSL one (I think it installs it's own alongside) and that's the issue but the settings would imply otherwise. Does anyone know what might be happening?

Thanks!

Body:
I've recently had to start developing a Micronaut project in Android Studio instead of IntelliJ IDEA Ultimate. I'd assumed that because they share the same base this would be fine but when I load up my project I get this (the project is held in the wsl filesystem and all development has been using WSL with IDEA):

14:07   Project [name] is using the following JDK location when running Gradle:
            //wsl$/Ubuntu-22.04/usr/lib/jvm/java-11-openjdk-amd64
            Using different JDK locations on different processes might cause Gradle to
            spawn multiple daemons, for example, by executing Gradle tasks from a terminal
            while using Android Studio.

            More info...
            Select a JDK
            Do not show this warning again

It's unclear why this is happening, when I click 'Select a JDK', what is selected is the JDK installed on WSL that IntelliJ is using, likewise it is pointed at the same directory where my gradle properties is kept.

I'm not sure where to go with this, my guess would be maybe Android Studio is trying to run a gradle or java instance that's not the WSL one (I think it installs it's own alongside) and that's the issue but the settings would imply otherwise. Does anyone know what might be happening?

Thanks!


问:
Are there drawbacks of using flask-optimize?
We're using flask-optimize to optimize responses of a Flask backend (serving an Angular app), the main objective being to reduce server reponse time and improve the app's performance.

Most responses data types are json, so we use the decorator @flask_optimize.optimize('json').

The observed results are: significant reduction of response size (expected, thanks to gzip compression), slight reduction of average response time, slight improvement of average Lighthouse performance score at page load.

These preliminary results are mostly positive: flask-optimize seems to be improving performance. But the tests made were limited and non-exhaustive, so these aren't conclusive results.

Is there actually any drawback of using flask-optimize?

For example, we wonder if the gzip compression, although reducing response size, could actually increase response time?

I tried to search around online but didn't find many resources about flask-optimize.

If there are no drawbacks, we would use it in all routes.


问:
Does OpenVPN and Routing Tables Create an Asymmetrical Behaviour?
My setting is quite simple: a raspberry pi (tun0 IP is 172.32.0.130) is connected to aan AWS VPC (172.31.0.0/16) through AWS Client VPN, with an attachment to a public subnet (172.31.32.0/20). There’s an EC2 instance (172.31.37.157) up and running in this subnet. The raspberry pi can access all resources of the subnet and I can SSH into the EC2 instance, from the Raspberry PI, using the private IP address. This makes me believe that the VPN is working just fine.

The problem is when I try the opposite direction. If I try to SSH from the EC2 instance into the raspberry pi, I can’t reach the host. I’m assuming that I need to add some sort of routing configuration so the OpenVPN client running on the raspberry PI allows me to SSH into it, but I can’t figure out exactly how.

Here's the RBP routing table:

Destination
Gateway
Genmask
Flags
Metric
Ref
Use
Iface

0.0.0.0
192.168.86.1
0.0.0.0
UG
303
0
0
wlan0

172.31.0.0
172.32.0.129
255.255.0.0
UG
0
0
0
tun0

172.32.0.128
0.0.0.0
255.255.255.224
U
0
0
0
tun0

192.168.0.0
0.0.0.0
255.255.255.0
U
202
0
0
eth0

192.168.1.0
0.0.0.0
255.255.255.0
U
304
0
0
wlan1

192.168.86.0
0.0.0.0
255.255.255.0
U
303
0
0
wlan0

Here's the EC2 instance routing table:

Destination
Gateway
Genmask
Flags
Metric
Ref
Use
Iface

0.0.0.0
172.31.32.1
0.0.0.0
UG
100
0
0
eth0

172.31.0.2
172.31.32.1
255.255.255.255
UGH
100
0
0
eth0

172.31.32.0
0.0.0.0
255.255.240.0
U
100
0
0
eth0

172.31.32.1
0.0.0.0
255.255.255.255
UH
100
0
0
eth0

This is the Raspberry's PI OpenVPN client config:

```<code>client
dev tun
proto udp
remote xxx.clientvpn.eu-west-1.amazonaws.com 443
remote-random-hostname
resolv-retry infinite
nobind
cert client1.domain.tld.crt
key client1.domain.tld.key
remote-cert-tls server
cipher AES-256-GCM
verb 3
</code>```

Finally, because my Raspberry PI sits in front of several devices, I'm routing the internet coming from wlan0 to eth0 and wlan1 by adding an entry to iptables:

```<code>iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
</code>```

I'm not a network specialist and I can't figure out what's going on, but the asymmetrical nature of this behaviour makes me believe that the problem is on the Raspberry PI. What do you think?

Body:
My setting is quite simple: a raspberry pi (tun0 IP is 172.32.0.130) is connected to aan AWS VPC (172.31.0.0/16) through AWS Client VPN, with an attachment to a public subnet (172.31.32.0/20). There’s an EC2 instance (172.31.37.157) up and running in this subnet. The raspberry pi can access all resources of the subnet and I can SSH into the EC2 instance, from the Raspberry PI, using the private IP address. This makes me believe that the VPN is working just fine.

The problem is when I try the opposite direction. If I try to SSH from the EC2 instance into the raspberry pi, I can’t reach the host. I’m assuming that I need to add some sort of routing configuration so the OpenVPN client running on the raspberry PI allows me to SSH into it, but I can’t figure out exactly how.

Here's the RBP routing table:

Destination
Gateway
Genmask
Flags
Metric
Ref
Use
Iface

0.0.0.0
192.168.86.1
0.0.0.0
UG
303
0
0
wlan0

172.31.0.0
172.32.0.129
255.255.0.0
UG
0
0
0
tun0

172.32.0.128
0.0.0.0
255.255.255.224
U
0
0
0
tun0

192.168.0.0
0.0.0.0
255.255.255.0
U
202
0
0
eth0

192.168.1.0
0.0.0.0
255.255.255.0
U
304
0
0
wlan1

192.168.86.0
0.0.0.0
255.255.255.0
U
303
0
0
wlan0

Here's the EC2 instance routing table:

Destination
Gateway
Genmask
Flags
Metric
Ref
Use
Iface

0.0.0.0
172.31.32.1
0.0.0.0
UG
100
0
0
eth0

172.31.0.2
172.31.32.1
255.255.255.255
UGH
100
0
0
eth0

172.31.32.0
0.0.0.0
255.255.240.0
U
100
0
0
eth0

172.31.32.1
0.0.0.0
255.255.255.255
UH
100
0
0
eth0

This is the Raspberry's PI OpenVPN client config:

client
dev tun
proto udp
remote xxx.clientvpn.eu-west-1.amazonaws.com 443
remote-random-hostname
resolv-retry infinite
nobind
cert client1.domain.tld.crt
key client1.domain.tld.key
remote-cert-tls server
cipher AES-256-GCM
verb 3

Finally, because my Raspberry PI sits in front of several devices, I'm routing the internet coming from wlan0 to eth0 and wlan1 by adding an entry to iptables:

iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

I'm not a network specialist and I can't figure out what's going on, but the asymmetrical nature of this behaviour makes me believe that the problem is on the Raspberry PI. What do you think?


问:
How to draw an oval in a matplotlib scatter plot that encapsules two points using Ellipse
I have a pandas data frame that has columns Time, Lon, Lat, Alt.

Using columns Lon and Lat. I created a simple scatter plot using matplotlib.

I wanted to draw an oval that encapsules two consecutive coordinates. So I used ellipse to achieve the goal.
This is the code I have used to create an oval

```<code>ax = plt.gca()

for i in range(1, len(merged_df), 2):

    center_lat = (merged_df.iloc[i-1]['lat'] + merged_df.iloc[i]['lat']) / 2
    center_lon = (merged_df.iloc[i-1]['lon'] + merged_df.iloc[i]['lon']) / 2
    center = (center_lon, center_lat)

    width = abs(merged_df.iloc[i]['lon'] - merged_df.iloc[i - 1]['lon'])
    height = abs(merged_df.iloc[i]['lat'] - merged_df.iloc[i - 1]['lat'])
    # Create an Ellipse instance
    ellipse = Ellipse(center, width, height, fill=False)
    ax.add_patch(ellipse)

plt.show()
</code>```

This piece of code did draw an oval. But the oval was like below.

created oval

Rather, I want to draw an oval that looks like this,
forgive my horrible drawing.

wanted oval

Thank you in advance.

```<code>ax = plt.gca()

for i in range(1, len(merged_df), 2):

    center_lat = (merged_df.iloc[i-1]['lat'] + merged_df.iloc[i]['lat']) / 2
    center_lon = (merged_df.iloc[i-1]['lon'] + merged_df.iloc[i]['lon']) / 2
    center = (center_lon, center_lat)

    width = abs(merged_df.iloc[i]['lon'] - merged_df.iloc[i - 1]['lon'])
    height = abs(merged_df.iloc[i]['lat'] - merged_df.iloc[i - 1]['lat'])
    # Create an Ellipse instance
    ellipse = Ellipse(center, width, height, fill=False)
    ax.add_patch(ellipse)

plt.show()
</code>```

This piece of code did draw an oval. But the oval was like below.

created oval

Rather, I want to draw an oval that looks like this,
forgive my horrible drawing.

wanted oval

Body:
I have a pandas data frame that has columns Time, Lon, Lat, Alt.

Using columns Lon and Lat. I created a simple scatter plot using matplotlib.

I wanted to draw an oval that encapsules two consecutive coordinates. So I used ellipse to achieve the goal.
This is the code I have used to create an oval

ax = plt.gca()

for i in range(1, len(merged_df), 2):

    center_lat = (merged_df.iloc[i-1]['lat'] + merged_df.iloc[i]['lat']) / 2
    center_lon = (merged_df.iloc[i-1]['lon'] + merged_df.iloc[i]['lon']) / 2
    center = (center_lon, center_lat)

    width = abs(merged_df.iloc[i]['lon'] - merged_df.iloc[i - 1]['lon'])
    height = abs(merged_df.iloc[i]['lat'] - merged_df.iloc[i - 1]['lat'])
    # Create an Ellipse instance
    ellipse = Ellipse(center, width, height, fill=False)
    ax.add_patch(ellipse)

plt.show()

This piece of code did draw an oval. But the oval was like below.

created oval

Rather, I want to draw an oval that looks like this,
forgive my horrible drawing.

wanted oval

Thank you in advance.

ax = plt.gca()

for i in range(1, len(merged_df), 2):

    center_lat = (merged_df.iloc[i-1]['lat'] + merged_df.iloc[i]['lat']) / 2
    center_lon = (merged_df.iloc[i-1]['lon'] + merged_df.iloc[i]['lon']) / 2
    center = (center_lon, center_lat)

    width = abs(merged_df.iloc[i]['lon'] - merged_df.iloc[i - 1]['lon'])
    height = abs(merged_df.iloc[i]['lat'] - merged_df.iloc[i - 1]['lat'])
    # Create an Ellipse instance
    ellipse = Ellipse(center, width, height, fill=False)
    ax.add_patch(ellipse)

plt.show()

This piece of code did draw an oval. But the oval was like below.

created oval

Rather, I want to draw an oval that looks like this,
forgive my horrible drawing.

wanted oval


问:
Kubernetes secrets and storage of the files from which secret will be loaded
What is the preferred storage for the file from which the Kubernetes secret will be created?

To give more context about the use case: I would need to create a secret in the GitHub Actions workflow. The secret will be created using the Helm templates, there is a nice answer on how to do this in Read secrets from file in Helm StackOverflow question. Unfortunately, they do not deal with the storage of the secret except by putting it in the ignored local folder. I am interested if it is possible to store the file in an environment variable for example base64 string and load it in the secret. It's important that when the secret is mounted it would be in PFX format.


问:
encoding decoding Error of Uf0b7 in python
Error in Uf0b7 code:

```<code>return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\uf0b7' in position 63: character maps to <undefined>
</code>```

from PyPDF2 import PdfReader, PdfFileReader

a = open("Count4.txt", "a+")
reader = PdfReader("Count4.pdf")

pdf_reader = PdfFileReader("Count4.pdf")
print(f"The total number of pages in the pdf document is {pdf_reader.numPages}")

for i in range(0, pdf_reader.numPages):
    page = reader.pages[i]
    print(page.extract_text())

    a.Write(page.extract_text())
```

Body:
Error in Uf0b7 code:

return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\uf0b7' in position 63: character maps to <undefined>

from PyPDF2 import PdfReader, PdfFileReader

a = open("Count4.txt", "a+")
reader = PdfReader("Count4.pdf")

pdf_reader = PdfFileReader("Count4.pdf")
print(f"The total number of pages in the pdf document is {pdf_reader.numPages}")

for i in range(0, pdf_reader.numPages):
    page = reader.pages[i]
    print(page.extract_text())

    a.Write(page.extract_text())


问:
Scraping with Python
I need to get the data from a toll table in Argentina. The website where this information is located here

Now, I try to put together the code to bring the information that is inside the "tbody", and the "tr" and "td" to be able to create a list and then a dataframe with that information but every time I try to bring the information from the " tbody", brings up very little data. It is impossible for me to get the information from the rows of the table. I leave you the code:

import requests
import pandas as pd
from bs4 import BeautifulSoup

url = 'https://www.argentina.gob.ar/obras-publicas/vialidad-nacional/institucional/informacion-publica/tarifas-de-peajes'
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
rows = soup.find('table',attrs={"class":"table table-spaced table-align-middle table-mobile"}).find_all('tbody')
rows
```
<p>This code returns the following:</p>
```[

]
```

I've tried fetching the "tr" and "td" elements directly but can't fetch the rows. Does anyone know what I could be doing wrong?

From already thank you very much!

Title: Scraping with Python

Body:
I need to get the data from a toll table in Argentina. The website where this information is located here

Now, I try to put together the code to bring the information that is inside the "tbody", and the "tr" and "td" to be able to create a list and then a dataframe with that information but every time I try to bring the information from the " tbody", brings up very little data. It is impossible for me to get the information from the rows of the table. I leave you the code:

import requests
import pandas as pd
from bs4 import BeautifulSoup

url = 'https://www.argentina.gob.ar/obras-publicas/vialidad-nacional/institucional/informacion-publica/tarifas-de-peajes'
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
rows = soup.find('table',attrs={"class":"table table-spaced table-align-middle table-mobile"}).find_all('tbody')
rows

This code returns the following:

[

]

I've tried fetching the "tr" and "td" elements directly but can't fetch the rows. Does anyone know what I could be doing wrong?

From already thank you very much!


问:
Profiling and performance issue, high Cstats16 and Cstats17 Simulink
We've been having issue with compilation and run time of some of our Controls Simulink model.
We've done some diagnostic work with a MATLAB tool and got results attached below: https://www.mathworks.com/help/simulink/slref/sldiagnostics.html.

We see that 2 factors are quite high compared to others. I'm not exactly familiar with this kind of report but I think it's related to state flow data exchanges and a high number of reference models in normal modes?

We wanted to get these number down for performance reasons. I was wondering what are good practices or common mistakes that would reduce or be the cause of those 2 problematic numbers.

Note, we've tried already.

Refactor some state machine with a lot of inter-dependencies and data exchanges into one.

Refactor to reduce the number of reference models.

We are considering changing some blocks to accelerator modes, but are looking at the trade-off/impact on our models.

Any other ideas?


问:
Plotly.js modebar buttons navigating to current page
I'm using Plotly.js on a SvelteKit app, and I have this issue that if I have a plot on the page, any  tag with no href attribute will trigger a route change to the same route when clicked, which is causing problems and a broken UX.
Any clue?

<svelte:head>


问:
Is there a way of updating metadata for an existing feature- or maplayer in a ArcGIS Service service
I would like to update the description field (by some API call) of a map- or feature service, for example see:
https://sampleserver6.arcgisonline.com/arcgis/rest/services/Hurricanes/MapServer/0

I am aware that it is possible to edit the description for hosted services, but we have services rererencing data in an enterprise geodatabase. Could it be the case that this type of data are read-only after the service has been published?

We have a federated Enterprise solution. And would like to be able to update both metadata in portal and server by some API.
Appreciate any help

We have been able to update the service description through ArcGIS Server admin api. But not the description and individual layer descriptions.


问:
try/catch segmentation fault in php
We have an issue with php-mime-mail-parser throwing a segmentation fault importing emails on our symfony 3.4 application. Since its an automated process we want to be either notified or skip the importing of the particular email that causes the segmentation fault. Is it possible to try catch the segmentation fault in php? Linux version is CentOS 7.</p>

Title: try/catch segmentation fault in php


问:
I have a problem implementing DDPG algorithm with Pendulum-v1 environment
I don't know if I'm wrong in the code or the implementation of the theoretical part

this is Experience Replay code:

```<code>class BatchBuffer:
  def __init__(self,rewards,actions,states,next_states,dones):
     self.rewards = rewards
     self.actions = actions
     self.states = states
     self.next_states = next_states
     self.dones = dones
  def unpack(self):
      return self.rewards,self.actions,self.states,self.next_states,self.dones
  def to(self,device):
     self.rewards = self.rewards.to(device)
     self.actions = self.actions.to(device)
     self.states = self.states.to(device)
     self.next_states=self.next_states.to(device)
     self.dones = self.dones.to(device)

class Replay_buffer:
    def __init__(self,name='Replay_buffer',max_size=1000000):
        self.name = name
        self.exp_replay = deque(maxlen=max_size)
    def _to_tensor(self,x):
        return torch.tensor(x,dtype=torch.float32)

    def store_trasitions(self,reward,action,state,next_state,done):
        transition = [reward,action,state,next_state,done]
        transition = list(map(self._to_tensor,transition))
        self.exp_replay.append(transition)

    def recall(self,batch_size):
        batch = random.sample(self.exp_replay,batch_size)
        rewards,actions,states,next_states,dones = map(torch.stack,zip(*batch))
        return BatchBuffer(rewards,actions,states,next_states,dones)
</code>```

batchBuffer is just a custom dataclass to organize things a little bit

```<code>import copy
from torch import optim
class DDPG:
    def __init__(self,state_dim,actors_feats:Union[tuple,Sequence[int]],
                    critic_feats:Union[tuple,Sequence[int]],
                    action_dim,
                    max_action,
                    tau=0.001,
                    policy_update=5,
                    policy_noise=0.2,
                    noise_clip=0.5,
                    discount=0.99) -> None:
        self.actor = Actor(feats=actors_feats,action_dim=action_dim,max_action=max_action).to(DEVICE)
        self.critic = Critic(critic_feats,action_dim,state_dim).to(DEVICE)
        self.target_actor = copy.deepcopy(self.actor).to(DEVICE)
        self.target_critic = copy.deepcopy(self.critic).to(DEVICE)
        self.device = DEVICE
        self.tau = tau
        self.policy_update = policy_update
        self.policy_noise = policy_noise
        self.noise_clip = noise_clip
        self.discount = discount
        self.max_action = max_action
        self.step =0
        self.burning = int(1e4)
        self.learn_every = 5

    def set_up_noise(self,mus,stds):
        self.noise_fn = OUActionNoise(mus,stds)

    def compile(self):
        self._critic_opt = optim.Adam(self.critic.parameters(),1e-3)
        self._actor_opt = optim.Adam(self.actor.parameters(),1e-2)

    def update_lr(self,critic_lr=1e-3,actor_lr=1e-4):
        for critic_param,actor_param in zip(self._critic_opt.param_groups,self._actor_opt.param_groups):
            critic_param['lr'] = critic_lr
            actor_param['lr'] = actor_lr

    @torch.no_grad()
    def act(self,obs,with_noise=True):
        self.step +=1
        obs = torch.tensor(obs,dtype=torch.float32).reshape(1,-1).to(self.device)
        action = self.actor(obs)
        if with_noise:
          action = (action+self.policy_noise*self.noise_fn().to(self.device))\
                                      .clamp(-self.max_action,self.max_action)
        return action.cpu().numpy().reshape((1,))

    @torch.no_grad()
    def compute_targets(self,next_sts,dones,rewards):
        next_actions = self.target_actor(next_sts)
        q = self.target_critic(next_sts,next_actions).squeeze()
        return rewards+(1-dones)*self.discount*q

    def learn(self,Buffer:Replay_buffer,batch_size=100):
        assert self.noise_fn is not None, "you must set up the noise function"
        if self.step<self.burning:
          return None,None
        if self.step%self.learn_every!=0:
          return None,None

        batch = Buffer.recall(batch_size)
        batch.to(self.device)
        targets  = self.compute_targets(batch.next_states,batch.dones,batch.rewards)

        self._critic_opt.zero_grad()
        q= self.critic(batch.states,batch.actions)
        q = q.squeeze()
        td_error = F.smooth_l1_loss(q,targets.detach())
        td_error.backward()
        self._critic_opt.step()

        self._actor_opt.zero_grad()
        actions=self.actor(batch.states)
        actor_loss = -self.critic(batch.states,actions).mean()
        actor_loss.backward()
        self._actor_opt.step()

        self._update_tar(self.critic.parameters(),self.target_critic.parameters())
        self._update_tar(self.actor.parameters(),self.target_actor.parameters())
        return td_error,actor_loss

    def _update_tar(self,params,tar_params):
       for p,tp in zip(params,tar_params):
          tp.data.copy_(self.tau*p.data+(1-self.tau)*tp.data)

    def save(self,filename):
      torch.save(self.actor.state_dict(),f"{filename}_actor.pb")
      torch.save(self.critic.state_dict(),f"{filename}_critic.pb")
    def load(self,actor_path,critic_path):
        self.actor.load_state_dict(torch.load(actor_path))
        self.critic.load_state_dict(torch.load(critic_path))
</code>```

I don't know what's wrong with my code but I my policy is not improving and the rewards is not increasing it oscillates then after some steps it's not improving anymore this is the training history as you can see my policy is not evolving

Body:
I don't know if I'm wrong in the code or the implementation of the theoretical part

this is Experience Replay code:

class BatchBuffer:
  def __init__(self,rewards,actions,states,next_states,dones):
     self.rewards = rewards
     self.actions = actions
     self.states = states
     self.next_states = next_states
     self.dones = dones
  def unpack(self):
      return self.rewards,self.actions,self.states,self.next_states,self.dones
  def to(self,device):
     self.rewards = self.rewards.to(device)
     self.actions = self.actions.to(device)
     self.states = self.states.to(device)
     self.next_states=self.next_states.to(device)
     self.dones = self.dones.to(device)

class Replay_buffer:
    def __init__(self,name='Replay_buffer',max_size=1000000):
        self.name = name
        self.exp_replay = deque(maxlen=max_size)
    def _to_tensor(self,x):
        return torch.tensor(x,dtype=torch.float32)

    def store_trasitions(self,reward,action,state,next_state,done):
        transition = [reward,action,state,next_state,done]
        transition = list(map(self._to_tensor,transition))
        self.exp_replay.append(transition)

    def recall(self,batch_size):
        batch = random.sample(self.exp_replay,batch_size)
        rewards,actions,states,next_states,dones = map(torch.stack,zip(*batch))
        return BatchBuffer(rewards,actions,states,next_states,dones)

batchBuffer is just a custom dataclass to organize things a little bit

import copy
from torch import optim
class DDPG:
    def __init__(self,state_dim,actors_feats:Union[tuple,Sequence[int]],
                    critic_feats:Union[tuple,Sequence[int]],
                    action_dim,
                    max_action,
                    tau=0.001,
                    policy_update=5,
                    policy_noise=0.2,
                    noise_clip=0.5,
                    discount=0.99) -> None:
        self.actor = Actor(feats=actors_feats,action_dim=action_dim,max_action=max_action).to(DEVICE)
        self.critic = Critic(critic_feats,action_dim,state_dim).to(DEVICE)
        self.target_actor = copy.deepcopy(self.actor).to(DEVICE)
        self.target_critic = copy.deepcopy(self.critic).to(DEVICE)
        self.device = DEVICE
        self.tau = tau
        self.policy_update = policy_update
        self.policy_noise = policy_noise
        self.noise_clip = noise_clip
        self.discount = discount
        self.max_action = max_action
        self.step =0
        self.burning = int(1e4)
        self.learn_every = 5

    def set_up_noise(self,mus,stds):
        self.noise_fn = OUActionNoise(mus,stds)

    def compile(self):
        self._critic_opt = optim.Adam(self.critic.parameters(),1e-3)
        self._actor_opt = optim.Adam(self.actor.parameters(),1e-2)

    def update_lr(self,critic_lr=1e-3,actor_lr=1e-4):
        for critic_param,actor_param in zip(self._critic_opt.param_groups,self._actor_opt.param_groups):
            critic_param['lr'] = critic_lr
            actor_param['lr'] = actor_lr

    @torch.no_grad()
    def act(self,obs,with_noise=True):
        self.step +=1
        obs = torch.tensor(obs,dtype=torch.float32).reshape(1,-1).to(self.device)
        action = self.actor(obs)
        if with_noise:
          action = (action+self.policy_noise*self.noise_fn().to(self.device))\
                                      .clamp(-self.max_action,self.max_action)
        return action.cpu().numpy().reshape((1,))

    @torch.no_grad()
    def compute_targets(self,next_sts,dones,rewards):
        next_actions = self.target_actor(next_sts)
        q = self.target_critic(next_sts,next_actions).squeeze()
        return rewards+(1-dones)*self.discount*q

    def learn(self,Buffer:Replay_buffer,batch_size=100):
        assert self.noise_fn is not None, "you must set up the noise function"
        if self.step<self.burning:
          return None,None
        if self.step%self.learn_every!=0:
          return None,None

        batch = Buffer.recall(batch_size)
        batch.to(self.device)
        targets  = self.compute_targets(batch.next_states,batch.dones,batch.rewards)

        self._critic_opt.zero_grad()
        q= self.critic(batch.states,batch.actions)
        q = q.squeeze()
        td_error = F.smooth_l1_loss(q,targets.detach())
        td_error.backward()
        self._critic_opt.step()

        self._actor_opt.zero_grad()
        actions=self.actor(batch.states)
        actor_loss = -self.critic(batch.states,actions).mean()
        actor_loss.backward()
        self._actor_opt.step()

        self._update_tar(self.critic.parameters(),self.target_critic.parameters())
        self._update_tar(self.actor.parameters(),self.target_actor.parameters())
        return td_error,actor_loss

    def _update_tar(self,params,tar_params):
       for p,tp in zip(params,tar_params):
          tp.data.copy_(self.tau*p.data+(1-self.tau)*tp.data)

    def save(self,filename):
      torch.save(self.actor.state_dict(),f"{filename}_actor.pb")
      torch.save(self.critic.state_dict(),f"{filename}_critic.pb")
    def load(self,actor_path,critic_path):
        self.actor.load_state_dict(torch.load(actor_path))
        self.critic.load_state_dict(torch.load(critic_path))

I don't know what's wrong with my code but I my policy is not improving and the rewards is not increasing it oscillates then after some steps it's not improving anymore this is the training history as you can see my policy is not evolving


问:
Create all mesh vnet connection possibilities in Terraform
I'm trying to establish a mesh connection between all vnets.

paramfile.tfvars

```<code>vnetList = {
  vnets = [
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet001",
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet002",
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet003"
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet004"

] }
</code>```

locals.tf

```<code>   vnetArray = merge([for vnets in var.vnetList.vnets : {
    for rule in var.vnetList.vnets[vnets] :
    "${vnets}, ${rule}" => rule...
  }])
</code>```

Idea is to create in local files, array loop with all mesh vnets connection possibilities. I don't know what I'm doing wrong. Any idea?

Body:
I'm trying to establish a mesh connection between all vnets.

paramfile.tfvars

vnetList = {
  vnets = [
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet001",
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet002",
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet003"
    "/subscriptions/2xxxxxxxxxxxxxxxxxx/resourceGroups/rg001/providers/Microsoft.Network/virtualNetworks/vnet004"

] }

locals.tf

   vnetArray = merge([for vnets in var.vnetList.vnets : {
    for rule in var.vnetList.vnets[vnets] :
    "${vnets}, ${rule}" => rule...
  }])

Idea is to create in local files, array loop with all mesh vnets connection possibilities. I don't know what I'm doing wrong. Any idea?


问:
Create PDF from InputStream / ByteArray - Corrupted PDF in Adobe
I'm trying to solve a problem with generating a pdf from an inputStream or byte array. The file being opened in Adobe Reader is corrupted. When I set Chrome as my default pdf reader it opens normally, and if I save "Save as" from the browser and then open it in Adobe then the document is correct. I've already tried everything. Originally the method was written in omnifaces. I tried to write it in several ways (i.e. pdfbox), none of them work and the effect is the same.

The original method:

```<code>    public String openDocument(StringValueTO docHandle) throws AbstracAekoException {
        try {
            IMaVorgangsdatenService service = ServiceLocator.get(IMaVorgangsdatenService.class);
            DocumentTO documentTO = service.openDocument(ElementTOUtil.nullSafeString(docHandle));

            if (documentTO == null || documentTO.getBinaryData() == null || documentTO.getBinaryData().length == 0) {
                FacesUtil.addMessage(FacesMessage.SEVERITY_ERROR, Messages.KEY_PPS_DOCUMENT_NOT_AVAILABLE);
            } else {
                byte[] data = documentTO.getBinaryData();
                InputStream inputStream = new ByteArrayInputStream(data);
                Faces.sendFile(inputStream, documentTO.getFilename().getValue().toString(), true);

                getData().setForceOpenDocumentZaem(false);
            }
         } catch (IOException e) {
             e.printStackTrace();
         }

        return null;
</code>```

I changed to:

```<code>        try {
            DocumentTO documentTO = null;

            IMaVorgangsdatenService service = ServiceLocator.get(IMaVorgangsdatenService.class);
            documentTO = service.openDocument(ElementTOUtil.nullSafeString(docHandle));

        FacesContext facesContext = FacesContext.getCurrentInstance();

        HttpServletResponse response =
                (HttpServletResponse) facesContext.getExternalContext().getResponse();

        response.reset();
        response.setHeader("Content-Type", "application/pdf");
        response.setHeader("Content-Disposition", "attachment;filename=" + documentTO.getFilename().getValue().toString());

        OutputStream responseOutputStream = response.getOutputStream();

        byte[] data = documentTO.getBinaryData();
        InputStream inputStream = new ByteArrayInputStream(data);

        byte[] bytesBuffer = new byte[2048];
        int bytesRead;
        while ((bytesRead = inputStream.read(bytesBuffer)) > 0)
        {
            responseOutputStream.write(bytesBuffer, 0, bytesRead);
        }

        responseOutputStream.flush();

            inputStream.close();
            responseOutputStream.close();
            facesContext.responseComplete();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
</code>```

I tried different combinations. I completelly don't know why document is corrupted in Adobe Reader.

```<code>        <!-- PDF rendering -->
        <dependency org="org.apache.pdfbox" name="pdfbox" rev="2.0.11" conf="compile->default"/>
        <dependency org="org.apache.pdfbox" name="fontbox" rev="2.0.11" conf="compile->default"/>
</code>```
```<code>        <!-- PrimeFaces -->
        <dependency org="org.primefaces" name="primefaces" rev="8.0" conf="compile->default" transitive="false" />
        <dependency org="org.omnifaces" name="omnifaces" rev="1.6.1" conf="compile->default" />
</code>```

What I saw, that generated PDF file doesn't have trailer element at the end.
Any help from your site will be highly appreciated.

Body:
I'm trying to solve a problem with generating a pdf from an inputStream or byte array. The file being opened in Adobe Reader is corrupted. When I set Chrome as my default pdf reader it opens normally, and if I save "Save as" from the browser and then open it in Adobe then the document is correct. I've already tried everything. Originally the method was written in omnifaces. I tried to write it in several ways (i.e. pdfbox), none of them work and the effect is the same.

The original method:

    public String openDocument(StringValueTO docHandle) throws AbstracAekoException {
        try {
            IMaVorgangsdatenService service = ServiceLocator.get(IMaVorgangsdatenService.class);
            DocumentTO documentTO = service.openDocument(ElementTOUtil.nullSafeString(docHandle));

            if (documentTO == null || documentTO.getBinaryData() == null || documentTO.getBinaryData().length == 0) {
                FacesUtil.addMessage(FacesMessage.SEVERITY_ERROR, Messages.KEY_PPS_DOCUMENT_NOT_AVAILABLE);
            } else {
                byte[] data = documentTO.getBinaryData();
                InputStream inputStream = new ByteArrayInputStream(data);
                Faces.sendFile(inputStream, documentTO.getFilename().getValue().toString(), true);

                getData().setForceOpenDocumentZaem(false);
            }
         } catch (IOException e) {
             e.printStackTrace();
         }

        return null;

I changed to:

        try {
            DocumentTO documentTO = null;

            IMaVorgangsdatenService service = ServiceLocator.get(IMaVorgangsdatenService.class);
            documentTO = service.openDocument(ElementTOUtil.nullSafeString(docHandle));

        FacesContext facesContext = FacesContext.getCurrentInstance();

        HttpServletResponse response =
                (HttpServletResponse) facesContext.getExternalContext().getResponse();

        response.reset();
        response.setHeader("Content-Type", "application/pdf");
        response.setHeader("Content-Disposition", "attachment;filename=" + documentTO.getFilename().getValue().toString());

        OutputStream responseOutputStream = response.getOutputStream();

        byte[] data = documentTO.getBinaryData();
        InputStream inputStream = new ByteArrayInputStream(data);

        byte[] bytesBuffer = new byte[2048];
        int bytesRead;
        while ((bytesRead = inputStream.read(bytesBuffer)) > 0)
        {
            responseOutputStream.write(bytesBuffer, 0, bytesRead);
        }

        responseOutputStream.flush();

            inputStream.close();
            responseOutputStream.close();
            facesContext.responseComplete();

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

I tried different combinations. I completelly don't know why document is corrupted in Adobe Reader.

        <dependency org="org.apache.pdfbox" name="pdfbox" rev="2.0.11" conf="compile->default"/>
        <dependency org="org.apache.pdfbox" name="fontbox" rev="2.0.11" conf="compile->default"/>

        <dependency org="org.primefaces" name="primefaces" rev="8.0" conf="compile->default" transitive="false" />
        <dependency org="org.omnifaces" name="omnifaces" rev="1.6.1" conf="compile->default" />

What I saw, that generated PDF file doesn't have trailer element at the end.
Any help from your site will be highly appreciated.


Title: HOW TO COUNT HOW MUCH DAYS HAVE PASSED IN A YEAR FOR 190.000 VALUES AND NOT 2

Body:
i have the following dataframe

    Datetime
0   2022-06-01 00:00:00
1   2022-06-01 00:01:00
2   2022-06-01 00:02:00
3   2022-06-01 00:03:00
.       .         .
.       .         .
.       .         .

190076  2022-10-10 23:56:00
190077  2022-10-10 23:57:00
190078  2022-10-10 23:58:00
190079  2022-10-10 23:59:00

i want a new column that represents how many days have passed in a year
for example i want this OUTPUT

    Datetime                   DAYS OF YEAR
0   2022-06-01 00:00:00             151
1   2022-06-01 00:01:00             151
2   2022-06-01 00:02:00             151
3   2022-06-01 00:03:00             151
.       .         .
.       .         .
.       .         .

190076  2022-10-10 23:56:00          293
190077  2022-10-10 23:57:00          293
190078  2022-10-10 23:58:00          293
190079  2022-10-10 23:59:00          293

I tried to do the following code but it was wrong

passed_2022 = pd.Data({'datetime':pd.to_datetime_range([start='2022-06-01',end='2022-10-10'], format='%Y-%m-%d')})
list2020 = [i.strftime('%Y-%m-%d') for i in passed2020]
data = data ["list2020"]

what sould i have done ?
(my dataframe is called data)