当我尝试从 html 调用 getHistoryData() 时,出现错误“错误类型错误:无法设置未定义的属性‘id’”。
export class Data {
id : string ;
fromTime : any ;
toTime : any ;
deviceType : string ;
interval : any;
params : string;
}
Run Code Online (Sandbox Code Playgroud)
// payload : Data = {
// id : "00:12:4b:00:19:7b:27:7",
// fromTime: "1554422400000",
// toTime: "1554508799000" ,
// deviceType: "xxx",
// interval: "1199999",
// params: "temperature"
// }
payload : Data;
response : any;
generatePayload(){
this.payload.id = "00:12:4b:00:19:7b:27:7",
this.payload.fromTime = "1554422400000",
this.payload.toTime = "1554508799000",
this.payload.deviceType = 'xxx' , …
Run Code Online (Sandbox Code Playgroud) 我想创建 mat-cards 并在其中包含一些内容。卡片的数量可能因 api 的内容而异(如果 api 给我 5 个参数的数据,则必须创建 5 张卡片)这些卡片必须像 3 或 4 排一样对齐。尝试谷歌搜索如何做,但找不到。有人能帮我吗?
<div fxLayout="row" fxLayoutAlign="center">
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
</div>
Run Code Online (Sandbox Code Playgroud)
这给出了连续 5 个元素。我希望第 5 个元素在新行中开始,因为 fxFlex 百分比总和已达到 100%。
<div fxLayout="row" fxLayoutAlign="center">
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
<app-tile fxFlex="25%"></app-tile>
</div>
<div fxLayout="row" fxLayoutAlign="center">
<app-tile fxFlex="25%"></app-tile>
</div>
Run Code Online (Sandbox Code Playgroud)
当我这样做时效果很好。
但是当卡片数量动态变化时,我如何使用 ngFor 来做到这一点?
我正在使用 scipy.optimize.minimize 来查找目标函数的最佳参数。
我的代码:
import numpy as np
from scipy.optimize import minimize
from scipy.optimize import Bounds
bounds = Bounds([26,26,8,6,400,100,0,25,2],[36,38,28,28,1800,800,100,50,7])
energy_history = []
x_values = []
def objective(x):
x_trail = x.reshape(1,-1)
x_trail = sc_X.transform(x_trail)
y_trail = regressorSVR.predict(x_trail)
y_trail = y_trail.reshape(1,-1)
y_trail = sc_Y.inverse_transform(y_trail)
return y_trail[0]
def callback(x,y):
fobj = objective(x)
energy_history.append(fobj)
x_values.append(x)
x0 = np.array([26,28,15,7,400,377,40,43,4.3])
res = minimize(objective, x0, method='trust-constr',
options={'verbose': 1}, bounds=bounds,callback=callback)
optimal_values = res.x
energy = res.fun
Run Code Online (Sandbox Code Playgroud)
给定初始值后,我得到的最小化值(res.fun)是-7.1。我正在创建一个列表(energy_history)来查看它如何达到这个值。我在该列表中看到一些小于 -7.1 的值,但为什么 -7.1 被作为最小值返回。
目标函数多次达到 -21 的值,但为什么仍然返回 -7 作为最小值?
python optimization scipy scipy-optimize scipy-optimize-minimize
我有一个 mqtt beoker,我正在尝试用 python 连接并订阅它。代码
client = mqtt.Client("P1",clean_session=True) #create new instance
client.on_connect = on_connect
client.on_message = on_message #attach function to callback
client.on_disconnect = on_disconnect
Run Code Online (Sandbox Code Playgroud)
print("connecting to broker")
client.connect(broker_address, port=port) #connect to broker
print("Subscribing to topic","topic")
client.subscribe("topic")
client.loop_forever()
Run Code Online (Sandbox Code Playgroud)
回调函数
def on_connect(client, userdata, flags, rc):
if rc==0:
print("connected OK Returned code=",rc)
print(client)
else:
print("Bad connection Returned code=",rc)
def on_disconnect(client, userdata, rc):
print("Client Got Disconnected")
if rc != 0:
print('Unexpected MQTT disconnection. Will auto-reconnect')
else:
print('rc value:' + str(rc))
try:
print("Trying to Reconnect") …
Run Code Online (Sandbox Code Playgroud) 我已经使用 DQN 算法训练了一个 RL 代理。在 20000 集之后,我的奖励收敛了。现在当我测试这个代理时,代理总是采取相同的行动,而不管状态如何。我觉得这很奇怪。有人可以帮我弄这个吗。有没有原因,谁能想到为什么agent会这样?
奖励情节
当我测试代理时
state = env.reset()
print('State: ', state)
state_encod = np.reshape(state, [1, state_size])
q_values = model.predict(state_encod)
action_key = np.argmax(q_values)
print(action_key)
print(index_to_action_mapping[action_key])
print(q_values[0][0])
print(q_values[0][action_key])
q_values_plotting = []
for i in range(0,action_size):
q_values_plotting.append(q_values[0][i])
plt.plot(np.arange(0,action_size),q_values_plotting)
Run Code Online (Sandbox Code Playgroud)
每次它都会给出相同的 q_values 图,即使每次初始化的状态都不同。 下面是 q_Value 图。
测试:
代码
test_rewards = []
for episode in range(1000):
terminal_state = False
state = env.reset()
episode_reward = 0
while terminal_state == False:
print('State: ', state)
state_encod = np.reshape(state, [1, state_size])
q_values = model.predict(state_encod)
action_key = …
Run Code Online (Sandbox Code Playgroud) 我正在使用角材料 mat-tab 内容。
我的代码看起来像 -
<mat-tab-group>
<mat-tab label="First"> Content 1 </mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)
我想实现类似的东西
<mat-tab-group>
<mat-tab label="First">
<button mat-button>Go to tab 2</button>
<button mat-button>Go to tab 3</button>
</mat-tab>
<mat-tab label="Second">
<button mat-button>Go to tab 1</button>
</mat-tab>
<mat-tab label="Third">
<button mat-button>Go to tab 1</button>
</mat-tab>
</mat-tab-group>
Run Code Online (Sandbox Code Playgroud)
如何实现点击按钮的功能,它应该转到不同的选项卡?
我正在尝试在我的角度应用程序中创建一个登录页面。
我的代码
<mat-card class="login">
<mat-card-content>
<div class="example-small-box mat-elevation-z4">
<form class="example-form">
<mat-form-field class="email example-full-width">
<input matInput placeholder="Email or User name" [(ngModel)]="username" name="username" required >
</mat-form-field>
<mat-form-field class="example-full-width">
<input matInput placeholder="Password" [(ngModel)]="password"type="password" name="password" required>
</mat-form-field>
</form>
<button class="btn" mat-raised-button color="primary" (click)="login()" >Login</button>
</div>
</mat-card-content>
</mat-card>
Run Code Online (Sandbox Code Playgroud)
垫卡未显示,空间方向也不正确。我已经导入了所有要求。
应用程序模块.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AhuComponent } from './ahu/ahu.component';
import { FlexLayoutModule …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用鼠标操作在图像上画一条线。我正在使用 OpenCV 库。我的代码
import matplotlib.pyplot as plt
import cv2
src_window = 'CV2 Window'
SHOW_DEBUG_STEPS = True
drag = 0
select_flag = 0
x1 = 0
x2 = 0
y1 = 0
y2 = 0
point1 = [x1,y1]
point2 = [x2,y2]
SCALAR_YELLOW = (0.0,255.0,255.0)
cap = cv2.VideoCapture('example_01.mp4')
def closeAll():
cap.release()
cv2.destroyAllWindows()
def retn(ret):
if not ret:
print('Error reading the frame')
closeAll()
def frm(fFrame):
if fFrame is None:
print('Error reading the frame')
closeAll()
def drawMyLine(frame):
global point1
global point2
cv2.line(frame,(point1[0],point1[1]),(point2[0],point2[1]),SCALAR_YELLOW,2,8)
def myMouseHandler(event,x,y,flags,param): …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Angular 作为客户端应用程序创建一个 .net core 3.0 SignalR 项目。我已经在客户端和服务器之间建立了成功的连接,并向所有连接的客户端发送消息。我打算将消息发送给特定用户而不是所有连接的客户端。为了实现这一目标,我尝试使用 ConnectionId、UserIdentifier 和 User.Identity.Name。
我的服务器端代码/消息中心
namespace SignalR_server
{
public class MessageHub : Hub
{
public static ConcurrentDictionary<string, string> MyUsers = new ConcurrentDictionary<string, string>();
public override Task OnConnectedAsync()
{
string name = Context.User.Identity.Name;
MyUsers.TryAdd( Context.ConnectionId,name);
return base.OnConnectedAsync();
}
public override Task OnDisconnectedAsync(Exception exception)
{
string garbage;
MyUsers.TryRemove(Context.ConnectionId, out garbage);
return base.OnDisconnectedAsync(exception);
}
public void Send(string msg)
{
string strMessage = string.Empty;
Clients.All.SendAsync("transfermessage",strMessage);
}
public string GetConnectionID()
{
return Context.ConnectionId;
}
public string GetUserIdentifier()
{ …
Run Code Online (Sandbox Code Playgroud) signalr signalr-hub signalr.client angular asp.net-core-signalr
我正在构建一个有角度的应用程序。我通过单击事件从第一个组件导航到第二个组件。在导航到第二个组件时,我愿意将一些数据从第一个组件传递到第二个组件。我已按照教程来实现此目的,但无法做到。下面是我的代码
第一个组件.ts
export class FirstComponent implements OnInit {
@Output() messageEvent = new EventEmitter<string>();
constructor(){
}
ngOnInit() {}
sendMessagetoSecond(ahu) {
this.messageEvent.emit(ahu)
console.log(ahu)
}
Run Code Online (Sandbox Code Playgroud)
第一个组件.html
<map name="ahuMap">
<area shape="rect" coords="818,232,917,262" (click)="sendMessagetoSecond()" [routerLink]="['/secondComponent']">
</map>
Run Code Online (Sandbox Code Playgroud)
第二个组件.ts
ahu : string
receiveMessage($event) {
this.ahu = $event
}
Run Code Online (Sandbox Code Playgroud)
第二个组件 .html
<body>
<app-first (messageEvent)="receiveMessage($event)"></app-first>
ahu: {{ahu}}
<div>
....
</div>
</body>
Run Code Online (Sandbox Code Playgroud)
这就是我尝试过的。我面临的问题是:
1-变量没有被传输到第二个组件
2-第一个组件的 HTML 也被加载到第二个组件中。
我是否遗漏或做错了什么?
我正在开发一个有角度的应用程序。作为它的一部分,我每10秒钟调用一次函数,该函数进行一次API调用。
我的功能看起来像
getData(ahu) {
console.log('In get data function')
console.log(ahu)
setInterval(() => {
this.getDataRealTime(ahu);
}, 10000);
}
Run Code Online (Sandbox Code Playgroud)
<button mat-flat-button (click)="getData(L1)">L1</button>
<button mat-flat-button (click)="getData(L2)">L2</button>
Run Code Online (Sandbox Code Playgroud)
因此,当我单击“ L1”按钮时,数据每10秒就会持续发送L1。现在,当我单击L2时,L2的数据到来,但是来自L1的数据没有停止。我只需要L1的数据。有人可以帮我弄这个吗?
谢谢
angular ×7
python ×3
html ×2
typescript ×2
api ×1
components ×1
css ×1
flexbox ×1
image ×1
javascript ×1
line ×1
mat-tab ×1
mqtt ×1
opencv ×1
optimization ×1
paho ×1
q-learning ×1
scipy ×1
setinterval ×1
signalr ×1
signalr-hub ×1