杀お生予夺

文章 评论 浏览 28

杀お生予夺 2025-02-21 01:52:22

这可以使用窗口函数(因此使用单个数据)

select
       name
     , sum_qty
     , metadata
     , execution_time
from (
     select 
            *
          , sum(Quantity) over(partition by name) sum_qty
          , row_number() over(partition by name, case when quantity > 0 then 1 else 0 end
                              order by Execution_time DESC) as rn
     from mytable
     ) d
where rn = 1 and quantity > 0
order by name

结果

+-------+---------+----------+----------------+
| name  | sum_qty | metadata | execution_time |
+-------+---------+----------+----------------+
| James |       0 | [2,18]   |              5 |
| Mike  |       1 | [5,42]   |              7 |
| Neil  |       1 | [4,1]    |              6 |
+-------+---------+----------+----------------+

db<> fiddle 此处

This can be achieved using window functions (hence with a single pass of the data)

select
       name
     , sum_qty
     , metadata
     , execution_time
from (
     select 
            *
          , sum(Quantity) over(partition by name) sum_qty
          , row_number() over(partition by name, case when quantity > 0 then 1 else 0 end
                              order by Execution_time DESC) as rn
     from mytable
     ) d
where rn = 1 and quantity > 0
order by name

result

+-------+---------+----------+----------------+
| name  | sum_qty | metadata | execution_time |
+-------+---------+----------+----------------+
| James |       0 | [2,18]   |              5 |
| Mike  |       1 | [5,42]   |              7 |
| Neil  |       1 | [4,1]    |              6 |
+-------+---------+----------+----------------+

db<>fiddle here

Postgres不同的行,同时总结

杀お生予夺 2025-02-20 19:35:40

您可以做这样的事情:

instance.method_1().__getattribute__("method_2" if dummy_condition else "method_3")()

这是利用__ getAttribute __ dunder然后调用它

You can do something like this instead:

instance.method_1().__getattribute__("method_2" if dummy_condition else "method_3")()

This utilises __getattribute__ dunder then calls it

条件的连锁类方法

杀お生予夺 2025-02-20 19:16:40

woocommerce_add_cart_item_data hook包含3个参数对1,
而且由于$ product_id是第二个,因此可以用来回答您的问题:

function filter_woocommerce_add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
    // Get product ID
    $product_id = $variation_id > 0 ? $variation_id : $product_id;
        
    // When product ID is in array (multiple product IDs can be added, separated by a comma)
    if ( in_array( $product_id, array( 1, 32, 30, 817 ) ) ) {
        wc_empty_cart();
    }

    return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'filter_woocommerce_add_cart_item_data', 10, 3 );

The woocommerce_add_cart_item_data hook contains 3 arguments versus 1,
and since $product_id is the 2nd it can be used to answer your question:

function filter_woocommerce_add_cart_item_data( $cart_item_data, $product_id, $variation_id ) {
    // Get product ID
    $product_id = $variation_id > 0 ? $variation_id : $product_id;
        
    // When product ID is in array (multiple product IDs can be added, separated by a comma)
    if ( in_array( $product_id, array( 1, 32, 30, 817 ) ) ) {
        wc_empty_cart();
    }

    return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'filter_woocommerce_add_cart_item_data', 10, 3 );

当将特定产品添加到WooCommerce购物车中时,然后添加产品

杀お生予夺 2025-02-20 16:00:26

您将不得不

使用重力底部创建一个自定义对话框()在OnViewCreated()中膨胀一个layout_bottom_button,因此膨胀的布局将始终保持在底部,

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT
    );
    params.gravity = Gravity.BOTTOM;
    View bottomButtonView = this.getLayoutInflater().inflate(R.layout.layout_bottom_button, null);
    
this.getDialog().addContentView(viewM, params);

请记住,recyClerview应该具有与Layout_bottom_bottom_bottom_button Layut高度相同的底部余量。

You will have to create a custom dialog

inside onViewCreated() inflate a layout_bottom_button using gravity bottom, so inflated layout will always be at bottom

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT
    );
    params.gravity = Gravity.BOTTOM;
    View bottomButtonView = this.getLayoutInflater().inflate(R.layout.layout_bottom_button, null);
    
this.getDialog().addContentView(viewM, params);

keep in mind that recyclerView should have bottom margin same as layout_bottom_button layout height, so that recyclerView does not hide below button.

保持按钮对话框的底部

杀お生予夺 2025-02-20 15:01:53

这里的一个古老问题,但我在其他地方没有找到更多信息。我必须将大小为25 GB(解压缩)的尺寸恢复文件,并尝试了NCK和NCCOPY。我认为NCCOPY实际上工作了,但花了大约48小时。

我最终使用了Xarray和Python,结果速度更快。在不到5分钟的时间内将25 GB的重新包装(包括压缩)。记忆使用率约为50 GB。这是我使用过的方法:

import xarray as xr

ds = xr.open_dataset('field_access_opt.nc') # chunks (time,lat,lon): 1,500,1000

#re-chunk variable 'GHI'
ds.to_netcdf("point_access_opt.nc",
encoding={'lat': {'zlib': False, '_FillValue': None},
    'lon': {'zlib': False, '_FillValue': None},
    'time': {'zlib': False, '_FillValue': None, 'dtype': 'double'},
    'GHI': {'chunksizes': [len(ds['GHI'].time),1,1], 'zlib': True, 
    'complevel': 1}})

An old question here, but I didn't find much more information elsewhere. I have to rechunk files of size 25 GB (unzipped) and tried both ncks and nccopy. I think nccopy actually worked but took about 48 hours.

I ended up using xarray and python and it turned out to be much faster. The 25 GB were rechunked in less than 5 Minutes (incl. compression). Memory usage was about 50 GB. Here is the approach I have used:

import xarray as xr

ds = xr.open_dataset('field_access_opt.nc') # chunks (time,lat,lon): 1,500,1000

#re-chunk variable 'GHI'
ds.to_netcdf("point_access_opt.nc",
encoding={'lat': {'zlib': False, '_FillValue': None},
    'lon': {'zlib': False, '_FillValue': None},
    'time': {'zlib': False, '_FillValue': None, 'dtype': 'double'},
    'GHI': {'chunksizes': [len(ds['GHI'].time),1,1], 'zlib': True, 
    'complevel': 1}})

在NetCDF文件中更改块块形状

杀お生予夺 2025-02-20 12:49:45

https://docs.gitlab.com/14.10/ee/ci/ci/ci/ci/ci /yaml/#规则

在创建管道时评估规则,并在
订购直到第一场比赛。找到比赛时,这项工作是
根据管道包括或排除在管道之外的
配置。

尝试,

stage: test
image: python:3.10.3-bullseye
rules:
  - if: $CI_COMMIT_BRANCH != "master"
    when: never
  - exists:
    - tests/**/*.py
before_script: *setup-python
script:
  - pip install -e .[dev]
  - pytest tests/

As in https://docs.gitlab.com/14.10/ee/ci/yaml/#rules,

Rules are evaluated when the pipeline is created, and evaluated in
order until the first match. When a match is found, the job is either
included or excluded from the pipeline, depending on the
configuration.

Try,

stage: test
image: python:3.10.3-bullseye
rules:
  - if: $CI_COMMIT_BRANCH != "master"
    when: never
  - exists:
    - tests/**/*.py
before_script: *setup-python
script:
  - pip install -e .[dev]
  - pytest tests/

如何添加&#x27;存在:&#x27;规则?

杀お生予夺 2025-02-20 10:48:15

只需将ElementMatcher使用,它们就可以链接:

ElementMatchers.isMethod().and(ElementMatchers.nameMatches(...))

如果更简单,您也可以实现自己的匹配器。

Simply use an ElementMatcher for it, they can be chained:

ElementMatchers.isMethod().and(ElementMatchers.nameMatches(...))

You can also implement your own matcher if that's simpler.

Bytebuddy ElementMatchers for Prioner表达式

杀お生予夺 2025-02-20 05:20:22

您正在看到的错误消息表明您调用的操作不会期望时间维:

ValueError: ('freq', 'dir') must be a permuted list of ('time', 'freq', 'dir'),
unless `...` is included

这可能表明wavepectra Extension conscentor .spec.plot()除了freqdir之外,还没有期望遇到任何其他维度。因此,您需要以某种方式降低数据的维度,例如提取单个时间片(例如a.isel(time = 0).spec.plot())或计算摘要统计量(例如a.mean(dim ='time')。spec.plot())。请参阅Xarray指南至索引和选择数据 href =“ https://docs.xarray.dev/en/latest/user-guide/computation.html” rel =“ nofollow noreferrer”> Computation 有关可用操作的更多信息。

请注意,wavepectra's spec访问者不是Xarray的一部分,因此您遇到的任何错误都是由于waveSpectra>库,不是Xarray本身的问题,因此您可能会通过与该库的开发人员联系,从而获得其他帮助。

The error message you're seeing indicates that the time dimension is not expected by the operation you're calling:

ValueError: ('freq', 'dir') must be a permuted list of ('time', 'freq', 'dir'),
unless `...` is included

This probably indicates that the wavespectra extension accessor .spec.plot() is not expecting to encounter any additional dimensions besides freq and dir. So you need to somehow reduce the dimensionality of your data, e.g. by extracting a single time slice (e.g. a.isel(time=0).spec.plot()) or computing a summary statistic (e.g. a.mean(dim='time').spec.plot()). See the xarray guides to Indexing and Selecting Data and Computation for more info about available operations.

Note that wavespectra's spec accessor is not a part of xarray, so any errors you encounter are due to the xarray integration built into the wavespectra library, not an issue with xarray itself, so you might have luck getting additional help by contacting the developers of that library.

(xarray)valueerror:(&#x27; freq&#x27;,&#x27; dir dir&#x27;)必须是(时间&#x27; time&#x27;,freq&#x27; freq&#x27; freq&#x27; freq&#x27; #x27; dir&#x27;),除非包括``...

杀お生予夺 2025-02-20 03:51:51

您可以维护一个物品列表的状态,并且可以操纵状态以增加列表的大小,以便网格的大小会自动增加。

以下是上述要求的示例:

import 'package:flutter/material.dart';

class WidgetTest extends StatefulWidget {
  WidgetTest({
    Key? key,
  }) : super(key: key);

  // final String title;

  @override
  State<WidgetTest> createState() => _WidgetTestState();
}

class _WidgetTestState extends State<WidgetTest> {
  int present = 0;
  int perPage = 5;

  int _count = 5;
  List<String> productList = [
    "Product 1",
    "Product 2",
    "Product 3",
    "Product 4",
    "Product 5",
    "Product 6",
    "Product 7",
    "Product 8",
    "Product 9",
    "Product 10",
    "Product 11",
    "Product 12",
    "Product 13",
    "Product 14",
    "Product 15",
    "Product 16",
    "Product 17",
    "Product 18",
    "Product 19",
    "Product 20",
    "Product 21",
  ];

  // final originalItems = categoryData;

  var items = <String>[];

  @override
  void initState() {
    setState(() {
      present = present + perPage;
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GridView.builder(
        itemCount: _count + 1,
        gridDelegate:
            SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
        itemBuilder: (context, index) {
          if (index == _count) {
            return InkWell(
              onTap: () {
                setState(() {
                  if (_count + 5 < productList.length) {
                    _count += 5;
                  } else {
                    _count += productList.length - _count;
                  }
                });
              },
              child: SizedBox(
                height: 100,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(100),
                        color: Colors.black,
                      ),
                      child: Icon(
                        Icons.add,
                        color: Colors.white,
                      ),
                      height: 50,
                      width: 50,
                    ),
                    const SizedBox(
                      height: 18,
                    ),
                    const Text(
                      "Show More",
                      overflow: TextOverflow.clip,
                      style: TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ],
                ),
              ),
            );
          }
          return SizedBox(
            height: 100,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Image.network(
                  "https://firebasestorage.googleapis.com/v0/b/ebuy-1ac5b.appspot.com/o/pngegg%201.png?alt=media&token=fb4dd43b-c537-4471-b81b-e325724f0919",
                  height: 30,
                  width: 90,
                  fit: BoxFit.cover,
                ),
                Text(
                  productList[index],
                  overflow: TextOverflow.clip,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}

You can maintain a state for list of items, and you can manipulate the state for increasing the size of list and so that the size of the grid will increase automatically.

Below is the example for the mentioned requirement:

import 'package:flutter/material.dart';

class WidgetTest extends StatefulWidget {
  WidgetTest({
    Key? key,
  }) : super(key: key);

  // final String title;

  @override
  State<WidgetTest> createState() => _WidgetTestState();
}

class _WidgetTestState extends State<WidgetTest> {
  int present = 0;
  int perPage = 5;

  int _count = 5;
  List<String> productList = [
    "Product 1",
    "Product 2",
    "Product 3",
    "Product 4",
    "Product 5",
    "Product 6",
    "Product 7",
    "Product 8",
    "Product 9",
    "Product 10",
    "Product 11",
    "Product 12",
    "Product 13",
    "Product 14",
    "Product 15",
    "Product 16",
    "Product 17",
    "Product 18",
    "Product 19",
    "Product 20",
    "Product 21",
  ];

  // final originalItems = categoryData;

  var items = <String>[];

  @override
  void initState() {
    setState(() {
      present = present + perPage;
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: GridView.builder(
        itemCount: _count + 1,
        gridDelegate:
            SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
        itemBuilder: (context, index) {
          if (index == _count) {
            return InkWell(
              onTap: () {
                setState(() {
                  if (_count + 5 < productList.length) {
                    _count += 5;
                  } else {
                    _count += productList.length - _count;
                  }
                });
              },
              child: SizedBox(
                height: 100,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(100),
                        color: Colors.black,
                      ),
                      child: Icon(
                        Icons.add,
                        color: Colors.white,
                      ),
                      height: 50,
                      width: 50,
                    ),
                    const SizedBox(
                      height: 18,
                    ),
                    const Text(
                      "Show More",
                      overflow: TextOverflow.clip,
                      style: TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ],
                ),
              ),
            );
          }
          return SizedBox(
            height: 100,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              children: [
                Image.network(
                  "https://firebasestorage.googleapis.com/v0/b/ebuy-1ac5b.appspot.com/o/pngegg%201.png?alt=media&token=fb4dd43b-c537-4471-b81b-e325724f0919",
                  height: 30,
                  width: 90,
                  fit: BoxFit.cover,
                ),
                Text(
                  productList[index],
                  overflow: TextOverflow.clip,
                  style: const TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}

扑面按钮分页GridView Builder

杀お生予夺 2025-02-19 07:12:26

Thank @tkausl and @topsail.

The utf8mb4_general_ci contain _ci that for case insensitive.

From https://stackoverflow.com/questions/4558707/case-sensitive-collation-in-mysql,
I should use utf8mb4_bin for the unique column that I want case sensitive and I can use ORDER BY column COLLATE utf8_general_ci.

SQL:如何使用case敏感的utf8mb4_general_ci的唯一键创建表?

杀お生予夺 2025-02-19 04:28:21

尝试要么:

fig = px.histogram(df,x='gender', y='count' ,color ='gender',barmode = 'group')

如果

fig = px.histogram(df,x='gender', y='count' ,color ='country',barmode = 'group')

您可以澄清要完成的目标,也将有所帮助。您的数据没有多大意义。我不确定您要实现什么。

编辑:您的澄清无济于事,但这可能是您要寻找的:

fig = px.histogram(df, x='country', y='count', color = 'gender')

或基于您的图片

fig = px.histogram(df, x="gender", y="count",color='country', barmode='group')

Try either:

fig = px.histogram(df,x='gender', y='count' ,color ='gender',barmode = 'group')

or

fig = px.histogram(df,x='gender', y='count' ,color ='country',barmode = 'group')

It would also help if you could clarify what you are trying to accomplish. Your data doesn't make much sense. I'm not exactly sure what you are trying to achieve.

EDIT: Your clarification didn't help much, but this may be what you're looking for:

fig = px.histogram(df, x='country', y='count', color = 'gender')

or based on your picture

fig = px.histogram(df, x="gender", y="count",color='country', barmode='group')

如何使用颜色参数绘制条形图

杀お生予夺 2025-02-18 22:48:33

分配数据框的大小和调用数据框之间是有区别的。在加入之前,请检查分配的数据帧大小并调用数据框。请仔细阅读官方文件。我在环境中使用示例代码遵循相同的方案。我添加了一张银桌,对我来说很好,没有错误。关注此

参考:

https://learn.microsoft.com/en-us/azure/databricks/data-engineering/delta-live-tables/delta-live-tables/delta-live-tables-tables-tables-tables-tables-tables-tables-tables-tables-tables-xquickstart#sql

delta live tables演示:现代软件工程ETL处理。

There is a difference between assigning the size of the data frame and calling the dataframe. Kindly check the assigning the dataframe size and calling the dataframe before joining. Kindly go through the official documentation. I followed the same scenario with the sample code in my environment. I added a silver table it's working fine for me without error. Follow this GitHub reference it has detailed information.

Reference:

https://learn.microsoft.com/en-us/azure/databricks/data-engineering/delta-live-tables/delta-live-tables-quickstart#sql

Delta Live Tables Demo: Modern software engineering for ETL processing.

对Databricks Delta Live Tables中Fields Structfield的模棱两可的引用

杀お生予夺 2025-02-18 22:10:10

可以使用@API_VIEW(['get'])来处理这。

您可以用装饰器将功能包裹起来,并将其与URL集成。

# Imports 
from rest_framework.decorators import api_view
from rest_framework.response import Response


def track_mentions_in_past_24_hours(reddit,subname,active_stocks,time_filter="day",limit=None):
    # ...
    return active_stocks

@api_view(['GET'])
def script_runner(request):
    data = track_mentions_in_past_24_hours(reddit,subname,active_stocks,time_filter="day",limit=None)
    return Response(data)

这就是您可以通过前端应用程序来设置端点的方式。

urlpatterns = [
    path('script/', views.script_runner),
]

有关更多详细信息: docs a>

This can be handled using @api_view(['GET']).

You could wrap the function with a decorator and integrate it with URLs.

# Imports 
from rest_framework.decorators import api_view
from rest_framework.response import Response


def track_mentions_in_past_24_hours(reddit,subname,active_stocks,time_filter="day",limit=None):
    # ...
    return active_stocks

@api_view(['GET'])
def script_runner(request):
    data = track_mentions_in_past_24_hours(reddit,subname,active_stocks,time_filter="day",limit=None)
    return Response(data)

And that's how you can set up the endpoint that will be callable from the front-end app.

urlpatterns = [
    path('script/', views.script_runner),
]

For more details: Docs

如何在Django后端添加端点以运行Python脚本?

杀お生予夺 2025-02-18 14:20:49

您需要使用等待如果右侧的值是一个承诺,并且您希望返回的解决值而不是承诺。

由于getCerturl标记为async,因此它将返回承诺。

您需要该值,因此您需要等待


另一方面,由于(Inside GetCerturl)您对api.getData()的承诺的价值无能为力,然后()。catch()。 (使其被诺言包裹起来)您可以从该功能省略等待async。如果您替换了,则您将具有更清晰的代码,然后() catch() 等待尝试{} catch {})。

You need to use await if the value on the right hand side is a promise and you want the resolved value returned instead of the promise.

Since getCertURL is marked as async, it will return a promise.

You need the value, so you need await.


On the other hand, since (inside getCertURL) you do nothing with value of the promise returned by Api.getData().then().catch() except return it (causing it to be wrapped in a promise) you could omit the await and async from that function. You'd have clearer code if you replaced the then() and catch() with await and try {} catch {} though).

如果在称呼它的位置,我是否应该在方法上等待一种方法?

杀お生予夺 2025-02-18 08:51:12
library(tidyverse)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

df <- read_table("PID   Sub D1  D2  D3
123 2015-02-26  2018-04-26  2015-02-26  2014-05-29
345 2014-03-11  2019-05-18  NA  2012-08-11
678 2016-01-22  2017-11-20  2016-01-21  NA
987 2020-06-15  NA  2018-08-19  2019-01-15")

df %>% 
  mutate(across(D1:D3, ~ .x - Sub))

#> # A tibble: 4 × 5
#>     PID Sub        D1        D2        D3       
#>   <dbl> <date>     <drtn>    <drtn>    <drtn>   
#> 1   123 2015-02-26 1155 days    0 days -273 days
#> 2   345 2014-03-11 1894 days   NA days -577 days
#> 3   678 2016-01-22  668 days   -1 days   NA days
#> 4   987 2020-06-15   NA days -666 days -517 days

library(tidyverse)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

df <- read_table("PID   Sub D1  D2  D3
123 2015-02-26  2018-04-26  2015-02-26  2014-05-29
345 2014-03-11  2019-05-18  NA  2012-08-11
678 2016-01-22  2017-11-20  2016-01-21  NA
987 2020-06-15  NA  2018-08-19  2019-01-15")

df %>% 
  mutate(across(D1:D3, ~ .x - Sub))

#> # A tibble: 4 × 5
#>     PID Sub        D1        D2        D3       
#>   <dbl> <date>     <drtn>    <drtn>    <drtn>   
#> 1   123 2015-02-26 1155 days    0 days -273 days
#> 2   345 2014-03-11 1894 days   NA days -577 days
#> 3   678 2016-01-22  668 days   -1 days   NA days
#> 4   987 2020-06-15   NA days -666 days -517 days

Created on 2022-06-29 by the reprex package (v2.0.1)

用r中的其他列减去一列的日期

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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