小编nop*_*nop的帖子

throwError(error) 现已弃用,但没有新的 Error(HttpErrorResponse)

显然throwError(error)现在已被弃用。VS Code 的 IntelliSense 建议throwError(() => new Error('error')new Error(...)仅接受字符串。在不破坏我的情况下更换它的正确方法是什么HttpErrorHandlerService

\n

http-error.interceptor.ts

\n
import { Injectable } from '@angular/core';\nimport {\n  HttpEvent,\n  HttpInterceptor,\n  HttpHandler,\n  HttpRequest,\n  HttpErrorResponse,\n  HttpResponse,\n  HttpHeaders\n} from '@angular/common/http';\nimport { Observable, EMPTY, finalize, catchError, timeout, map, throwError } from 'rxjs';\n\nimport { HttpErrorHandlerService } from '@core/services';\n\n@Injectable()\nexport class HttpErrorInterceptor implements HttpInterceptor {\n  private readonly APP_XHR_TIMEOUT = 6000;\n\n  constructor(private errorHandlerService: HttpErrorHandlerService) {}\n\n  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {\n    return next.handle(this.performRequest(request)).pipe(\n      timeout(this.APP_XHR_TIMEOUT),\n      map((event: HttpEvent<any>) => this.handleSuccessfulResponse(event)),\n      catchError((error: …
Run Code Online (Sandbox Code Playgroud)

rxjs typescript angular angular12

83
推荐指数
2
解决办法
6万
查看次数

数据网格组件要求所有行都具有唯一的“id”属性

我知道我必须使用 getRowId,但是我该如何使用它statIdid?它是独一无二的。id或者为它们每个人生成一个属性?

错误:MUI:数据网格组件要求所有行都具有唯一的id属性。或者,您可以使用getRowIdprop 为每行指定一个自定义 id。rows 属性中提供了没有 id 的行:{"statId":813183,"teamId":3,"season":2021,"name":"Atlanta Hawks","team":"ATL","wins" :41,“损失”:31,“fieldGoalsMade”:3492.1,“fieldGoalsAttempted”:7468.1,“fieldGoalsPercentage”:55.6,“twoPointersMade”:2427.9,“twoPointersAttempted”:4612.1,“twoPointersPercentage”:62.5,“ ThreePointersMade”:1064.2 ,“ ThreePointersAttempted”:2856,“ ThreePointersPercentage”:44.3,“ freeThrowsMade”:1684.8,“ freeThrowsAttempted”:2074.8,“ freeThrowsPercentage”:96.5,“进攻篮板”:903.6,“防守篮板”:3002.2,“篮板”:3905.9,“助攻”:2065.3、“抢断”:598.1、“封堵投篮”:405.4、“失误”:1086.7、“个人犯规”:1655.1、“得分”:9733.2、“双打”:120.1、“三双”:1.4}

import { useState, useEffect } from 'react';
import type { NextPage } from 'next';
import Container from '@mui/material/Container';
import Box from '@mui/material/Box';
import { DataGrid, GridColDef, GridRowIdGetter } from '@mui/x-data-grid';
import { Grid, Paper, Typography } from '@mui/material';
import Skeleton from '@mui/material/Skeleton';
import { blue } from '@mui/material/colors';

import FormOne from './../src/FormOne';
import …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs material-ui mui-x mui-x-data-grid

20
推荐指数
4
解决办法
5万
查看次数

ASP.NET Core 6 - 如何获得所需的服务

我正在遵循MSDN上的排队服务示例,但我不知道如何获取 的实例MonitorLoop,因为host.Services.GetRequiredService未定义。如何在 ASP.NET Core 6 中检索它?

或者更好的做法可能是使用后台范围的服务MonitorLoophttps://learn.microsoft.com/en-us/dotnet/core/extensions/scoped-service

public static class QueueServiceExtensions
{
    public static void AddQueueService(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddSingleton<MonitorLoop>();
        services.AddHostedService<QueuedHostedService>();
        services.AddSingleton<IBackgroundTaskQueue>(_ =>
        {
            if (!int.TryParse(configuration["QueueCapacity"], out var queueCapacity))
            {
                queueCapacity = 100;
            }

            return new DefaultBackgroundTaskQueue(queueCapacity);
        });
        
        // TODO: host.Services is undefined
        MonitorLoop monitorLoop = host.Services.GetRequiredService<MonitorLoop>()!;
        monitorLoop.StartMonitorLoop();
    }
}
Run Code Online (Sandbox Code Playgroud)

这就是我的Program.cs的样子

using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Identity.Web;
using QSGEngine.Web.QueueService;
using QSGEngine.Web.SignalR;
using Serilog;

var builder = WebApplication.CreateBuilder(args);

// Logging
builder.Host.UseSerilog((context, …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-6.0

13
推荐指数
2
解决办法
5万
查看次数

ESLint 异步管道不应被否定

我将 ESLint 与 Angular 一起使用,我不喜欢使用额外的代码,而(observable | async) === (false | null | undefined)不是仅仅使用(observable | async). 我如何禁用该规则?

E:\GitHub\skybot\angular\src\app\custom-layout\custom-layout.component.html
  6:75  error  Async pipes should not be negated. Use (observable | async) === (false | null | undefined) to check its value instead  @angular-eslint/template/no-negated-async
Run Code Online (Sandbox Code Playgroud)

自定义布局.component.html

<ng-template #sidenavRef>
  <vex-sidenav [collapsed]="sidenavCollapsed$ | async"></vex-sidenav>
</ng-template>

<ng-template #toolbarRef>
  <vex-toolbar [hasShadow]="toolbarShadowEnabled$ | async" [mobileQuery]="!(isDesktop$ | async)" class="vex-toolbar">
  </vex-toolbar>
</ng-template>

<ng-template #footerRef>
  <vex-footer *ngIf="isFooterVisible$ | async" class="vex-footer"></vex-footer>
</ng-template>

<ng-template #quickPanelRef>
  <vex-quick-panel></vex-quick-panel>
</ng-template>

<vex-layout [footerRef]="footerRef" [quickPanelRef]="quickPanelRef" …
Run Code Online (Sandbox Code Playgroud)

typescript eslint angular

12
推荐指数
2
解决办法
1万
查看次数

如何检测烛台图中的异常值

我想实施异常值检测,因为我应该找到市场何时安静。换句话说,我有一组给定的蜡烛,对于每 5 根蜡烛,我应该确定情况是否安静。

局势何时平静?

当满足以下要求时,情况是安静的:

  1. 所有这 5 根蜡烛都几乎很小。蜡烛的体积由以下公式计算:Math.Abs(candle.Open - candle.Close).

这里的问题是我不知道如何区分小蜡烛和大蜡烛。

在此处输入图片说明

  1. 最高和最低元素之间的距离不应该那么大。

在此处输入图片说明

这里的问题是如何确定最高和最低值之间的距离是大还是小

我的尝试:

我尝试计算标准偏差,但似乎对我的情况无济于事,因为结果太随机了。这些体积较大的蜡烛不应该满足条件。

  • StdDev = 标准偏差
  • CV = 变异系数
Open time: 11/27/2019 1:00:00 AM | StdDev: 7.188532534530273E-05 | CV: 0.004710394164556892
Open time: 11/27/2019 2:00:00 AM | StdDev: 6.919176251549048E-05 | CV: 0.004528256709128957
Open time: 11/27/2019 3:00:00 AM | StdDev: 3.946517452134247E-05 | CV: 0.0025799290397687433
Open time: 11/27/2019 4:00:00 AM | StdDev: 3.6979724174201114E-05 | CV: 0.002417133418798687
Open time: 11/27/2019 5:00:00 AM | StdDev: 3.110466202999165E-05 | CV: 0.002034447120805262
Open time: …
Run Code Online (Sandbox Code Playgroud)

c# math mathematical-optimization

5
推荐指数
1
解决办法
254
查看次数

Hangfire 在作业中使用变量

我知道hangfire 不会在与 ASP.NET 相同的上下文中运行,并且它有自己的线程池,但我应该在后台作业中使用变量。这是可以理解的,因为事实上,这些作业可能不在同一台服务器上运行。这意味着如果我执行_locked = false;(in Checker()),它将永远不会被应用,因为它在另一个上下文中运行。对于 来说BackgroundJob.Enqueue(() => Start(bot));,如果它是一个重复性作业(cron 作业),那么我在内部使用的那些变量总是会在弹出的每个 cron 作业上重置。

在这种情况下我该如何使用变量?

private UpdateSubscription _subscription;

private StringBuilder _sb = new StringBuilder();
private bool _locked = false;

public void RunStart(Bot bot)
{
    BackgroundJob.Enqueue(() => Start(bot));
}

public void Start(Bot bot)
{
    ApplyCredentialsOnClient();

    var lastKnownKline = _client.GetKlines(bot.CryptoPair.Symbol, bot.TimeInterval.Interval, limit: 2).Data.First();
    _subscription = _socketClient.SubscribeToKlineUpdates(bot.CryptoPair.Symbol, bot.TimeInterval.Interval, async data =>
    {
        if (data.Data.Final)
        {
            _logger.LogError($"Final | Open time: {data.Data.OpenTime.ToLocalTime()}");
        }

        if (lastKnownKline.OpenTime != data.Data.OpenTime)
        {
            // Static
            _logger.LogError($"Static …
Run Code Online (Sandbox Code Playgroud)

c# hangfire asp.net-core

5
推荐指数
1
解决办法
1516
查看次数

带有 Hangfire 的 CancellationToken

首先,我决定使用 Hangfire,因为它可以在不同的 Windows 服务中或实际上在不同的服务器上运行代码。我可以使用Task类轻松执行我的任务,但我的逻辑将在很长一段时间内 24/7 运行,直到它被用户停止,我认为任务无法处理这个。这就是我使用 Hangfire 的原因。我对不同的解决方案持开放态度。更具体地说,我的逻辑是使用 Web 套接字 24/7 全天候监控内容。

如果你看看我下面的代码,它有 Run 方法,它在 Hangfire 的 BackgroundJob 中生成一个新的机器人。问题是,当我必须停止一个特定的机器人(比如“机器人 1”)时,它应该以某种方式识别当前没有的机器人。

Hangfire 的文档不完整,或者至少我不明白如何从所写的内容中做到这一点。https://docs.hangfire.io/en/latest/background-methods/using-cancellation-tokens.html

private UpdateSubscription _subscription;
private readonly CancellationTokenSource _cts = new CancellationTokenSource();

public async Task RunAsync(string botName)
{
    var jobId = BackgroundJob.Enqueue(() => StartAsync(botName, _cts.Token));
    await _cache.SetAsync($"bot_{botName.Replace(" ", "_")}", jobId);
}

public void Start(Bot bot, CancellationToken token)
{
    // heavy logic
    _subscription = _socketClient.SubscribeToKlineUpdates(bot.CryptoPair.Symbol, bot.TimeInterval.Interval /*KlineInterval.OneHour*/, async data =>
    {
        ... logic ...

        if (token.IsCancellationRequested)
        {
            await …
Run Code Online (Sandbox Code Playgroud)

c# hangfire asp.net-core

5
推荐指数
1
解决办法
1173
查看次数

计算平均绝对偏差

我想计算平均绝对偏差,我目前正在使用来自 Stack Overflow(链接在这里)的以下类,由Alex发布:

public class MovingAverageCalculator
{
    private readonly int _period;
    private readonly double[] _window;
    private int _numAdded;
    private double _varianceSum;

    public MovingAverageCalculator(int period)
    {
        _period = period;
        _window = new double[period];
    }

    public double Average { get; private set; }

    public double StandardDeviation
    {
        get
        {
            var variance = Variance;
            if (variance >= double.Epsilon)
            {
                var sd = Math.Sqrt(variance);
                return double.IsNaN(sd) ? 0.0 : sd;
            }
            return 0.0;
        }
    }

    public double Variance …
Run Code Online (Sandbox Code Playgroud)

c#

5
推荐指数
0
解决办法
1029
查看次数

AddApiAuthorization 的默认设置(Scaffolded Angular + IdentityServer4)

我正在将这个脚手架示例用于 Angular + IdentityServer4。

dotnet new angular -o <output_directory_name> -au Individual
Run Code Online (Sandbox Code Playgroud)

的默认凭据、授权类型、客户端 ID、客户端密码是什么AddApiAuthorization,以便我可以使用 Postman 对其进行测试?因为我所能找到的就是我们可以添加额外的 API 资源、客户端等。我知道默认配置文件

链接到他们的实现:https : //github.com/dotnet/aspnetcore/blob/9a1810c1dbe432fc7bc7e8bc68fa22ab787c0452/src/Identity/ApiAuthorization.IdentityServer/src/IdentityServerBuilderConfigurationExtensions.cs

添加更多客户端和 API 资源的示例:

dotnet new angular -o <output_directory_name> -au Individual
Run Code Online (Sandbox Code Playgroud)

微软的脚手架方式:

AddApiAuthorization<ApplicationUser, ApplicationDbContext>(options =>
{
    options.Clients.AddSPA(
        "My SPA", spa =>
        spa.WithRedirectUri("http://www.example.com/authentication/login-callback")
           .WithLogoutRedirectUri(
               "http://www.example.com/authentication/logout-callback"));

    options.ApiResources.AddApiResource("MyExternalApi", resource =>
        resource.WithScopes("a", "b", "c"));
});
Run Code Online (Sandbox Code Playgroud)

我之前使用原始 IdentityServer4 包的配置。它使用带有 PKCE 的代码:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(
            configuration.GetConnectionString("DefaultConnection"),
            b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));

    services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = false)
        .AddEntityFrameworkStores<ApplicationDbContext>(); …
Run Code Online (Sandbox Code Playgroud)

identityserver4 angular asp.net-core-3.1

5
推荐指数
1
解决办法
3129
查看次数

为 appsettings.json 编写自定义转换器

我想创建一个 appsettings.json 转换器,将其转换SymbolsIReadOnlyCollection<Symbol>. 转换器应按 分割字符串/,这将生成 BaseAsset/QuoteAsset。然后应该检查是否QuoteAsset等于StakeCurrency。如果没有,则抛出异常。使用自定义转换器实现此目的的最佳方法是什么?我不想使用绑定。是否可以使用自定义 JsonConverter?

  • 应用程序设置.json
{
  "BacktestConfiguration": {
    "StakeCurrency": "USDT",
    "Symbols": [ "TRX/USDT", "BTC/USDT", "ETH/USDT" ]
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 课程
{
  "BacktestConfiguration": {
    "StakeCurrency": "USDT",
    "Symbols": [ "TRX/USDT", "BTC/USDT", "ETH/USDT" ]
  }
}
Run Code Online (Sandbox Code Playgroud)

c# appsettings jsonconverter

5
推荐指数
1
解决办法
1983
查看次数