雨轻弹

文章 评论 浏览 27

雨轻弹 2025-02-20 20:09:15

你跑地平线吗?如果您将事件发送到后台,则需要地平线

Do you run horizon? If you sent event to background you need horizon

如何在命令内核中使用工作?

雨轻弹 2025-02-20 11:01:55

:: 1 地址是环回地址,带有该地址的数据包在主机外部的网络上不存在。它不能用作网络上的源或目标地址。我认为您打算使用 :: 未指定的地址,该地址将在所有主机地址上收听。

The ::1 address is the loopback address, and packets with that address cannot exist on a network outside the host. It cannot be used as either a source or destination address on a network. I think you meant to use the :: unspecified address that will listen on all host addresses.

IPv6服务器上拒绝连接

雨轻弹 2025-02-18 16:36:28

如果您希望MySQL Server决定字符集,而不是php作为客户端(我认为旧行为;首选),请尝试将 skip-character-character-set-client handshake 添加到<代码> my.cnf ,在 [mysqld] 下,重新启动 mySQL

如果您使用UTF-8以外的任何其他内容,这可能会导致麻烦。

If you want a MySQL server to decide the character set, and not PHP as a client (old behaviour; preferred, in my opinion), try adding skip-character-set-client-handshake to your my.cnf, under [mysqld], and restart mysql.

This may cause trouble in case you're using anything other than UTF-8.

UTF-8一直通过

雨轻弹 2025-02-18 13:37:16

有时,您需要最新版本的Angular和迁移配置。

例如,假设 Angular 17.1于2024年1月17日发布,,但截至今天(1月22日),最后一个可用版本根据Angular和Nx版本矩阵 IS:

Angular Version    Nx Version
~17.0.0            17.1.0 <= latest

也许您已经使用了这些命令(如NX)

# Update Nx to the latest version
  nx update @nrwl/workspace

# Migrate Nx to the latest version
  nx migrate latest

# If migration.json is created
  nx migrate --run-migrations=migrations.json

# Update all packages to the latest version
  npm install

:流程已将您的设置更新为版本17.0.0,,但要立即使用Angular 17.1(最新的版本)

在这种情况下,您可以尝试:

  npx npm-check-updates -u
  npm i --legacy-peer-deps

第一个命令将您的 package.json 更新为最新的软件包版本,而第二个命令则负责安装更新,以尊重必要的同行依赖关系。

使用 - 传统peer-deps 可以通过绕过对等自动安装来帮助您。在处理版本不匹配或未匹配的同伴依赖性时,它特别有用。

但是没有保证,每次都可以工作。在尝试这样做之前,最好使用版本控制系统(例如Git)。

ps我今天可以成功地升级到Angular 17.1。

Sometimes you need the very latest version of Angular and but a migration configuration is not yet available.

For instance, let's say Angular 17.1 is released on January 17, 2024, but as of today (January 22), the last available version according to the Angular and Nx Version Matrix is:

Angular Version    Nx Version
~17.0.0            17.1.0 <= latest

Maybe you have already used these commands (as recommended by Nx):

# Update Nx to the latest version
  nx update @nrwl/workspace

# Migrate Nx to the latest version
  nx migrate latest

# If migration.json is created
  nx migrate --run-migrations=migrations.json

# Update all packages to the latest version
  npm install

And this process has updated your setup to version 17.0.0, but want to use Angular 17.1 (the latest possible version) immediately.

In this scenario, you might try:

  npx npm-check-updates -u
  npm i --legacy-peer-deps

The first command updates your package.json to the latest package versions, while the second command takes care of installing the updates, respecting the necessary peer dependencies.

Using --legacy-peer-deps can help you out, by bypassing the peer deps auto-installation. It is particularly useful when dealing with version mismatches or unmeet peer dependencies.

But there is no guarantee, that can work so in each time. Better use a versioning system (e.g. git) before you try to do so.

p.s. I could successfully upgrade to Angular 17.1 today.

将NX角项目更新为特定的Angular

雨轻弹 2025-02-18 06:09:35

如果您只想运行一次(第一个Prop值),则只需删除依赖项并留下空数组 - useffect(()=&gt; ...,[])。如果问题是第一个值可能是空数组或未定义的,则在Useref中引入稳定的常数并在使用效果中填充它,但只有以前没有填充,并且像这样,您将在参考中只有第一个有效的值。

If you want to run it only once(on first prop value) then just remove dependency and leave empty array - useEffect(() => ..., []). If the problem is that first value might be the empty array, or undefined, then introduce stable constant with useRef and fill it in useEffect, but only if not previously filled, and like that you will have only first valid value in reference.

未能第二次更新变量值

雨轻弹 2025-02-18 00:28:56

这样的东西?:

SP500 = ['MSFT', 'AAPL', 'AMZN', 'TSLA', 'GOOGL', 'GOOG', 'FB']
weight500 = [6, 5.9, 3, 2.5, 2.3, 2.1, 2]
SP_wight_dict = dict(zip(SP500, weight500))
portfolio = ['MSFT', 'GOOGL', 'GOOG']

for i in portfolio:
    print(f"Weight = {SP_wight_dict[i]}, Index = {SP500.index(i)}")

something like this?:

SP500 = ['MSFT', 'AAPL', 'AMZN', 'TSLA', 'GOOGL', 'GOOG', 'FB']
weight500 = [6, 5.9, 3, 2.5, 2.3, 2.1, 2]
SP_wight_dict = dict(zip(SP500, weight500))
portfolio = ['MSFT', 'GOOGL', 'GOOG']

for i in portfolio:
    print(f"Weight = {SP_wight_dict[i]}, Index = {SP500.index(i)}")

如何循环浏览列表并在另一个列表中找到共同元素的索引?

雨轻弹 2025-02-17 18:30:06

下一条言论的一线式

一线似乎似乎是多余的,但实际上它们在那里覆盖边缘案例。

// Length fixed at "50"
const trim50 = str => str?.match(/^.{0,50}.*?(?=\b| |$)/)[0];

// Dynamic length
const trim = (str, n) => new RegExp(`^.{0,${n}}.*?(?=\b| |$)`).exec(str)[0];

// Demo
console.log(trim('Contrary to popular belief, Lorem Ipsum is not simply text', 50))

无正

const trim = (str, n) => {
  const start = str.substring(0, n);
  const index = str.indexOf(' ', n - 1);
  const end   = str.slice(n, index < 0 ? str.length : index);
  return start + end;
}

console.log(trim('Contrary to popular belief, Lorem Ipsum is not simply text', 50));

测试案例

由于SO内置控制台的局限性, ,请使用F12提升DevTools的控制台,然后然后 运行以下代码以进行一些演示。

const testCases = [
  { input:    'Contrary to popular belief, Lorem Ipsum is not simply text',
    expected: 'Contrary to popular belief, Lorem Ipsum is not simply' },
  { input:    '1234 6789 1234 6789 1234 6789 1234 6789 1234 678901234 6789',
    expected: '1234 6789 1234 6789 1234 6789 1234 6789 1234 678901234' },
  { input:    '1234 6789 1234 6789 1234 6789 1234 6789 1234 6789 1234 6789',
    expected: '1234 6789 1234 6789 1234 6789 1234 6789 1234 6789 ' },
  { input:    '1234 6789 1234 6789 1234 6789 1234 6789 1234 67890123456789',
    expected: '1234 6789 1234 6789 1234 6789 1234 6789 1234 67890123456789' },
  { input:    '                                                            ',
    expected: '                                                  ' },
  { input:    '1234 5678',
    expected: '1234 5678' },
  { input:    '1234',
    expected: '1234' },
  { input:    '',
    expected: '' }
];

const test = trim => {
  console.table(
    testCases.map(
      testCase => Object.assign(
        Object.assign(testCase, { output: trim(testCase.input) }),
        { pass: testCase.output === testCase.expected }
      )
    )
  );
};

test(str => str?.match(/^.{0,50}.*?(?=\b| |$)/)[0]);

Regex one-liners

Parts of the below regexes may seem redundant, but they are actually there to cover the edge cases.

// Length fixed at "50"
const trim50 = str => str?.match(/^.{0,50}.*?(?=\b| |$)/)[0];

// Dynamic length
const trim = (str, n) => new RegExp(`^.{0,${n}}.*?(?=\b| |$)`).exec(str)[0];

// Demo
console.log(trim('Contrary to popular belief, Lorem Ipsum is not simply text', 50))

Regex-free

const trim = (str, n) => {
  const start = str.substring(0, n);
  const index = str.indexOf(' ', n - 1);
  const end   = str.slice(n, index < 0 ? str.length : index);
  return start + end;
}

console.log(trim('Contrary to popular belief, Lorem Ipsum is not simply text', 50));

Test cases

Due to the limitations of the SO's built-in console, please first bring up the DevTools's console with F12, and then run the below code for a little demo.

const testCases = [
  { input:    'Contrary to popular belief, Lorem Ipsum is not simply text',
    expected: 'Contrary to popular belief, Lorem Ipsum is not simply' },
  { input:    '1234 6789 1234 6789 1234 6789 1234 6789 1234 678901234 6789',
    expected: '1234 6789 1234 6789 1234 6789 1234 6789 1234 678901234' },
  { input:    '1234 6789 1234 6789 1234 6789 1234 6789 1234 6789 1234 6789',
    expected: '1234 6789 1234 6789 1234 6789 1234 6789 1234 6789 ' },
  { input:    '1234 6789 1234 6789 1234 6789 1234 6789 1234 67890123456789',
    expected: '1234 6789 1234 6789 1234 6789 1234 6789 1234 67890123456789' },
  { input:    '                                                            ',
    expected: '                                                  ' },
  { input:    '1234 5678',
    expected: '1234 5678' },
  { input:    '1234',
    expected: '1234' },
  { input:    '',
    expected: '' }
];

const test = trim => {
  console.table(
    testCases.map(
      testCase => Object.assign(
        Object.assign(testCase, { output: trim(testCase.input) }),
        { pass: testCase.output === testCase.expected }
      )
    )
  );
};

test(str => str?.match(/^.{0,50}.*?(?=\b| |$)/)[0]);

缩短50个字符后的文字,但仅在当前单词之后

雨轻弹 2025-02-17 14:52:52

尝试此而不是 scanfiles

    bootstrapFiles:
        - /app/vendor/bin/.phpunit/phpunit-9.5-0/vendor/autoload.php

Try this instead of scanFiles:

    bootstrapFiles:
        - /app/vendor/bin/.phpunit/phpunit-9.5-0/vendor/autoload.php

用Symfony配置Phpstan

雨轻弹 2025-02-17 05:55:19

您的初始状态是错误的。虚拟API返回“数据”字段下的数组,因此您需要在初始状态下匹配该结构。

    this.state = {
      menu:false,
      userData:{ data: [] }
    }

Your initial state is wrong. The dummy api returns the array under the "data" field, so you need to match that structure in the initial state.

    this.state = {
      menu:false,
      userData:{ data: [] }
    }

如何使用API​​在React中渲染列表

雨轻弹 2025-02-16 02:05:07

我认为这就是您想做的。这使用状态变量来跟踪执行器所处的状态。

执行器关闭后,循环将检查温度,如果温度高于27度,它将开始打开执行器。然后,循环将简单地使用Millis()监视时间,直到执行器打开为止 - 因此您可以将其他代码放入其他传感器的循环中。

如果执行器打开,也会发生同样的情况,当温度低于26度时,它将关闭执行器(在此处保持差异,以阻止代码不断触发,如果温度悬停在27度左右)。

当前,这将在执行器开放或关闭时读取循环的每一个迭代的温度 - 因此,我在循环末端放了一个小延迟以限制这一点。

请注意 - 由于没有硬件可以交付,我尚未测试代码中的任何更改。但是它会编译,并应该让您了解如何使用 millis()使用状态模型来处理此类事情,而不会延迟循环。

#include <Adafruit_BME280.h>
#include <WiFi.h>

const char* ssid     = "#####"; // ESP32 and ESP8266 uses 2.4GHZ wifi only
const char* password = "#####";

//MQTT Setup Start
#include <PubSubClient.h>
#define mqtt_server "####.###.##.##"
WiFiClient espClient;
PubSubClient client(espClient);
#define mqttActuator "growShed/Acuator"
#define mqttTemp1 "growShed/temp1"

int actuatorUp = 15; //GPIO de l'actuator
int actuatorDown = 2; //GPIO de l'actuator
int actuatorUpread = (!digitalRead(actuatorUp)); //read state of gpio : on or off
int actuatorDownread = (!digitalRead(actuatorDown)); //read state of gpio : on or off

//MQTT Setup End

Adafruit_BME280 bme1; // I2C

//utiliser les virgules sur les capteurs suivants
float temp1, hum1, pres1;

//gestion des délais entre chaque captations de data
unsigned long millisNow1 = 0; //for delay purposes (laisser 0)
unsigned int sendDelay1 = 2000; //delay before sending sensor info via MQTT

//gestion des délais entre chaque captations de data
unsigned long millisNow3 = 0; //for delay purposes (laisser 0)
unsigned int sendDelay3 = 7000; //delay before sending sensor info via MQTT


// The states the actuator can be in. 
enum ActuatorState  
{
   OPENING,
   OPEN,
   CLOSING,
   CLOSED 
};
ActuatorState actuatorState; 

// When opening or closing the actuator - this is the time to stop. 
unsigned long actuatorEndTime = 0 ;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println();
  
  // begin Wifi connect
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(2000);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address (wifi RaspPi) : ");
  Serial.println(WiFi.localIP());
  //end Wifi connect

  client.setServer(mqtt_server, 1883);

  //BME
  delay(5000);
  unsigned status;
  status = bme1.begin(0x76); 
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme1.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1);
    }

  //Acuator
    pinMode(actuatorUp, OUTPUT);
    digitalWrite(actuatorDown, HIGH); //Begin with actuator switched off
    pinMode(actuatorDown, OUTPUT);
    digitalWrite(actuatorUp, HIGH); //Begin with actuator switched off

    actuatorState = CLOSED ; 

  //End Actuator

}

bool getValues() {

  temp1 = round(bme1.readTemperature()); //rounded values
  actuatorUpread = (digitalRead(actuatorUp)); //inverted value as the relay is inverted

  Serial.print("BME 1 Temperature = ");
  Serial.print(temp1);
  Serial.println(" °C");

  Serial.print("État de l'actuator haut = ");
  Serial.println(actuatorUpread);

  Serial.print("État de l'actuator bas = ");
  Serial.print(actuatorDownread);

  Serial.println();
}

void reconnect() {
  
// Loop until we're reconnected
  int counter = 0;
  while (!client.connected()) {
    if (counter==5){
      ESP.restart();
    }
    counter+=1;
    Serial.println("Attempting MQTT connection...");
    // Attempt to connect
   
    if (client.connect("growTentController")) {
      Serial.println("connected");
    } else {
      Serial.println("failed, rc=");
      Serial.println(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 10 seconds before retrying
      delay(5000);
    }
  }
  
}

void loop() {
  // put your main code here, to run repeatedly:
   if (!client.connected()){
    reconnect();
   }
     if (millis() > millisNow1 + sendDelay1){
    if (getValues()) {
   client.publish(mqttTemp1, String(temp1).c_str(),true);  
   client.publish(mqttActuator, String(actuatorUpread).c_str(),true);
   millisNow1 = millis();
    }
  }

  //Acuator moving according to BME280 temperature sensor
  switch ( actuatorState ) {
    case OPEN: 
      // Does it need closing (use value lower than 27 so we're not constantly opening and 
      // closing the actuator if the temperature is floating around 27)
      temp1 = bme1.readTemperature();
      if ( temp1 < 26 ) {
        digitalWrite(actuatorDown, LOW);
        actuatorState = CLOSING; 
        actuatorEndTime = millis() + 7000 ;
      }
      break; 
      
    case CLOSED: 
      // Does it need opening? 
      temp1 = bme1.readTemperature();
      if ( temp1 > 27 ) {
        digitalWrite(actuatorUp, LOW);
        actuatorState = OPENING; 
        actuatorEndTime = millis() + 7000; 
      }
      break ;

    case OPENING: 
      // Is it fully open? 
      if ( millis() >= actuatorEndTime ) {
        digitalWrite(actuatorUp, HIGH);
        actuatorState = OPEN ;
      }
      break ;

    case CLOSING: 
      // Is it fully closed? 
      if ( millis() >= actuatorEndTime ) {
        digitalWrite(actuatorDown, HIGH);
        actuatorState = CLOSED ;
      }
      break ;
  }

  // small delay to run the loop - and do the temperature check 5 times per second. 
  delay(200); 
}

I think this is what you want to do. This uses a state variable to keep track of what state the actuator is in.

When the actuator is closed, the loop will check the temperature and, if the temperature goes above 27 degrees, it will start opening the actuator. Then the loop will simply monitor the time using millis() until the actuator is open - so you can put other code in the loop for other sensors.

The same happens if the actuator is open, it will close the actuator when the temperature is lower than 26 degrees (kept a degree difference here to stop the code constantly triggering if the temperature hovers around 27 degrees).

Currently this will read the temperature on every iteration of the loop whilst the actuator is either open or closed - so I've put a small delay at the end of the loop to restrict this.

Please note - I have not tested any of the changes in the code as I don't have the hardware to hand. But it compiles, and should give you an idea of how you can use a state model with millis() to handle this sort of thing without delaying the loop.

#include <Adafruit_BME280.h>
#include <WiFi.h>

const char* ssid     = "#####"; // ESP32 and ESP8266 uses 2.4GHZ wifi only
const char* password = "#####";

//MQTT Setup Start
#include <PubSubClient.h>
#define mqtt_server "####.###.##.##"
WiFiClient espClient;
PubSubClient client(espClient);
#define mqttActuator "growShed/Acuator"
#define mqttTemp1 "growShed/temp1"

int actuatorUp = 15; //GPIO de l'actuator
int actuatorDown = 2; //GPIO de l'actuator
int actuatorUpread = (!digitalRead(actuatorUp)); //read state of gpio : on or off
int actuatorDownread = (!digitalRead(actuatorDown)); //read state of gpio : on or off

//MQTT Setup End

Adafruit_BME280 bme1; // I2C

//utiliser les virgules sur les capteurs suivants
float temp1, hum1, pres1;

//gestion des délais entre chaque captations de data
unsigned long millisNow1 = 0; //for delay purposes (laisser 0)
unsigned int sendDelay1 = 2000; //delay before sending sensor info via MQTT

//gestion des délais entre chaque captations de data
unsigned long millisNow3 = 0; //for delay purposes (laisser 0)
unsigned int sendDelay3 = 7000; //delay before sending sensor info via MQTT


// The states the actuator can be in. 
enum ActuatorState  
{
   OPENING,
   OPEN,
   CLOSING,
   CLOSED 
};
ActuatorState actuatorState; 

// When opening or closing the actuator - this is the time to stop. 
unsigned long actuatorEndTime = 0 ;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println();
  
  // begin Wifi connect
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(2000);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address (wifi RaspPi) : ");
  Serial.println(WiFi.localIP());
  //end Wifi connect

  client.setServer(mqtt_server, 1883);

  //BME
  delay(5000);
  unsigned status;
  status = bme1.begin(0x76); 
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
        Serial.print("SensorID was: 0x"); Serial.println(bme1.sensorID(),16);
        Serial.print("        ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
        Serial.print("   ID of 0x56-0x58 represents a BMP 280,\n");
        Serial.print("        ID of 0x60 represents a BME 280.\n");
        Serial.print("        ID of 0x61 represents a BME 680.\n");
        while (1);
    }

  //Acuator
    pinMode(actuatorUp, OUTPUT);
    digitalWrite(actuatorDown, HIGH); //Begin with actuator switched off
    pinMode(actuatorDown, OUTPUT);
    digitalWrite(actuatorUp, HIGH); //Begin with actuator switched off

    actuatorState = CLOSED ; 

  //End Actuator

}

bool getValues() {

  temp1 = round(bme1.readTemperature()); //rounded values
  actuatorUpread = (digitalRead(actuatorUp)); //inverted value as the relay is inverted

  Serial.print("BME 1 Temperature = ");
  Serial.print(temp1);
  Serial.println(" °C");

  Serial.print("État de l'actuator haut = ");
  Serial.println(actuatorUpread);

  Serial.print("État de l'actuator bas = ");
  Serial.print(actuatorDownread);

  Serial.println();
}

void reconnect() {
  
// Loop until we're reconnected
  int counter = 0;
  while (!client.connected()) {
    if (counter==5){
      ESP.restart();
    }
    counter+=1;
    Serial.println("Attempting MQTT connection...");
    // Attempt to connect
   
    if (client.connect("growTentController")) {
      Serial.println("connected");
    } else {
      Serial.println("failed, rc=");
      Serial.println(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 10 seconds before retrying
      delay(5000);
    }
  }
  
}

void loop() {
  // put your main code here, to run repeatedly:
   if (!client.connected()){
    reconnect();
   }
     if (millis() > millisNow1 + sendDelay1){
    if (getValues()) {
   client.publish(mqttTemp1, String(temp1).c_str(),true);  
   client.publish(mqttActuator, String(actuatorUpread).c_str(),true);
   millisNow1 = millis();
    }
  }

  //Acuator moving according to BME280 temperature sensor
  switch ( actuatorState ) {
    case OPEN: 
      // Does it need closing (use value lower than 27 so we're not constantly opening and 
      // closing the actuator if the temperature is floating around 27)
      temp1 = bme1.readTemperature();
      if ( temp1 < 26 ) {
        digitalWrite(actuatorDown, LOW);
        actuatorState = CLOSING; 
        actuatorEndTime = millis() + 7000 ;
      }
      break; 
      
    case CLOSED: 
      // Does it need opening? 
      temp1 = bme1.readTemperature();
      if ( temp1 > 27 ) {
        digitalWrite(actuatorUp, LOW);
        actuatorState = OPENING; 
        actuatorEndTime = millis() + 7000; 
      }
      break ;

    case OPENING: 
      // Is it fully open? 
      if ( millis() >= actuatorEndTime ) {
        digitalWrite(actuatorUp, HIGH);
        actuatorState = OPEN ;
      }
      break ;

    case CLOSING: 
      // Is it fully closed? 
      if ( millis() >= actuatorEndTime ) {
        digitalWrite(actuatorDown, HIGH);
        actuatorState = CLOSED ;
      }
      break ;
  }

  // small delay to run the loop - and do the temperature check 5 times per second. 
  delay(200); 
}

如何使用ESP32和BME280传感器控制线性执行器

雨轻弹 2025-02-15 18:15:07

这归结为IMO的是R和(基于C的)Numpy阵列的方式:R-列首先,Numpy-首先。

一个简单的解决方案是转置您的numpy数组:

np_data_measurment.transpose((2,1,0))

这将为您提供与R相同的显示。

array([[[  1.,   2.,   3.,   4.],
        [  5.,   6.,   7.,   8.],
        [  9.,  10.,  11.,  12.]],

       [[ 10.,  20.,  30.,  40.],
        [ 50.,  60.,  70.,  80.],
        [ 90., 100., 110., 120.]]])

只要您不将此转换阵列放回R中,您就可以了。 (如果您这样做,则需要重新翻新。)

What this boils down to IMO is how R and (C-based) numpy arrays are laid out in memory: R - column first, numpy - row first.

A simple solution is to transpose your numpy array:

np_data_measurment.transpose((2,1,0))

This will give you the same display as R.

array([[[  1.,   2.,   3.,   4.],
        [  5.,   6.,   7.,   8.],
        [  9.,  10.,  11.,  12.]],

       [[ 10.,  20.,  30.,  40.],
        [ 50.,  60.,  70.,  80.],
        [ 90., 100., 110., 120.]]])

As long as you are not putting this transposed array back into R, you will be fine. (You need to retranspose if you are doing so.)

rpy2 r-&gt; python数组:无尺寸翻译

雨轻弹 2025-02-15 10:10:47

要用一个实际值替换占位符,您需要用参数调用构建

    String url = "http://example.com/{id}";

    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
    URI uri = builder.build("12");

    System.out.println(uri);

To replace placeholder with a real value, you need to call build with parameters

    String url = "http://example.com/{id}";

    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
    URI uri = builder.build("12");

    System.out.println(uri);

如何使用UricomponentsBuilder替换程体

雨轻弹 2025-02-15 09:17:12

您需要转换并执行 获得上一个出发日期:

# arrival
a = pd.to_datetime(df_corp['arrival_date'], dayfirst=True)
# previous departure per ID
l = pd.to_datetime(df_corp['leaving_date'], dayfirst=True).groupby(df_corp['ID']).shift()
# difference in days
df_corp['time_between'] = (a-l).dt.days

输出:

   ID arrival_date leaving_date  time_between
0   1     01/02/20     05/02/20           NaN
1   2     01/03/20     07/03/20           NaN
2   1     12/02/20     20/02/20           7.0
3   1     07/03/20     10/03/20          16.0
4   2     10/03/20     15/03/20           3.0

You need to convert to_datetime and to perform a GroupBy.shift to get the previous departure date:

# arrival
a = pd.to_datetime(df_corp['arrival_date'], dayfirst=True)
# previous departure per ID
l = pd.to_datetime(df_corp['leaving_date'], dayfirst=True).groupby(df_corp['ID']).shift()
# difference in days
df_corp['time_between'] = (a-l).dt.days

output:

   ID arrival_date leaving_date  time_between
0   1     01/02/20     05/02/20           NaN
1   2     01/03/20     07/03/20           NaN
2   1     12/02/20     20/02/20           7.0
3   1     07/03/20     10/03/20          16.0
4   2     10/03/20     15/03/20           3.0

将一个日期列与另一个行中的另一列进行比较

雨轻弹 2025-02-15 09:00:44

正如@arundeep Chohan一样,正确指出了Web驱动程序在来回移动时丢失参考,因此我必须重新抓住所有元素。
正确的代码是:

def get_all_events_in_each_event(self):
        inner_events  = self.get_all_inner_events()
        
        for i in range(len(inner_events)):
            
            self.click_inner_event(inner_events[i])
            self.get_event_loc()
            self.get_talent()
            self.get_facebook()
            self.get_date()
            self.get_showtime_city()
            self.get_ticket_doors()
            self.back()
            inner_events = self.get_all_inner_events() #regrabbing the elements

感谢Arundeep的答案。

As @Arundeep Chohan , correctly pointed that web driver loses reference when moving back and forth so I had to re grab all the elements.
Correct code is:

def get_all_events_in_each_event(self):
        inner_events  = self.get_all_inner_events()
        
        for i in range(len(inner_events)):
            
            self.click_inner_event(inner_events[i])
            self.get_event_loc()
            self.get_talent()
            self.get_facebook()
            self.get_date()
            self.get_showtime_city()
            self.get_ticket_doors()
            self.back()
            inner_events = self.get_all_inner_events() #regrabbing the elements

Thanks arundeep for the answer.

Selenium Web驱动程序即使存在CSS选择器也找不到CSS选择器(Python)

雨轻弹 2025-02-15 03:42:15

学习 awk SED 仅适合这种情况的强大工具。

learn awk and sed powerful tools just for this type of situation.

将文本文件转换为JSON作为钥匙值对或带有CSV的python或JavaScript或PHP的标题

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文