我正在使用gin-gonic/gin来编写我的服务器。
似乎即使连接丢失,处理程序函数仍在运行。例如,如果我访问http://127.0.0.1:8080/ping并突然关闭浏览器,屏幕将继续打印所有数字。
package main
import (
"github.com/gin-gonic/gin"
"log"
"time"
)
func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
for i := 1; i < 15; i++ {
time.Sleep(time.Second * 1)
log.Println(i)
}
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run("127.0.0.1:8080")
}
Run Code Online (Sandbox Code Playgroud)
我应该如何立即停止处理程序功能(例如减少服务器负载)?
我正在尝试将一个列表中的列表项插入另一个列表中。我找到了两种有效的解决方案,但对我来说似乎没有必要复杂。
我正在寻找的基本上是这样的列表:[1, 2, 4, 5, 3]
someList = [1, 2, 3]
anotherList = [4, 5]
Run Code Online (Sandbox Code Playgroud)
第一个解决方案:
for item in anotherList:
someList.insert(2, item)
Run Code Online (Sandbox Code Playgroud)
第二种解决方案:
someList = someList[:2]+anotherList[:]+someList[2:]
Run Code Online (Sandbox Code Playgroud)
我的直觉是使用类似的东西,但它将插入列表,而不是列表项。
someList.insert(2,anotherList)
Run Code Online (Sandbox Code Playgroud) 我最近开始使用 Pandas,目前我正在尝试估算数据集中的一些缺失值。
我想根据中位数(对于数字条目)和模式(对于分类条目)来估算缺失值。但是,我不想计算整个数据集的中位数和众数,而是基于GroupBy名为"make".
对于数值,我做了以下工作:
data = data.fillna(data.groupby("make").transform("median"))
Run Code Online (Sandbox Code Playgroud)
--> 这完美地工作,并用NA它们的中位数替换了我所有的数值"make"。
但是,我无法为模式做同样的事情,即将所有分类 NA 值替换为它们的"make".
有谁知道怎么做?
PS C:\Users\TOHEEB> composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.10.7 2020-06-03 10:03:56
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force …Run Code Online (Sandbox Code Playgroud) 我正在尝试解决我的回收器视图与底部应用栏重叠的问题。这是我的布局代码。
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/notes_container_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:padding="8dp"
android:text="@string/myTasksHeader"
android:textColor="@color/appBarTextColor"
android:textSize="40dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="16dp"
android:scrollbars="none"
tools:listitem="@layout/note_list_item" />
</ScrollView>
</LinearLayout>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorPrimary"
app:hideOnScroll="false"
app:menu="@menu/appbar_menu"
app:navigationIcon="@drawable/ic_menu" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_note_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/medium_margin"
android:backgroundTint="@color/colorPrimary"
app:layout_anchor="@id/bottomAppBar"
app:srcCompat="@drawable/ic_add_black_24dp"
tools:ignore="VectorDrawableCompat" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
当我填写列表时,我无法到达回收器视图中的最后一个项目。我尝试添加保证金,但没有成功。

android android-layout android-fragments kotlin android-mvvm

我想让国家/地区代码选择textformfield()像前缀图标一样出现在里面。我怎么做?。这是我从intl_phone_number_input使用的代码。
InternationalPhoneNumberInput(
onInputChanged: (PhoneNumber number) {
print(number.phoneNumber);
},
onInputValidated: (bool value) {
print(value);
},
selectorConfig: SelectorConfig(
selectorType: PhoneInputSelectorType.BOTTOM_SHEET,
),
ignoreBlank: false,
autoValidateMode: AutovalidateMode.disabled,
selectorTextStyle: TextStyle(color: Colors.black),
initialValue: number,
textFieldController: controller,
formatInput: false,
keyboardType:
TextInputType.numberWithOptions(signed: true, decimal: true),
inputBorder: OutlineInputBorder(),
onSaved: (PhoneNumber number) {
print('On Saved: $number');
},
),
Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数来清理字典数据,其中包含一个键值对,显示日期和该日期的降雨量。数据清洗的条件需要去除和键值对满足以下条件的值:
def clean_data (adic):
newDic = {}
for (date,inches) in adic.items():
print (date,inches)
if not type(inches) == float:
if not type(inches) == int:
print ("type")
continue
elif inches < 0:
print ("below 0")
continue
elif inches > 100:
print ("above 100")
continue
else:
print ("added")
newDic[date]=inches
return newDic
rainfall = {"20190101": 5, "20190102": "6", "20190103": 7.5,
"20190104": 0, "20190105": -7, "20190106": 102,
"20190107": 1}
print(clean_data(rainfall))
Run Code Online (Sandbox Code Playgroud)
出于某种原因,我的代码正在输出:
20190101 5
20190102 6
type
20190103 7.5 …Run Code Online (Sandbox Code Playgroud) sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20221026-22941-v40jeb.rb extconf.rb
checking for ffi.h... \*\*\* extconf.rb failed \*\*\*
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME) …Run Code Online (Sandbox Code Playgroud) 我知道这是一个非常经典的问题,可能会在本论坛中多次回答,但是我找不到任何明确的答案从头开始清楚地解释这一点。
首先,我的数据集 my_data 有 4 个变量,例如 my_data = variable1、variable2、variable3、target_variable
所以,让我们来解决我的问题。我将解释我的所有步骤,并就我遇到的问题寻求您的帮助:
# STEP1 : split my_data into [predictors] and [targets]
predictors = my_data[[
'variable1',
'variable2',
'variable3'
]]
targets = my_data.target_variable
# STEP2 : import the required libraries
from sklearn import cross_validation
from sklearn.ensemble import RandomForestRegressor
#STEP3 : define a simple Random Forest model attirbutes
model = RandomForestClassifier(n_estimators=100)
#STEP4 : Simple K-Fold cross validation. 3 folds.
cv = cross_validation.KFold(len(my_data), n_folds=3, random_state=30)
# STEP 5
Run Code Online (Sandbox Code Playgroud)
在这一步,我想根据训练数据集拟合我的模型,然后在测试数据集上使用该模型并预测测试目标。我还想计算所需的统计数据,例如 MSE、r2 等,以了解我的模型的性能。
如果有人帮助我了解 Step5 的一些基本代码行,我将不胜感激。
regression machine-learning random-forest scikit-learn cross-validation