假装爱人

文章 评论 浏览 30

假装爱人 2025-02-20 23:29:43

我假设您将将响应转换为模型对象。因此,一旦拥有模型对象,您的模型看起来像这样的东西,

struct ImageParts: Codable {
    let image: [String]
    let outputScore: [Int]
    let totalScore: Double

    enum CodingKeys: String, CodingKey {
        case image = "Image"
        case outputScore = "OutputScore"
        case totalScore = "TotalScore"
    }
}

可以使用以下函数来获取所有平均值

func getAvgerageMapped(from model: ImageParts, for parts: [String]) -> [[String: Double]]{
    return parts.map { key -> [String: Double] in
        var op = [Int]()
        model.image.enumerated().reduce(op) { partialResult, sequence in
            if sequence.element.contains(key) {
                op.append(model.outputScore[sequence.offset])
            }
            return op
        }
        var avg = 0.0
        op.reduce(into: avg) { _, i in
            avg += Double(i)
        }
        avg = avg/Double(op.count)
        return [key:avg]
    }
}

let averages = getAvgerageMapped(from: model, for: ["Chin", "Forehead", "L Cheek", "Nose"])
print(averages) //[["Chin": 7.0], ["Forehead": 3.0], ["L Cheek": 1.0], ["Nose": 6.0]]

I'm assuming that you will be converting your response to Model object. So, your model looks something like this

struct ImageParts: Codable {
    let image: [String]
    let outputScore: [Int]
    let totalScore: Double

    enum CodingKeys: String, CodingKey {
        case image = "Image"
        case outputScore = "OutputScore"
        case totalScore = "TotalScore"
    }
}

Once you have your model object you can use below function to get the all averages mapped

func getAvgerageMapped(from model: ImageParts, for parts: [String]) -> [[String: Double]]{
    return parts.map { key -> [String: Double] in
        var op = [Int]()
        model.image.enumerated().reduce(op) { partialResult, sequence in
            if sequence.element.contains(key) {
                op.append(model.outputScore[sequence.offset])
            }
            return op
        }
        var avg = 0.0
        op.reduce(into: avg) { _, i in
            avg += Double(i)
        }
        avg = avg/Double(op.count)
        return [key:avg]
    }
}

let averages = getAvgerageMapped(from: model, for: ["Chin", "Forehead", "L Cheek", "Nose"])
print(averages) //[["Chin": 7.0], ["Forehead": 3.0], ["L Cheek": 1.0], ["Nose": 6.0]]

通过基于其索引比较2个不同的数组来获取整数值的平均值

假装爱人 2025-02-20 23:24:15

我认为您可能需要将load_env()放入配置类中。我知道烧瓶具有阅读.ENV文件的方法,但也许可以尝试。

I think you might need to put load_env() in your Config class. I understand that flask has it's own way to reading .env files but maybe try it.

AttributeError:' nonepy'对象没有属性'驱动器' URI配置实现错误

假装爱人 2025-02-20 16:27:21

您可以使用 .pipe> .pipe() 将数据, 然后使用 tap() 将值提取到组件中存在的变量中。

@Component({
  template: `
    <div *ngIf="subject$ | async as subject">
      <!-- do something with "subject" -->
      <span>{{subject.someProp}}</span>
    </div>
  `
})
export class MyComponent {
  // Used within the typescript
  subject = '';

  // Used within the html
  // Assuming data is retrieved through some sort of service
  subject$ = this.service.getData().pipe(
    tap(i => this.subject = i)
  )
}

You can use a .pipe() to pipe the data, then use tap() to extract the value into a variable that exists within the component.

@Component({
  template: `
    <div *ngIf="subject$ | async as subject">
      <!-- do something with "subject" -->
      <span>{{subject.someProp}}</span>
    </div>
  `
})
export class MyComponent {
  // Used within the typescript
  subject = '';

  // Used within the html
  // Assuming data is retrieved through some sort of service
  subject$ = this.service.getData().pipe(
    tap(i => this.subject = i)
  )
}

如何在管道异步和组件中使用对象?

假装爱人 2025-02-20 13:26:48

我认为,如果您只有一个字段,则可以将数据存储在本地存储中

I think if you have just one field you can store data in local storage

通过单击按钮将文件存储在索引db中

假装爱人 2025-02-20 06:30:35

帖子发表于 Gabor grothendieck R-Help邮件列表

years<-c("20 years old", "1 years old")

library(gsubfn)
pat <- "[-+.e0-9]*\\d"
sapply(years, function(x) strapply(x, pat, as.numeric)[[1]])

After the post from Gabor Grothendieck post at the r-help mailing list

years<-c("20 years old", "1 years old")

library(gsubfn)
pat <- "[-+.e0-9]*\\d"
sapply(years, function(x) strapply(x, pat, as.numeric)[[1]])

从字符串向量提取数字

假装爱人 2025-02-19 22:37:37

问题的字符串看起来像没有标签的HTML链接元素。通过简单的字符串操纵甚至正则表达式从HTML中提取信息非常脆弱,因为这些元素可能会改变a lot 。相同的元素可能是空的,也可能没有内容,浏览器将相同。属性或属性名称及其值之间可能有新线或额外的空格。

似乎实际的问题是如何找到下一步和上一则读取分类结果中的下一个和上一页。这曾经使用链接rel ='next'链接rel ='以前的'在Google决定停止使用这些页面的指示与页面相关的指示之前。 Google的页面说明了如何将rel用于分页的页面没有这些链接。

使用html解析器,例如 anglesharp 。以下代码检索Google页面,并搜索链接pre ='search'元素的HREF。 AnglesHarp允许使用DOM/CSS选择器或LINQ搜索元素。在这种情况下,代码将使用CSS选择器搜索:link [pre ='search']

using AngleSharp;
using AngleSharp.Dom;
using AngleSharp.Html.Dom;

IBrowsingContext context = BrowsingContext.New(Configuration.Default.WithDefaultLoader());
var url="https://developers.google.com/search/blog/2011/09/pagination-with-relnext-and-relprev";
IDocument document = await context.OpenAsync(url);

var link = document.QuerySelector<IHtmlLinkElement>("link[rel='search']");
Console.WriteLine(link.Href);

The question's string looks like an HTML link element without the tags. Extracting information from HTML with simple string manipulations or even regular expressions is very fragile because the elements can vary a lot. The same element may be empty or have no content and the browser will treat it the same. There may be newlines or extra whitespace between attributes or attribute names and their values.

It seems the actual problem is how to find the URLs of the next and previous read the next and previous pages in paged results. This used to be done using link rel='next' and link rel='previous' before Google decided to stop using these as an indication that pages are related. Google's page that explains how rel is used for paging doesn't have these links.

It's a lot safer and faster to use an HTML parser like AngleSharp. The following code retrieves the Google page and searches for the HREF of a link pre='search' element. AngleSharp allows searching for elements using DOM/CSS selectors or LINQ. In this case the code is searching using a CSS selector : link[pre='search']

using AngleSharp;
using AngleSharp.Dom;
using AngleSharp.Html.Dom;

IBrowsingContext context = BrowsingContext.New(Configuration.Default.WithDefaultLoader());
var url="https://developers.google.com/search/blog/2011/09/pagination-with-relnext-and-relprev";
IDocument document = await context.OpenAsync(url);

var link = document.QuerySelector<IHtmlLinkElement>("link[rel='search']");
Console.WriteLine(link.Href);

基于它的关系的caputure正确的一部分

假装爱人 2025-02-19 15:32:49

你尝试过吗?

var findings = Drive.Files.list( { 
    q: query,
    useDomainAdminAccess: true
  }) || [];

Did you try like this?

var findings = Drive.Files.list( { 
    q: query,
    useDomainAdminAccess: true
  }) || [];

在带有应用程序脚本的共享驱动器中查找文件

假装爱人 2025-02-19 13:51:48

我想您只需要跨函数的名称参数:

raw_data %>% 
    mutate(Amount=as.character(Amount)) %>% 
    mutate(across(where(is.numeric),  ~ . * as.numeric(Amount), .names = "{col}_AMOUNT"))

  Category Amount   Ad   ST   WT   MM Ad_AMOUNT ST_AMOUNT WT_AMOUNT MM_AMOUNT
1        A     19 0.73 0.54 0.30 0.79     13.87     10.26      5.70     15.01
2        B     14 0.78 0.74 0.20 0.35     10.92     10.36      2.80      4.90
3        C     19 0.37 0.86 0.94 0.87      7.03     16.34     17.86     16.53
4        D     11 0.32 0.57 0.90 0.76      3.52      6.27      9.90      8.36
5        E      2 0.62 0.98 0.75 0.74      1.24      1.96      1.50      1.48
6        F     11 0.76 0.58 0.39 0.55      8.36      6.38      4.29      6.05
7        G     13 0.25 0.35 0.23 0.72      3.25      4.55      2.99      9.36

I guess all you need is the names argument of the across function:

raw_data %>% 
    mutate(Amount=as.character(Amount)) %>% 
    mutate(across(where(is.numeric),  ~ . * as.numeric(Amount), .names = "{col}_AMOUNT"))

  Category Amount   Ad   ST   WT   MM Ad_AMOUNT ST_AMOUNT WT_AMOUNT MM_AMOUNT
1        A     19 0.73 0.54 0.30 0.79     13.87     10.26      5.70     15.01
2        B     14 0.78 0.74 0.20 0.35     10.92     10.36      2.80      4.90
3        C     19 0.37 0.86 0.94 0.87      7.03     16.34     17.86     16.53
4        D     11 0.32 0.57 0.90 0.76      3.52      6.27      9.90      8.36
5        E      2 0.62 0.98 0.75 0.74      1.24      1.96      1.50      1.48
6        F     11 0.76 0.58 0.39 0.55      8.36      6.38      4.29      6.05
7        G     13 0.25 0.35 0.23 0.72      3.25      4.55      2.99      9.36

在r/dplyr中,如何根据现有变量批量添加新变量

假装爱人 2025-02-19 13:04:14

每2秒钟打印一次“ AAA”,并每5秒打印一次“ BBB”

您将计时器设置为每一个1000 ms

uv_timer_start(&timer, cb2, 5, 1000);

设置时,您不能期望它每2秒发射一次计时器每秒反复发射。

关于uv_idle_t handle:

尽管名称,闲置手柄将在每个循环迭代中都会被调用,而不是当循环实际上是“空闲”时。

然后是这样:

loop = new uv_loop_t;
// ...
free(loop);

永远不要这样做。如果您使用new创建某些内容,则应Delete在完成时间后。不过,您不必在这里创建Dyncamam,因此只需创建一个自动变量即可。

如果您想要两个定时事件,请将两个事件允许:

#include <uv.h>

#include <cstdio>

void cb2(uv_timer_t* handler) {
    std::puts("bbb");
}

void cb(uv_timer_t* handler) {
    std::puts("aaa");
}

int main() {
    uv_loop_t loop;
    uv_loop_init(&loop);

    uv_timer_t timer_1;
    uv_timer_init(&loop, &timer_1);
    uv_timer_start(&timer_1, cb2, 0, 1000);

    uv_timer_t timer_5;
    uv_timer_init(&loop, &timer_5);
    uv_timer_start(&timer_5, cb, 0, 5000);

    uv_run(&loop, UV_RUN_DEFAULT);

    uv_loop_close(&loop);
}

请注意,uv_loop_close永远不会到达,因为没有什么可以关闭事件循环。

print the "aaa" for every about 2 seconds and print "bbb" for every 5 seconds

You set the timer to fire repeatedly every 1000 ms:

uv_timer_start(&timer, cb2, 5, 1000);

You can't expect it to fire every 2 seconds when setting the timer to fire repeatedly every second.

Regarding the uv_idle_t handle:

Despite the name, idle handles will get their callbacks called on every loop iteration, not when the loop is actually “idle”.

Then there's this:

loop = new uv_loop_t;
// ...
free(loop);

Never do this. If you create something with new you should delete it when done time it. You don't have to create it dyncamically here though, so just create an automatic variable.

If you want two timed events, make them both so:

#include <uv.h>

#include <cstdio>

void cb2(uv_timer_t* handler) {
    std::puts("bbb");
}

void cb(uv_timer_t* handler) {
    std::puts("aaa");
}

int main() {
    uv_loop_t loop;
    uv_loop_init(&loop);

    uv_timer_t timer_1;
    uv_timer_init(&loop, &timer_1);
    uv_timer_start(&timer_1, cb2, 0, 1000);

    uv_timer_t timer_5;
    uv_timer_init(&loop, &timer_5);
    uv_timer_start(&timer_5, cb, 0, 5000);

    uv_run(&loop, UV_RUN_DEFAULT);

    uv_loop_close(&loop);
}

Note that uv_loop_close will never be reached since there's nothing shutting down the event loop.

在Libuv框架中,使用两个回电功能时,它们为什么会互相影响

假装爱人 2025-02-19 09:29:39

收到您收到的错误列表

如果您只想在不停止代码的情况

try:
        #Get Url
        get = requests.get(url, allow_redirects=True, timeout=1,verify=True,headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"})
        # if the request succeeds
        if get.status_code == 200:
            print(f"{count} {url}: is reachable. status_code: {get.status_code}")
        else:
            print(f"{count} {url}: is Not reachable, status_code: {get.status_code}")
    #Exception
except Exception as e:
        print(f"{url}: is Not reachable \nErr: {e}")

下 捕获所有和所有的错误都比发生的所有错误,因此请确保正确记录它们,以帮助您是否出现需求。

If you only want to produce a list of errors you are receiving without stopping your code, you can just use the base class of all exceptions: Exception:

Your code will then become:

try:
        #Get Url
        get = requests.get(url, allow_redirects=True, timeout=1,verify=True,headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36"})
        # if the request succeeds
        if get.status_code == 200:
            print(f"{count} {url}: is reachable. status_code: {get.status_code}")
        else:
            print(f"{count} {url}: is Not reachable, status_code: {get.status_code}")
    #Exception
except Exception as e:
        print(f"{url}: is Not reachable \nErr: {e}")

Keep in mind that this obviously catches any and all errors than can occur, so make sure you log them properly to aid in debugging if the need ever arises.

如何在许多网站中搜索时如何获取所有唯一错误

假装爱人 2025-02-18 10:52:52

当我尝试这样做时,我遇到了同样的错误。就我而言,我发现Google有时是空的,并导致此类错误。我通过在您的情况下宣布doc const,只是检查Google是否为空。

I was getting the same error when I was trying to do this. In my case I found out that the googleId is sometimes empty and causes this type of error. I solved it by putting an IF statement before declaring in your case the doc const and simply just checking if the googleId is empty.. Tell me if that works for you, if not I am more than happy to help.

cb = gapi.loaded_0?le = scs:230 und typeError:无法破坏属性&#x27; name&#x27;响应。因为它不确定

假装爱人 2025-02-18 09:37:31

您正在更新使用效果内的日期,这是您更改日期的每一个使用效率重新运行的方法,这会导致它再次重新运行并创建循环。尝试将其他内容触发使用效果而不是日期触发。也许您可以尝试将其更改为“值”,而不是使用日期,并在使用效率之外提取响应,并将其置于值。

useEffect(() => {
      setDates(values);
  }
  , [values]);
    
  console.log(values);

You are updating dates inside the useEffect, and that is way on every useEffect rerun you change the dates and that causes it to rerun again and creates a loop. Try to put something else to trigger the useEffect instead of the dates. Maybe you can try to put it on change of "values" instead of dates and fetch response outside of useEffect and put it in values.

useEffect(() => {
      setDates(values);
  }
  , [values]);
    
  console.log(values);

当数据不更改时,请启发我有关使用效应循环

假装爱人 2025-02-17 17:25:44

从文档

<!--
  Routes without a path are default routes.
  They will match if no other Route could be matched
-->
<Route component="{Home}"></Route>

From the documentation

<!--
  Routes without a path are default routes.
  They will match if no other Route could be matched
-->
<Route component="{Home}"></Route>

Svelte-Navigator的默认路线?

假装爱人 2025-02-17 07:47:29

您无法将API密钥用于凭据。您必须通过Google身份验证或Google Service帐户获得承载令牌,

此错误将显示您是否在此处使用API​​密钥

Request is missing required authentication credential.
 
Expected OAuth 2 access token, login cookie or other valid authentication credential. 

See https://developers.google.com/identity/sign-in/web/devconsole-project.

,我将显示如何生成携带者令牌: https://stackoverflow.com/a/75963509/11096674

You could not use the API key for credentials. You must get the Bearer token via Google authentication or Google Service account

This error will show if you are using API Key

Request is missing required authentication credential.
 
Expected OAuth 2 access token, login cookie or other valid authentication credential. 

See https://developers.google.com/identity/sign-in/web/devconsole-project.

Here I will show how to generate Bearer Token: https://stackoverflow.com/a/75963509/11096674

如何使用C#和Curl的API键调用Google顶点AI端点

假装爱人 2025-02-16 22:05:47

剪接的第一个论点是项目索引,第二个参数是您要从该索引中删除多少个项目。

const deleteTag = (index) => {
  setTags((prevState) => {
    prevState.splice(index, 1)
    return [...prevState]
   });
 };

Update

如果您使用的是&lt; strictmode&gt; SetState将执行两次,并且将删除两个项目而不是一个项目。

Splice's first argument is the item index, and the second argument is how many items you want to delete from that index.

const deleteTag = (index) => {
  setTags((prevState) => {
    prevState.splice(index, 1)
    return [...prevState]
   });
 };

UPDATE

If you are using <StrictMode> the setState will execute twice and will delete two items instead of one.

&#x27;剪接&#x27;而不是滤镜&#x27;

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

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