禾厶谷欠

文章 评论 浏览 32

禾厶谷欠 2025-02-21 00:18:42

我认为您对“ sumofactivities”发布的预期结果没有:3 用户数组中有效。

假设您正在尝试达到以下结果:

[{
  "_id": "80b1565a-faf4-4e68-9bd6-8344060e8d3a",
  "users": [...],
  "sumOfActivities": 3
}]

查询有点长:

  1. $ set - set activeuserslookup field aid object。

    1.1。 $ first - 从 1.2

    获取第一个文档

    1.2。 $ filter - activeuserslookup 通过匹配 _id activeuserslookup 中的文档 _id (根文档)。

  2. $ set

    2.1。 - 设置用户数组。

    2.1.1。 $ map - 迭代用户> randar中的文档并返回新数组。

    2.1.2。 $ MergeObjects - 将当前文档与活动合并字段。

    2.1.3。 $ ifnull - set 活动 as 0如果没有结果从 2.1.4

    返回

    2.1.4。 $ getfield - 从结果 2.1.5

    2.1.5。 $ first - 从结果 2.1.6

    中获取第一个文档

    2.1.6。 $ filter - 过滤 activeuserslookup.users 文档通过匹配 _id for 用户 array) > _id 当前文档。

    2.2。 SET sumofactivities 字段。

  3. $ unset - 删除 activeuserslookup field。

db.collection.aggregate([
  {
    $set: {
      activeUsersLookup: {
        $first: {
          $filter: {
            input: "$activeUsersLookup",
            cond: {
              $eq: [
                "$this._id",
                "$_id"
              ]
            }
          }
        }
      }
    }
  },
  {
    $set: {
      users: {
        $map: {
          input: "$users",
          as: "user",
          in: {
            $mergeObjects: [
              "$user",
              {
                activities: {
                  "$ifNull": [
                    {
                      "$getField": {
                        "field": "activities",
                        "input": {
                          $first: {
                            $filter: {
                              input: "$activeUsersLookup.users",
                              cond: {
                                $eq: [
                                  "$this._id",
                                  "$user._id"
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    0
                  ]
                }
              }
            ]
          }
        }
      },
      sumOfActivities: "$activeUsersLookup.sumOfActivities"
    }
  },
  {
    $unset: "activeUsersLookup"
  }
])

示例mongo playground

I don't think the expected result you posted for the "sumOfActivities": 3 in the users array is valid.

Assume that you are trying to achieve the result as below:

[{
  "_id": "80b1565a-faf4-4e68-9bd6-8344060e8d3a",
  "users": [...],
  "sumOfActivities": 3
}]

The query is a bit long:

  1. $set - Set activeUsersLookup field as object.

    1.1. $first - Get the first document from 1.2.

    1.2. $filter - Filter document(s) from activeUsersLookup by matching _id for the document in activeUsersLookup with _id (root document).

  2. $set

    2.1. - Set users array.

    2.1.1. $map - Iterate the documents in users array and return a new array.

    2.1.2. $mergeObjects - Merge current documents with the documents with activities field.

    2.1.3. $ifNull - Set activities as 0 if no result returned from 2.1.4.

    2.1.4. $getField - Get the activities field from the result 2.1.5.

    2.1.5. $first - Get the first document from the result 2.1.6.

    2.1.6. $filter - Filter the activeUsersLookup.users documents by matching _id for the document (users array) with _id for the current document.

    2.2. Set sumOfActivities field.

  3. $unset - Remove activeUsersLookup field.

db.collection.aggregate([
  {
    $set: {
      activeUsersLookup: {
        $first: {
          $filter: {
            input: "$activeUsersLookup",
            cond: {
              $eq: [
                "$this._id",
                "$_id"
              ]
            }
          }
        }
      }
    }
  },
  {
    $set: {
      users: {
        $map: {
          input: "$users",
          as: "user",
          in: {
            $mergeObjects: [
              "$user",
              {
                activities: {
                  "$ifNull": [
                    {
                      "$getField": {
                        "field": "activities",
                        "input": {
                          $first: {
                            $filter: {
                              input: "$activeUsersLookup.users",
                              cond: {
                                $eq: [
                                  "$this._id",
                                  "$user._id"
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    0
                  ]
                }
              }
            ]
          }
        }
      },
      sumOfActivities: "$activeUsersLookup.sumOfActivities"
    }
  },
  {
    $unset: "activeUsersLookup"
  }
])

Sample Mongo Playground

mongodb-将一些字段从数组移动到另一个数组

禾厶谷欠 2025-02-20 23:38:14

每当您更改单元高 时,它都需要说明表视图。

您尚未显示 的“加载更多项目要收集查看” ...但是在这样做之后,请致电:

tableView.performBatchUpdates(nil, completion: nil)

这将导致表视图重新计算和更新行高度,而无需调用 .reloaddata()

Any time you change a cell height after it has been displayed, you need to tell the table view about it.

You haven't shown how or when you "load more items to collection view" ... but after you do that, call:

tableView.performBatchUpdates(nil, completion: nil)

That will cause the table view to recalculate and update the row heights, without calling .reloadData().

如何在表视图单元格中创建动态收集视图,而无需重新加载表视图swift?

禾厶谷欠 2025-02-20 23:38:04

我不会标记每个数据点。只需使用传说,并突出显示您的物种,例如。红色和所有其他物种绿色。

您没有提供示例数据,因此我为您提供了其他示例数据的解决方案。请参阅下面的代码。使用FactoExtra(和FactoMiner)为所有数值列制作PCA。然后在绘制PCA的两个维度时,添加一个因子变量作为物种的荧光笔。只需使用简单的iFelse列制作一个新的因子VAR即可将您的物种与其他物种分开。使用此因子列在FVIZ_PCA_IND图中突出显示。请参阅下面的代码:

library(FactoMineR)
library(ggplot2)
library(factoextra)

data("iris")
iris2 <- iris[1:4]
head(iris2)

# PCA analysis to get PCs
iris.pca <- PCA(iris2, scale.unit = TRUE, graph = FALSE)

# use Species from iris to change habillage
fviz_pca_ind(iris.pca, label="none", habillage = iris$Species)


library("FactoMineR")
res.pca <- PCA(df,  graph = FALSE)

iris$new_species <- as.factor(ifelse(iris$Species == "virginica", 
"my_species", "other_species"))

# Only highlight one species - rest black
fviz_pca_ind(iris.pca, label="none", habillage = 
iris$new_species)

”在此处输入图像说明”

I would not label every data point. Just use a legend and highlight your species with, eg. red color, and all other species green.

You did not provide example data, so I give you a solution with other sample data. See the code below. Using factoextra (and factominer) make your pca for all numerical columns. Then add a factor variable as a highlighter of your species when plotting the 2 dimensions of the PCA. Just make a new factor var with a simple ifelse column to separate your species from the rest. Use this factor column for highlighting in the fviz_pca_ind plot. See code below for an example:

library(FactoMineR)
library(ggplot2)
library(factoextra)

data("iris")
iris2 <- iris[1:4]
head(iris2)

# PCA analysis to get PCs
iris.pca <- PCA(iris2, scale.unit = TRUE, graph = FALSE)

# use Species from iris to change habillage
fviz_pca_ind(iris.pca, label="none", habillage = iris$Species)


library("FactoMineR")
res.pca <- PCA(df,  graph = FALSE)

iris$new_species <- as.factor(ifelse(iris$Species == "virginica", 
"my_species", "other_species"))

# Only highlight one species - rest black
fviz_pca_ind(iris.pca, label="none", habillage = 
iris$new_species)

enter image description here

如何在R中突出显示特定变量或个人的特定变量或个人

禾厶谷欠 2025-02-20 22:12:06

如果要添加/减法日期/数据时间,则需要使用相关函数进行以下操作:

select *, convert(varchar(5), dateadd(minute, datediff(minute, [TimeOut], TimeIn), convert(time, '00:00'))) TimeDifference
    -- , CONVERT(TIME, [TimeOut], TimeIn) -- gives an error anyway?
from (
    values
    (convert(time, '05:45 PM'), convert(time, '03:30 PM'))
) x (TimeIn, [TimeOut]);

返回:

TimeIn Timeout TimeDifference
17:45:00.0000000 15:30:00.0000000 02:15

If you want to add/subtract dates/datetimes you need to use the relevant functions to do so as follows:

select *, convert(varchar(5), dateadd(minute, datediff(minute, [TimeOut], TimeIn), convert(time, '00:00'))) TimeDifference
    -- , CONVERT(TIME, [TimeOut], TimeIn) -- gives an error anyway?
from (
    values
    (convert(time, '05:45 PM'), convert(time, '03:30 PM'))
) x (TimeIn, [TimeOut]);

Returns:

TimeIn TimeOut TimeDifference
17:45:00.0000000 15:30:00.0000000 02:15

将时间计算转换为HH中的时间:mm

禾厶谷欠 2025-02-20 18:45:12

您可以将 glob 用于获取所有文件 coord。*在路径中,并用 os.rename 重命名它们。

import os
import glob

path = 'Files/'

for file in glob.glob(path+'coord.*'):
    f,s = file.split('.',1)
    file_new = f+'N.'+s
    os.rename(file, file_new)

第一个文件名:

coord.1.txt
coord.1.png

重命名后:

coordN.1.txt
coordN.1.png

You can use glob for get all files with pattern coord.* in your path and rename them with os.rename.

import os
import glob

path = 'Files/'

for file in glob.glob(path+'coord.*'):
    f,s = file.split('.',1)
    file_new = f+'N.'+s
    os.rename(file, file_new)

First filenames:

coord.1.txt
coord.1.png

After renaming:

coordN.1.txt
coordN.1.png

重命名具有特定格式(如文本)的文件。

禾厶谷欠 2025-02-20 18:02:50

正如您在问题中提到的那样,您的ISPRIME方法似乎存在一个问题,因为它以25为质量数字。我设法通过仅执行与您所做的类似的循环来修复它,但是希望您缺少您的空白:

public static boolean isPrime(int N) {
    if (N == 1)
        return false;
    if (N == 2 || N == 3)
        return true;
    for (int i = 2; i <= Math.sqrt(N); i++)
        if (N % i == 0)
            return false;
    return true;
}

此外,您的恰好3Divisors方法不需要一些神奇的数字来泄漏数字。如果您必须这样做,那可能意味着您的逻辑在某个地方有问题。由于我们已经诊断出ISPRIME存在问题,因此事实证明,几乎消除了对任何其他变量的需求:

public static int exactly3Divisors(int N) {
    int count = 0;
    for (int i = 2; i * i <= N; i++) {
        if (isPrime(i)) {
            count++;
        }
    }
    return count;
}

这应该给您正确的答案。正好运行3个分动机(625)应该给您9!

As you mentioned in your question, there appears to be an issue with your isPrime method, since it's taking 25 as a prime number. I managed to fix it up a bit, by just doing a loop similar to what you did, but hopefully missing the gaps yours may have left:

public static boolean isPrime(int N) {
    if (N == 1)
        return false;
    if (N == 2 || N == 3)
        return true;
    for (int i = 2; i <= Math.sqrt(N); i++)
        if (N % i == 0)
            return false;
    return true;
}

Additionally, your exactly3Divisors method does not need some magic number for leaking numbers. If you ever have to do that, it probably means your logic is faulty somewhere. Since we already diagnosed that there was an issue with isPrime, it turns out that pretty much removed the need for any other variables than count:

public static int exactly3Divisors(int N) {
    int count = 0;
    for (int i = 2; i * i <= N; i++) {
        if (isPrime(i)) {
            count++;
        }
    }
    return count;
}

This should give you the correct answer. Running exactly3Divisors(625) should give you 9!

我试图解决这个问题到分数问题的数量,但是在某些输入之后它不能很好地工作

禾厶谷欠 2025-02-20 16:38:57

我似乎还记得Sunos随附Perl,因此,如果您没有支持 date - date =“ ...” ,您应该能够做:

date=$(perl -MPOSIX -e '
    print POSIX::strftime "%d%m%Y", localtime time-(60*60*24*7)
')

I seem to recall SunOS comes with Perl, so if you don't have a date that supports --date="...", you should be able to do:

date=$(perl -MPOSIX -e '
    print POSIX::strftime "%d%m%Y", localtime time-(60*60*24*7)
')

如何在上周获得bash sunos的日期

禾厶谷欠 2025-02-20 15:16:20

您可以尝试使用JS和CSS

CSS:

.ripple {
    background-color: red;
}

.ripple:active, .ripple.active {
    background-color: green;
}

JS:

let btn = document.querySelector('.ripple');

btn.addEventListener('click', e => {
    btn.classList.add('active');
    setTimeout(() => {
        btn.classList.remove('active');
    }, 500);
});


setInterval(() => {
    console.log('click');
    btn.click();
}, 2000);

You can try to recreate "active" event using js and css

CSS :

.ripple {
    background-color: red;
}

.ripple:active, .ripple.active {
    background-color: green;
}

JS :

let btn = document.querySelector('.ripple');

btn.addEventListener('click', e => {
    btn.classList.add('active');
    setTimeout(() => {
        btn.classList.remove('active');
    }, 500);
});


setInterval(() => {
    console.log('click');
    btn.click();
}, 2000);

是否可以从“ ripple”更改按钮CSS类状态。到“波纹:活动”通过使用JS而无需手动单击按钮?

禾厶谷欠 2025-02-20 12:37:57

也许你也可以这样尝试

import itertools

#MERGE LIST1
l1 = [[1,2,3],[5,6],[7,8,9,10]]
merged = list(itertools.chain(*l1))

#MERGE LIST2
l2 = [[1,8,10],[3,9],[5,6]]
merged2 = list(itertools.chain(*l2))

#FIND THE ELEMENTS NOT IN SECOND LIST
newlist =  [item for item in merged if item not in merged2]

#APPEND THE NEWLIST TO LIST2
l2.append(newlist)

print(l2)

May be you can try like this also

import itertools

#MERGE LIST1
l1 = [[1,2,3],[5,6],[7,8,9,10]]
merged = list(itertools.chain(*l1))

#MERGE LIST2
l2 = [[1,8,10],[3,9],[5,6]]
merged2 = list(itertools.chain(*l2))

#FIND THE ELEMENTS NOT IN SECOND LIST
newlist =  [item for item in merged if item not in merged2]

#APPEND THE NEWLIST TO LIST2
l2.append(newlist)

print(l2)

从第一个列表中查找第二列表中缺少元素,然后将它们添加到第二个列表中

禾厶谷欠 2025-02-20 01:00:18

我遇到了完全相同的问题,但是在Android中。我搜索了几个小时,并尝试了许多不同的事情。
问题在于我有一件代码很好的代码调用Unity方法onapplicationpause()。该方法是负责关闭窗口的一种方法。仔细检查是否不是您的案例或类似的情况!

I had the exact same problem but in Android. I searched for hours and tried many different things.
The problem was that I had a piece of code well hidden invoking Unity method OnApplicationPause(). That method was the one responsible for closing the window. Double check if that's not ur case or something like it!

损失焦点统一iOS后重新启动游戏

禾厶谷欠 2025-02-19 16:21:50

使用 - show-errors 客户端支持 https://docs.vespa.ai/en/vespa-feed-client.html

./vespa-feed-client-cli/vespa-feed-client --help
usage: vespa-feed-client <options>
Vespa feed client
    --benchmark                           Print statistics to stdout when
                                          done
    --ca-certificates <arg>               Path to file containing CA X.509
                                          certificates encoded as PEM
    --certificate <arg>                   Path to PEM encoded X.509
                                          certificate file
    --connections <arg>                   Number of concurrent HTTP/2
                                          connections
    --disable-ssl-hostname-verification   Disable SSL hostname
                                          verification
    --dryrun                              Enable dryrun mode where each
                                          operation succeeds after 1ms
    --endpoint <arg>                      URI to feed endpoint
    --file <arg>                          Path to feed file in JSON format
    --header <arg>                        HTTP header on the form 'Name:
                                          value'
    --help
    --max-failure-seconds <arg>           Exit if specified number of
                                          seconds ever pass without any
                                          successful operations. Disabled
                                          by default
    --max-streams-per-connection <arg>    Maximum number of concurrent
                                          streams per HTTP/2 connection
    --private-key <arg>                   Path to PEM/PKCS#8 encoded
                                          private key file
    --proxy <arg>                         URI to proxy endpoint
    --route <arg>                         Target Vespa route for feed
                                          operations
    --show-all                            Print the result of every feed
                                          operation
    --show-errors                         Print every feed operation
                                          failure
    --silent                              Disable periodic status printing
                                          to stderr
    --stdin                               Read JSON input from standard
                                          input
    --timeout <arg>                       Feed operation timeout (in
                                          seconds)
    --trace <arg>                         The trace level of network
                                          traffic. Disabled by default
                                          (=0)
    --verbose                             Print stack traces on errors
    --version

Use the --show-errors flag which the client supports https://docs.vespa.ai/en/vespa-feed-client.html

./vespa-feed-client-cli/vespa-feed-client --help
usage: vespa-feed-client <options>
Vespa feed client
    --benchmark                           Print statistics to stdout when
                                          done
    --ca-certificates <arg>               Path to file containing CA X.509
                                          certificates encoded as PEM
    --certificate <arg>                   Path to PEM encoded X.509
                                          certificate file
    --connections <arg>                   Number of concurrent HTTP/2
                                          connections
    --disable-ssl-hostname-verification   Disable SSL hostname
                                          verification
    --dryrun                              Enable dryrun mode where each
                                          operation succeeds after 1ms
    --endpoint <arg>                      URI to feed endpoint
    --file <arg>                          Path to feed file in JSON format
    --header <arg>                        HTTP header on the form 'Name:
                                          value'
    --help
    --max-failure-seconds <arg>           Exit if specified number of
                                          seconds ever pass without any
                                          successful operations. Disabled
                                          by default
    --max-streams-per-connection <arg>    Maximum number of concurrent
                                          streams per HTTP/2 connection
    --private-key <arg>                   Path to PEM/PKCS#8 encoded
                                          private key file
    --proxy <arg>                         URI to proxy endpoint
    --route <arg>                         Target Vespa route for feed
                                          operations
    --show-all                            Print the result of every feed
                                          operation
    --show-errors                         Print every feed operation
                                          failure
    --silent                              Disable periodic status printing
                                          to stderr
    --stdin                               Read JSON input from standard
                                          input
    --timeout <arg>                       Feed operation timeout (in
                                          seconds)
    --trace <arg>                         The trace level of network
                                          traffic. Disabled by default
                                          (=0)
    --verbose                             Print stack traces on errors
    --version

在哪里可以看到Vespa提要错误细节日志?

禾厶谷欠 2025-02-19 02:07:49

不,您不能因为“ googleservice-info.plist ”,每个帐户都是唯一的。

No you can't because of "GoogleService-Info.plist" it is unique for each Account.

是否可以将我现有的Firebase项目(iOS和Android)集成到不丢失当前数据的情况下分离Google Analytic帐户

禾厶谷欠 2025-02-19 00:41:10

您可以尝试取消中文模式0x1c + 0x2e
一些便宜的Aliexpress BT打印机在中文模式,字符&GT中默认为默认值; 127

You can try Cancel chinese mode 0x1C + 0x2E
Some cheap aliexpress BT printers are default in Chinese mode, characters > 127

通过ESC/pos将炭集放在热式打印机上

禾厶谷欠 2025-02-18 17:37:29

如果薪金是该元素的名称,则您可以更一般地选择XPath中的任何元素,然后使用*,然后应用谓词过滤器来测试是否 local -name()与所选元素值的变量匹配 $ sortElement

let $sortelement := 'Salary'
for $doc in collection('employee')
order by $doc/*[local-name() eq $sortelement]
return $doc

对集合中的所有项目进行排序的方式可能与较少的文档一起使用,但是如果您正在使用数百个文档在数千或数百万的文档中,您可能会发现,退回所有文档都是慢或吹出扩展的树缓存

一个更有效的解决方案是在您打算排序的元素上创建范围索引,然后可以执行搜索,并使用指定的选项进行搜索,以订购结果

例如:

let $sortelement := 'Salary'
return 
  cts:search(doc(), 
    cts:collection-query("employee"), 
    cts:index-order(cts:element-reference(xs:QName($sortelement)))
  )

If Salary is the name of the element, then you could more generically select any element in the XPath with * and then apply a predicate filter to test whether the local-name() matches the variable for the selected element value $sortelement:

let $sortelement := 'Salary'
for $doc in collection('employee')
order by $doc/*[local-name() eq $sortelement]
return $doc

This manner of sorting all items in the collection may work with smaller number of documents, but if you are working with hundreds of thousands or millions of documents, you may find that pulling back all docs is either slow or blows out the Expanded Tree Cache.

A more efficient solution would be to create range indexes on the elements that you intend to sort on, and could then perform a search with options specified to order the results by cts:index-order with an appropriate reference to the indexed item, such as cts:element-reference(), cts:json-property-reference(), cts:field-reference().

For example:

let $sortelement := 'Salary'
return 
  cts:search(doc(), 
    cts:collection-query("employee"), 
    cts:index-order(cts:element-reference(xs:QName($sortelement)))
  )

在Xquery Marklogic中如何动态分类?

禾厶谷欠 2025-02-18 09:03:07

实际上,您不能这样做。因为 pipe 主题转换为可观察,并且此记录与此相似: new objoce()。asobservable()

但是,您可以创建自己的主题,例如从源( https://github.com/reactivex/rxjs/blob/master/src/src/internal/behaviorsubject.ts )。并使任何功能都在内部调用。

Actually you cannot do this. Because pipe converts Subject to Observable and this record is similar to this: new Subject().asObservable().

But, you can create your own Subject, for example from source (https://github.com/ReactiveX/rxjs/blob/master/src/internal/BehaviorSubject.ts). And make any function to invoke inside.

如何用预定义的管算机导出RXJS主题?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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