烂人

文章 评论 浏览 29

烂人 2025-02-20 23:16:57

这是另一种方法

df <- plyr::ldply(by(df,df$id,subset), function(ID_subset){
    temp_subset <- plyr::ldply(by(ID_subset, ID_subset$country, subset), function(country_subset){
        country_subset
        for (i in 1:nrow(country_subset)) {
          if (is.na(country_subset$value[i])) {
            country_subset$value[i] <- country_subset$value[i - 1] + (country_subset$value[i - 1] * country_subset$pct[i - 1])
          }
        }}}

Here is another approach

df <- plyr::ldply(by(df,df$id,subset), function(ID_subset){
    temp_subset <- plyr::ldply(by(ID_subset, ID_subset$country, subset), function(country_subset){
        country_subset
        for (i in 1:nrow(country_subset)) {
          if (is.na(country_subset$value[i])) {
            country_subset$value[i] <- country_subset$value[i - 1] + (country_subset$value[i - 1] * country_subset$pct[i - 1])
          }
        }}}

根据先前的行值计算行

烂人 2025-02-20 21:41:08

据我所知,您忘了初始化“手”。

List<Card> hand;

您正在创建两个新玩家。在玩家的构造函数中,您正在初始化分数和名称。

public Player(String name) {
    this.score = 0;
    this.name = name;
}

目前,手尚未初始化。如果您在非初始化的手列表上调用“ add()”方法,则会抛出Null-POINTER,因为未初始化列表为null。

Player p1 = new Player("Harvey");
Player p2 = new Player("Dee");
    
for(int i = 1; i < 26; i++) {
    p1.hand.add(deck.draw());
    p2.hand.add(deck.draw());
}

您需要初始化带有空数组/列表的数组或列表。要初始化列表,您应该做类似的事情:

List<Card> hand = new ArrayList<Card>();

有关更多信息,请查看此问题:
如何初始化list&lt&gt; Java中的对象?

As far as i can see you forgot to initialize "hand".

List<Card> hand;

You are creating two new players. In the constructor of the player you are initializing the score and the name.

public Player(String name) {
    this.score = 0;
    this.name = name;
}

The hand is still not initialized at this moment. If you call the "add()" method on the not-initialized hand-list it throws the null-pointer because the not initialized list is null.

Player p1 = new Player("Harvey");
Player p2 = new Player("Dee");
    
for(int i = 1; i < 26; i++) {
    p1.hand.add(deck.draw());
    p2.hand.add(deck.draw());
}

You need to initialize arrays or lists with empty arrays/lists. To initialize the list you should do something like:

List<Card> hand = new ArrayList<Card>();

For further information have a look at this question:
How to initialize List<String> object in Java?

创建卡游戏 - 获取nullpointer异常?不知道我做错了什么

烂人 2025-02-20 15:05:19
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $conn->prepare("INSERT INTO prelaunch (Email) VALUES (?)");
$stmt->bind_param("s", $email);

// set parameters and execute
$email = "[email protected]";

$stmt->execute();

如果您不想使用已准备好的语句(即使您应该使用),只有一个缺少的'字符是一个字符串:

插入电子邮件pellaunch(电子邮件) values('” $电子邮件。

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// prepare and bind
$stmt = $conn->prepare("INSERT INTO prelaunch (Email) VALUES (?)");
$stmt->bind_param("s", $email);

// set parameters and execute
$email = "[email protected]";

$stmt->execute();

If you don't want to use prepared statement (even if you should), there is only a missing ' character because $email is a String :

INSERT INTO Emails-prelaunch (Email) VALUES ('" . $email . "')"

我试图使用PHP从HTML输入到MySQL的单个值(电子邮件地址)

烂人 2025-02-20 08:18:06

根据官方文档:
在Express
中提供静态文件
要提供静态文件,例如图像,CSS文件和JavaScript文件,请在Express中使用Express.Stext。

函数签名为:

express.static(root,[options])
根参数指定从中提供静态资产的根目录。有关选项参数的更多信息,请参见表达静态

例如,使用以下代码在名为public的目录中使用图像,CSS文件和JavaScript

app.use(express.static('public'))

http://localhost:3000/images/kitten.jpg
http://localhost:3000/css/style.css
http://localhost:3000/js/app.js
http://localhost:3000/images/bg.png
http://localhost:3000/hello.html

文件 en/启动器/静态files.html“ rel =“ nofollow noreferrer”>服务静态文件express express

According to official docs:
Serving static files in Express
To serve static files such as images, CSS files, and JavaScript files, use the express.static built-in middleware function in Express.

The function signature is:

express.static(root, [options])
The root argument specifies the root directory from which to serve static assets. For more information on the options argument, see express static.

For example, use the following code to serve images, CSS files, and JavaScript files in a directory named public:

app.use(express.static('public'))

Now, you can load the files that are in the public directory:

http://localhost:3000/images/kitten.jpg
http://localhost:3000/css/style.css
http://localhost:3000/js/app.js
http://localhost:3000/images/bg.png
http://localhost:3000/hello.html

Serving static files Express

如何从root Path提供静态文件&#x27;/&#x27;

烂人 2025-02-20 08:07:39

因此,我进行了尝试,但同时,我在这里问了这个问题,我在Microsoft Tech论坛上发布了问题,因为这是他们的产品之一! :)

因此,我正确地意识到我的上述计算只是根据过滤器计算维度的成员。

答案是在“衡量标准组”中添加核心行列量度(创建新度量时的下拉列表中的选择计数)。

我还将B/S字符串分为具有身份列的表格,然后在事实表中用IDS(1和2)代替了B/S,因此它更清洁,我认为更多的性能(基于东西存储的方式,在事实表中)。

然后将您的维度与度量的混合组合为元组,以放置在计算成员的MDX表达式窗口中:

 ([DimBuySell].[BuySell].&[B], [Measures].[Row count])

 ([DimBuySell].[BuySell].&[S], [Measures].[Row count])

我的MS问题中: https://learn.microsoft.com/en-us/aswers/questions/questions/914130/mss-ssas-calculation-member-to-to-wo--to-to-aggregate-count-count-count-count-a.html?

So I carried on trying stuff but also, at the same time I asked the question here, I posted on the Microsoft Tech Forums as after all it is one of their products! :)

So I had correctly realised my above calc was merely counting the members of the dimension based on the filter.

The answer was to add a core RowCount measure in the Measures group (select count of rows in dropdown when creating new measure).

I also separated out my B/S strings into a table with IDENTITY column and then in my fact table replaced the B/S with the IDs (1 and 2) so it's cleaner and i think more performant (based on the way stuff gets stored in the fact table).

Then combine a mix of your dimension with the measure as a tuple to be placed in the MDX expression window of a CalculatedMember:

 ([DimBuySell].[BuySell].&[B], [Measures].[Row count])

and

 ([DimBuySell].[BuySell].&[S], [Measures].[Row count])

from my MS question: https://learn.microsoft.com/en-us/answers/questions/914130/ms-ssas-calculated-member-to-aggregate-count-of-a.html?childToView=916215#answer-916215

MS SSAS-计算的成员以汇总每行基础数据出现的维度计数

烂人 2025-02-20 01:04:09

如果对您来说似乎更容易,请尝试此流程:

    const conditionOne = true
    const conditionTwo = true
    const conditionThree = false

if (conditionOne && conditionTwo && !conditionThree) {
    console.log('SetFirstValue  set somevalue 1')
}else if(conditionOne && conditionTwo && conditionThree){
    console.log('SetSecondValue  set somevalue 2')
}else if(conditionOne && !conditionTwo && !conditionThree){
    console.log('SetThirdValue  set somevalue 3')
}else if(conditionOne && !conditionTwo && !conditionThree){
    console.log('SetThirdValue  set somevalue 3')
}

Try this flow if seems easier to you:

    const conditionOne = true
    const conditionTwo = true
    const conditionThree = false

if (conditionOne && conditionTwo && !conditionThree) {
    console.log('SetFirstValue  set somevalue 1')
}else if(conditionOne && conditionTwo && conditionThree){
    console.log('SetSecondValue  set somevalue 2')
}else if(conditionOne && !conditionTwo && !conditionThree){
    console.log('SetThirdValue  set somevalue 3')
}else if(conditionOne && !conditionTwo && !conditionThree){
    console.log('SetThirdValue  set somevalue 3')
}

如果其他条件进行优化和改进

烂人 2025-02-19 09:52:37

我们可以创建在不同的.py文件及其.KV定义中定义的多个屏幕。为了集成所有文件,我们可以创建一个main.kv文件,其内容如下:

#  import the python files defining the Screens
#: import Screen1 libs.baseclass.screen1.Screen1
#: import Screen2 libs.baseclass.screen2.Screen2

#  include the kv files for the other Screens
#: include libs/kvs/screen1.kv
#: include libs/kvs/screen2.kv

ScreenManager:
    Screen1:
    Screen2:

最终通过应用程序中的构建器加载此文件。

We can create multiple screens defined in different .py files and their .kv definition in separate files. In order to integrate all the files, we can create a main.kv file whose content looks like below:

#  import the python files defining the Screens
#: import Screen1 libs.baseclass.screen1.Screen1
#: import Screen2 libs.baseclass.screen2.Screen2

#  include the kv files for the other Screens
#: include libs/kvs/screen1.kv
#: include libs/kvs/screen2.kv

ScreenManager:
    Screen1:
    Screen2:

FInally load this file through Builder in an App.

多个.kv文件的集成

烂人 2025-02-19 09:52:10

我认为,如果您现在正在升级内容,最好使用Mongotemplate。您可以从import org.springframework.data.data.mongodb.core.query.query.query;使用QUERY来构建查询和criteria导入org.springframework.data.mongodb.core.query.criteria;

这是您可以结帐的片段,您的代码可以是类似的(我猜不是完全):

        Query query = new Query();
        Criteria criteria = Criteria.where("configType").is("configType")
                .and("parentConfig").is(flowerId)
                .and("configKey").is(subTypeId)
                .orOperator(Criteria.where("isDeleted").is(false)
                        .and("isDeleted").exists(false));
        query.addCriteria(criteria);

        BasicDBObject result = mongoTemplate.findOne(query,BasicDBObject.class,"flowers");

I think it's better to use MongoTemplate if you are upgrading things now. You can use Query from import org.springframework.data.mongodb.core.query.Query; to build query and Criteria from import org.springframework.data.mongodb.core.query.Criteria;.

here is a snippet you can checkout and your code can be something like that (not exactly i guess) :

        Query query = new Query();
        Criteria criteria = Criteria.where("configType").is("configType")
                .and("parentConfig").is(flowerId)
                .and("configKey").is(subTypeId)
                .orOperator(Criteria.where("isDeleted").is(false)
                        .and("isDeleted").exists(false));
        query.addCriteria(criteria);

        BasicDBObject result = mongoTemplate.findOne(query,BasicDBObject.class,"flowers");

需要帮助将此代码转换为新的Mongo Java驱动程序

烂人 2025-02-19 03:18:22

并非您拥有的所有新元素都与您的分区之一相匹配。通过创建一个或多个分区来解决这个问题,例如

alter table "HR"."USER_PARTITION" add partition <some name> values less than <the highest REGION in your csv + 1>;

Not all the new elements you have are matching one of your partitions. To solve this issue by the creation of one or more further partitions, like

alter table "HR"."USER_PARTITION" add partition <some name> values less than <the highest REGION in your csv + 1>;

Oracle:ORA-14400错误,将数据导入Excel中时

烂人 2025-02-19 00:41:24

fun函数的第一个调用将创建标题,添加第一个数据,并将终端线填充'^'*31。为了确保它确实是第一个呼叫,并且在每个后续调用中不会重新创建标题,如果 block都有

当第一个调用打开time.txt在阅读模式'r'中,所有其他调用都以'r+'模式打开该文件均用于阅读和写作。当读取文件并将其所有内容保存到保存(所有内容,但对于终点行)时,将解析器的光标移动到打开的文件的开始,以便可以重写它带有新数据,带有后线。

def fun():
    import time
    import os.path
    seperator='|'+'-'*31+'|\n'
    end = '|'+'^'*31+'|'
    if not os.path.isfile('time.txt'): #checking if the file exist
        with open('time.txt','w') as f:
            header= '_'*32+'\n'+\
                    '|Day |Month |Year |Hour |Minute |\n'
            t=time.localtime()
            data = (f'|{t[2]:<4}|{t[1]:<6}|{t[0]:<5}'
                    f'|{t[3]:<5}|{t[4]:<7}|\n')
            f.write(header+seperator+data+end)
    else:
        with open('time.txt','r+') as f:
            saved=f.readlines()[:-1] #saving all, but the end line
            f.seek(0) #set the cursor to the start of the file
            t=time.localtime()
            data = (f'|{t[2]:<4}|{t[1]:<6}|{t[0]:<5}'
                    f'|{t[3]:<5}|{t[4]:<7}|\n')
            f.writelines(saved+[seperator,data,end])            

这可能不是满足您需求的理想选择...而且我不敢说代码是无瑕的。

注意:如果“ time.txt”已经存在,但是没有标题,则不会创建标头。

The first call to the fun function will create the header, add the first data and put the end line filled with '^'*31. To ensure, that it is indeed the first call and do not create the header anew at each subsequent call there is the if block.

While the first call opens time.txt in the reading mode 'r', all other calls open it in the 'r+' mode which opens the file both for reading and writing. When the file is read and everything from it is saved to saved (everything, but for the end line), the cursor of the parser is moved the start of the opened file, so that it can be rewritten with the new data with the trailing end line.

def fun():
    import time
    import os.path
    seperator='|'+'-'*31+'|\n'
    end = '|'+'^'*31+'|'
    if not os.path.isfile('time.txt'): #checking if the file exist
        with open('time.txt','w') as f:
            header= '_'*32+'\n'+\
                    '|Day |Month |Year |Hour |Minute |\n'
            t=time.localtime()
            data = (f'|{t[2]:<4}|{t[1]:<6}|{t[0]:<5}'
                    f'|{t[3]:<5}|{t[4]:<7}|\n')
            f.write(header+seperator+data+end)
    else:
        with open('time.txt','r+') as f:
            saved=f.readlines()[:-1] #saving all, but the end line
            f.seek(0) #set the cursor to the start of the file
            t=time.localtime()
            data = (f'|{t[2]:<4}|{t[1]:<6}|{t[0]:<5}'
                    f'|{t[3]:<5}|{t[4]:<7}|\n')
            f.writelines(saved+[seperator,data,end])            

It may not be the ideal option that will meet your needs... And i dare not say that the code is faultlessly.

Note: If the 'time.txt' already exists, but empty or/and without the header then the header won't be created.

如何制作自定义打印格式?

烂人 2025-02-19 00:22:23
FOR /F %%I in ('kubectl get pods^|findstr /i /b /L /C:"%~1"') DO (

应该做你想做的。

Caret逃脱了管道,告诉cmd该管道是要执行的命令的一部分。

findstr找到/b以字符串%〜1开始的字符串,这是批处理的第一个参数。

不再需要跳过,因为标题线不会从任何目标字符串开始。

/i是可选的,使匹配项不敏感。

呢请勿在代码块中使用::注释(括号的序列序列)实际上是一个损坏的标签,它混淆了cmd。在代码块中使用REM

修订 - 由于任何字符串均可用于%1,使用/l指定l iTeral比较以覆盖默认值/r(REGEX匹配)

/c:“ String”匹配还补偿了字符串>%〜1中空间的可能性。如果一个空间出现在%〜1中(通过提供引用的参数“一个两个”),则没有/c:Findstr将搜索一个两个。使用/c:,搜索是一个 space 两个

FOR /F %%I in ('kubectl get pods^|findstr /i /b /L /C:"%~1"') DO (

should do what you want.

The caret escapes the pipe, telling cmd that the pipe is part of the command to be executed.

findstr finds any string that /b begins with the string %~1, which is the first parameter to the batch.

The skip is no longer needed as the header line would not start with any of the target strings.

The /i is optional, making the match case-insensitive.

! Do not use :: comments in a code block (parenthesised sequence of lines) as it's actually a broken label, which confuses cmd. Use rem in code blocks.

Amended - Since any string may be used for %1, using /L to specify Literal comparison to override the default /r (regex match)

The /c:"string" match also compensates for the possibility of a space in the string %~1. If a space appears in %~1 (by supplying a quoted parameter "one two") then without the /c:, findstr would search for one OR two. With /c:, the search is for oneSpacetwo.

过滤元素

烂人 2025-02-18 22:27:14

我知道这是一个不清楚的问题,但是我现在正在研究一个类似的项目,这就是为什么我要回答的原因。您说“想有一种方法,当一个人是单击时,它会显示一个表单” ,我想您应该创建类(让它称为myClass),该类有一些属性您将使用并显示在ListBox中,例如按钮,您可以通过dataTemplate进行操作,并将列表框绑定到observableCollection&lt&lt; t&gt;您的myClass对象的 listbox将自动更新或从那里添加或删除某些内容,不要忘记使用viewmodel和命令 >按钮 s。对于您的问题的一部分,我认为您可以创建从窗口类继承的类myform,这将具有项目所需的属性。例如,您想将文本保存在您的表单中,这些文本第二次单击按钮时将显示。

public MyForm : Window
{
    private string FormsText { get; set;}
}

然后,您可以创建MyForm类对象的列表,并使用XML序列化将它们保存在文件中,从而保存对象的每个属性,并且可以基于此编写逻辑。

I know this is an unclear question, but I am working on a similar project right now, that's why I gonna try to answer. You say "want to have a way that when one is clicked it displays a form", I guess you should create class(let call it MyClass) that has some properties which you will use and is displayed in ListBox like Button, you can do it by DataTemplate and bind your ListBox to ObservableCollection<T> of your MyClass objects so your ListBox would automatically update when you add or remove something from there, don't forget to use ViewModel and Commands for you Buttons. For form part of your question, I think you can create class MyForm that is inherited from window class, that would have properties required for your project. For example you want to save text in your form that will be displayed when you click button second time.

public MyForm : Window
{
    private string FormsText { get; set;}
}

Then you can create List of MyForm class objects and save them in file with xml serialization that will save every property of your object and you can write logic based on this.

如何在WPF应用程序中动态创建表单?

烂人 2025-02-18 20:51:47

尝试使用正则


display(df.loc[df['A'].str.contains(r'\|', regex=True)])
display(df.loc[df['A'].str.contains(r'a', regex=True)]) 

            A       B
1   bbb | aaa   a | b

            A       B
0   aaa       abababa
1   bbb | aaa   a | b

Try to use the regex


display(df.loc[df['A'].str.contains(r'\|', regex=True)])
display(df.loc[df['A'].str.contains(r'a', regex=True)]) 

            A       B
1   bbb | aaa   a | b

            A       B
0   aaa       abababa
1   bbb | aaa   a | b

df.col.str.contains(somester&#x27;)d没有工作

烂人 2025-02-18 16:38:00

Thanks to Nick Vu's answer I realised I could also do this:

parseFloat(entry as string)

const possibleNum: string | number = '3'

const changeType = (entry: string | number) => {
  const parseEntry = parseFloat(entry as string)
  return !isNaN(parseEntry) ? parseEntry : entry
}

const res = changeType(possibleNum)

console.log(typeof res)

Thanks to Nick Vu's answer I realised I could also do this:

parseFloat(entry as string)

const possibleNum: string | number = '3'

const changeType = (entry: string | number) => {
  const parseEntry = parseFloat(entry as string)
  return !isNaN(parseEntry) ? parseEntry : entry
}

const res = changeType(possibleNum)

console.log(typeof res)

Playground

力量类型变更打字稿

烂人 2025-02-17 16:50:04

没有办法周围。无论如何,您必须在某个时间点升级到最新版本,这是由于创作文物的未来版本。因此,如果您试图在旧项目中使用撰写,可以更好地升级所有内容。这适用于Android Studiokotlinandroidx以及大多数第一个派对库,例如NAV-Component,Lifecycle,Lifecycle,Canceranist等

。基本上,不是面包和黄油的东西,您必须再次重写整个UI层。 在这里 在描述同一件事。它还具有迁移指南

一种意见 - &GT;由于您提到了一个非常旧的项目,并且如果您不使用任何诸如mvvm的体系结构(它可以很好地与DI和可观察的支持合作)。考虑到撰写仍在增长,从头开始创建一个新的项目,这将是一个更好的主意,并且许多事情仍在实验中,您必须将代码保持在撰写版本上。

There is No way around it . you have to upgrade to latest version anyway at some point of time because of Compose artifact future releases . So if you are trying to use Compose in Old project better upgrade everything. This goes for Android Studio, kotlin, androidX and most of the first party libraries like nav-component, lifecycle, Accompanist etc.

Migrating to compose is not bread and butter stuff basically you have to re-write Whole UI layer again . Here is Doc describing the same thing. It also has a Migration guide .

One Opinion -> Since you mentioned its a very old project and if you are not using any architecture like MVVM(it goes well with Compose with DI and observable support out of the box) . It will be a better idea to create a new project from scratch considering compose is still growing and lots of things are still experimental and u have to keep your code it up to date with compose versions..

什么是JetPack撰写的最小Kotlin和Gradle版本要求

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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