甚是思念

文章 评论 浏览 28

甚是思念 2025-02-20 16:57:26
const result = firstData.map((firstEl) => {
  const secondEl = secondData.find((el) =>
    keys.every((key) => firstEl[key] === el[key])
  );
  return { ...firstEl, ...secondEl };
});

说明: firstData 中映射所有元素,在 seconddata 中找到其匹配(在给定键中具有相同的值),然后合并它们使用传播操作员(...)

注意:请小心在比较非主要值时。

const result = firstData.map((firstEl) => {
  const secondEl = secondData.find((el) =>
    keys.every((key) => firstEl[key] === el[key])
  );
  return { ...firstEl, ...secondEl };
});

Explanation: Map all the elements from firstData, find their match (that has the same values in given keys) in secondData and merge them using spread operator (...)

Note: Be careful on comparing non-primitive values.

根据键组合对象数组

甚是思念 2025-02-20 06:26:34

对于初学者,它不是C ++代码。这是一个C代码。

逻辑错误隐藏在 if-else 语句中。

例如,请考虑例如此代码段

        if (key.month < hellos[i].month)
        {
            // printf("\nmpla3");
            while (i >= 0 && key.month < hellos[i].month && key.year == hellos[i].year)
            {
                hellos[i + 1] = hellos[i];
                i = i - 1;
            }
            hellos[i + 1] = key;
        }
        else if (key.month == hellos[i].month)
        {
            //...
        }

,如果 key.month 小于 hellos [i] .month ,那么否则语句

else if (key.month == hellos[i].month)

将无法获得控件,尽管可以有对象(之后前面的if语句)带有 key.month 等于 hellos [i] .month ,但 key.day 小于 Hellos [i] .day

我建议编写一个单独的比较函数,类似于 QSort 使用的功能,并称其为比较结构类型的两个对象。例如,

int cmp( const void *a, const void *b )
{
    const hello *left  = a;
    const hello *right = b;

    int result = ( right->year < left->year ) - ( left->year < right->year );

    if ( result == 0 )
    {
        result = ( right->month < left->month ) - ( left->month < right->month );
        if ( result == 0 )
        {
            result = ( right->day < left->day ) - ( left->day < right->day );
        }
    }

    return result;
}        

这里是一个演示程序,该程序基于调用 QSort 使用此功能。

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int month;
    int day;
    int year;
} hello;

int cmp( const void *a, const void *b )
{
    const hello *left  = a;
    const hello *right = b;

    int result = ( right->year < left->year ) - ( left->year < right->year );

    if ( result == 0 )
    {
        result = ( right->month < left->month ) - ( left->month < right->month );
        if ( result == 0 )
        {
            result = ( right->day < left->day ) - ( left->day < right->day );
        }
    }

    return result;
}

int main( void )
{
    hello hellos[] =
    {
        { 02, 02, 2015 },
        { 02, 01, 2015 },
        { 01, 30, 2015 },
        { 01, 31, 2015 },
        { 01, 29, 2015 },
        { 01, 28, 2015 },
    };
    size_t N = sizeof( hellos ) / sizeof( *hellos );

    qsort( hellos, N, sizeof( hello ), cmp );

    for ( size_t i = 0; i < N; i++ )
    {
        printf( "%02d/%02d/%d\n", hellos[i].month, hellos[i].day, hellos[i].year );
    }
}

程序输出为

01/28/2015
01/29/2015
01/30/2015
01/31/2015
02/01/2015
02/02/2015

您可以在您的功能中仅在一个if语句中插入比较函数的调用和以下循环时,例如

if ( cmp( &key, &hellos[i] ) < 0 )
{
    //...
}

将您的评论考虑到我的答案,似乎您无法了解应该做什么。因此,我将包括一个演示程序。

#include <stdio.h>

typedef struct
{
    int month;
    int day;
    int year;
} hello;

int cmp( const void *a, const void *b )
{
    const hello *left  = a;
    const hello *right = b;

    int result = ( right->year < left->year ) - ( left->year < right->year );

    if ( result == 0 )
    {
        result = ( right->month < left->month ) - ( left->month < right->month );
        if ( result == 0 )
        {
            result = ( right->day < left->day ) - ( left->day < right->day );
        }
    }

    return result;
}

void insertionSort( hello hellos[], size_t records )
{
    for ( size_t i = 1; i < records; i++ )
    {
        if ( cmp( &hellos[i], &hellos[i-1] ) < 0 )
        {
            hello tmp = hellos[i];
            size_t j = i;

            while ( j != 0 && cmp( &tmp, &hellos[j -1] ) < 0 )  
            {   --j;
                hellos[j + 1] = hellos[j];               
            } 

            hellos[j] = tmp;
        }
    }
}

int main( void )
{
    hello hellos[] =
    {
        { 02, 02, 2015 },
        { 02, 01, 2015 },
        { 01, 30, 2015 },
        { 01, 31, 2015 },
        { 01, 29, 2015 },
        { 01, 28, 2015 },
    };
    size_t N = sizeof( hellos ) / sizeof( *hellos );

    insertionSort( hellos, N );

    for ( size_t i = 0; i < N; i++ )
    {
        printf( "%02d/%02d/%d\n", hellos[i].month, hellos[i].day, hellos[i].year );
    }
}

程序输出与上面显示的相同

01/28/2015
01/29/2015
01/30/2015
01/31/2015
02/01/2015
02/02/2015

或在C ++中相同,使用标准C ++函数 std :: TIE 在标题&lt; tuple&gt; 中声明。

类似

if ( std::tie( key.year, key.month, key.day ) < 
     std::tie( hellos[i].year, hellos[i].month, hellos[i].day ) ) 
{
    //...
} 

For starters it is not a C++ code. It is a C code.

The logical error is hidden in the if-else statements.

Consider for example this code snippet

        if (key.month < hellos[i].month)
        {
            // printf("\nmpla3");
            while (i >= 0 && key.month < hellos[i].month && key.year == hellos[i].year)
            {
                hellos[i + 1] = hellos[i];
                i = i - 1;
            }
            hellos[i + 1] = key;
        }
        else if (key.month == hellos[i].month)
        {
            //...
        }

If key.month is less than hellos[i].month then the else if statement

else if (key.month == hellos[i].month)

will not get the control though there can be objects (after the preceding if statement) with key.month equal to hellos[i].month but with key.day less than hellos[i].day.

I advice to write a separate comparison function similarly to the function used by qsort and call it to compare two objects of the structure type. For example

int cmp( const void *a, const void *b )
{
    const hello *left  = a;
    const hello *right = b;

    int result = ( right->year < left->year ) - ( left->year < right->year );

    if ( result == 0 )
    {
        result = ( right->month < left->month ) - ( left->month < right->month );
        if ( result == 0 )
        {
            result = ( right->day < left->day ) - ( left->day < right->day );
        }
    }

    return result;
}        

Here is a demonstration program of using this function based on calling qsort.

#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int month;
    int day;
    int year;
} hello;

int cmp( const void *a, const void *b )
{
    const hello *left  = a;
    const hello *right = b;

    int result = ( right->year < left->year ) - ( left->year < right->year );

    if ( result == 0 )
    {
        result = ( right->month < left->month ) - ( left->month < right->month );
        if ( result == 0 )
        {
            result = ( right->day < left->day ) - ( left->day < right->day );
        }
    }

    return result;
}

int main( void )
{
    hello hellos[] =
    {
        { 02, 02, 2015 },
        { 02, 01, 2015 },
        { 01, 30, 2015 },
        { 01, 31, 2015 },
        { 01, 29, 2015 },
        { 01, 28, 2015 },
    };
    size_t N = sizeof( hellos ) / sizeof( *hellos );

    qsort( hellos, N, sizeof( hello ), cmp );

    for ( size_t i = 0; i < N; i++ )
    {
        printf( "%02d/%02d/%d\n", hellos[i].month, hellos[i].day, hellos[i].year );
    }
}

The program output is

01/28/2015
01/29/2015
01/30/2015
01/31/2015
02/01/2015
02/02/2015

You can insert a call of the comparison function in only one if statement within your function and the following while loop as for example

if ( cmp( &key, &hellos[i] ) < 0 )
{
    //...
}

Taking into account your comments to my answer it seems you are unable to understand what should be done. So I will just include a demonstration program.

#include <stdio.h>

typedef struct
{
    int month;
    int day;
    int year;
} hello;

int cmp( const void *a, const void *b )
{
    const hello *left  = a;
    const hello *right = b;

    int result = ( right->year < left->year ) - ( left->year < right->year );

    if ( result == 0 )
    {
        result = ( right->month < left->month ) - ( left->month < right->month );
        if ( result == 0 )
        {
            result = ( right->day < left->day ) - ( left->day < right->day );
        }
    }

    return result;
}

void insertionSort( hello hellos[], size_t records )
{
    for ( size_t i = 1; i < records; i++ )
    {
        if ( cmp( &hellos[i], &hellos[i-1] ) < 0 )
        {
            hello tmp = hellos[i];
            size_t j = i;

            while ( j != 0 && cmp( &tmp, &hellos[j -1] ) < 0 )  
            {   --j;
                hellos[j + 1] = hellos[j];               
            } 

            hellos[j] = tmp;
        }
    }
}

int main( void )
{
    hello hellos[] =
    {
        { 02, 02, 2015 },
        { 02, 01, 2015 },
        { 01, 30, 2015 },
        { 01, 31, 2015 },
        { 01, 29, 2015 },
        { 01, 28, 2015 },
    };
    size_t N = sizeof( hellos ) / sizeof( *hellos );

    insertionSort( hellos, N );

    for ( size_t i = 0; i < N; i++ )
    {
        printf( "%02d/%02d/%d\n", hellos[i].month, hellos[i].day, hellos[i].year );
    }
}

The program output is the same as shown above

01/28/2015
01/29/2015
01/30/2015
01/31/2015
02/01/2015
02/02/2015

Or in C++ this done very easy using the standard C++ function std::tie declared in the header <tuple>.

Something like

if ( std::tie( key.year, key.month, key.day ) < 
     std::tie( hellos[i].year, hellos[i].month, hellos[i].day ) ) 
{
    //...
} 

为什么我的插入排序只能对90%的数据进行排序?

甚是思念 2025-02-20 05:55:03

首先,这实际上是一个不好的计划,您要节省一个可以轻松计算的值。但是,即使它经常导致并发症,这似乎很普遍。您需要的函数触发;更具体地说,是触发功能和评论上的触发器。 (请参阅

create or replace function record_a_review_air()
  returns trigger 
 language plpgsql 
as $
begin 
    update products 
       set reviews = reviews+1
     where prod_id = new.prod_id;
    return new;
end;
$;

create trigger reviews_air
         after insert 
           on reviews
          for each row 
          execute function record_a_review_air();

”插入产品时,这样做将设定一个值。但是,该产品将再也不会被调用。

First off this is actually a bad plan, you are saving a value the can easily be calculated. However, it seems quite common even though it often leads to complications. The function you need is a trigger; more specifically a trigger function and a trigger on reviews. (see demo)

create or replace function record_a_review_air()
  returns trigger 
 language plpgsql 
as $
begin 
    update products 
       set reviews = reviews+1
     where prod_id = new.prod_id;
    return new;
end;
$;

create trigger reviews_air
         after insert 
           on reviews
          for each row 
          execute function record_a_review_air();

NOTE: Setting a DEFAULT will not accomplish what you want. Doing so would set the a value when the Product is inserted. But would never be invoked again for that Product.

函数以自动设置一个表中的相应记录数量为第二个表中的默认值

甚是思念 2025-02-20 00:17:23

为了避免回调地狱,您可以在订阅呼叫之外定义回调功能。

  setData = (response: Car) => {
    this.car = response;
    this.carId = response.carId;
    this.rows = response.carData;
    this.pollingHandler();
    this.loading = false;
  };

  handleError = (response: any) => {
    this.rows = [];
    this.loading = false;
    this.notificationUtilService.addErrorToastNotification(
      response?.error?.message ?? 'Error getting car data'
    );
  };

  fetchTableData(carId: string): void {
    this.resetFilterForm();
    this.carService.getcar(carId).pipe(takeUntil(this.destroy$)).subscribe({
      next: this.setData,
      error: this.handleError,
    });
  }

To avoid callback hell, you can define your callback functions outside of the subscribe call.

  setData = (response: Car) => {
    this.car = response;
    this.carId = response.carId;
    this.rows = response.carData;
    this.pollingHandler();
    this.loading = false;
  };

  handleError = (response: any) => {
    this.rows = [];
    this.loading = false;
    this.notificationUtilService.addErrorToastNotification(
      response?.error?.message ?? 'Error getting car data'
    );
  };

  fetchTableData(carId: string): void {
    this.resetFilterForm();
    this.carService.getcar(carId).pipe(takeUntil(this.destroy$)).subscribe({
      next: this.setData,
      error: this.handleError,
    });
  }

如何处理订阅回调中的逻辑?

甚是思念 2025-02-19 16:33:50

在有更好的解决方案之前,我将发布我当前的解决方案(及其缺点):

我们的清理任务现在围绕以下解决方案构建,评估由 tkn Pipelineruns list列表>:

tkn pipelineruns list --show-managed-fields -n e-dodo-tmgr --label tekton.dev/pipeline=deploy-pipeline | awk '$6~/Succeeded/ && $3~/day|week|month/ {print $1}'

优势:

  • 如果没有广泛的呼叫或其他计算,它应该做什么。

缺点:

  • 时间仅限于“超过一个小时 /每天 /一周的年龄段”……但是这是可以接受的,因为只有成功的构建。
  • 我猜该设计非常脆弱,因为随着TKN-CLIENT的变化,表格的格式可能会更改,这意味着AWK会选择错误的列或类似的模式合并。

总而言之,我希望该解决方案能够保留,直到有更多有用的客户端功能使所需信息可以直接过滤。实际上,我希望 tkn Pipelineruns删除 - State成功-Period P1D
该时间段的符号来自ISO8601。

Until a better solution is there, I'll post my current solution (and its drawbacks):

Our cleanup-task is now built around the following solution, evaluating the table returned by tkn pipelineruns list:

tkn pipelineruns list --show-managed-fields -n e-dodo-tmgr --label tekton.dev/pipeline=deploy-pipeline | awk '$6~/Succeeded/ && $3~/day|week|month/ {print $1}'

Advantages:

  • It does what it should without extensive calls or additional calculation.

Disadvantages:

  • Time is limited to "older than an hour / a day / a week ..." But that's acceptable, since only successful builds are concerned.
  • I guess the design is quite brittle, because with changes in the tkn-Client the format of the table might change which implies that awk will pick the wrong columns, or similar pattern-probs.

All in all I hope the solution will hold until there are some more helpful client-features that make the desired info directly filterable. Actually I'd hope for something like tkn pipelineruns delete --state successful --period P1D.
The notation for the time period is from ISO8601.

Tekton:如何删除成功的管道?

甚是思念 2025-02-19 09:07:44

我的问题是通过使用命令重置反应本机缓存来解决的:

npm start-reset-cache

My problem was solved by resetting the react native cache with the command:

npm start -- --reset-cache

REECT本机中的重置PNG缓存

甚是思念 2025-02-19 01:36:20

您需要在使用 MAP 之前检查,无论 HeaderGroup 数据是否具有。

{headerGroups && headerGroups.map((headerGroup) => (
   <tr {...headerGroup.getHeaderGroupProps()}>
      {headerGroup && headerGroup.map((column) => (
         <th {...column.getHeaderProps()}>{column.render("Header")}</th>
       ))}
    </tr>
))}

you need to check before using the map, whether headerGroup data have or not.

{headerGroups && headerGroups.map((headerGroup) => (
   <tr {...headerGroup.getHeaderGroupProps()}>
      {headerGroup && headerGroup.map((column) => (
         <th {...column.getHeaderProps()}>{column.render("Header")}</th>
       ))}
    </tr>
))}

React-Table Unduckurk TypeError:headerGroup.map不是功能

甚是思念 2025-02-18 19:26:45

您可以提供自己的自定义 AccessDeniedHandler 实现。

@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
    AuthenticationManager authenticationManager = authenticationConfiguration.getAuthenticationManager();
    var jwtAuthenticationFilter = new JwtAuthenticationFilter(authenticationManager);

    var jwtAuthorisationFilter = new JwtAuthorisationFilter();

    http.cors().and().csrf().disable().authorizeRequests()
        .anyRequest().authenticated().and()
        .addFilter(jwtAuthenticationFilter)
        .addFilterAfter(jwtAuthorisationFilter, BasicAuthenticationFilter.class)
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .exceptionHandling()
        .accessDeniedHandler( (request, response, exception) ->
             response.sendError(HttpStatus.UNAUTHORIZED.value(), exception.getMessage()
        ));

    return http.build();
}

You can provide your own custom AccessDeniedHandler implementation.

@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
    AuthenticationManager authenticationManager = authenticationConfiguration.getAuthenticationManager();
    var jwtAuthenticationFilter = new JwtAuthenticationFilter(authenticationManager);

    var jwtAuthorisationFilter = new JwtAuthorisationFilter();

    http.cors().and().csrf().disable().authorizeRequests()
        .anyRequest().authenticated().and()
        .addFilter(jwtAuthenticationFilter)
        .addFilterAfter(jwtAuthorisationFilter, BasicAuthenticationFilter.class)
        .sessionManagement()
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .exceptionHandling()
        .accessDeniedHandler( (request, response, exception) ->
             response.sendError(HttpStatus.UNAUTHORIZED.value(), exception.getMessage()
        ));

    return http.build();
}

当身份验证失败时,将弹簧安全性更改为返回401

甚是思念 2025-02-18 18:50:00

您是对的,搜索需要3LO,这里的最大优势是您可以递归地使用它。

为了避免需要3LO,您可以使用获取文件夹内容递归,就像我们

请注意,您还可以组合有了这个请求,
并充分利用
elasticsearch 进行搜索。

还有一个示例使用elasticsearch 在这里(在这种情况下,基于模型元数据搜索)。

You're right, search requires 3LO and the great advantage here is that you can use it recursively.

To avoid the need of 3LO you can use Get folder contents recursively, as we did here.

Note that you can also combine filters with this request,
and take advantage of Elasticsearch for searching.

There's also a sample using Elasticsearch here (in this case to search based on models metadata).

Autodesk Integration-在没有3腿令牌的文件夹中搜索

甚是思念 2025-02-18 11:42:42

我们可能需要

SS <- c(5, 10, 15, 25, 50, 75, 100,    250,    500,    750,    1000,   1250,   1500,   2000,   2500,   3000,   3500,   4000,   4500,   5000)
QU <- sapply(SS, function(x) {
           x1 <- sample(dat, x, replace = TRUE)
           unname(quantile(x1, .60))
    })
data.frame(SS, QU)

- 输出

  SS       QU
1     5 107.8017
2    10 101.2228
3    15 101.6636
4    25 103.1269
5    50 101.7254
6    75 102.4818
7   100 104.6631
8   250 103.1844
9   500 102.4056
10  750 102.5745
11 1000 102.8261
12 1250 103.0092
13 1500 102.5766
14 2000 102.7607
15 2500 102.6239
16 3000 102.2122
17 3500 102.6231
18 4000 102.7531
19 4500 102.6493
20 5000 102.5840

We may need

SS <- c(5, 10, 15, 25, 50, 75, 100,    250,    500,    750,    1000,   1250,   1500,   2000,   2500,   3000,   3500,   4000,   4500,   5000)
QU <- sapply(SS, function(x) {
           x1 <- sample(dat, x, replace = TRUE)
           unname(quantile(x1, .60))
    })
data.frame(SS, QU)

-output

  SS       QU
1     5 107.8017
2    10 101.2228
3    15 101.6636
4    25 103.1269
5    50 101.7254
6    75 102.4818
7   100 104.6631
8   250 103.1844
9   500 102.4056
10  750 102.5745
11 1000 102.8261
12 1250 103.0092
13 1500 102.5766
14 2000 102.7607
15 2500 102.6239
16 3000 102.2122
17 3500 102.6231
18 4000 102.7531
19 4500 102.6493
20 5000 102.5840

我如何根据R中的不同样本量计算分位数

甚是思念 2025-02-18 11:01:16

eagnir '是编码您自己的重复过滤器功能的好方法。您还可以使用JavaScript的内置主题对象来构造两个数组中的一组唯一值,然后将其转换回一个数组。

对于此解决方案,我假设您的 state.sensordata 将是一个唯一的对象,因为我不确定您是否总是在 state < /code>和您的数据对象。然后,您只需修改以下代码即可嵌套另一个循环。

运行示例(滚动到底部以查看解决方案):

let data = {
  SensorData: [
    {
      SensorID: 1,
      BatteryPct: 100,
      LastActiveTime: 1656461958000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 2,
      BatteryPct: 80,
      LastActiveTime: 1656461593000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 3,
      BatteryPct: 80,
      LastActiveTime: 1656462563000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 4,
      BatteryPct: 80,
      LastActiveTime: 1656462563000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 5,
      BatteryPct: 42,
      LastActiveTime: 1656424819000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 6,
      BatteryPct: null,
      LastActiveTime: 1656318675000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 7,
      BatteryPct: null,
      LastActiveTime: 1656253855000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 8,
      BatteryPct: 80,
      LastActiveTime: 1656447026000,
      LastStatus: 'OFFLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
  ],
};

const state = {
  sensorData: {
    Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 100)),
  },
};

console.log(data.SensorData[0].Events.length); //50
for (let i = 0; i < data.SensorData.length; i++) {
  let hashSet = new Set();
  data.SensorData[i].Events.forEach((e) => hashSet.add(e));
  state.sensorData.Events.forEach((e) => hashSet.add(e));
  data.SensorData[i].Events = Array.from(hashSet);
}

//should be 100 events but it stays 50
console.log(data.SensorData[0].Events.length); //100

Eagnir's answer is a good way to go about it coding your own duplicate filter function. You can also use javascript's built in hashset object to construct an set of unique values from your two arrays, then convert it back to an array.

For this solution, I've assumed that your state.sensorData will be a unique object because I'm not sure if you will always get a 1-to-1 match between your state and your data objects. You would then just modify the below code to nest another for-loop.

Running example (scroll to bottom to see solution):

let data = {
  SensorData: [
    {
      SensorID: 1,
      BatteryPct: 100,
      LastActiveTime: 1656461958000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 2,
      BatteryPct: 80,
      LastActiveTime: 1656461593000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 3,
      BatteryPct: 80,
      LastActiveTime: 1656462563000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 4,
      BatteryPct: 80,
      LastActiveTime: 1656462563000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 5,
      BatteryPct: 42,
      LastActiveTime: 1656424819000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 6,
      BatteryPct: null,
      LastActiveTime: 1656318675000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 7,
      BatteryPct: null,
      LastActiveTime: 1656253855000,
      LastStatus: 'ONLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
    {
      SensorID: 8,
      BatteryPct: 80,
      LastActiveTime: 1656447026000,
      LastStatus: 'OFFLINE',
      Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 50)),
    },
  ],
};

const state = {
  sensorData: {
    Events: Array.from({ length: 50 }, () => Math.floor(Math.random() * 100)),
  },
};

console.log(data.SensorData[0].Events.length); //50
for (let i = 0; i < data.SensorData.length; i++) {
  let hashSet = new Set();
  data.SensorData[i].Events.forEach((e) => hashSet.add(e));
  state.sensorData.Events.forEach((e) => hashSet.add(e));
  data.SensorData[i].Events = Array.from(hashSet);
}

//should be 100 events but it stays 50
console.log(data.SensorData[0].Events.length); //100

无法在两个阵列中连接两个阵列而无需重复

甚是思念 2025-02-18 01:22:20

您应该使用状态变量来控制DIV的可见性。

class App extends Component {
  constructor() {
    super();
    this.state = { hidden: false };
  }

  handleFinish = () => {
    console.log("CLickedddd");
    this.setState({ hidden: !this.state.hidden });
  };

  render() {
    return (
      <>
        <button id="finish" onClick={this.handleFinish}>
          Finish
        </button>
        <div
          style={{ height: 300, width: 300, backgroundColor: "red" }}
          className={this.state.hidden ? "hidden" : ""}
        ></div>
      </>
    );
  }
}

请参阅 this Sandbox

You should use a state variable to control your div's visibility.

class App extends Component {
  constructor() {
    super();
    this.state = { hidden: false };
  }

  handleFinish = () => {
    console.log("CLickedddd");
    this.setState({ hidden: !this.state.hidden });
  };

  render() {
    return (
      <>
        <button id="finish" onClick={this.handleFinish}>
          Finish
        </button>
        <div
          style={{ height: 300, width: 300, backgroundColor: "red" }}
          className={this.state.hidden ? "hidden" : ""}
        ></div>
      </>
    );
  }
}

See this sandbox

当我单击React中的按钮时,如何定位并更改不同元素的样式

甚是思念 2025-02-17 16:56:16

首先,用户输入1个“向后1”选项卡,从外观中,您试图在用户输入之间为此目的获取随机否否 randy.randint.randint 这是无错误的代码。

import random

def main():

    userNumber1 = int(input("Choose a number from 1-20"))
    userNumber2 = int(input("Choose another number from 1-20"))
    if userNumber1 == userNumber2:
        print("Invalid input")
    else:
        num1 = random.randint(userNumber1,userNumber2)
        num2 = random.randint(userNumber1,userNumber2)
        num3 = random.randint(userNumber1,userNumber2)
    while (num1==num2 or num1==num3 or num3==num2):
        if (num3==num2):
            del num2
            num2 = random.randint(userNumber1,userNumber2)
        elif (num1==num3):
            del num3
            num3 = random.randint(userNumber1,userNumber2)
        elif (num1==num2):
            del num2
            num2 = random.randint(userNumber1,userNumber2)
        else:
            pass
    print(str(num1)+str(num2)+str(num3))
main()

First of all indent user Inputs 1 tab backwards,from the look of it you are trying to get a random no between user inputs for this purpose use Random.randint here is the error free code .

import random

def main():

    userNumber1 = int(input("Choose a number from 1-20"))
    userNumber2 = int(input("Choose another number from 1-20"))
    if userNumber1 == userNumber2:
        print("Invalid input")
    else:
        num1 = random.randint(userNumber1,userNumber2)
        num2 = random.randint(userNumber1,userNumber2)
        num3 = random.randint(userNumber1,userNumber2)
    while (num1==num2 or num1==num3 or num3==num2):
        if (num3==num2):
            del num2
            num2 = random.randint(userNumber1,userNumber2)
        elif (num1==num3):
            del num3
            num3 = random.randint(userNumber1,userNumber2)
        elif (num1==num2):
            del num2
            num2 = random.randint(userNumber1,userNumber2)
        else:
            pass
    print(str(num1)+str(num2)+str(num3))
main()

TypeError:__Init __()从1到2个位置论点,但我的代码中给出了3个

甚是思念 2025-02-17 15:46:14

考虑到我对您的应用程序的理解,并且专注于您提出的实际问题,我正在括起来是否使用 Strata()是最佳的建模选择。

Schoenfeld残留物用于诊断违反比例危害的COX模型的协变量。您的模型规范没有协变量。 ergo,您没有侵犯诊断和可能正确的pH违规行为,这就是为什么 cox.zph 正在抛出“ null Model”错误,就像在“此模型”中仅估算(Cox Model的AN)版本拦截术语”。

换句话说:Schoenfeld残留物是协变量特异性的,因此,如果Cox模型中没有协变量,则没有可以计算的Schoenfeld。 cox.zph 的计算涉及Schoenfeld残差,因此错误。

相反,您有一个 strata()术语。分层允许不同的组具有不同的基线危险率(从启发式上讲,Cox的拦截术语版本)。您可能会分层的原因有很多,但是其中之一是正确可能违反pH,这是一个使您首先运行 cox.zph 的问题。如果您继续对处理进行分层,则没有与pH相关的模型诊断供您运行。

(作为一方面:对于 GGCOXDIAMGNOSTICS 在您的MWE中,您需要传递 coxph 对象,而不是 cox.zph 对象。

I'm bracketing whether using strata() is the best modeling choice, given what I understand of your application, and focusing on the actual question you asked.

Schoenfeld residuals are used to diagnose proportional hazard violations a Cox model's covariates. Your model specification has no covariates. Ergo, you have no PH violations to diagnose and potentially correct, which is why cox.zph is throwing a "null model" error, as in "this model only estimates the (Cox model's version of an) intercept term".

Put differently: Schoenfeld residuals are covariate-specific quantities, so if there are no covariates in the Cox model, there are no Schoenfelds to calculate. cox.zph's calculations involve the Schoenfeld residuals, hence the error.

Instead, you have a strata() term. Stratifying permits different groups to have a different baseline hazard rate (= the Cox's version of an intercept term, heuristically speaking). There are many reasons you might stratify, but one of them is to correct for possible PH violations—the very issue that's leading you to run cox.zph in the first place. If you keep stratifying on treatment, there are no PH-related model diagnostics for you to run.

(As an aside: for ggcoxdiagnostics in your MWE, you need to pass in the coxph object, not the cox.zph object.)

当用coxph(生存包)中的分层变量上的模型诊断时出错

甚是思念 2025-02-17 04:39:57

您可以替换SUB_MODEL的所有空间,然后以这种方式与您的类似条件进行比较。

select * from [table] where replace(sub_model,' ','') like  '%A30%';

You can replace all the spaces of sub_model and then compare with your like condition in that way it will work.

select * from [table] where replace(sub_model,' ','') like  '%A30%';

选择查询,例如%A30%的陈述会导致%A30%,%A 30%,%A3 0%

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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